mythix 2.8.2 → 2.8.4

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.2",
3
+ "version": "2.8.4",
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);
@@ -288,6 +288,10 @@ module.exports = defineCommand('deploy', ({ Parent }) => {
288
288
  }
289
289
  }
290
290
 
291
+ async postCloneProject() {
292
+
293
+ }
294
+
291
295
  async copyFile(dryRun, sourceFilePath, targetFilePath) {
292
296
  let targetDir = Path.dirname(targetFilePath);
293
297
  if (!FileSystem.existsSync(targetDir))
@@ -361,6 +365,7 @@ module.exports = defineCommand('deploy', ({ Parent }) => {
361
365
 
362
366
  async archiveProject(deployConfig) {
363
367
  let {
368
+ dryRun,
364
369
  tempLocation,
365
370
  version,
366
371
  } = deployConfig;
@@ -368,7 +373,7 @@ module.exports = defineCommand('deploy', ({ Parent }) => {
368
373
  let archiveLocation = deployConfig.archiveLocation = Path.join(tempLocation, `${version}.tar.gz`);
369
374
 
370
375
  await this.spawnCommand(
371
- false,
376
+ dryRun,
372
377
  'tar',
373
378
  [
374
379
  '-czf',
@@ -653,26 +658,28 @@ module.exports = defineCommand('deploy', ({ Parent }) => {
653
658
  relativeConfigPath,
654
659
  } = deployConfig;
655
660
 
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');
661
+ if (relativeConfigPath) {
662
+ let deployLocation = this.joinUnixPath(decodeURIComponent(target.pathname), '' + deployConfig.version);
663
+ let targetConfigPath = this.joinUnixPath(decodeURIComponent(target.pathname), 'shared', 'config');
664
+ let sourceConfigPath = this.joinUnixPath(deployLocation, relativeConfigPath);
665
+ let nodeModulesLink = this.joinUnixPath(targetConfigPath, 'node_modules');
660
666
 
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
- ]);
667
+ // Ensure shared/config exists
668
+ await this.executeRemoteCommands(target, deployConfig, [
669
+ { command: 'test', args: [ '!', '-d', `"${targetConfigPath}"`, '&&', `${this.sudo(deployConfig)}cp -a "${sourceConfigPath}" "${targetConfigPath}"`, '|| true' ] },
670
+ ]);
665
671
 
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
- ]);
672
+ // Ensure shared/config/node_modules symlink exists
673
+ await this.executeRemoteCommands(target, deployConfig, [
674
+ { command: 'test', args: [ '!', '-e', `"${nodeModulesLink}"`, '&&', `{ cd "${targetConfigPath}"; ${this.sudo(deployConfig)}ln -s "../../current/node_modules" "node_modules"; }`, '|| true' ] },
675
+ ]);
670
676
 
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
- ]);
677
+ // Remove app/config and symlink to ../shared/app/config
678
+ await this.executeRemoteCommands(target, deployConfig, [
679
+ { command: 'rm', args: [ '-fr', `"${sourceConfigPath}"` ] },
680
+ { command: 'ln', args: [ '-s', `"${targetConfigPath}"`, `"${sourceConfigPath}"` ] },
681
+ ]);
682
+ }
676
683
 
677
684
  await this.installModulesForApp(target, deployConfig);
678
685
  }
@@ -692,7 +699,7 @@ module.exports = defineCommand('deploy', ({ Parent }) => {
692
699
  { command: 'ls', args: [ '-1', `"${deployLocation}"`, '|', 'grep', '-P', '"\\d+"' ] },
693
700
  ]);
694
701
 
695
- let versions = result.stdout.split(/\n+/g).map((part) => part.trim()).filter(Boolean).sort();
702
+ let versions = (result.stdout || '').split(/\n+/g).map((part) => part.trim()).filter(Boolean).sort();
696
703
  let versionsToRemove = versions.slice(0, -LATEST_DEPLOY_VERSIONS_TO_KEEP);
697
704
 
698
705
  if (Nife.isNotEmpty(versionsToRemove)) {
@@ -809,7 +816,8 @@ module.exports = defineCommand('deploy', ({ Parent }) => {
809
816
  if (!deployConfig.rootPath)
810
817
  deployConfig.rootPath = Path.dirname(configPath);
811
818
 
812
- deployConfig.relativeConfigPath = appOptions.configPath.substring(deployConfig.rootPath.length).replace(/^[/\\.]+/, '').replace(/[/\\]+$/, '');
819
+ if (appOptions.configPath)
820
+ deployConfig.relativeConfigPath = appOptions.configPath.substring(deployConfig.rootPath.length).replace(/^[/\\.]+/, '').replace(/[/\\]+$/, '');
813
821
 
814
822
  let git = deployConfig.git || {};
815
823
  if (git.useGitIgnore) {
@@ -894,7 +902,7 @@ module.exports = defineCommand('deploy', ({ Parent }) => {
894
902
 
895
903
  console.log(`-------- Deploy ${deployConfig.version} --------`);
896
904
  console.log(` Application name: ${appName}`);
897
- console.log(` Application config location: ./${deployConfig.relativeConfigPath}`);
905
+ console.log(` Application config location: ${(deployConfig.relativeConfigPath) ? `./${deployConfig.relativeConfigPath}` : '<none>'}`);
898
906
  console.log(` Temporary file location: ${deployConfig.tempLocation}`);
899
907
  console.log(` Project file location: ${deployConfig.rootPath}`);
900
908
  console.log('');
@@ -916,8 +924,8 @@ module.exports = defineCommand('deploy', ({ Parent }) => {
916
924
  console.log(' Command log:');
917
925
 
918
926
  try {
919
- this.mkdirSync(dryRun, tempLocation);
920
- this.mkdirSync(dryRun, Path.join(tempLocation, deployConfig.version));
927
+ this.mkdirSync(false, tempLocation);
928
+ this.mkdirSync(false, Path.join(tempLocation, deployConfig.version));
921
929
 
922
930
  if (Nife.isNotEmpty(branch) && Nife.isEmpty(repository)) {
923
931
  repository = await this.getRepositoryURL(remoteName);
@@ -926,6 +934,7 @@ module.exports = defineCommand('deploy', ({ Parent }) => {
926
934
  }
927
935
 
928
936
  await this.cloneProject(deployConfig);
937
+ await this.postCloneProject(deployConfig);
929
938
  await this.copyProjectFilesToDeployFolder(deployConfig);
930
939
  await this.prepProjectPreDeploy(deployConfig);
931
940
  await this.archiveProject(deployConfig);
@@ -59,16 +59,17 @@ module.exports = defineCommand('migrate', ({ Parent }) => {
59
59
  let revision = ('' + _revision);
60
60
 
61
61
  let index = migrationFiles.findIndex((fullFileName) => {
62
- let fileName = Path.basename(fullFileName);
62
+ let fileName = Path.basename(fullFileName);
63
+ let migrationFileTS = fileName.substring(0, TIMESTAMP_LENGTH);
63
64
 
64
- if (fileName.substring(0, TIMESTAMP_LENGTH) === revision)
65
+ if (BigInt(revision) >= BigInt(migrationFileTS))
65
66
  return true;
66
67
 
67
68
  return false;
68
69
  });
69
70
 
70
71
  if (index < 0)
71
- throw new Error(`Error, migration revision ${revision} not found. Aborting...`);
72
+ return migrationFiles.slice();
72
73
 
73
74
  return migrationFiles.slice((isRollback) ? index : index + 1);
74
75
  }