velocious 1.0.88 → 1.0.89
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 +1 -1
- package/src/cli/base-command.js +25 -2
- package/src/cli/commands/destroy/migration.js +1 -29
- package/src/cli/commands/generate/migration.js +1 -27
- package/src/cli/commands/generate/model.js +1 -27
- package/src/cli/index.js +1 -1
- package/src/environment-handlers/base.js +14 -0
- package/src/environment-handlers/browser.js +12 -0
- package/src/environment-handlers/node/cli/commands/destroy/migration.js +35 -0
- package/src/environment-handlers/node/cli/commands/generate/migration.js +33 -0
- package/src/environment-handlers/node/cli/commands/generate/model.js +33 -0
- package/src/environment-handlers/node.js +15 -0
- package/src/cli/commands/destroy/migration.native.js +0 -7
- package/src/cli/commands/generate/migration.native.js +0 -7
- package/src/cli/commands/generate/model.native.js +0 -7
package/package.json
CHANGED
package/src/cli/base-command.js
CHANGED
|
@@ -1,16 +1,39 @@
|
|
|
1
1
|
import restArgsError from "../utils/rest-args-error.js"
|
|
2
2
|
|
|
3
3
|
export default class VelociousCliBaseCommand {
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* @param {object} args
|
|
6
|
+
* @param {object} args.args
|
|
7
|
+
*/
|
|
8
|
+
constructor({args = {}, ...restArgs}) {
|
|
5
9
|
restArgsError(restArgs)
|
|
6
10
|
|
|
7
11
|
this.args = args
|
|
8
12
|
this._configuration = args.configuration
|
|
9
|
-
this._environmentHandler =
|
|
13
|
+
this._environmentHandler = args.configuration.getEnvironmentHandler()
|
|
10
14
|
this.processArgs = args.processArgs
|
|
11
15
|
}
|
|
12
16
|
|
|
17
|
+
/**
|
|
18
|
+
* @returns {string}
|
|
19
|
+
*/
|
|
13
20
|
directory() { return this.getConfiguration().getDirectory() }
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @interface
|
|
24
|
+
*/
|
|
25
|
+
execute() {
|
|
26
|
+
throw new Error("execute not implemented")
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @returns {import("../configuration.js").default}
|
|
31
|
+
*/
|
|
14
32
|
getConfiguration() { return this._configuration }
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @template T extends import("../environment-handlers/base.js").default
|
|
36
|
+
* @returns {T}
|
|
37
|
+
*/
|
|
15
38
|
getEnvironmentHandler() { return this._environmentHandler }
|
|
16
39
|
}
|
|
@@ -1,35 +1,7 @@
|
|
|
1
1
|
import BaseCommand from "../../base-command.js"
|
|
2
|
-
import fs from "fs/promises"
|
|
3
2
|
|
|
4
3
|
export default class DbDestroyMigration extends BaseCommand {
|
|
5
4
|
async execute() {
|
|
6
|
-
|
|
7
|
-
const migrationDir = `${this.getConfiguration().getDirectory()}/src/database/migrations`
|
|
8
|
-
const migrationFiles = await fs.readdir(migrationDir)
|
|
9
|
-
const destroyed = []
|
|
10
|
-
|
|
11
|
-
for (const migrationFile of migrationFiles) {
|
|
12
|
-
const match = migrationFile.match(/^(\d{14})-(.+)\.js$/)
|
|
13
|
-
|
|
14
|
-
if (!match) {
|
|
15
|
-
continue
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const fileName = match[2]
|
|
19
|
-
|
|
20
|
-
if (fileName != migrationName) continue
|
|
21
|
-
|
|
22
|
-
const fullFilePath = `${migrationDir}/${migrationFile}`
|
|
23
|
-
destroyed.push(fileName)
|
|
24
|
-
|
|
25
|
-
if (!this.args.testing) {
|
|
26
|
-
console.log(`Destroy src/database/migrations/${migrationFile}`)
|
|
27
|
-
await fs.unlink(fullFilePath)
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (this.args.testing) {
|
|
32
|
-
return {destroyed}
|
|
33
|
-
}
|
|
5
|
+
return await this.getConfiguration().getEnvironmentHandler().cliCommandsMigrationDestroy(this)
|
|
34
6
|
}
|
|
35
7
|
}
|
|
@@ -1,33 +1,7 @@
|
|
|
1
1
|
import BaseCommand from "../../base-command.js"
|
|
2
|
-
import fileExists from "../../../utils/file-exists.js"
|
|
3
|
-
import fs from "fs/promises"
|
|
4
|
-
import * as inflection from "inflection"
|
|
5
|
-
import strftime from "strftime"
|
|
6
2
|
|
|
7
3
|
export default class DbGenerateMigration extends BaseCommand {
|
|
8
4
|
async execute() {
|
|
9
|
-
|
|
10
|
-
const migrationNameCamelized = inflection.camelize(migrationName.replaceAll("-", "_"))
|
|
11
|
-
const date = new Date()
|
|
12
|
-
const migrationNumber = strftime("%Y%m%d%H%M%S")
|
|
13
|
-
const migrationFileName = `${migrationNumber}-${migrationName}.js`
|
|
14
|
-
const velociousPath = await this.getEnvironmentHandler().getVelociousPath()
|
|
15
|
-
const templateFilePath = `${velociousPath}/src/templates/generate-migration.js`
|
|
16
|
-
const migrationContentBuffer = await fs.readFile(templateFilePath)
|
|
17
|
-
const migrationContent = migrationContentBuffer.toString().replaceAll("__MIGRATION_NAME__", migrationNameCamelized)
|
|
18
|
-
const migrationDir = `${process.cwd()}/src/database/migrations`
|
|
19
|
-
const migrationPath = `${migrationDir}/${migrationFileName}`
|
|
20
|
-
|
|
21
|
-
if (this.args.testing) {
|
|
22
|
-
return {date, migrationContent, migrationName, migrationNameCamelized, migrationNumber, migrationPath}
|
|
23
|
-
} else {
|
|
24
|
-
if (!await fileExists(migrationDir)) {
|
|
25
|
-
await fs.mkdir(migrationDir, {recursive: true})
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
await fs.writeFile(migrationPath, migrationContent)
|
|
29
|
-
|
|
30
|
-
console.log(`create src/database/migrations/${migrationFileName}`)
|
|
31
|
-
}
|
|
5
|
+
return await this.getConfiguration().getEnvironmentHandler().cliCommandsMigrationGenerate(this)
|
|
32
6
|
}
|
|
33
7
|
}
|
|
@@ -1,33 +1,7 @@
|
|
|
1
1
|
import BaseCommand from "../../base-command.js"
|
|
2
|
-
import fileExists from "../../../utils/file-exists.js"
|
|
3
|
-
import fs from "fs/promises"
|
|
4
|
-
import * as inflection from "inflection"
|
|
5
2
|
|
|
6
3
|
export default class DbGenerateModel extends BaseCommand {
|
|
7
4
|
async execute() {
|
|
8
|
-
|
|
9
|
-
const modelNameCamelized = inflection.camelize(modelName.replaceAll("-", "_"))
|
|
10
|
-
const date = new Date()
|
|
11
|
-
const modelFileName = `${inflection.dasherize(inflection.underscore(modelName))}.js`
|
|
12
|
-
const velociousPath = await this.getEnvironmentHandler().getVelociousPath()
|
|
13
|
-
const templateFilePath = `${velociousPath}/src/templates/generate-model.js`
|
|
14
|
-
const modelContentBuffer = await fs.readFile(templateFilePath)
|
|
15
|
-
const modelContent = modelContentBuffer.toString().replaceAll("__MODEL_NAME__", modelNameCamelized)
|
|
16
|
-
const modelsDir = `${process.cwd()}/src/models`
|
|
17
|
-
const modelPath = `${modelsDir}/${modelFileName}`
|
|
18
|
-
|
|
19
|
-
if (await fileExists(modelPath)) throw new Error(`Model file already exists: ${modelPath}`)
|
|
20
|
-
|
|
21
|
-
if (this.args.testing) {
|
|
22
|
-
return {date, modelContent, modelName, modelNameCamelized, modelPath}
|
|
23
|
-
} else {
|
|
24
|
-
if (!await fileExists(modelsDir)) {
|
|
25
|
-
await fs.mkdir(modelsDir, {recursive: true})
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
await fs.writeFile(modelPath, modelContent)
|
|
29
|
-
|
|
30
|
-
console.log(`create src/models/${modelFileName}`)
|
|
31
|
-
}
|
|
5
|
+
return await this.getConfiguration().getEnvironmentHandler().cliCommandsModelGenerate(this)
|
|
32
6
|
}
|
|
33
7
|
}
|
package/src/cli/index.js
CHANGED
|
@@ -23,7 +23,7 @@ export default class VelociousCli {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
const CommandClass = await this.environmentHandler.requireCommand({commandParts: parsedCommandParts})
|
|
26
|
-
const commandInstance = new CommandClass({args: this.args
|
|
26
|
+
const commandInstance = new CommandClass({args: this.args})
|
|
27
27
|
|
|
28
28
|
if (commandInstance.initialize) {
|
|
29
29
|
await commandInstance.initialize()
|
|
@@ -9,6 +9,20 @@ export default class VelociousEnvironmentHandlerBase {
|
|
|
9
9
|
*/
|
|
10
10
|
async findMigrations() { throw new Error("findMigrations not implemneted") }
|
|
11
11
|
|
|
12
|
+
/**
|
|
13
|
+
* @template T extends import("../cli/base-command.js").default
|
|
14
|
+
* @param {T} command
|
|
15
|
+
* @param {typeof T} CommandClass
|
|
16
|
+
* @returns {any}
|
|
17
|
+
*/
|
|
18
|
+
async forwardCommand(command, CommandClass) {
|
|
19
|
+
const newCommand = new CommandClass({
|
|
20
|
+
args: command.args
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
return await newCommand.execute()
|
|
24
|
+
}
|
|
25
|
+
|
|
12
26
|
/**
|
|
13
27
|
* @interface
|
|
14
28
|
*/
|
|
@@ -15,6 +15,18 @@ export default class VelociousEnvironmentsHandlerBrowser extends Base {
|
|
|
15
15
|
this.migrationsRequireContextCallback = migrationsRequireContextCallback
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
async cliCommandsMigrationGenerate(_command) { // eslint-disable-line no-unused-vars
|
|
19
|
+
throw new Error("Unsupported on browser")
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async cliCommandsMigrationDestroy(_command) { // eslint-disable-line no-unused-vars
|
|
23
|
+
throw new Error("Unsupported on browser")
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async cliCommandsModelGenerate(_command) { // eslint-disable-line no-unused-vars
|
|
27
|
+
throw new Error("Unsupported on browser")
|
|
28
|
+
}
|
|
29
|
+
|
|
18
30
|
/**
|
|
19
31
|
* @returns {object}
|
|
20
32
|
*/
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import BaseCommand from "../../../../../cli/base-command.js"
|
|
2
|
+
import fs from "fs/promises"
|
|
3
|
+
|
|
4
|
+
export default class DbDestroyMigration extends BaseCommand {
|
|
5
|
+
async execute() {
|
|
6
|
+
const migrationName = this.processArgs[1]
|
|
7
|
+
const migrationDir = `${this.getConfiguration().getDirectory()}/src/database/migrations`
|
|
8
|
+
const migrationFiles = await fs.readdir(migrationDir)
|
|
9
|
+
const destroyed = []
|
|
10
|
+
|
|
11
|
+
for (const migrationFile of migrationFiles) {
|
|
12
|
+
const match = migrationFile.match(/^(\d{14})-(.+)\.js$/)
|
|
13
|
+
|
|
14
|
+
if (!match) {
|
|
15
|
+
continue
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const fileName = match[2]
|
|
19
|
+
|
|
20
|
+
if (fileName != migrationName) continue
|
|
21
|
+
|
|
22
|
+
const fullFilePath = `${migrationDir}/${migrationFile}`
|
|
23
|
+
destroyed.push(fileName)
|
|
24
|
+
|
|
25
|
+
if (!this.args.testing) {
|
|
26
|
+
console.log(`Destroy src/database/migrations/${migrationFile}`)
|
|
27
|
+
await fs.unlink(fullFilePath)
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (this.args.testing) {
|
|
32
|
+
return {destroyed}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import BaseCommand from "../../../../../cli/base-command.js"
|
|
2
|
+
import fileExists from "../../../../../utils/file-exists.js"
|
|
3
|
+
import fs from "fs/promises"
|
|
4
|
+
import * as inflection from "inflection"
|
|
5
|
+
import strftime from "strftime"
|
|
6
|
+
|
|
7
|
+
export default class DbGenerateMigration extends BaseCommand {
|
|
8
|
+
async execute() {
|
|
9
|
+
const migrationName = this.processArgs[1]
|
|
10
|
+
const migrationNameCamelized = inflection.camelize(migrationName.replaceAll("-", "_"))
|
|
11
|
+
const date = new Date()
|
|
12
|
+
const migrationNumber = strftime("%Y%m%d%H%M%S")
|
|
13
|
+
const migrationFileName = `${migrationNumber}-${migrationName}.js`
|
|
14
|
+
const velociousPath = await this.getEnvironmentHandler().getVelociousPath()
|
|
15
|
+
const templateFilePath = `${velociousPath}/src/templates/generate-migration.js`
|
|
16
|
+
const migrationContentBuffer = await fs.readFile(templateFilePath)
|
|
17
|
+
const migrationContent = migrationContentBuffer.toString().replaceAll("__MIGRATION_NAME__", migrationNameCamelized)
|
|
18
|
+
const migrationDir = `${process.cwd()}/src/database/migrations`
|
|
19
|
+
const migrationPath = `${migrationDir}/${migrationFileName}`
|
|
20
|
+
|
|
21
|
+
if (this.args.testing) {
|
|
22
|
+
return {date, migrationContent, migrationName, migrationNameCamelized, migrationNumber, migrationPath}
|
|
23
|
+
} else {
|
|
24
|
+
if (!await fileExists(migrationDir)) {
|
|
25
|
+
await fs.mkdir(migrationDir, {recursive: true})
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
await fs.writeFile(migrationPath, migrationContent)
|
|
29
|
+
|
|
30
|
+
console.log(`create src/database/migrations/${migrationFileName}`)
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import BaseCommand from "../../../../../cli/base-command.js"
|
|
2
|
+
import fileExists from "../../../../../utils/file-exists.js"
|
|
3
|
+
import fs from "fs/promises"
|
|
4
|
+
import * as inflection from "inflection"
|
|
5
|
+
|
|
6
|
+
export default class DbGenerateModel extends BaseCommand {
|
|
7
|
+
async execute() {
|
|
8
|
+
const modelName = this.processArgs[1]
|
|
9
|
+
const modelNameCamelized = inflection.camelize(modelName.replaceAll("-", "_"))
|
|
10
|
+
const date = new Date()
|
|
11
|
+
const modelFileName = `${inflection.dasherize(inflection.underscore(modelName))}.js`
|
|
12
|
+
const velociousPath = await this.getEnvironmentHandler().getVelociousPath()
|
|
13
|
+
const templateFilePath = `${velociousPath}/src/templates/generate-model.js`
|
|
14
|
+
const modelContentBuffer = await fs.readFile(templateFilePath)
|
|
15
|
+
const modelContent = modelContentBuffer.toString().replaceAll("__MODEL_NAME__", modelNameCamelized)
|
|
16
|
+
const modelsDir = `${process.cwd()}/src/models`
|
|
17
|
+
const modelPath = `${modelsDir}/${modelFileName}`
|
|
18
|
+
|
|
19
|
+
if (await fileExists(modelPath)) throw new Error(`Model file already exists: ${modelPath}`)
|
|
20
|
+
|
|
21
|
+
if (this.args.testing) {
|
|
22
|
+
return {date, modelContent, modelName, modelNameCamelized, modelPath}
|
|
23
|
+
} else {
|
|
24
|
+
if (!await fileExists(modelsDir)) {
|
|
25
|
+
await fs.mkdir(modelsDir, {recursive: true})
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
await fs.writeFile(modelPath, modelContent)
|
|
29
|
+
|
|
30
|
+
console.log(`create src/models/${modelFileName}`)
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import Base from "./base.js"
|
|
2
|
+
import CliCommandsDestroyMigration from "./node/cli/commands/destroy/migration.js"
|
|
3
|
+
import CliCommandsGenerateMigration from "./node/cli/commands/generate/migration.js"
|
|
4
|
+
import CliCommandsGenerateModel from "./node/cli/commands/generate/model.js"
|
|
2
5
|
import {dirname} from "path"
|
|
3
6
|
import {fileURLToPath} from "url"
|
|
4
7
|
import fs from "fs/promises"
|
|
@@ -42,6 +45,18 @@ export default class VelociousEnvironmentHandlerNode extends Base{
|
|
|
42
45
|
return commands
|
|
43
46
|
}
|
|
44
47
|
|
|
48
|
+
async cliCommandsMigrationGenerate(command) {
|
|
49
|
+
return await this.forwardCommand(command, CliCommandsGenerateMigration)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async cliCommandsMigrationDestroy(command) {
|
|
53
|
+
return await this.forwardCommand(command, CliCommandsDestroyMigration)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async cliCommandsModelGenerate(command) {
|
|
57
|
+
return await this.forwardCommand(command, CliCommandsGenerateModel)
|
|
58
|
+
}
|
|
59
|
+
|
|
45
60
|
/**
|
|
46
61
|
* @param {Array<string>} commandParts
|
|
47
62
|
* @template T extends import ("./base-command.js").default
|