mythix-cli 1.3.7 → 1.3.8

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.
Files changed (2) hide show
  1. package/bin/runner.js +50 -26
  2. package/package.json +1 -1
package/bin/runner.js CHANGED
@@ -94,11 +94,33 @@ function spawnProcess(name, args, options) {
94
94
  });
95
95
  }
96
96
 
97
- function createTemplateEngineContext(appName) {
98
- let context = Object.create(null);
97
+ function getFormattedAppName(appName) {
98
+ return appName.trim().replace(/[^\w-]+/g, '-').replace(/^[^a-zA-Z0-9]+/g, '').replace(/[^a-zA-Z0-9]+$/g, '').toLowerCase();
99
+ }
100
+
101
+ function getFormattedAppDisplayName(appName) {
102
+ return Nife.capitalize(getFormattedAppName(appName).replace(/[^a-zA-Z0-9]+/g, ' ').trim(), true);
103
+ }
104
+
105
+ function createTemplateEngineContext(templateClonePath, _appName) {
106
+ let context = Object.create(null);
107
+ let appName = getFormattedAppName(_appName);
108
+ let appDisplayName = getFormattedAppDisplayName(_appName);
109
+
110
+ context.APP_NAME = () => appName;
111
+ context.APP_DISPLAY_NAME = () => appDisplayName;
112
+ context.RANDOM_SHA256 = () => randomHash('sha256');
99
113
 
100
- context.APP_NAME = () => appName;
101
- context.RANDOM_SHA256 = () => randomHash('sha256');
114
+ try {
115
+ let helpersPath = require.resolve(Path.join(templateClonePath, 'mythix-cli-template-helpers'));
116
+ let projectHelpers = require(helpersPath);
117
+ if (projectHelpers && projectHelpers.default)
118
+ projectHelpers = projectHelpers.default;
119
+
120
+ context = Object.assign({}, projectHelpers, context);
121
+
122
+ FileSystem.unlinkSync(helpersPath);
123
+ } catch (error) {}
102
124
 
103
125
  return context;
104
126
  }
@@ -163,14 +185,14 @@ function runTemplateEngineOnProject(projectPath, context) {
163
185
  );
164
186
  }
165
187
 
166
- async function initApplication(args) {
188
+ async function createApplication(args) {
167
189
  if (!args.dir || !('' + args.dir).match(/\S/))
168
190
  args.dir = Path.resolve(process.env.PWD);
169
191
  else
170
192
  args.dir = Path.resolve(args.dir);
171
193
 
172
194
  try {
173
- let templateClonePath = Path.resolve(args.dir, args.appName);
195
+ let templateClonePath = Path.resolve(args.dir, getFormattedAppName(args.appName));
174
196
  let processArgs = [ args.template, templateClonePath ];
175
197
  let tag;
176
198
 
@@ -186,17 +208,19 @@ async function initApplication(args) {
186
208
 
187
209
  FileSystem.rmSync(Path.resolve(templateClonePath, '.git'), { recursive: true, force: true });
188
210
 
189
- runTemplateEngineOnProject(templateClonePath, createTemplateEngineContext(args.appName));
190
-
191
211
  await spawnProcess('npm', [ 'i' ], { env: { PWD: templateClonePath, CWD: templateClonePath }, cwd: templateClonePath });
192
212
 
193
- console.log(`Empty mythix project created at ${templateClonePath}`);
213
+ runTemplateEngineOnProject(templateClonePath, createTemplateEngineContext(templateClonePath, args.appName));
214
+
215
+ console.log(`Mythix application created at ${templateClonePath}`);
194
216
  console.log('To finalize setup you need to:');
195
- console.log(' 1) Select and configure the correct database driver for mythix-orm');
217
+ console.log(' 1) Install the correct database driver (default is mythix-orm-postgresql), and update configuration files:');
218
+ console.log(` a) Open and modify ${Path.join(templateClonePath, 'app', 'config', 'db-config.js')} for database configuration`);
219
+ console.log(` b) Open and modify ${Path.join(templateClonePath, 'app', 'config', 'sensitive.js')} for API keys`);
196
220
  console.log(' 2) Define the models for your application');
197
- console.log(' 3) Create an initial migration for your models: `npx mythix-cli makemigrations --name initial`');
198
- console.log(' 4) Run migrations: `npx mythix-cli migrate`');
199
- console.log(' 5) Finally run your application: `npx mythix-cli serve`');
221
+ console.log(' 3) Run migrations: `npx mythix-cli migrate`');
222
+ console.log(' 4) Run the DB seeder: `mythix-cli shell` + `await seedDB();`');
223
+ console.log(' 5) Finally run your application: `npm run -s start`');
200
224
  } catch (error) {
201
225
  console.error('ERROR: ', error);
202
226
  process.exit(1);
@@ -296,8 +320,8 @@ async function commandRunners(application, commandsObj, context, showHelp) {
296
320
  // Consume to VOID
297
321
  $('--', () => {});
298
322
 
299
- $('init', ({ scope }) => {
300
- return scope('init', ({ $ }) => {
323
+ $('create', ({ scope }) => {
324
+ return scope('create', ({ $ }) => {
301
325
  $('--dir', Types.STRING({ format: Path.resolve }), { name: 'dir' })
302
326
  || $('-d', Types.STRING({ format: Path.resolve }), { name: 'dir' })
303
327
  || store({ dir: Path.resolve('./') });
@@ -306,12 +330,12 @@ async function commandRunners(application, commandsObj, context, showHelp) {
306
330
  || $('-t', Types.STRING(), { name: 'template' })
307
331
  || store({ template: 'https://github.com/th317erd/mythix-app-template.git' });
308
332
 
309
- return $(/^([\w](?:[\w-]+)?)$/, ({ store }, parserResult) => {
310
- store({ name: parserResult.name });
333
+ return $(/^.*$/, ({ store }, parserResult) => {
334
+ store({ appName: parserResult.appName });
311
335
  return true;
312
336
  }, {
313
- formatParserResult: (value) => {
314
- return { name: value[1] };
337
+ formatParsedResult: (value) => {
338
+ return { appName: value[0] };
315
339
  },
316
340
  });
317
341
  });
@@ -331,22 +355,22 @@ async function commandRunners(application, commandsObj, context, showHelp) {
331
355
  '--config={config file path} | --config {config file path}': 'Specify the path to ".mythix-config.js". Default = "{CWD}/.mythix-config.js".',
332
356
  '-e={environment} | -e {environment} | --env={environment} | --env {environment}': 'Specify the default environment to use. Default = "development".',
333
357
  '--runtime={runtime} | --runtime {runtime}': 'Specify the runtime to use to launch the command. Default = "node"',
334
- 'init': {
335
- '@usage': 'mythix-cli init app-name [options]',
358
+ 'create': {
359
+ '@usage': 'mythix-cli create [app name] [options]',
336
360
  '@title': 'Initialize a blank mythix application',
337
- '@see': 'See: \'mythix-cli init --help\' for more help',
361
+ '@see': 'See: \'mythix-cli create --help\' for more help',
338
362
  '-d={path} | -d {path} | --dir={path} | --dir {path}': 'Specify directory to create new application in. Default = "./"',
339
363
  '-t={url} | -t {url} | --template={url} | --template {url}': 'Specify a git repository URL to use for a template to create the application with. Default = "https://github.com/th317erd/mythix-app-template.git".'
340
364
  },
341
365
  };
342
366
 
343
- if (argOptions.init) {
344
- if (Nife.isEmpty(argOptions.init)) {
345
- showHelp(help.init);
367
+ if (argOptions.create) {
368
+ if (Nife.isEmpty(argOptions.create)) {
369
+ showHelp(help.create);
346
370
  return process.exit(1);
347
371
  }
348
372
 
349
- await initApplication(argOptions.init);
373
+ await createApplication(argOptions.create);
350
374
 
351
375
  return;
352
376
  }
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "mythix-cli": "./bin/mythix-cli.js"
4
4
  },
5
5
  "name": "mythix-cli",
6
- "version": "1.3.7",
6
+ "version": "1.3.8",
7
7
  "description": "Mythix CLI utility",
8
8
  "main": "src/index.js",
9
9
  "scripts": {