mythix-cli 1.3.8 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/bin/{mythix-cli.js → mythix-cli.mjs} +9 -5
- package/bin/{runner.js → runner.mjs} +78 -26
- package/package.json +7 -6
- package/src/index.mjs +1 -0
- package/src/index.js +0 -1
package/LICENSE
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
import Path from 'node:path';
|
|
4
|
+
import { spawn } from 'node:child_process';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
import { CMDed, Types } from 'cmded';
|
|
7
|
+
|
|
8
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
9
|
+
const __dirname = Path.dirname(__filename);
|
|
6
10
|
|
|
7
11
|
function spawnCommand(command, args, options) {
|
|
8
12
|
return new Promise((resolve, reject) => {
|
|
@@ -47,7 +51,7 @@ function spawnCommand(command, args, options) {
|
|
|
47
51
|
});
|
|
48
52
|
|
|
49
53
|
try {
|
|
50
|
-
config =
|
|
54
|
+
config = await import(argOptions.config);
|
|
51
55
|
} catch (error) {
|
|
52
56
|
config = {};
|
|
53
57
|
}
|
|
@@ -62,7 +66,7 @@ function spawnCommand(command, args, options) {
|
|
|
62
66
|
let command = commands[i];
|
|
63
67
|
|
|
64
68
|
try {
|
|
65
|
-
await spawnCommand(command, runtimeArgs.concat([ Path.resolve(__dirname, 'runner.
|
|
69
|
+
await spawnCommand(command, runtimeArgs.concat([ Path.resolve(__dirname, 'runner.mjs') ], args));
|
|
66
70
|
break;
|
|
67
71
|
} catch (error) {
|
|
68
72
|
if (error.code === 'ENOENT' && (i + 1) < commands.length)
|
|
@@ -1,17 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import Path from 'node:path';
|
|
2
|
+
import FileSystem from 'node:fs';
|
|
3
|
+
import { spawn } from 'node:child_process';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import { createRequire } from 'node:module';
|
|
6
|
+
import Nife from 'nife';
|
|
7
|
+
|
|
8
|
+
const require = createRequire(import.meta.url);
|
|
9
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
10
|
+
const __dirname = Path.dirname(__filename);
|
|
11
|
+
|
|
12
|
+
import {
|
|
7
13
|
CMDed,
|
|
8
14
|
showHelp,
|
|
9
|
-
}
|
|
15
|
+
} from 'cmded';
|
|
10
16
|
|
|
11
|
-
|
|
17
|
+
import {
|
|
12
18
|
createHash,
|
|
13
19
|
randomFillSync,
|
|
14
|
-
}
|
|
20
|
+
} from 'node:crypto';
|
|
15
21
|
|
|
16
22
|
function randomBytes(length) {
|
|
17
23
|
let buffer = Buffer.alloc(length);
|
|
@@ -47,7 +53,6 @@ function walkDir(rootPath, _options, _callback, _allFiles, _depth) {
|
|
|
47
53
|
else if (filterFunc instanceof RegExp && !filterFunc.match(fullFileName))
|
|
48
54
|
continue;
|
|
49
55
|
|
|
50
|
-
|
|
51
56
|
if (stats.isDirectory()) {
|
|
52
57
|
walkDir(fullFileName, options, callback, allFiles, depth + 1);
|
|
53
58
|
|
|
@@ -102,7 +107,29 @@ function getFormattedAppDisplayName(appName) {
|
|
|
102
107
|
return Nife.capitalize(getFormattedAppName(appName).replace(/[^a-zA-Z0-9]+/g, ' ').trim(), true);
|
|
103
108
|
}
|
|
104
109
|
|
|
105
|
-
function
|
|
110
|
+
function resolveJavascriptFileName(filePathWithoutExtension) {
|
|
111
|
+
if (FileSystem.existsSync(filePathWithoutExtension)) {
|
|
112
|
+
let stats = FileSystem.statSync(filePathWithoutExtension);
|
|
113
|
+
if (stats.isDirectory())
|
|
114
|
+
return resolveJavascriptFileName(`${filePathWithoutExtension}/index`);
|
|
115
|
+
|
|
116
|
+
return filePathWithoutExtension;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
let filePath = `${filePathWithoutExtension}.mjs`;
|
|
120
|
+
if (FileSystem.existsSync(filePath))
|
|
121
|
+
return filePath;
|
|
122
|
+
|
|
123
|
+
filePath = `${filePathWithoutExtension}.cjs`;
|
|
124
|
+
if (FileSystem.existsSync(filePath))
|
|
125
|
+
return filePath;
|
|
126
|
+
|
|
127
|
+
filePath = `${filePathWithoutExtension}.js`;
|
|
128
|
+
if (FileSystem.existsSync(filePath))
|
|
129
|
+
return filePath;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
async function createTemplateEngineContext(templateClonePath, _appName) {
|
|
106
133
|
let context = Object.create(null);
|
|
107
134
|
let appName = getFormattedAppName(_appName);
|
|
108
135
|
let appDisplayName = getFormattedAppDisplayName(_appName);
|
|
@@ -112,24 +139,26 @@ function createTemplateEngineContext(templateClonePath, _appName) {
|
|
|
112
139
|
context.RANDOM_SHA256 = () => randomHash('sha256');
|
|
113
140
|
|
|
114
141
|
try {
|
|
115
|
-
let helpersPath =
|
|
116
|
-
let projectHelpers =
|
|
142
|
+
let helpersPath = resolveJavascriptFileName(Path.join(templateClonePath, 'mythix-cli-template-helpers'));
|
|
143
|
+
let projectHelpers = await import(helpersPath);
|
|
117
144
|
if (projectHelpers && projectHelpers.default)
|
|
118
145
|
projectHelpers = projectHelpers.default;
|
|
119
146
|
|
|
120
147
|
context = Object.assign({}, projectHelpers, context);
|
|
121
148
|
|
|
122
149
|
FileSystem.unlinkSync(helpersPath);
|
|
123
|
-
} catch (error) {
|
|
150
|
+
} catch (error) {
|
|
151
|
+
console.error('Unable to import helpers: ', error);
|
|
152
|
+
}
|
|
124
153
|
|
|
125
154
|
return context;
|
|
126
155
|
}
|
|
127
156
|
|
|
128
157
|
function getTemplatedFileName(fileName, context) {
|
|
129
|
-
return fileName.replace(
|
|
158
|
+
return fileName.replace(/\b__([A-Z0-9_-]+)__\b/g, function(m, varName) {
|
|
130
159
|
let func = context[varName];
|
|
131
160
|
if (typeof func !== 'function')
|
|
132
|
-
return
|
|
161
|
+
return varName;
|
|
133
162
|
|
|
134
163
|
return func();
|
|
135
164
|
}).replace(/__/g, '');
|
|
@@ -210,7 +239,7 @@ async function createApplication(args) {
|
|
|
210
239
|
|
|
211
240
|
await spawnProcess('npm', [ 'i' ], { env: { PWD: templateClonePath, CWD: templateClonePath }, cwd: templateClonePath });
|
|
212
241
|
|
|
213
|
-
runTemplateEngineOnProject(templateClonePath, createTemplateEngineContext(templateClonePath, args.appName));
|
|
242
|
+
runTemplateEngineOnProject(templateClonePath, await createTemplateEngineContext(templateClonePath, args.appName));
|
|
214
243
|
|
|
215
244
|
console.log(`Mythix application created at ${templateClonePath}`);
|
|
216
245
|
console.log('To finalize setup you need to:');
|
|
@@ -295,9 +324,20 @@ async function commandRunners(application, commandsObj, context, showHelp) {
|
|
|
295
324
|
return false;
|
|
296
325
|
}
|
|
297
326
|
|
|
327
|
+
function loadJSON(filePath, defaultValue) {
|
|
328
|
+
try {
|
|
329
|
+
let content = FileSystem.readFileSync(filePath, 'utf8');
|
|
330
|
+
return JSON.parse(content);
|
|
331
|
+
} catch (error) {
|
|
332
|
+
console.error(`Error loading JSON file "${filePath}": `, error);
|
|
333
|
+
return (arguments.length > 1) ? defaultValue : {};
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
|
|
298
338
|
(async function() {
|
|
299
339
|
const packageJSONPath = Path.resolve(__dirname, '..', 'package.json');
|
|
300
|
-
const packageJSON =
|
|
340
|
+
const packageJSON = loadJSON(packageJSONPath, {});
|
|
301
341
|
|
|
302
342
|
// Windows hack
|
|
303
343
|
if(!process.env.PWD)
|
|
@@ -387,20 +427,32 @@ async function commandRunners(application, commandsObj, context, showHelp) {
|
|
|
387
427
|
showHelp(subHelp)
|
|
388
428
|
};
|
|
389
429
|
|
|
390
|
-
let rootOptions
|
|
391
|
-
let mythixPath
|
|
392
|
-
let
|
|
393
|
-
let mythixCLI
|
|
394
|
-
let config
|
|
430
|
+
let rootOptions;
|
|
431
|
+
let mythixPath;
|
|
432
|
+
let mythixCLIPath;
|
|
433
|
+
let mythixCLI;
|
|
434
|
+
let config;
|
|
435
|
+
|
|
436
|
+
try {
|
|
437
|
+
rootOptions = { help, showHelp: customShowHelp, helpArgPattern: null };
|
|
438
|
+
mythixCLIPath = Path.resolve(require.resolve('mythix', { paths: [ process.env.PWD, Path.resolve(process.env.PWD, 'node_modules') ] }));
|
|
439
|
+
mythixPath = Path.dirname(mythixCLIPath);
|
|
440
|
+
mythixCLI = (await import(mythixCLIPath)).CLI;
|
|
441
|
+
config = await mythixCLI.loadMythixConfig(argOptions.config);
|
|
442
|
+
} catch (error) {
|
|
443
|
+
console.error('THERE WAS AN ERROR: ', error);
|
|
444
|
+
customShowHelp(help);
|
|
445
|
+
process.exit(1);
|
|
446
|
+
}
|
|
395
447
|
|
|
396
|
-
let Application = config.getApplicationClass(config);
|
|
448
|
+
let Application = await config.getApplicationClass(config);
|
|
397
449
|
if (typeof Application !== 'function')
|
|
398
450
|
throw new Error('Expected to find an Application class from "getApplicationClass", but none was returned.');
|
|
399
451
|
|
|
400
|
-
let application = await mythixCLI.createApplication(Application, {
|
|
452
|
+
let application = await mythixCLI.createApplication(Application, { cli: true, database: false, httpServer: false });
|
|
401
453
|
let applicationOptions = application.getOptions();
|
|
402
454
|
|
|
403
|
-
let commands =
|
|
455
|
+
let commands = Application.getCommandList();
|
|
404
456
|
await generateCommandHelp(application, commands, help);
|
|
405
457
|
|
|
406
458
|
let commandContext = await CMDed(async (context) => {
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"bin": {
|
|
3
|
-
"mythix-cli": "./bin/mythix-cli.
|
|
3
|
+
"mythix-cli": "./bin/mythix-cli.mjs"
|
|
4
4
|
},
|
|
5
5
|
"name": "mythix-cli",
|
|
6
|
-
"version": "
|
|
6
|
+
"version": "2.0.0",
|
|
7
7
|
"description": "Mythix CLI utility",
|
|
8
|
-
"main": "src/index.
|
|
8
|
+
"main": "src/index.mjs",
|
|
9
|
+
"type": "module",
|
|
9
10
|
"scripts": {
|
|
10
11
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
11
12
|
},
|
|
@@ -27,13 +28,13 @@
|
|
|
27
28
|
},
|
|
28
29
|
"homepage": "https://github.com/th317erd/mythix-cli#readme",
|
|
29
30
|
"peerDependencies": {
|
|
30
|
-
"mythix": "^
|
|
31
|
+
"mythix": "^4.0.1"
|
|
31
32
|
},
|
|
32
33
|
"dependencies": {
|
|
33
34
|
"cmded": "^1.2.5",
|
|
34
|
-
"nife": "^1.
|
|
35
|
+
"nife": "^1.12.1"
|
|
35
36
|
},
|
|
36
37
|
"devDependencies": {
|
|
37
|
-
"eslint": "^8.
|
|
38
|
+
"eslint": "^8.43.0"
|
|
38
39
|
}
|
|
39
40
|
}
|
package/src/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/src/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = {};
|