mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-17 16:38:18 +00:00
feature: cloudcmd: get rid of simport
This commit is contained in:
parent
2aaf0a5385
commit
1f95f18898
4 changed files with 29 additions and 36 deletions
|
|
@ -4,21 +4,20 @@ import process from 'node:process';
|
||||||
import {createRequire} from 'node:module';
|
import {createRequire} from 'node:module';
|
||||||
import {promisify} from 'node:util';
|
import {promisify} from 'node:util';
|
||||||
import {tryToCatch} from 'try-to-catch';
|
import {tryToCatch} from 'try-to-catch';
|
||||||
import {createSimport} from 'simport';
|
|
||||||
import parse from 'yargs-parser';
|
import parse from 'yargs-parser';
|
||||||
import exit from '../server/exit.js';
|
import exit from '../server/exit.js';
|
||||||
import {createConfig, configPath} from '../server/config.js';
|
import {createConfig, configPath} from '../server/config.js';
|
||||||
import * as env from '../server/env.js';
|
import * as env from '../server/env.js';
|
||||||
import prefixer from '../server/prefixer.js';
|
import prefixer from '../server/prefixer.js';
|
||||||
import * as validate from '../server/validate.js';
|
import * as validate from '../server/validate.js';
|
||||||
|
import Info from '../package.json' with {
|
||||||
|
type: 'json',
|
||||||
|
};
|
||||||
|
|
||||||
process.on('unhandledRejection', exit);
|
process.on('unhandledRejection', exit);
|
||||||
|
|
||||||
const require = createRequire(import.meta.url);
|
const require = createRequire(import.meta.url);
|
||||||
|
|
||||||
const Info = require('../package.json');
|
|
||||||
const isUndefined = (a) => typeof a === 'undefined';
|
const isUndefined = (a) => typeof a === 'undefined';
|
||||||
const simport = createSimport(import.meta.url);
|
|
||||||
|
|
||||||
const choose = (a, b) => {
|
const choose = (a, b) => {
|
||||||
if (isUndefined(a))
|
if (isUndefined(a))
|
||||||
|
|
@ -170,7 +169,7 @@ else
|
||||||
main();
|
main();
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
const {validateArgs} = await simport('@putout/cli-validate-args');
|
const {validateArgs} = await import('@putout/cli-validate-args');
|
||||||
|
|
||||||
const error = await validateArgs(args, [
|
const error = await validateArgs(args, [
|
||||||
...yargsOptions.boolean,
|
...yargsOptions.boolean,
|
||||||
|
|
@ -251,7 +250,7 @@ async function main() {
|
||||||
if (args.showConfig)
|
if (args.showConfig)
|
||||||
await showConfig();
|
await showConfig();
|
||||||
|
|
||||||
const {distributeImport} = await simport('../server/distribute/import.js');
|
const {distributeImport} = await import('../server/distribute/import.js');
|
||||||
const importConfig = promisify(distributeImport);
|
const importConfig = promisify(distributeImport);
|
||||||
|
|
||||||
await start(options, config);
|
await start(options, config);
|
||||||
|
|
@ -273,7 +272,7 @@ function validateRoot(root, config) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getPassword(password) {
|
async function getPassword(password) {
|
||||||
const criton = await simport('criton');
|
const {default: criton} = await import('criton');
|
||||||
return criton(password, config('algo'));
|
return criton(password, config('algo'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -282,12 +281,10 @@ function version() {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function start(options, config) {
|
async function start(options, config) {
|
||||||
const SERVER = `../server/server.js`;
|
|
||||||
|
|
||||||
if (!args.server)
|
if (!args.server)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const server = await simport(SERVER);
|
const {default: server} = await import('../server/server.js');
|
||||||
server(options, config);
|
server(options, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -311,13 +308,13 @@ async function readConfig(name) {
|
||||||
if (!name)
|
if (!name)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const tryToCatch = await simport('try-to-catch');
|
const {default: forEachKey} = await import('for-each-key');
|
||||||
const forEachKey = await simport('for-each-key');
|
|
||||||
|
|
||||||
const [error, data] = await tryToCatch(simport, name);
|
const data = await import(name, {
|
||||||
|
with: {
|
||||||
if (error)
|
type: 'json',
|
||||||
return exit(error.message);
|
},
|
||||||
|
});
|
||||||
|
|
||||||
forEachKey(config, data);
|
forEachKey(config, data);
|
||||||
}
|
}
|
||||||
|
|
@ -329,8 +326,8 @@ async function help() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const forEachKey = await simport('for-each-key');
|
const {default: forEachKey} = await import('for-each-key');
|
||||||
const currify = await simport('currify');
|
const {currify} = await import('currify');
|
||||||
|
|
||||||
const usage = 'Usage: cloudcmd [options]';
|
const usage = 'Usage: cloudcmd [options]';
|
||||||
const url = Info.homepage;
|
const url = Info.homepage;
|
||||||
|
|
@ -348,9 +345,9 @@ function repl() {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function checkUpdate() {
|
async function checkUpdate() {
|
||||||
const load = await simport('package-json');
|
const {default: load} = await import('package-json');
|
||||||
|
|
||||||
const {version} = await load(Info.name, 'latest');
|
const {version} = await load(Info.name, 'latest');
|
||||||
|
|
||||||
await showUpdateInfo(version);
|
await showUpdateInfo(version);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -358,7 +355,7 @@ async function showUpdateInfo(version) {
|
||||||
if (version === Info.version)
|
if (version === Info.version)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const chalk = await simport('chalk');
|
const {default: chalk} = await import('chalk');
|
||||||
|
|
||||||
const latestVersion = chalk.green.bold(`v${version}`);
|
const latestVersion = chalk.green.bold(`v${version}`);
|
||||||
const latest = `update available: ${latestVersion}`;
|
const latest = `update available: ${latestVersion}`;
|
||||||
|
|
|
||||||
|
|
@ -3,17 +3,16 @@
|
||||||
import {promisify} from 'node:util';
|
import {promisify} from 'node:util';
|
||||||
import process from 'node:process';
|
import process from 'node:process';
|
||||||
import {tryToCatch} from 'try-to-catch';
|
import {tryToCatch} from 'try-to-catch';
|
||||||
import {createSimport} from 'simport';
|
|
||||||
import minor from 'minor';
|
import minor from 'minor';
|
||||||
import _place from 'place';
|
import _place from 'place';
|
||||||
import {rendy} from 'rendy';
|
import {rendy} from 'rendy';
|
||||||
import shortdate from 'shortdate';
|
import shortdate from 'shortdate';
|
||||||
|
import Info from '../package.json' with {
|
||||||
|
type: 'json',
|
||||||
|
};
|
||||||
|
|
||||||
const simport = createSimport(import.meta.url);
|
|
||||||
const place = promisify(_place);
|
const place = promisify(_place);
|
||||||
|
|
||||||
const Info = await simport('../package.json');
|
|
||||||
|
|
||||||
await main();
|
await main();
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
|
|
|
||||||
|
|
@ -135,7 +135,6 @@
|
||||||
"restafary": "^13.0.1",
|
"restafary": "^13.0.1",
|
||||||
"restbox": "^4.0.0",
|
"restbox": "^4.0.0",
|
||||||
"shortdate": "^2.0.0",
|
"shortdate": "^2.0.0",
|
||||||
"simport": "^1.0.1",
|
|
||||||
"socket.io": "^4.0.0",
|
"socket.io": "^4.0.0",
|
||||||
"socket.io-client": "^4.0.1",
|
"socket.io-client": "^4.0.1",
|
||||||
"squad": "^3.0.0",
|
"squad": "^3.0.0",
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
import path, {dirname} from 'node:path';
|
import path from 'node:path';
|
||||||
import fs from 'node:fs';
|
import fs from 'node:fs';
|
||||||
import Emitter from 'node:events';
|
import Emitter from 'node:events';
|
||||||
import {homedir} from 'node:os';
|
import {homedir} from 'node:os';
|
||||||
import {fileURLToPath} from 'node:url';
|
|
||||||
import currify from 'currify';
|
import currify from 'currify';
|
||||||
import wraptile from 'wraptile';
|
import wraptile from 'wraptile';
|
||||||
import {tryToCatch} from 'try-to-catch';
|
import {tryToCatch} from 'try-to-catch';
|
||||||
|
|
@ -15,15 +14,16 @@ import {tryCatch} from 'try-catch';
|
||||||
import criton from 'criton';
|
import criton from 'criton';
|
||||||
import * as CloudFunc from '#common/cloudfunc';
|
import * as CloudFunc from '#common/cloudfunc';
|
||||||
import exit from './exit.js';
|
import exit from './exit.js';
|
||||||
|
import rootConfig from '../json/config.json' with {
|
||||||
|
type: 'json',
|
||||||
|
};
|
||||||
|
|
||||||
const __filename = fileURLToPath(import.meta.url);
|
|
||||||
const __dirname = dirname(__filename);
|
|
||||||
const DIR_SERVER = `${__dirname}/`;
|
|
||||||
const isUndefined = (a) => typeof a === 'undefined';
|
const isUndefined = (a) => typeof a === 'undefined';
|
||||||
const DIR = `${DIR_SERVER}../`;
|
|
||||||
const HOME = homedir();
|
const HOME = homedir();
|
||||||
|
|
||||||
const resolve = Promise.resolve.bind(Promise);
|
const resolve = Promise.resolve.bind(Promise);
|
||||||
|
|
||||||
const formatMsg = currify((a, b) => CloudFunc.formatMsg(a, b));
|
const formatMsg = currify((a, b) => CloudFunc.formatMsg(a, b));
|
||||||
|
|
||||||
const {apiURL} = CloudFunc;
|
const {apiURL} = CloudFunc;
|
||||||
|
|
@ -32,10 +32,10 @@ const key = (a) => Object
|
||||||
.keys(a)
|
.keys(a)
|
||||||
.pop();
|
.pop();
|
||||||
|
|
||||||
const ConfigPath = path.join(DIR, 'json/config.json');
|
|
||||||
|
|
||||||
const connection = currify(_connection);
|
const connection = currify(_connection);
|
||||||
|
|
||||||
const connectionWrapped = wraptile(_connection);
|
const connectionWrapped = wraptile(_connection);
|
||||||
|
|
||||||
const middle = currify(_middle);
|
const middle = currify(_middle);
|
||||||
|
|
||||||
const readjsonSync = (name) => {
|
const readjsonSync = (name) => {
|
||||||
|
|
@ -44,8 +44,6 @@ const readjsonSync = (name) => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const rootConfig = readjsonSync(ConfigPath);
|
|
||||||
|
|
||||||
function read(filename) {
|
function read(filename) {
|
||||||
if (!filename)
|
if (!filename)
|
||||||
return rootConfig;
|
return rootConfig;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue