Skip to content

Commit 457c83d

Browse files
committed
feature: client: migrate to ESM
1 parent f8a941b commit 457c83d

7 files changed

Lines changed: 28 additions & 35 deletions

File tree

client/dom/index.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import renameCurrent from './operations/rename-current.mjs';
1111
import * as CurrentFile from './current-file.mjs';
1212
import * as DOMTree from './dom-tree.mjs';
1313
import * as Cmd from './cmd.mjs';
14-
import IO from './io/index.js';
14+
import * as IO from './io/index.mjs';
1515
import {uploadDirectory} from './directory.mjs';
1616
import * as Buffer from './buffer.mjs';
1717
import {loadRemote as _loadRemote} from './load-remote.mjs';
Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
'use strict';
2-
3-
const {FS} = require('#common/cloudfunc');
4-
const _sendRequest = require('./send-request');
1+
import {FS} from '#common/cloudfunc';
2+
import {sendRequest as _sendRequest} from './send-request.mjs';
53

64
const imgPosition = {
75
top: true,
86
};
97

10-
module.exports.delete = async (url, data) => {
8+
export const remove = async (url, data) => {
119
return await _sendRequest({
1210
method: 'DELETE',
1311
url: FS + url,
@@ -18,7 +16,7 @@ module.exports.delete = async (url, data) => {
1816
});
1917
};
2018

21-
module.exports.patch = async (url, data) => {
19+
export const patch = async (url, data) => {
2220
return await _sendRequest({
2321
method: 'PATCH',
2422
url: FS + url,
@@ -27,7 +25,7 @@ module.exports.patch = async (url, data) => {
2725
});
2826
};
2927

30-
module.exports.write = async (url, data) => {
28+
export const write = async (url, data) => {
3129
return await _sendRequest({
3230
method: 'PUT',
3331
url: FS + url,
@@ -36,7 +34,7 @@ module.exports.write = async (url, data) => {
3634
});
3735
};
3836

39-
module.exports.createDirectory = async (url, overrides = {}) => {
37+
export const createDirectory = async (url, overrides = {}) => {
4038
const {
4139
sendRequest = _sendRequest,
4240
} = overrides;
@@ -48,7 +46,7 @@ module.exports.createDirectory = async (url, overrides = {}) => {
4846
});
4947
};
5048

51-
module.exports.read = async (url, dataType = 'text') => {
49+
export const read = async (url, dataType = 'text') => {
5250
const notLog = !url.includes('?');
5351

5452
return await _sendRequest({
@@ -59,7 +57,7 @@ module.exports.read = async (url, dataType = 'text') => {
5957
});
6058
};
6159

62-
module.exports.copy = async (from, to, names) => {
60+
export const copy = async (from, to, names) => {
6361
return await _sendRequest({
6462
method: 'PUT',
6563
url: '/copy',
@@ -72,23 +70,23 @@ module.exports.copy = async (from, to, names) => {
7270
});
7371
};
7472

75-
module.exports.pack = async (data) => {
73+
export const pack = async (data) => {
7674
return await _sendRequest({
7775
method: 'PUT',
7876
url: '/pack',
7977
data,
8078
});
8179
};
8280

83-
module.exports.extract = async (data) => {
81+
export const extract = async (data) => {
8482
return await _sendRequest({
8583
method: 'PUT',
8684
url: '/extract',
8785
data,
8886
});
8987
};
9088

91-
module.exports.move = async (from, to, names) => {
89+
export const move = async (from, to, names) => {
9290
return await _sendRequest({
9391
method: 'PUT',
9492
url: '/move',
@@ -101,7 +99,7 @@ module.exports.move = async (from, to, names) => {
10199
});
102100
};
103101

104-
module.exports.rename = async (from, to) => {
102+
export const rename = async (from, to) => {
105103
return await _sendRequest({
106104
method: 'PUT',
107105
url: '/rename',
@@ -113,7 +111,7 @@ module.exports.rename = async (from, to) => {
113111
});
114112
};
115113

116-
module.exports.Config = {
114+
export const Config = {
117115
read: async () => {
118116
return await _sendRequest({
119117
method: 'GET',
@@ -133,7 +131,7 @@ module.exports.Config = {
133131
},
134132
};
135133

136-
module.exports.Markdown = {
134+
export const Markdown = {
137135
read: async (url) => {
138136
return await _sendRequest({
139137
method: 'GET',
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
'use strict';
2-
3-
const {test, stub} = require('supertape');
4-
const io = require('.');
1+
import {test, stub} from 'supertape';
2+
import * as io from './index.mjs';
53

64
test('client: dom: io', (t) => {
75
const sendRequest = stub();
Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
'use strict';
2-
31
/* global CloudCmd */
4-
const {promisify} = require('es6-promisify');
5-
6-
const Images = require('#dom/images');
7-
const load = require('#dom/load');
2+
import {promisify} from 'es6-promisify';
3+
import * as Images from '#dom/images';
4+
import * as load from '#dom/load';
85

9-
module.exports = promisify((params, callback) => {
6+
export const sendRequest = promisify((params, callback) => {
107
const p = params;
118
const {prefixURL} = CloudCmd;
129

@@ -40,7 +37,8 @@ module.exports = promisify((params, callback) => {
4037
});
4138
});
4239

43-
module.exports._replaceHash = replaceHash;
40+
export const _replaceHash = replaceHash;
41+
4442
function replaceHash(url) {
4543
/*
4644
* if we send ajax request -
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
'use strict';
2-
3-
const {test} = require('supertape');
4-
const {_replaceHash} = require('./send-request');
1+
import {test} from 'supertape';
2+
import {_replaceHash} from './send-request.mjs';
53

64
test('cloudcmd: client: io: replaceHash', (t) => {
75
const url = '/hello/####world';

client/dom/rest.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {tryToCatch} from 'try-to-catch';
22
import * as Dialog from '#dom/dialog';
33
import * as Images from '#dom/images';
44
import {encode} from '#common/entity';
5-
import IO from './io/index.js';
5+
import * as IO from './io/index.mjs';
66

77
const handleError = (promise) => async (...args) => {
88
const [e, data] = await tryToCatch(promise, ...args);
@@ -18,7 +18,7 @@ const handleError = (promise) => async (...args) => {
1818
return [e, data];
1919
};
2020

21-
export const remove = handleError(IO.delete);
21+
export const remove = handleError(IO.remove);
2222
export const patch = handleError(IO.patch);
2323
export const write = handleError(IO.write);
2424
export const createDirectory = handleError(IO.createDirectory);

client/modules/markdown.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {Markdown} from '#dom/rest';
44
import {alert} from '#dom/dialog';
55

66
const {CloudCmd} = globalThis;
7+
78
CloudCmd.Markdown = {
89
init,
910
show,

0 commit comments

Comments
 (0)