mythix 2.8.3 → 2.8.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mythix",
3
- "version": "2.8.3",
3
+ "version": "2.8.5",
4
4
  "description": "Mythix is a NodeJS web-app framework",
5
5
  "main": "src/index",
6
6
  "scripts": {
@@ -235,14 +235,18 @@ class Application extends EventEmitter {
235
235
  }
236
236
 
237
237
  loadConfig(configPath) {
238
- try {
239
- let appOptions = this.getOptions();
238
+ let appOptions = this.getOptions();
239
+ let environment = (appOptions.environment || process.NODE_ENV || 'development');
240
+
241
+ if (!configPath)
242
+ return wrapConfig(Object.assign({}, { environment }));
240
243
 
244
+ try {
241
245
  let config = require(configPath);
242
246
  if (config.__esModule)
243
247
  config = config['default'];
244
248
 
245
- return wrapConfig(Object.assign({}, config || {}, { environment: (appOptions.environment || config.environment || 'development')}));
249
+ return wrapConfig(Object.assign({}, config || {}, { environment }));
246
250
  } catch (error) {
247
251
  this.getLogger().error(`Error while trying to load application configuration ${configPath}: `, error);
248
252
  throw error;
@@ -324,6 +324,9 @@ function loadCommand(name) {
324
324
 
325
325
  function getCommandFiles(commandsPath, filterFunc) {
326
326
  try {
327
+ if (!commandsPath)
328
+ return [];
329
+
327
330
  return walkDir(commandsPath, {
328
331
  filter: (fullFileName, fileName, stats) => {
329
332
  if (typeof filterFunc === 'function')
@@ -390,7 +393,7 @@ function resolveConfig(config) {
390
393
 
391
394
  function loadMythixConfig(_mythixConfigPath, _appRootPath) {
392
395
  let mythixConfigPath = _mythixConfigPath;
393
- let configPath = mythixConfigPath;
396
+ let configPath = mythixConfigPath;
394
397
 
395
398
  try {
396
399
  let stats = FileSystem.statSync(mythixConfigPath);
@@ -112,6 +112,7 @@ module.exports = defineCommand('deploy', ({ Parent }) => {
112
112
 
113
113
  let {
114
114
  relativeFileName,
115
+ stats,
115
116
  } = context;
116
117
 
117
118
  let shouldIncludeFile = true;
@@ -121,7 +122,7 @@ module.exports = defineCommand('deploy', ({ Parent }) => {
121
122
  if (useGitIgnore && matchesAnyPattern(useGitIgnore))
122
123
  shouldIncludeFile = false;
123
124
 
124
- if (Nife.isNotEmpty(include))
125
+ if (Nife.isNotEmpty(include) && !stats.isDirectory())
125
126
  shouldIncludeFile = matchesAnyPattern(include);
126
127
 
127
128
  if (Nife.isNotEmpty(exclude) && matchesAnyPattern(exclude))
@@ -288,6 +289,10 @@ module.exports = defineCommand('deploy', ({ Parent }) => {
288
289
  }
289
290
  }
290
291
 
292
+ async postCloneProject() {
293
+
294
+ }
295
+
291
296
  async copyFile(dryRun, sourceFilePath, targetFilePath) {
292
297
  let targetDir = Path.dirname(targetFilePath);
293
298
  if (!FileSystem.existsSync(targetDir))
@@ -297,6 +302,14 @@ module.exports = defineCommand('deploy', ({ Parent }) => {
297
302
  FileSystem.copyFileSync(sourceFilePath, targetFilePath);
298
303
  }
299
304
 
305
+ formatOutputPath(context, deployConfig) {
306
+ let { formatOutputPath } = deployConfig;
307
+ if (typeof formatOutputPath === 'function')
308
+ return formatOutputPath.call(this, context, deployConfig);
309
+
310
+ return context.targetPath;
311
+ }
312
+
300
313
  async copyProjectFilesToDeployFolder(deployConfig) {
301
314
  let {
302
315
  tempLocation,
@@ -316,7 +329,13 @@ module.exports = defineCommand('deploy', ({ Parent }) => {
316
329
  for (let i = 0, il = filesToDeploy.length; i < il; i++) {
317
330
  let sourcePath = filesToDeploy[i];
318
331
  let relativeFilePath = sourcePath.substring(projectLocation.length).replace(/^[/\\]+/, '');
319
- let targetPath = Path.join(deployFolderLocation, relativeFilePath);
332
+ let targetPath = this.formatOutputPath({
333
+ targetPath: Path.join(deployFolderLocation, relativeFilePath),
334
+ outputPath: projectLocation,
335
+ deployPath: deployFolderLocation,
336
+ relativeFilePath,
337
+ sourcePath,
338
+ }, deployConfig);
320
339
 
321
340
  await this.copyFile(dryRun, sourcePath, targetPath);
322
341
  }
@@ -335,19 +354,19 @@ module.exports = defineCommand('deploy', ({ Parent }) => {
335
354
 
336
355
  let deployLocation = Path.join(tempLocation, ('' + version));
337
356
 
338
- if (!installModulesCommand) {
357
+ if (installModulesCommand == null) {
339
358
  let yarnLockLocation = Path.join(deployLocation, 'yarn.lock');
340
359
  if (FileSystem.existsSync(yarnLockLocation))
341
360
  installModulesCommand = { command: 'bash', args: [ '--login', '-c', '"yarn --prod"' ] };
342
361
  else
343
362
  installModulesCommand = { command: 'bash', args: [ '--login', '-c', '"npm i --omit=dev"' ] };
344
- } else if (Nife.isEmpty(typeof installModulesCommand !== 'function' && Nife.isEmpty(installModulesCommand.command))) {
363
+ } else if (installModulesCommand !== false && Nife.isEmpty(typeof installModulesCommand !== 'function' && Nife.isEmpty(installModulesCommand.command))) {
345
364
  throw new Error('You specified a "installModulesCommand" in your deploy config, but no "command" property found... you need to specify "installModulesCommand" as an object "{ installModulesCommand: { command: "npm", args: [ "i" ] } }", or as a function.');
346
365
  }
347
366
 
348
367
  if (typeof installModulesCommand === 'function') {
349
368
  await installModulesCommand(deployConfig);
350
- } else {
369
+ } else if (installModulesCommand) {
351
370
  await this.executeRemoteCommands(target, deployConfig, [
352
371
  { sudo: false, command: 'cd', args: [ `"${remoteLocation}"` ]},
353
372
  installModulesCommand,
@@ -361,6 +380,7 @@ module.exports = defineCommand('deploy', ({ Parent }) => {
361
380
 
362
381
  async archiveProject(deployConfig) {
363
382
  let {
383
+ dryRun,
364
384
  tempLocation,
365
385
  version,
366
386
  } = deployConfig;
@@ -368,7 +388,7 @@ module.exports = defineCommand('deploy', ({ Parent }) => {
368
388
  let archiveLocation = deployConfig.archiveLocation = Path.join(tempLocation, `${version}.tar.gz`);
369
389
 
370
390
  await this.spawnCommand(
371
- false,
391
+ dryRun,
372
392
  'tar',
373
393
  [
374
394
  '-czf',
@@ -552,9 +572,15 @@ module.exports = defineCommand('deploy', ({ Parent }) => {
552
572
  if (typeof target.preDeploy === 'function')
553
573
  return await target.preDeploy.call(this, target, deployConfig);
554
574
 
555
- await this.executeRemoteCommands(target, deployConfig, [
556
- { command: 'mkdir', args: [ '-p', this.joinUnixPath(decodeURIComponent(target.pathname), 'shared') ] },
557
- ]);
575
+ let {
576
+ relativeConfigPath,
577
+ } = deployConfig;
578
+
579
+ if (relativeConfigPath) {
580
+ await this.executeRemoteCommands(target, deployConfig, [
581
+ { command: 'mkdir', args: [ '-p', this.joinUnixPath(decodeURIComponent(target.pathname), 'shared') ] },
582
+ ]);
583
+ }
558
584
  }
559
585
 
560
586
  async allRemotesDeploy(deployConfig) {
@@ -653,26 +679,28 @@ module.exports = defineCommand('deploy', ({ Parent }) => {
653
679
  relativeConfigPath,
654
680
  } = deployConfig;
655
681
 
656
- let deployLocation = this.joinUnixPath(decodeURIComponent(target.pathname), '' + deployConfig.version);
657
- let targetConfigPath = this.joinUnixPath(decodeURIComponent(target.pathname), 'shared', 'config');
658
- let sourceConfigPath = this.joinUnixPath(deployLocation, relativeConfigPath);
659
- let nodeModulesLink = this.joinUnixPath(targetConfigPath, 'node_modules');
682
+ if (relativeConfigPath) {
683
+ let deployLocation = this.joinUnixPath(decodeURIComponent(target.pathname), '' + deployConfig.version);
684
+ let targetConfigPath = this.joinUnixPath(decodeURIComponent(target.pathname), 'shared', 'config');
685
+ let sourceConfigPath = this.joinUnixPath(deployLocation, relativeConfigPath);
686
+ let nodeModulesLink = this.joinUnixPath(targetConfigPath, 'node_modules');
660
687
 
661
- // Ensure shared/config exists
662
- await this.executeRemoteCommands(target, deployConfig, [
663
- { command: 'test', args: [ '!', '-d', `"${targetConfigPath}"`, '&&', `${this.sudo(deployConfig)}cp -a "${sourceConfigPath}" "${targetConfigPath}"`, '|| true' ] },
664
- ]);
688
+ // Ensure shared/config exists
689
+ await this.executeRemoteCommands(target, deployConfig, [
690
+ { command: 'test', args: [ '!', '-d', `"${targetConfigPath}"`, '&&', `${this.sudo(deployConfig)}cp -a "${sourceConfigPath}" "${targetConfigPath}"`, '|| true' ] },
691
+ ]);
665
692
 
666
- // Ensure shared/config/node_modules symlink exists
667
- await this.executeRemoteCommands(target, deployConfig, [
668
- { command: 'test', args: [ '!', '-e', `"${nodeModulesLink}"`, '&&', `{ cd "${targetConfigPath}"; ${this.sudo(deployConfig)}ln -s "../../current/node_modules" "node_modules"; }`, '|| true' ] },
669
- ]);
693
+ // Ensure shared/config/node_modules symlink exists
694
+ await this.executeRemoteCommands(target, deployConfig, [
695
+ { command: 'test', args: [ '!', '-e', `"${nodeModulesLink}"`, '&&', `{ cd "${targetConfigPath}"; ${this.sudo(deployConfig)}ln -s "../../current/node_modules" "node_modules"; }`, '|| true' ] },
696
+ ]);
670
697
 
671
- // Remove app/config and symlink to ../shared/app/config
672
- await this.executeRemoteCommands(target, deployConfig, [
673
- { command: 'rm', args: [ '-fr', `"${sourceConfigPath}"` ] },
674
- { command: 'ln', args: [ '-s', `"${targetConfigPath}"`, `"${sourceConfigPath}"` ] },
675
- ]);
698
+ // Remove app/config and symlink to ../shared/app/config
699
+ await this.executeRemoteCommands(target, deployConfig, [
700
+ { command: 'rm', args: [ '-fr', `"${sourceConfigPath}"` ] },
701
+ { command: 'ln', args: [ '-s', `"${targetConfigPath}"`, `"${sourceConfigPath}"` ] },
702
+ ]);
703
+ }
676
704
 
677
705
  await this.installModulesForApp(target, deployConfig);
678
706
  }
@@ -692,7 +720,7 @@ module.exports = defineCommand('deploy', ({ Parent }) => {
692
720
  { command: 'ls', args: [ '-1', `"${deployLocation}"`, '|', 'grep', '-P', '"\\d+"' ] },
693
721
  ]);
694
722
 
695
- let versions = result.stdout.split(/\n+/g).map((part) => part.trim()).filter(Boolean).sort();
723
+ let versions = (result.stdout || '').split(/\n+/g).map((part) => part.trim()).filter(Boolean).sort();
696
724
  let versionsToRemove = versions.slice(0, -LATEST_DEPLOY_VERSIONS_TO_KEEP);
697
725
 
698
726
  if (Nife.isNotEmpty(versionsToRemove)) {
@@ -717,7 +745,7 @@ module.exports = defineCommand('deploy', ({ Parent }) => {
717
745
  { command: 'ln', args: [ '-s', `"${deployLocation}"`, `"${currentLinkLocation}"` ] },
718
746
  ]);
719
747
 
720
- if (target.index === 0) {
748
+ if (target.index === 0 && deployConfig.migrations !== false) {
721
749
  let targetLocation = `"${decodeURIComponent(target.pathname)}/current"`;
722
750
 
723
751
  let serviceUser = target.serviceUser || target.uri.username;
@@ -732,11 +760,11 @@ module.exports = defineCommand('deploy', ({ Parent }) => {
732
760
  // Cleanup old deploy versions
733
761
  await this.cleanupOldDeployVersions(target, deployConfig);
734
762
 
735
- if (Nife.isNotEmpty(target.restartService)) {
763
+ if (target.restartService !== false && Nife.isNotEmpty(target.restartService)) {
736
764
  await this.executeRemoteCommands(target, deployConfig, [
737
765
  target.restartService,
738
766
  ]);
739
- } else {
767
+ } else if (target.restartService !== false) {
740
768
  console.log(` !!!NOTICE!!! "restartService" command is not defined on your deploy "targets[${target.index}]". Your service will not be automatically restarted. Please make sure to manually restart your application service on this remote target.`);
741
769
  }
742
770
  }
@@ -809,7 +837,8 @@ module.exports = defineCommand('deploy', ({ Parent }) => {
809
837
  if (!deployConfig.rootPath)
810
838
  deployConfig.rootPath = Path.dirname(configPath);
811
839
 
812
- deployConfig.relativeConfigPath = appOptions.configPath.substring(deployConfig.rootPath.length).replace(/^[/\\.]+/, '').replace(/[/\\]+$/, '');
840
+ if (appOptions.configPath)
841
+ deployConfig.relativeConfigPath = appOptions.configPath.substring(deployConfig.rootPath.length).replace(/^[/\\.]+/, '').replace(/[/\\]+$/, '');
813
842
 
814
843
  let git = deployConfig.git || {};
815
844
  if (git.useGitIgnore) {
@@ -894,7 +923,7 @@ module.exports = defineCommand('deploy', ({ Parent }) => {
894
923
 
895
924
  console.log(`-------- Deploy ${deployConfig.version} --------`);
896
925
  console.log(` Application name: ${appName}`);
897
- console.log(` Application config location: ./${deployConfig.relativeConfigPath}`);
926
+ console.log(` Application config location: ${(deployConfig.relativeConfigPath) ? `./${deployConfig.relativeConfigPath}` : '<none>'}`);
898
927
  console.log(` Temporary file location: ${deployConfig.tempLocation}`);
899
928
  console.log(` Project file location: ${deployConfig.rootPath}`);
900
929
  console.log('');
@@ -916,8 +945,8 @@ module.exports = defineCommand('deploy', ({ Parent }) => {
916
945
  console.log(' Command log:');
917
946
 
918
947
  try {
919
- this.mkdirSync(dryRun, tempLocation);
920
- this.mkdirSync(dryRun, Path.join(tempLocation, deployConfig.version));
948
+ this.mkdirSync(false, tempLocation);
949
+ this.mkdirSync(false, Path.join(tempLocation, deployConfig.version));
921
950
 
922
951
  if (Nife.isNotEmpty(branch) && Nife.isEmpty(repository)) {
923
952
  repository = await this.getRepositoryURL(remoteName);
@@ -926,6 +955,7 @@ module.exports = defineCommand('deploy', ({ Parent }) => {
926
955
  }
927
956
 
928
957
  await this.cloneProject(deployConfig);
958
+ await this.postCloneProject(deployConfig);
929
959
  await this.copyProjectFilesToDeployFolder(deployConfig);
930
960
  await this.prepProjectPreDeploy(deployConfig);
931
961
  await this.archiveProject(deployConfig);