Skip to content

Commit 1f95f18

Browse files
committed
feature: cloudcmd: get rid of simport
1 parent 2aaf0a5 commit 1f95f18

4 files changed

Lines changed: 29 additions & 36 deletions

File tree

bin/cloudcmd.js

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,20 @@ import process from 'node:process';
44
import {createRequire} from 'node:module';
55
import {promisify} from 'node:util';
66
import {tryToCatch} from 'try-to-catch';
7-
import {createSimport} from 'simport';
87
import parse from 'yargs-parser';
98
import exit from '../server/exit.js';
109
import {createConfig, configPath} from '../server/config.js';
1110
import * as env from '../server/env.js';
1211
import prefixer from '../server/prefixer.js';
1312
import * as validate from '../server/validate.js';
13+
import Info from '../package.json' with {
14+
type: 'json',
15+
};
1416

1517
process.on('unhandledRejection', exit);
16-
1718
const require = createRequire(import.meta.url);
1819

19-
const Info = require('../package.json');
2020
const isUndefined = (a) => typeof a === 'undefined';
21-
const simport = createSimport(import.meta.url);
2221

2322
const choose = (a, b) => {
2423
if (isUndefined(a))
@@ -170,7 +169,7 @@ else
170169
main();
171170

172171
async function main() {
173-
const {validateArgs} = await simport('@putout/cli-validate-args');
172+
const {validateArgs} = await import('@putout/cli-validate-args');
174173

175174
const error = await validateArgs(args, [
176175
...yargsOptions.boolean,
@@ -251,7 +250,7 @@ async function main() {
251250
if (args.showConfig)
252251
await showConfig();
253252

254-
const {distributeImport} = await simport('../server/distribute/import.js');
253+
const {distributeImport} = await import('../server/distribute/import.js');
255254
const importConfig = promisify(distributeImport);
256255

257256
await start(options, config);
@@ -273,7 +272,7 @@ function validateRoot(root, config) {
273272
}
274273

275274
async function getPassword(password) {
276-
const criton = await simport('criton');
275+
const {default: criton} = await import('criton');
277276
return criton(password, config('algo'));
278277
}
279278

@@ -282,12 +281,10 @@ function version() {
282281
}
283282

284283
async function start(options, config) {
285-
const SERVER = `../server/server.js`;
286-
287284
if (!args.server)
288285
return;
289286

290-
const server = await simport(SERVER);
287+
const {default: server} = await import('../server/server.js');
291288
server(options, config);
292289
}
293290

@@ -311,13 +308,13 @@ async function readConfig(name) {
311308
if (!name)
312309
return;
313310

314-
const tryToCatch = await simport('try-to-catch');
315-
const forEachKey = await simport('for-each-key');
311+
const {default: forEachKey} = await import('for-each-key');
316312

317-
const [error, data] = await tryToCatch(simport, name);
318-
319-
if (error)
320-
return exit(error.message);
313+
const data = await import(name, {
314+
with: {
315+
type: 'json',
316+
},
317+
});
321318

322319
forEachKey(config, data);
323320
}
@@ -329,8 +326,8 @@ async function help() {
329326
},
330327
});
331328

332-
const forEachKey = await simport('for-each-key');
333-
const currify = await simport('currify');
329+
const {default: forEachKey} = await import('for-each-key');
330+
const {currify} = await import('currify');
334331

335332
const usage = 'Usage: cloudcmd [options]';
336333
const url = Info.homepage;
@@ -348,17 +345,17 @@ function repl() {
348345
}
349346

350347
async function checkUpdate() {
351-
const load = await simport('package-json');
352-
348+
const {default: load} = await import('package-json');
353349
const {version} = await load(Info.name, 'latest');
350+
354351
await showUpdateInfo(version);
355352
}
356353

357354
async function showUpdateInfo(version) {
358355
if (version === Info.version)
359356
return;
360357

361-
const chalk = await simport('chalk');
358+
const {default: chalk} = await import('chalk');
362359

363360
const latestVersion = chalk.green.bold(`v${version}`);
364361
const latest = `update available: ${latestVersion}`;

bin/release.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,16 @@
33
import {promisify} from 'node:util';
44
import process from 'node:process';
55
import {tryToCatch} from 'try-to-catch';
6-
import {createSimport} from 'simport';
76
import minor from 'minor';
87
import _place from 'place';
98
import {rendy} from 'rendy';
109
import shortdate from 'shortdate';
10+
import Info from '../package.json' with {
11+
type: 'json',
12+
};
1113

12-
const simport = createSimport(import.meta.url);
1314
const place = promisify(_place);
1415

15-
const Info = await simport('../package.json');
16-
1716
await main();
1817

1918
async function main() {

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@
135135
"restafary": "^13.0.1",
136136
"restbox": "^4.0.0",
137137
"shortdate": "^2.0.0",
138-
"simport": "^1.0.1",
139138
"socket.io": "^4.0.0",
140139
"socket.io-client": "^4.0.1",
141140
"squad": "^3.0.0",

server/config.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import path, {dirname} from 'node:path';
1+
import path from 'node:path';
22
import fs from 'node:fs';
33
import Emitter from 'node:events';
44
import {homedir} from 'node:os';
5-
import {fileURLToPath} from 'node:url';
65
import currify from 'currify';
76
import wraptile from 'wraptile';
87
import {tryToCatch} from 'try-to-catch';
@@ -15,15 +14,16 @@ import {tryCatch} from 'try-catch';
1514
import criton from 'criton';
1615
import * as CloudFunc from '#common/cloudfunc';
1716
import exit from './exit.js';
17+
import rootConfig from '../json/config.json' with {
18+
type: 'json',
19+
};
1820

19-
const __filename = fileURLToPath(import.meta.url);
20-
const __dirname = dirname(__filename);
21-
const DIR_SERVER = `${__dirname}/`;
2221
const isUndefined = (a) => typeof a === 'undefined';
23-
const DIR = `${DIR_SERVER}../`;
22+
2423
const HOME = homedir();
2524

2625
const resolve = Promise.resolve.bind(Promise);
26+
2727
const formatMsg = currify((a, b) => CloudFunc.formatMsg(a, b));
2828

2929
const {apiURL} = CloudFunc;
@@ -32,10 +32,10 @@ const key = (a) => Object
3232
.keys(a)
3333
.pop();
3434

35-
const ConfigPath = path.join(DIR, 'json/config.json');
36-
3735
const connection = currify(_connection);
36+
3837
const connectionWrapped = wraptile(_connection);
38+
3939
const middle = currify(_middle);
4040

4141
const readjsonSync = (name) => {
@@ -44,8 +44,6 @@ const readjsonSync = (name) => {
4444
});
4545
};
4646

47-
const rootConfig = readjsonSync(ConfigPath);
48-
4947
function read(filename) {
5048
if (!filename)
5149
return rootConfig;

0 commit comments

Comments
 (0)