mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-17 16:38:18 +00:00
feature: client: dom: load-remote: migrate to ESM
This commit is contained in:
parent
145bc48722
commit
0054cfa363
7 changed files with 62 additions and 59 deletions
|
|
@ -57,6 +57,7 @@ export default {
|
|||
'watch:test:client': async () => `nodemon -w client -w test/client -x ${await run('test:client')}`,
|
||||
'watch:test:server': async () => `nodemon -w client -w test/client -x ${await run('test:server')}`,
|
||||
'watch:coverage': async () => [testEnv, `nodemon -w server -w test -w common -x ${await cutEnv('coverage')}`],
|
||||
'watch:fix:lint': async () => `nodemon -w client -w server -w test -w common -x '${await run('fix:lint')}'`,
|
||||
'build': async () => run('6to5:*'),
|
||||
'build:dev': async () => run('build:client:dev'),
|
||||
'build:client': () => run('6to5:client'),
|
||||
|
|
|
|||
|
|
@ -1,2 +1,2 @@
|
|||
[files]
|
||||
extend-exclude= ["ChangeLog"]
|
||||
extend-exclude = ["ChangeLog"]
|
||||
|
|
|
|||
|
|
@ -53,6 +53,9 @@ const plugins = [
|
|||
NODE_ENV,
|
||||
}),
|
||||
new WebpackBar(),
|
||||
new webpack.ProvidePlugin({
|
||||
process: 'process/browser',
|
||||
}),
|
||||
];
|
||||
|
||||
const splitChunks = {
|
||||
|
|
@ -96,6 +99,7 @@ export default {
|
|||
fallback: {
|
||||
path: import.meta.resolve('path-browserify'),
|
||||
process: import.meta.resolve('process/browser'),
|
||||
util: import.meta.resolve('util'),
|
||||
},
|
||||
},
|
||||
devtool,
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@ import * as Dialog from '#dom/dialog';
|
|||
import * as Events from '#dom/events';
|
||||
import {getExt} from '#common/util';
|
||||
import * as Storage from '#dom/storage';
|
||||
import * as Images from './images.mjs';
|
||||
import * as RESTful from '#dom/rest';
|
||||
import * as Images from './images.mjs';
|
||||
import renameCurrent from './operations/rename-current.js';
|
||||
import * as CurrentFile from './current-file.mjs';
|
||||
import * as DOMTree from './dom-tree.mjs';
|
||||
|
|
@ -14,7 +14,7 @@ import * as Cmd from './cmd.mjs';
|
|||
import IO from './io/index.js';
|
||||
import {uploadDirectory} from './directory.mjs';
|
||||
import * as Buffer from './buffer.mjs';
|
||||
import _loadRemote from './load-remote.js';
|
||||
import {loadRemote as _loadRemote} from './load-remote.mjs';
|
||||
import {selectByPattern} from './select-by-pattern.mjs';
|
||||
|
||||
const {assign} = Object;
|
||||
|
|
|
|||
|
|
@ -1,56 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
/* global CloudCmd */
|
||||
const rendy = require('rendy');
|
||||
const itype = require('itype');
|
||||
const load = require('load.js');
|
||||
const {tryToCatch} = require('try-to-catch');
|
||||
|
||||
const {findObjByNameInArr} = require('#common/util');
|
||||
|
||||
const Files = require('#dom/files');
|
||||
|
||||
module.exports = (name, options, callback = options) => {
|
||||
const {prefix, config} = CloudCmd;
|
||||
const o = options;
|
||||
|
||||
if (o.name && window[o.name])
|
||||
return callback();
|
||||
|
||||
Files.get('modules').then(async (modules) => {
|
||||
const online = config('online') && navigator.onLine;
|
||||
const module = findObjByNameInArr(modules.remote, name);
|
||||
|
||||
const isArray = itype.array(module.local);
|
||||
const {version} = module;
|
||||
|
||||
let remoteTmpls;
|
||||
let local;
|
||||
|
||||
if (isArray) {
|
||||
remoteTmpls = module.remote;
|
||||
({local} = module);
|
||||
} else {
|
||||
remoteTmpls = [module.remote];
|
||||
local = [module.local];
|
||||
}
|
||||
|
||||
const localURL = local.map((url) => prefix + url);
|
||||
|
||||
const remoteURL = remoteTmpls.map((tmpl) => {
|
||||
return rendy(tmpl, {
|
||||
version,
|
||||
});
|
||||
});
|
||||
|
||||
if (online) {
|
||||
const [e] = await tryToCatch(load.parallel, remoteURL);
|
||||
|
||||
if (!e)
|
||||
return callback();
|
||||
}
|
||||
|
||||
const [e] = await tryToCatch(load.parallel, localURL);
|
||||
callback(e);
|
||||
});
|
||||
};
|
||||
52
client/dom/load-remote.mjs
Normal file
52
client/dom/load-remote.mjs
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
/* global CloudCmd */
|
||||
import {callbackify} from 'node:util';
|
||||
import rendy from 'rendy';
|
||||
import itype from 'itype';
|
||||
import load from 'load.js';
|
||||
import {tryToCatch} from 'try-to-catch';
|
||||
import {findObjByNameInArr} from '#common/util';
|
||||
import * as Files from '#dom/files';
|
||||
|
||||
export const loadRemote = callbackify(async (name, options) => {
|
||||
const {prefix, config} = CloudCmd;
|
||||
const o = options;
|
||||
|
||||
if (o.name && window[o.name])
|
||||
return;
|
||||
|
||||
const modules = await Files.get('modules');
|
||||
|
||||
const online = config('online') && navigator.onLine;
|
||||
const module = findObjByNameInArr(modules.remote, name);
|
||||
|
||||
const isArray = itype.array(module.local);
|
||||
const {version} = module;
|
||||
|
||||
let remoteTmpls;
|
||||
let local;
|
||||
|
||||
if (isArray) {
|
||||
remoteTmpls = module.remote;
|
||||
({local} = module);
|
||||
} else {
|
||||
remoteTmpls = [module.remote];
|
||||
local = [module.local];
|
||||
}
|
||||
|
||||
const localURL = local.map((url) => prefix + url);
|
||||
|
||||
const remoteURL = remoteTmpls.map((tmpl) => {
|
||||
return rendy(tmpl, {
|
||||
version,
|
||||
});
|
||||
});
|
||||
|
||||
if (online) {
|
||||
const [e] = await tryToCatch(load.parallel, remoteURL);
|
||||
|
||||
if (!e)
|
||||
return;
|
||||
}
|
||||
|
||||
await load.parallel(localURL);
|
||||
});
|
||||
|
|
@ -72,6 +72,7 @@
|
|||
"watch:test:client": "madrun watch:test:client",
|
||||
"watch:test:server": "madrun watch:test:server",
|
||||
"watch:coverage": "madrun watch:coverage",
|
||||
"watch:fix:lint": "madrun watch:fix:lint",
|
||||
"build": "madrun build",
|
||||
"build:dev": "madrun build:dev",
|
||||
"build:client": "madrun build:client",
|
||||
|
|
@ -212,6 +213,7 @@
|
|||
"tar-stream": "^3.0.0",
|
||||
"unionfs": "^4.0.0",
|
||||
"url-loader": "^4.0.0",
|
||||
"util": "^0.12.5",
|
||||
"webpack": "^5.99.9",
|
||||
"webpack-cli": "^6.0.1",
|
||||
"webpack-merge": "^6.0.1",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue