velocious 1.0.89 → 1.0.91

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
@@ -3,7 +3,7 @@
3
3
  "velocious": "bin/velocious.js"
4
4
  },
5
5
  "name": "velocious",
6
- "version": "1.0.89",
6
+ "version": "1.0.91",
7
7
  "main": "index.js",
8
8
  "scripts": {
9
9
  "lint": "eslint",
@@ -1,56 +1,8 @@
1
1
  import BaseCommand from "../base-command.js"
2
- import fileExists from "../../utils/file-exists.js"
3
- import fs from "fs/promises"
4
2
 
5
3
  export default class VelociousCliCommandsInit extends BaseCommand {
6
4
  async execute() {
7
- const velociousPath = await this.getEnvironmentHandler().getVelociousPath()
8
- const projectPath = this.getConfiguration()?.getDirectory() || process.cwd()
9
- const projectConfigPath = `${projectPath}/src/config`
10
- const fileMappings = [
11
- {
12
- source: `${velociousPath}/src/templates/configuration.js`,
13
- target: `${projectConfigPath}/configuration.js`
14
- },
15
- {
16
- source: `${velociousPath}/src/templates/routes.js`,
17
- target: `${projectConfigPath}/routes.js`
18
- }
19
- ]
20
- const paths = [
21
- projectConfigPath,
22
- `${projectPath}/src/database/migrations`,
23
- `${projectPath}/src/models`,
24
- `${projectPath}/src/routes`
25
- ]
26
-
27
- if (this.args.testing) {
28
- return {
29
- fileMappings
30
- }
31
- }
32
-
33
- for (const path of paths) {
34
- if (await fileExists(path)) {
35
- console.log(`Config dir already exists: ${path}`)
36
- } else {
37
- console.log(`Config dir doesn't exists: ${path}`)
38
- await fs.mkdir(path, {recursive: true})
39
- }
40
- }
41
-
42
- for (const fileMapping of fileMappings) {
43
- if (!await fileExists(fileMapping.source)) {
44
- throw new Error(`Template doesn't exist: ${fileMapping.source}`)
45
- }
46
-
47
- if (await fileExists(fileMapping.target)) {
48
- console.log(`File already exists: ${fileMapping.target}`)
49
- } else {
50
- console.log(`File doesnt exist: ${fileMapping.target}`)
51
- await fs.copyFile(fileMapping.source, fileMapping.target)
52
- }
53
- }
5
+ return await this.getConfiguration().getEnvironmentHandler().cliCommandsInit(this)
54
6
  }
55
7
  }
56
8
 
@@ -1,33 +1,7 @@
1
1
  import BaseCommand from "../base-command.js"
2
- import TestFilesFinder from "../../testing/test-files-finder.js"
3
- import TestRunner from "../../testing/test-runner.js"
4
2
 
5
3
  export default class VelociousCliCommandsTest extends BaseCommand {
6
4
  async execute() {
7
- this.getConfiguration().setEnvironment("test")
8
-
9
- const directory = process.env.VELOCIOUS_TEST_DIR || this.directory()
10
- const testFilesFinder = new TestFilesFinder({directory, processArgs: this.processArgs})
11
- const testFiles = await testFilesFinder.findTestFiles()
12
- const testRunner = new TestRunner({configuration: this.getConfiguration(), testFiles})
13
-
14
- await testRunner.prepare()
15
-
16
- if (testRunner.getTestsCount() === 0) {
17
- throw new Error("No tests has been found")
18
- }
19
-
20
- await testRunner.run()
21
-
22
- if (testRunner.isFailed()) {
23
- console.error(`\nTest run failed with ${testRunner.getFailedTests()} failed tests and ${testRunner.getSuccessfulTests()} successfull`)
24
- process.exit(1)
25
- } else if (testRunner.areAnyTestsFocussed()) {
26
- console.error(`\nFocussed run with ${testRunner.getFailedTests()} failed tests and ${testRunner.getSuccessfulTests()} successfull`)
27
- process.exit(1)
28
- } else {
29
- console.log(`\nTest run succeeded with ${testRunner.getSuccessfulTests()} successful tests`)
30
- process.exit(0)
31
- }
5
+ return await this.getConfiguration().getEnvironmentHandler().cliCommandsTest(this)
32
6
  }
33
7
  }
@@ -15,6 +15,10 @@ export default class VelociousEnvironmentsHandlerBrowser extends Base {
15
15
  this.migrationsRequireContextCallback = migrationsRequireContextCallback
16
16
  }
17
17
 
18
+ async cliCommandsInit(_command) { // eslint-disable-line no-unused-vars
19
+ throw new Error("Unsupported on browser")
20
+ }
21
+
18
22
  async cliCommandsMigrationGenerate(_command) { // eslint-disable-line no-unused-vars
19
23
  throw new Error("Unsupported on browser")
20
24
  }
@@ -27,6 +31,10 @@ export default class VelociousEnvironmentsHandlerBrowser extends Base {
27
31
  throw new Error("Unsupported on browser")
28
32
  }
29
33
 
34
+ async cliCommandsTest(_command) { // eslint-disable-line no-unused-vars
35
+ throw new Error("Unsupported on browser")
36
+ }
37
+
30
38
  /**
31
39
  * @returns {object}
32
40
  */
@@ -0,0 +1,59 @@
1
+ import BaseCommand from "../../../../cli/base-command.js"
2
+ import fileExists from "../../../../utils/file-exists.js"
3
+ import fs from "fs/promises"
4
+
5
+ export default class VelociousCliCommandsInit extends BaseCommand {
6
+ async execute() {
7
+ const velociousPath = await this.getEnvironmentHandler().getVelociousPath()
8
+ const projectPath = this.getConfiguration()?.getDirectory() || process.cwd()
9
+ const projectConfigPath = `${projectPath}/src/config`
10
+ const fileMappings = [
11
+ {
12
+ source: `${velociousPath}/src/templates/configuration.js`,
13
+ target: `${projectConfigPath}/configuration.js`
14
+ },
15
+ {
16
+ source: `${velociousPath}/src/templates/routes.js`,
17
+ target: `${projectConfigPath}/routes.js`
18
+ }
19
+ ]
20
+ const paths = [
21
+ projectConfigPath,
22
+ `${projectPath}/src/database/migrations`,
23
+ `${projectPath}/src/models`,
24
+ `${projectPath}/src/routes`
25
+ ]
26
+
27
+ if (this.args.testing) {
28
+ return {
29
+ fileMappings
30
+ }
31
+ }
32
+
33
+ for (const path of paths) {
34
+ if (await fileExists(path)) {
35
+ console.log(`Config dir already exists: ${path}`)
36
+ } else {
37
+ console.log(`Config dir doesn't exists: ${path}`)
38
+ await fs.mkdir(path, {recursive: true})
39
+ }
40
+ }
41
+
42
+ for (const fileMapping of fileMappings) {
43
+ if (!await fileExists(fileMapping.source)) {
44
+ throw new Error(`Template doesn't exist: ${fileMapping.source}`)
45
+ }
46
+
47
+ if (await fileExists(fileMapping.target)) {
48
+ console.log(`File already exists: ${fileMapping.target}`)
49
+ } else {
50
+ console.log(`File doesnt exist: ${fileMapping.target}`)
51
+ await fs.copyFile(fileMapping.source, fileMapping.target)
52
+ }
53
+ }
54
+ }
55
+ }
56
+
57
+ const dontLoadConfiguration = true
58
+
59
+ export {dontLoadConfiguration}
@@ -0,0 +1,33 @@
1
+ import BaseCommand from "../../../../cli/base-command.js"
2
+ import TestFilesFinder from "../../../../testing/test-files-finder.js"
3
+ import TestRunner from "../../../../testing/test-runner.js"
4
+
5
+ export default class VelociousCliCommandsTest extends BaseCommand {
6
+ async execute() {
7
+ this.getConfiguration().setEnvironment("test")
8
+
9
+ const directory = process.env.VELOCIOUS_TEST_DIR || this.directory()
10
+ const testFilesFinder = new TestFilesFinder({directory, processArgs: this.processArgs})
11
+ const testFiles = await testFilesFinder.findTestFiles()
12
+ const testRunner = new TestRunner({configuration: this.getConfiguration(), testFiles})
13
+
14
+ await testRunner.prepare()
15
+
16
+ if (testRunner.getTestsCount() === 0) {
17
+ throw new Error("No tests has been found")
18
+ }
19
+
20
+ await testRunner.run()
21
+
22
+ if (testRunner.isFailed()) {
23
+ console.error(`\nTest run failed with ${testRunner.getFailedTests()} failed tests and ${testRunner.getSuccessfulTests()} successfull`)
24
+ process.exit(1)
25
+ } else if (testRunner.areAnyTestsFocussed()) {
26
+ console.error(`\nFocussed run with ${testRunner.getFailedTests()} failed tests and ${testRunner.getSuccessfulTests()} successfull`)
27
+ process.exit(1)
28
+ } else {
29
+ console.log(`\nTest run succeeded with ${testRunner.getSuccessfulTests()} successful tests`)
30
+ process.exit(0)
31
+ }
32
+ }
33
+ }
@@ -1,7 +1,9 @@
1
1
  import Base from "./base.js"
2
2
  import CliCommandsDestroyMigration from "./node/cli/commands/destroy/migration.js"
3
+ import CliCommandsInit from "./node/cli/commands/init.js"
3
4
  import CliCommandsGenerateMigration from "./node/cli/commands/generate/migration.js"
4
5
  import CliCommandsGenerateModel from "./node/cli/commands/generate/model.js"
6
+ import CliCommandsTest from "./node/cli/commands/test.js"
5
7
  import {dirname} from "path"
6
8
  import {fileURLToPath} from "url"
7
9
  import fs from "fs/promises"
@@ -45,6 +47,10 @@ export default class VelociousEnvironmentHandlerNode extends Base{
45
47
  return commands
46
48
  }
47
49
 
50
+ async cliCommandsInit(command) {
51
+ return await this.forwardCommand(command, CliCommandsInit)
52
+ }
53
+
48
54
  async cliCommandsMigrationGenerate(command) {
49
55
  return await this.forwardCommand(command, CliCommandsGenerateMigration)
50
56
  }
@@ -57,6 +63,10 @@ export default class VelociousEnvironmentHandlerNode extends Base{
57
63
  return await this.forwardCommand(command, CliCommandsGenerateModel)
58
64
  }
59
65
 
66
+ async cliCommandsTest(command) {
67
+ return await this.forwardCommand(command, CliCommandsTest)
68
+ }
69
+
60
70
  /**
61
71
  * @param {Array<string>} commandParts
62
72
  * @template T extends import ("./base-command.js").default