mythix 3.0.0 → 4.0.2
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/README.md +27 -30
- package/{src → lib}/application.d.ts +25 -39
- package/{src/application.js → lib/application.mjs} +110 -135
- package/lib/cli/cli-utils.d.ts +21 -0
- package/lib/cli/cli-utils.mjs +319 -0
- package/lib/cli/command-base.d.ts +33 -0
- package/lib/cli/command-base.mjs +118 -0
- package/lib/cli/command-executor.mjs +14 -0
- package/lib/cli/commands/deploy-command.mjs +1010 -0
- package/lib/cli/commands/generators/generate-command.mjs +117 -0
- package/lib/cli/commands/generators/index.mjs +2 -0
- package/{src/cli/generators/migration-generator.js → lib/cli/commands/generators/migration-generator.mjs} +11 -13
- package/lib/cli/commands/index.mjs +22 -0
- package/lib/cli/commands/migrate-command.mjs +184 -0
- package/lib/cli/commands/routes-command.mjs +40 -0
- package/lib/cli/commands/serve-command.mjs +63 -0
- package/lib/cli/commands/shell-command.mjs +95 -0
- package/lib/cli/index.mjs +3 -0
- package/{src → lib}/controllers/controller-base.d.ts +1 -1
- package/{src/controllers/controller-base.js → lib/controllers/controller-base.mjs} +3 -9
- package/{src → lib}/controllers/controller-module.d.ts +3 -3
- package/lib/controllers/controller-module.mjs +70 -0
- package/lib/controllers/generate-client-api-interface-spec.mjs +44 -0
- package/{src → lib}/controllers/generate-client-api-interface.d.ts +1 -0
- package/{src/controllers/generate-client-api-interface.js → lib/controllers/generate-client-api-interface.mjs} +39 -16
- package/{src → lib}/controllers/index.d.ts +2 -3
- package/lib/controllers/index.mjs +4 -0
- package/lib/controllers/routes/index.mjs +4 -0
- package/{src/controllers/routes/route-capture.js → lib/controllers/routes/route-capture.mjs} +2 -8
- package/{src/controllers/routes/route-endpoint.js → lib/controllers/routes/route-endpoint.mjs} +8 -8
- package/{src/controllers/routes/route-scope-base.js → lib/controllers/routes/route-scope-base.mjs} +19 -15
- package/{src/controllers/routes/route-scope.js → lib/controllers/routes/route-scope.mjs} +10 -12
- package/{src/http-server/http-errors.js → lib/http/http-errors.mjs} +9 -20
- package/{src/utils/http-interface.js → lib/http/http-interface.mjs} +6 -14
- package/{src/http-server → lib/http}/http-server-module.d.ts +2 -2
- package/{src/http-server/http-server-module.js → lib/http/http-server-module.mjs} +7 -11
- package/{src/http-server/http-server.js → lib/http/http-server.mjs} +17 -21
- package/lib/http/index.d.ts +4 -0
- package/lib/http/index.mjs +5 -0
- package/lib/index.d.ts +30 -0
- package/lib/index.mjs +31 -0
- package/lib/logger-spec.mjs +121 -0
- package/{src → lib}/logger.d.ts +1 -3
- package/{src/logger.js → lib/logger.mjs} +10 -24
- package/lib/models/index.d.ts +2 -0
- package/lib/models/index.mjs +2 -0
- package/{src/models/migration-model.js → lib/models/migration-model.mjs} +3 -11
- package/lib/models/model.d.ts +10 -0
- package/lib/models/model.mjs +28 -0
- package/{src → lib}/modules/database-module.d.ts +2 -2
- package/{src/modules/database-module.js → lib/modules/database-module.mjs} +19 -14
- package/lib/modules/index.d.ts +2 -0
- package/lib/modules/index.mjs +2 -0
- package/{src/modules/base-module.d.ts → lib/modules/module-base.d.ts} +3 -10
- package/{src/modules/base-module.js → lib/modules/module-base.mjs} +16 -6
- package/lib/tasks/index.d.ts +2 -0
- package/lib/tasks/index.mjs +2 -0
- package/{src → lib}/tasks/task-base.d.ts +4 -14
- package/lib/tasks/task-base.mjs +73 -0
- package/{src → lib}/tasks/task-module.d.ts +3 -3
- package/{src/tasks/task-module.js → lib/tasks/task-module.mjs} +43 -98
- package/{src/utils/config-utils.js → lib/utils/config-utils.mjs} +2 -10
- package/lib/utils/crypto-utils-spec.mjs +24 -0
- package/{src/utils/crypto-utils.js → lib/utils/crypto-utils.mjs} +16 -38
- package/lib/utils/file-utils-spec.mjs +10 -0
- package/{src/utils/file-utils.js → lib/utils/file-utils.mjs} +4 -11
- package/{src/utils/http-utils.js → lib/utils/http-utils.mjs} +3 -10
- package/{src → lib}/utils/index.d.ts +1 -1
- package/lib/utils/index.mjs +6 -0
- package/lib/utils/mime-utils-spec.mjs +171 -0
- package/{src/utils/mime-utils.js → lib/utils/mime-utils.mjs} +5 -14
- package/{src/utils/test-utils.js → lib/utils/test-utils.mjs} +14 -42
- package/package.json +5 -5
- package/src/cli/cli-utils.d.ts +0 -80
- package/src/cli/cli-utils.js +0 -547
- package/src/cli/command-executor.js +0 -31
- package/src/cli/deploy-command.js +0 -1010
- package/src/cli/generators/generate-command.js +0 -149
- package/src/cli/index.js +0 -5
- package/src/cli/migrate-command.js +0 -181
- package/src/cli/routes-command.js +0 -40
- package/src/cli/serve-command.js +0 -63
- package/src/cli/shell-command.js +0 -96
- package/src/controllers/controller-module.js +0 -126
- package/src/controllers/controller-utils.d.ts +0 -19
- package/src/controllers/controller-utils.js +0 -24
- package/src/controllers/index.js +0 -19
- package/src/controllers/routes/index.js +0 -31
- package/src/http-server/index.d.ts +0 -3
- package/src/http-server/index.js +0 -16
- package/src/index.d.ts +0 -49
- package/src/index.js +0 -47
- package/src/models/index.d.ts +0 -4
- package/src/models/index.js +0 -17
- package/src/models/model-module.d.ts +0 -9
- package/src/models/model-module.js +0 -130
- package/src/models/model-utils.d.ts +0 -20
- package/src/models/model-utils.js +0 -46
- package/src/models/model.d.ts +0 -20
- package/src/models/model.js +0 -65
- package/src/modules/file-watcher-module.d.ts +0 -13
- package/src/modules/file-watcher-module.js +0 -220
- package/src/modules/index.d.ts +0 -3
- package/src/modules/index.js +0 -11
- package/src/tasks/index.d.ts +0 -3
- package/src/tasks/index.js +0 -11
- package/src/tasks/task-base.js +0 -117
- package/src/tasks/task-utils.d.ts +0 -46
- package/src/tasks/task-utils.js +0 -130
- package/src/utils/index.js +0 -25
- /package/{src → lib}/cli/index.d.ts +0 -0
- /package/{src → lib}/controllers/routes/index.d.ts +0 -0
- /package/{src → lib}/controllers/routes/route-capture.d.ts +0 -0
- /package/{src → lib}/controllers/routes/route-endpoint.d.ts +0 -0
- /package/{src → lib}/controllers/routes/route-scope-base.d.ts +0 -0
- /package/{src → lib}/controllers/routes/route-scope.d.ts +0 -0
- /package/{src/http-server → lib/http}/http-errors.d.ts +0 -0
- /package/{src/utils → lib/http}/http-interface.d.ts +0 -0
- /package/{src/http-server → lib/http}/http-server.d.ts +0 -0
- /package/{src → lib}/interfaces/common.ts +0 -0
- /package/{src → lib}/models/migration-model.d.ts +0 -0
- /package/{src → lib}/utils/config-utils.d.ts +0 -0
- /package/{src → lib}/utils/crypto-utils.d.ts +0 -0
- /package/{src → lib}/utils/file-utils.d.ts +0 -0
- /package/{src → lib}/utils/http-utils.d.ts +0 -0
- /package/{src → lib}/utils/mime-utils.d.ts +0 -0
- /package/{src → lib}/utils/test-utils.d.ts +0 -0
package/src/cli/cli-utils.js
DELETED
|
@@ -1,547 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/* global process, __dirname, Buffer */
|
|
4
|
-
|
|
5
|
-
const Path = require('path');
|
|
6
|
-
const FileSystem = require('fs');
|
|
7
|
-
const Nife = require('nife');
|
|
8
|
-
const { Logger } = require('../logger');
|
|
9
|
-
|
|
10
|
-
const {
|
|
11
|
-
walkDir,
|
|
12
|
-
fileNameWithoutExtension,
|
|
13
|
-
} = require('../utils/file-utils');
|
|
14
|
-
|
|
15
|
-
const {
|
|
16
|
-
CMDed,
|
|
17
|
-
showHelp,
|
|
18
|
-
} = require('cmded');
|
|
19
|
-
|
|
20
|
-
class CommandBase {
|
|
21
|
-
constructor(application, options) {
|
|
22
|
-
Object.defineProperties(this, {
|
|
23
|
-
'application': {
|
|
24
|
-
writable: false,
|
|
25
|
-
enumerable: false,
|
|
26
|
-
configurable: true,
|
|
27
|
-
value: application,
|
|
28
|
-
},
|
|
29
|
-
'options': {
|
|
30
|
-
writable: false,
|
|
31
|
-
enumerable: false,
|
|
32
|
-
configurable: true,
|
|
33
|
-
value: options,
|
|
34
|
-
},
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
getOptions() {
|
|
39
|
-
return this.options;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
getApplication() {
|
|
43
|
-
return this.application;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
getLogger() {
|
|
47
|
-
let app = this.getApplication();
|
|
48
|
-
return app.getLogger();
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
getConnection(connection) {
|
|
52
|
-
let application = this.getApplication();
|
|
53
|
-
return application.getConnection(connection);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// Deprecated
|
|
57
|
-
getDBConnection(connection) {
|
|
58
|
-
return this.getConnection(connection);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
spawnCommand(command, args, options) {
|
|
62
|
-
const { spawn } = require('child_process');
|
|
63
|
-
|
|
64
|
-
return new Promise((resolve, reject) => {
|
|
65
|
-
try {
|
|
66
|
-
let childProcess = spawn(
|
|
67
|
-
command,
|
|
68
|
-
args,
|
|
69
|
-
Object.assign({ shell: true }, options || {}, {
|
|
70
|
-
env: Object.assign({}, process.env, (options || {}).env || {}),
|
|
71
|
-
}),
|
|
72
|
-
);
|
|
73
|
-
|
|
74
|
-
let output = [];
|
|
75
|
-
let errors = [];
|
|
76
|
-
|
|
77
|
-
childProcess.stdout.on('data', (data) => {
|
|
78
|
-
output.push(data);
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
childProcess.stderr.on('data', (data) => {
|
|
82
|
-
errors.push(data);
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
childProcess.on('error', (error) => {
|
|
86
|
-
if (options && options.ignoreExitCode) {
|
|
87
|
-
resolve({
|
|
88
|
-
stdout: Buffer.concat(output).toString('utf8'),
|
|
89
|
-
stderr: Buffer.concat(errors).toString('utf8'),
|
|
90
|
-
code: 0,
|
|
91
|
-
error,
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
reject({
|
|
98
|
-
stdout: Buffer.concat(output).toString('utf8'),
|
|
99
|
-
stderr: Buffer.concat(errors).toString('utf8'),
|
|
100
|
-
code: 1,
|
|
101
|
-
error,
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
childProcess.on('close', (code) => {
|
|
106
|
-
if (code !== 0) {
|
|
107
|
-
let error = Buffer.concat(errors).toString('utf8');
|
|
108
|
-
|
|
109
|
-
reject({
|
|
110
|
-
stdout: Buffer.concat(output).toString('utf8'),
|
|
111
|
-
stderr: error,
|
|
112
|
-
error: error,
|
|
113
|
-
code,
|
|
114
|
-
});
|
|
115
|
-
} else {
|
|
116
|
-
resolve({
|
|
117
|
-
stdout: Buffer.concat(output).toString('utf8'),
|
|
118
|
-
stderr: Buffer.concat(errors).toString('utf8'),
|
|
119
|
-
error: null,
|
|
120
|
-
code,
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
} catch (error) {
|
|
125
|
-
reject({
|
|
126
|
-
stdout: '',
|
|
127
|
-
stderr: '',
|
|
128
|
-
code: 1,
|
|
129
|
-
error,
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
getCommandFiles(filterFunc) {
|
|
136
|
-
let application = this.getApplication();
|
|
137
|
-
let applicationOptions = application.getOptions();
|
|
138
|
-
let internalCommands = getCommandFiles(getInternalCommandsPath(), filterFunc);
|
|
139
|
-
let externalCommands = [];
|
|
140
|
-
|
|
141
|
-
if (Nife.isNotEmpty(applicationOptions.commandsPath))
|
|
142
|
-
externalCommands = getCommandFiles(applicationOptions.commandsPath, filterFunc);
|
|
143
|
-
|
|
144
|
-
return [].concat(internalCommands, externalCommands);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
let loadingAllCommandsInProgress = false;
|
|
149
|
-
|
|
150
|
-
function defineCommand(_commandName, definer, _parent) {
|
|
151
|
-
if (!CommandBase.commands) {
|
|
152
|
-
Object.defineProperties(CommandBase, {
|
|
153
|
-
'commands': {
|
|
154
|
-
writable: false,
|
|
155
|
-
enumerable: false,
|
|
156
|
-
configurable: true,
|
|
157
|
-
value: {},
|
|
158
|
-
},
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
let commandName = _commandName.toLowerCase();
|
|
163
|
-
let parent = _parent;
|
|
164
|
-
|
|
165
|
-
if (Nife.instanceOf(parent, 'string')) {
|
|
166
|
-
if (!CommandBase.commands[parent])
|
|
167
|
-
throw new Error(`Can not find parent class for command "${commandName}": No such parent class "${parent}" found`);
|
|
168
|
-
|
|
169
|
-
parent = CommandBase.commands[parent];
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
let parentClass = parent || CommandBase;
|
|
173
|
-
|
|
174
|
-
let Klass = definer({
|
|
175
|
-
Parent: parentClass,
|
|
176
|
-
commandName,
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
if (typeof Klass.prototype.execute !== 'function')
|
|
180
|
-
throw new Error(`Error while defining command ${commandName}: "execute" method is required`);
|
|
181
|
-
|
|
182
|
-
Klass.commandName = commandName;
|
|
183
|
-
|
|
184
|
-
// Executor method. This gets invoked in a separate node process
|
|
185
|
-
// The command script is executed directly via node when the
|
|
186
|
-
// command is invoked via the CLI. The process starts at
|
|
187
|
-
// "executeCommand" below, which spawns a node process that
|
|
188
|
-
// targets this command script.
|
|
189
|
-
Klass.execute = async function() {
|
|
190
|
-
let helpShown = false;
|
|
191
|
-
|
|
192
|
-
const customShowHelp = (subHelp) => {
|
|
193
|
-
if (helpShown)
|
|
194
|
-
return;
|
|
195
|
-
|
|
196
|
-
helpShown = true;
|
|
197
|
-
|
|
198
|
-
showHelp(subHelp);
|
|
199
|
-
};
|
|
200
|
-
|
|
201
|
-
const getArgumentsContext = async (application) => {
|
|
202
|
-
// eslint-disable-next-line new-cap
|
|
203
|
-
return await CMDed(async (context) => {
|
|
204
|
-
let { $, Types, store, scope } = context;
|
|
205
|
-
|
|
206
|
-
// Parse these even though they are no longer needed
|
|
207
|
-
// so that we ensure they are "consumed".
|
|
208
|
-
$('--config', Types.STRING({
|
|
209
|
-
format: Path.resolve,
|
|
210
|
-
})) || store({ config: (Nife.isNotEmpty(process.env.MYTHIX_CONFIG_PATH)) ? Path.resolve(process.env.MYTHIX_CONFIG_PATH) : Path.join(process.env.PWD, '.mythix-config') });
|
|
211
|
-
|
|
212
|
-
$('--runtime', Types.STRING());
|
|
213
|
-
|
|
214
|
-
$('-e', Types.STRING(), { name: 'environment' });
|
|
215
|
-
$('--env', Types.STRING(), { name: 'environment' });
|
|
216
|
-
|
|
217
|
-
if (!application)
|
|
218
|
-
return true;
|
|
219
|
-
|
|
220
|
-
store('executing', true);
|
|
221
|
-
store('mythixApplication', application);
|
|
222
|
-
|
|
223
|
-
// Consume the command name
|
|
224
|
-
$(commandName, ({ fetch, showHelp }) => {
|
|
225
|
-
if (fetch('help', false))
|
|
226
|
-
showHelp(commandName);
|
|
227
|
-
|
|
228
|
-
return true;
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
let runner = null;
|
|
232
|
-
if (typeof Klass.commandArguments === 'function') {
|
|
233
|
-
let result = ((await Klass.commandArguments(application, 'runner')) || {});
|
|
234
|
-
runner = result.runner;
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
return await scope(commandName, async (context) => {
|
|
238
|
-
if (typeof runner === 'function')
|
|
239
|
-
return await runner(context);
|
|
240
|
-
|
|
241
|
-
return true;
|
|
242
|
-
});
|
|
243
|
-
}, {
|
|
244
|
-
helpArgPattern: null,
|
|
245
|
-
showHelp: customShowHelp,
|
|
246
|
-
});
|
|
247
|
-
};
|
|
248
|
-
|
|
249
|
-
let commandContext = await getArgumentsContext();
|
|
250
|
-
if (!commandContext)
|
|
251
|
-
return;
|
|
252
|
-
|
|
253
|
-
let application;
|
|
254
|
-
|
|
255
|
-
try {
|
|
256
|
-
let PWD = process.env['PWD'];
|
|
257
|
-
let mythixConfigPath = commandContext.config || process.env['MYTHIX_CONFIG_PATH'];
|
|
258
|
-
|
|
259
|
-
if (Nife.isEmpty(mythixConfigPath))
|
|
260
|
-
mythixConfigPath = PWD;
|
|
261
|
-
|
|
262
|
-
let config = loadMythixConfig(mythixConfigPath);
|
|
263
|
-
let Application = config.getApplicationClass(config);
|
|
264
|
-
let applicationConfig = Klass.applicationConfig;
|
|
265
|
-
|
|
266
|
-
if (typeof applicationConfig === 'function')
|
|
267
|
-
applicationConfig = applicationConfig(config, Application);
|
|
268
|
-
else if (applicationConfig)
|
|
269
|
-
applicationConfig = Nife.extend(true, { cli: true, httpServer: false, autoReload: false, logger: { level: Logger.LEVEL_WARN }, runTasks: false }, applicationConfig);
|
|
270
|
-
|
|
271
|
-
if (!applicationConfig)
|
|
272
|
-
applicationConfig = { cli: true, httpServer: false, autoReload: false, logger: { level: Logger.LEVEL_WARN }, runTasks: false };
|
|
273
|
-
|
|
274
|
-
let doStartApplication = (applicationConfig.autoStart !== false);
|
|
275
|
-
|
|
276
|
-
delete applicationConfig.autoStart;
|
|
277
|
-
|
|
278
|
-
application = await createApplication(Application, Object.assign({ exitOnShutdown: 1 }, applicationConfig), false);
|
|
279
|
-
|
|
280
|
-
let environment = commandContext.environment;
|
|
281
|
-
if (Nife.isEmpty(environment))
|
|
282
|
-
environment = application.getConfigValue('environment', 'development');
|
|
283
|
-
|
|
284
|
-
application.setConfig({ environment: environment });
|
|
285
|
-
|
|
286
|
-
if (doStartApplication)
|
|
287
|
-
await application.start();
|
|
288
|
-
|
|
289
|
-
commandContext = await getArgumentsContext(application);
|
|
290
|
-
|
|
291
|
-
let commandOptions = commandContext[commandName] || {};
|
|
292
|
-
let commandInstance = new Klass(application, commandOptions);
|
|
293
|
-
|
|
294
|
-
const doExecuteCommand = async () => {
|
|
295
|
-
return await commandInstance.execute.call(commandInstance, commandOptions, commandContext);
|
|
296
|
-
};
|
|
297
|
-
|
|
298
|
-
let dbConnection = (typeof application.getConnection === 'function') ? application.getConnection() : undefined;
|
|
299
|
-
let result;
|
|
300
|
-
|
|
301
|
-
if (dbConnection && typeof dbConnection.createContext === 'function')
|
|
302
|
-
result = await dbConnection.createContext(doExecuteCommand, dbConnection, dbConnection);
|
|
303
|
-
else
|
|
304
|
-
result = await doExecuteCommand();
|
|
305
|
-
|
|
306
|
-
await application.stop(result || 0);
|
|
307
|
-
} catch (error) {
|
|
308
|
-
console.log(`Error while executing command "${commandName}"`, error);
|
|
309
|
-
|
|
310
|
-
if (application)
|
|
311
|
-
await application.stop(1);
|
|
312
|
-
}
|
|
313
|
-
};
|
|
314
|
-
|
|
315
|
-
CommandBase.commands[commandName] = Klass;
|
|
316
|
-
|
|
317
|
-
return Klass;
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
async function createApplication(ApplicationClass, opts) {
|
|
321
|
-
let application = new ApplicationClass(Object.assign({ cli: true }, opts || {}));
|
|
322
|
-
|
|
323
|
-
if (Nife.isNotEmpty(opts))
|
|
324
|
-
application.setOptions(Object.assign(opts || {}));
|
|
325
|
-
|
|
326
|
-
return application;
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
function loadCommand(name) {
|
|
330
|
-
let fullPath = require.resolve(name);
|
|
331
|
-
let CommandKlass = require(fullPath);
|
|
332
|
-
|
|
333
|
-
if (CommandKlass && typeof CommandKlass !== 'function' && typeof CommandKlass.default === 'function')
|
|
334
|
-
CommandKlass = CommandKlass.default;
|
|
335
|
-
|
|
336
|
-
CommandKlass.path = fullPath;
|
|
337
|
-
|
|
338
|
-
return CommandKlass;
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
function getCommandFiles(commandsPath, filterFunc) {
|
|
342
|
-
try {
|
|
343
|
-
if (!commandsPath)
|
|
344
|
-
return [];
|
|
345
|
-
|
|
346
|
-
return walkDir(commandsPath, {
|
|
347
|
-
filter: (fullFileName, fileName, stats) => {
|
|
348
|
-
if (typeof filterFunc === 'function')
|
|
349
|
-
return filterFunc(fullFileName, fileName, stats);
|
|
350
|
-
|
|
351
|
-
if (fileName.match(/^_/))
|
|
352
|
-
return false;
|
|
353
|
-
|
|
354
|
-
if (stats.isFile() && !fileNameWithoutExtension(fileName).match(/-command$/))
|
|
355
|
-
return false;
|
|
356
|
-
|
|
357
|
-
return true;
|
|
358
|
-
},
|
|
359
|
-
});
|
|
360
|
-
} catch (error) {
|
|
361
|
-
if (error.code === 'ENOENT')
|
|
362
|
-
return [];
|
|
363
|
-
|
|
364
|
-
console.error(error);
|
|
365
|
-
throw error;
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
function getInternalCommandsPath() {
|
|
370
|
-
return Path.resolve(__dirname);
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
function loadCommands(applicationCommandsPath, skip) {
|
|
374
|
-
if (loadingAllCommandsInProgress)
|
|
375
|
-
return;
|
|
376
|
-
|
|
377
|
-
loadingAllCommandsInProgress = true;
|
|
378
|
-
|
|
379
|
-
let mythixCommandFiles = getCommandFiles(getInternalCommandsPath());
|
|
380
|
-
let applicationCommandFiles = getCommandFiles(applicationCommandsPath);
|
|
381
|
-
let allCommandFiles = [].concat(mythixCommandFiles, applicationCommandFiles);
|
|
382
|
-
|
|
383
|
-
allCommandFiles.forEach((commandPath) => {
|
|
384
|
-
if (skip && skip.indexOf(commandPath) >= 0)
|
|
385
|
-
return;
|
|
386
|
-
|
|
387
|
-
loadCommand(commandPath);
|
|
388
|
-
});
|
|
389
|
-
|
|
390
|
-
loadingAllCommandsInProgress = false;
|
|
391
|
-
|
|
392
|
-
return CommandBase.commands;
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
function resolveConfig(config) {
|
|
396
|
-
let keys = Object.keys(config);
|
|
397
|
-
for (let i = 0, il = keys.length; i < il; i++) {
|
|
398
|
-
let key = keys[i];
|
|
399
|
-
let value = config[key];
|
|
400
|
-
|
|
401
|
-
if (key.match(/Path/) && typeof value === 'function')
|
|
402
|
-
value = value(config);
|
|
403
|
-
|
|
404
|
-
config[key] = value;
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
return config;
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
function loadMythixConfig(_mythixConfigPath, _appRootPath) {
|
|
411
|
-
let mythixConfigPath = _mythixConfigPath;
|
|
412
|
-
let configPath = mythixConfigPath;
|
|
413
|
-
|
|
414
|
-
try {
|
|
415
|
-
let stats = FileSystem.statSync(mythixConfigPath);
|
|
416
|
-
if (stats.isDirectory())
|
|
417
|
-
configPath = Path.resolve(mythixConfigPath, '.mythix-config');
|
|
418
|
-
else if (stats.isFile(mythixConfigPath))
|
|
419
|
-
mythixConfigPath = Path.dirname(mythixConfigPath);
|
|
420
|
-
} catch (error) {
|
|
421
|
-
if (error.code === 'ENOENT') {
|
|
422
|
-
if (!mythixConfigPath.match(/[/\\]$/))
|
|
423
|
-
mythixConfigPath = Path.dirname(mythixConfigPath);
|
|
424
|
-
} else {
|
|
425
|
-
throw error;
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
let appRootPath = (_appRootPath) ? Path.resolve(_appRootPath) : Path.resolve(mythixConfigPath, 'app');
|
|
430
|
-
|
|
431
|
-
let defaultConfig = {
|
|
432
|
-
runtime: process.env.MYTHIX_RUNTIME || 'node',
|
|
433
|
-
runtimeArgs: (process.env.MYTHIX_RUNTIME_ARGS || '').split(/\s+/g).filter(Boolean),
|
|
434
|
-
applicationPath: (config) => Path.resolve(config.appRootPath, 'application'),
|
|
435
|
-
getApplicationClass: (config) => {
|
|
436
|
-
let Application = require(config.applicationPath);
|
|
437
|
-
if (Application && typeof Application !== 'function' && typeof Application.Application === 'function')
|
|
438
|
-
Application = Application.Application;
|
|
439
|
-
|
|
440
|
-
return Application;
|
|
441
|
-
},
|
|
442
|
-
configPath,
|
|
443
|
-
appRootPath,
|
|
444
|
-
};
|
|
445
|
-
|
|
446
|
-
try {
|
|
447
|
-
if (FileSystem.existsSync(configPath)) {
|
|
448
|
-
let mythixConfig = require(configPath);
|
|
449
|
-
if (mythixConfig.__esModule)
|
|
450
|
-
mythixConfig = mythixConfig['default'];
|
|
451
|
-
|
|
452
|
-
if (!mythixConfig.appRootPath)
|
|
453
|
-
mythixConfig.appRootPath = appRootPath;
|
|
454
|
-
|
|
455
|
-
mythixConfig.configPath = configPath;
|
|
456
|
-
|
|
457
|
-
return resolveConfig(Object.assign({}, defaultConfig, mythixConfig));
|
|
458
|
-
}
|
|
459
|
-
} catch (error) {
|
|
460
|
-
if (error.code !== 'ENOENT')
|
|
461
|
-
throw error;
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
return resolveConfig(defaultConfig);
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
function spawnCommand(args, options, _config) {
|
|
468
|
-
const config = _config || {};
|
|
469
|
-
const { spawn } = require('child_process');
|
|
470
|
-
|
|
471
|
-
return new Promise((resolve, reject) => {
|
|
472
|
-
try {
|
|
473
|
-
let childProcess = spawn(
|
|
474
|
-
config.runtime || 'node',
|
|
475
|
-
(config.runtimeArgs || []).concat(args).filter(Boolean),
|
|
476
|
-
Object.assign({}, options || {}, {
|
|
477
|
-
env: Object.assign({}, process.env, (options || {}).env || {}),
|
|
478
|
-
stdio: 'inherit',
|
|
479
|
-
}),
|
|
480
|
-
);
|
|
481
|
-
|
|
482
|
-
childProcess.on('error', (error) => {
|
|
483
|
-
if (options && options.ignoreExitCode) {
|
|
484
|
-
resolve(0);
|
|
485
|
-
return;
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
reject(error);
|
|
489
|
-
});
|
|
490
|
-
|
|
491
|
-
childProcess.on('close', (code) => {
|
|
492
|
-
resolve(code);
|
|
493
|
-
});
|
|
494
|
-
} catch (error) {
|
|
495
|
-
reject(error);
|
|
496
|
-
}
|
|
497
|
-
});
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
async function executeCommand(_config, appOptions, commandContext, CommandKlass, argv) {
|
|
501
|
-
let command = commandContext.command;
|
|
502
|
-
|
|
503
|
-
try {
|
|
504
|
-
let config = _config || {};
|
|
505
|
-
let configPath = commandContext.config;
|
|
506
|
-
let commandPath = CommandKlass.path;
|
|
507
|
-
let commandsPath = appOptions.commandsPath;
|
|
508
|
-
let runtime = commandContext.runtime || config.runtime || process.env.MYTHIX_RUNTIME || 'node';
|
|
509
|
-
let runtimeArguments = ((CommandKlass.runtimeArguments || {})[runtime]) || [];
|
|
510
|
-
let args = runtimeArguments.concat([ Path.resolve(__dirname, 'command-executor.js') ], argv);
|
|
511
|
-
|
|
512
|
-
let code = await spawnCommand(
|
|
513
|
-
args,
|
|
514
|
-
{
|
|
515
|
-
env: {
|
|
516
|
-
NODE_ENV: commandContext.environment || process.env.NODE_ENV,
|
|
517
|
-
MYTHIX_RUNTIME: runtime,
|
|
518
|
-
MYTHIX_CONFIG_PATH: configPath,
|
|
519
|
-
MYTHIX_COMMAND_PATH: commandPath,
|
|
520
|
-
MYTHIX_APPLICATION_COMMANDS: commandsPath,
|
|
521
|
-
MYTHIX_EXECUTE_COMMAND: command,
|
|
522
|
-
},
|
|
523
|
-
},
|
|
524
|
-
{
|
|
525
|
-
...config,
|
|
526
|
-
...commandContext,
|
|
527
|
-
},
|
|
528
|
-
);
|
|
529
|
-
|
|
530
|
-
process.exit(code);
|
|
531
|
-
} catch (error) {
|
|
532
|
-
console.error(`Error while running command "${command}": `, error);
|
|
533
|
-
process.exit(1);
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
|
-
|
|
537
|
-
module.exports = {
|
|
538
|
-
CommandBase,
|
|
539
|
-
loadMythixConfig,
|
|
540
|
-
getInternalCommandsPath,
|
|
541
|
-
getCommandFiles,
|
|
542
|
-
loadCommand,
|
|
543
|
-
loadCommands,
|
|
544
|
-
defineCommand,
|
|
545
|
-
createApplication,
|
|
546
|
-
executeCommand,
|
|
547
|
-
};
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/* global process */
|
|
4
|
-
|
|
5
|
-
const Nife = require('nife');
|
|
6
|
-
const {
|
|
7
|
-
CommandBase,
|
|
8
|
-
loadCommands,
|
|
9
|
-
} = require('./cli-utils');
|
|
10
|
-
|
|
11
|
-
(async function() {
|
|
12
|
-
let commandName = process.env['MYTHIX_EXECUTE_COMMAND'];
|
|
13
|
-
if (Nife.isEmpty(commandName))
|
|
14
|
-
return;
|
|
15
|
-
|
|
16
|
-
// First load all commands
|
|
17
|
-
let mythixCommandPath = process.env['MYTHIX_COMMAND_PATH'];
|
|
18
|
-
let mythixApplicationCommandsPath = process.env['MYTHIX_APPLICATION_COMMANDS'];
|
|
19
|
-
if (mythixCommandPath && mythixApplicationCommandsPath)
|
|
20
|
-
loadCommands(mythixApplicationCommandsPath);
|
|
21
|
-
|
|
22
|
-
let Klass = CommandBase.commands[commandName];
|
|
23
|
-
if (!Klass || typeof Klass.execute !== 'function')
|
|
24
|
-
return;
|
|
25
|
-
|
|
26
|
-
try {
|
|
27
|
-
await Klass.execute();
|
|
28
|
-
} catch (error) {
|
|
29
|
-
console.error(error);
|
|
30
|
-
}
|
|
31
|
-
})();
|