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