mythix-cli 1.3.9 → 2.0.1
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/.nvmrc +1 -0
- package/LICENSE +1 -1
- package/bin/{mythix-cli.js → mythix-cli.mjs} +9 -5
- package/bin/{runner.js → runner.mjs} +81 -27
- package/package.json +15 -6
- package/src/index.mjs +1 -0
- package/src/index.js +0 -1
package/.nvmrc
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
24.13.0
|
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)
|
|
@@ -389,29 +429,43 @@ async function commandRunners(application, commandsObj, context, showHelp) {
|
|
|
389
429
|
|
|
390
430
|
let rootOptions;
|
|
391
431
|
let mythixPath;
|
|
392
|
-
let
|
|
432
|
+
let mythixIndexPath;
|
|
393
433
|
let mythixCLI;
|
|
394
434
|
let config;
|
|
395
435
|
|
|
396
436
|
try {
|
|
397
|
-
rootOptions
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
mythixCLI
|
|
401
|
-
config
|
|
437
|
+
rootOptions = { help, showHelp: customShowHelp, helpArgPattern: null };
|
|
438
|
+
mythixIndexPath = Path.resolve(require.resolve('mythix', { paths: [ process.env.PWD, Path.resolve(process.env.PWD, 'node_modules') ] }));
|
|
439
|
+
mythixPath = Path.dirname(mythixIndexPath);
|
|
440
|
+
mythixCLI = (await import(mythixIndexPath)).CLI;
|
|
441
|
+
config = await mythixCLI.loadMythixConfig(argOptions.config);
|
|
402
442
|
} catch (error) {
|
|
403
443
|
customShowHelp(help);
|
|
444
|
+
|
|
445
|
+
if (error.code !== 'MODULE_NOT_FOUND') {
|
|
446
|
+
console.error('\nError:', error.message || error);
|
|
447
|
+
} else {
|
|
448
|
+
console.log('\nNote: Run from within a mythix project to see additional commands.');
|
|
449
|
+
}
|
|
450
|
+
|
|
404
451
|
process.exit(1);
|
|
405
452
|
}
|
|
406
453
|
|
|
407
|
-
|
|
454
|
+
if (!config.applicationPath) {
|
|
455
|
+
customShowHelp(help);
|
|
456
|
+
console.error('\nNo mythix application found. Run this command from within a mythix project directory,');
|
|
457
|
+
console.error('or use "mythix-cli create <app-name>" to create a new project.');
|
|
458
|
+
return process.exit(1);
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
let Application = await config.getApplicationClass(config);
|
|
408
462
|
if (typeof Application !== 'function')
|
|
409
463
|
throw new Error('Expected to find an Application class from "getApplicationClass", but none was returned.');
|
|
410
464
|
|
|
411
|
-
let application = await mythixCLI.createApplication(Application, {
|
|
465
|
+
let application = await mythixCLI.createApplication(Application, { cli: true, database: false, httpServer: false });
|
|
412
466
|
let applicationOptions = application.getOptions();
|
|
413
467
|
|
|
414
|
-
let commands =
|
|
468
|
+
let commands = Application.getCommandList();
|
|
415
469
|
await generateCommandHelp(application, commands, help);
|
|
416
470
|
|
|
417
471
|
let commandContext = await CMDed(async (context) => {
|
package/package.json
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
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.1",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=18.0.0"
|
|
9
|
+
},
|
|
7
10
|
"description": "Mythix CLI utility",
|
|
8
|
-
"main": "src/index.
|
|
11
|
+
"main": "src/index.mjs",
|
|
12
|
+
"type": "module",
|
|
9
13
|
"scripts": {
|
|
10
14
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
11
15
|
},
|
|
@@ -27,13 +31,18 @@
|
|
|
27
31
|
},
|
|
28
32
|
"homepage": "https://github.com/th317erd/mythix-cli#readme",
|
|
29
33
|
"peerDependencies": {
|
|
30
|
-
"mythix": "^
|
|
34
|
+
"mythix": "^4.0.1"
|
|
35
|
+
},
|
|
36
|
+
"peerDependenciesMeta": {
|
|
37
|
+
"mythix": {
|
|
38
|
+
"optional": true
|
|
39
|
+
}
|
|
31
40
|
},
|
|
32
41
|
"dependencies": {
|
|
33
42
|
"cmded": "^1.2.5",
|
|
34
|
-
"nife": "^1.
|
|
43
|
+
"nife": "^1.12.1"
|
|
35
44
|
},
|
|
36
45
|
"devDependencies": {
|
|
37
|
-
"eslint": "^8.
|
|
46
|
+
"eslint": "^8.43.0"
|
|
38
47
|
}
|
|
39
48
|
}
|
package/src/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/src/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = {};
|