@devbro/pashmak 0.1.9 → 0.1.10
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/dist/app/console/DefaultCommand.mjs +3 -1
- package/dist/app/console/DefaultCommand.mjs.map +1 -1
- package/dist/app/console/KeyGenerateCommand.mjs +19 -17
- package/dist/app/console/KeyGenerateCommand.mjs.map +1 -1
- package/dist/app/console/StartCommand.mjs +9 -13
- package/dist/app/console/StartCommand.mjs.map +1 -1
- package/dist/app/console/generate/GenerateControllerCommand.mjs +14 -17
- package/dist/app/console/generate/GenerateControllerCommand.mjs.map +1 -1
- package/dist/app/console/generate/index.mjs +1 -1
- package/dist/app/console/generate/index.mjs.map +1 -1
- package/dist/app/console/index.mjs +7 -7
- package/dist/app/console/index.mjs.map +1 -1
- package/dist/app/console/migrate/GenerateMigrateCommand.mjs +14 -17
- package/dist/app/console/migrate/GenerateMigrateCommand.mjs.map +1 -1
- package/dist/app/console/migrate/MigrateCommand.mjs +5 -10
- package/dist/app/console/migrate/MigrateCommand.mjs.map +1 -1
- package/dist/app/console/migrate/MigrateRollbackCommand.mjs +2 -9
- package/dist/app/console/migrate/MigrateRollbackCommand.mjs.map +1 -1
- package/dist/app/console/migrate/index.mjs +3 -3
- package/dist/app/console/migrate/index.mjs.map +1 -1
- package/dist/app/console/project/CreateProjectCommand.mjs +17 -23
- package/dist/app/console/project/CreateProjectCommand.mjs.map +1 -1
- package/dist/bin/app/console/DefaultCommand.cjs +5 -3
- package/dist/bin/app/console/KeyGenerateCommand.cjs +23 -21
- package/dist/bin/app/console/StartCommand.cjs +11 -15
- package/dist/bin/app/console/generate/GenerateControllerCommand.cjs +20 -23
- package/dist/bin/app/console/generate/index.cjs +20 -23
- package/dist/bin/app/console/index.cjs +110 -134
- package/dist/bin/app/console/migrate/GenerateMigrateCommand.cjs +19 -22
- package/dist/bin/app/console/migrate/MigrateCommand.cjs +9 -14
- package/dist/bin/app/console/migrate/MigrateRollbackCommand.cjs +7 -14
- package/dist/bin/app/console/migrate/index.cjs +33 -48
- package/dist/bin/app/console/project/CreateProjectCommand.cjs +21 -27
- package/dist/bin/bin/pashmak_cli.cjs +21 -27
- package/dist/bin/index.cjs +123 -150
- package/dist/bin/pashmak_cli.mjs +2 -2
- package/dist/bin/pashmak_cli.mjs.map +1 -1
- package/dist/index.d.mts +1 -0
- package/dist/index.mjs +2 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -19,7 +19,9 @@ class DefaultCommand extends Command {
|
|
|
19
19
|
async execute() {
|
|
20
20
|
const commandList = cli().registrations;
|
|
21
21
|
const paths = [];
|
|
22
|
-
commandList.forEach(
|
|
22
|
+
commandList.forEach(
|
|
23
|
+
(index, val) => paths.push(index.builder.paths[0]?.join(" ") || "")
|
|
24
|
+
);
|
|
23
25
|
console.log("Available commands:");
|
|
24
26
|
for (const cmd of paths) {
|
|
25
27
|
if (cmd) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/app/console/DefaultCommand.
|
|
1
|
+
{"version":3,"sources":["../../../src/app/console/DefaultCommand.mts"],"sourcesContent":["import { Command, Option } from \"clipanion\";\nimport { cli } from \"../../facades.mjs\";\n\nexport class DefaultCommand extends Command {\n static usage = Command.Usage({\n category: `Main`,\n description: `server management command line.`,\n details: `\n The base command for running and managing your server.\n\n Make sure you understand how things work.\n `,\n examples: [],\n });\n\n async execute() {\n // @ts-ignore\n const commandList = cli().registrations; //.definitions().map((def:any) => def.paths.map((path:any) => path.join(' '))).flat();\n\n const paths: string[] = [];\n commandList.forEach((index, val) =>\n paths.push(index.builder.paths[0]?.join(\" \") || \"\"),\n );\n\n console.log(\"Available commands:\");\n for (const cmd of paths) {\n if (cmd) {\n console.log(cmd);\n }\n }\n }\n}\n\ncli().register(DefaultCommand);\n"],"mappings":";;AAAA,SAAS,eAAuB;AAChC,SAAS,WAAW;AAEb,MAAM,uBAAuB,QAAQ;AAAA,EAH5C,OAG4C;AAAA;AAAA;AAAA,EAC1C,OAAO,QAAQ,QAAQ,MAAM;AAAA,IAC3B,UAAU;AAAA,IACV,aAAa;AAAA,IACb,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA,IAKT,UAAU,CAAC;AAAA,EACb,CAAC;AAAA,EAED,MAAM,UAAU;AAEd,UAAM,cAAc,IAAI,EAAE;AAE1B,UAAM,QAAkB,CAAC;AACzB,gBAAY;AAAA,MAAQ,CAAC,OAAO,QAC1B,MAAM,KAAK,MAAM,QAAQ,MAAM,CAAC,GAAG,KAAK,GAAG,KAAK,EAAE;AAAA,IACpD;AAEA,YAAQ,IAAI,qBAAqB;AACjC,eAAW,OAAO,OAAO;AACvB,UAAI,KAAK;AACP,gBAAQ,IAAI,GAAG;AAAA,MACjB;AAAA,IACF;AAAA,EACF;AACF;AAEA,IAAI,EAAE,SAAS,cAAc;","names":[]}
|
|
@@ -9,12 +9,7 @@ class KeyGenerateCommand extends Command {
|
|
|
9
9
|
static {
|
|
10
10
|
__name(this, "KeyGenerateCommand");
|
|
11
11
|
}
|
|
12
|
-
static paths = [
|
|
13
|
-
[
|
|
14
|
-
`generate`,
|
|
15
|
-
"key"
|
|
16
|
-
]
|
|
17
|
-
];
|
|
12
|
+
static paths = [[`generate`, "key"]];
|
|
18
13
|
static usage = Command.Usage({
|
|
19
14
|
category: `Main`,
|
|
20
15
|
description: `generate keys`,
|
|
@@ -23,14 +18,8 @@ class KeyGenerateCommand extends Command {
|
|
|
23
18
|
Use --rotate flag to preserve old public key.
|
|
24
19
|
`,
|
|
25
20
|
examples: [
|
|
26
|
-
[
|
|
27
|
-
|
|
28
|
-
`generate key`
|
|
29
|
-
],
|
|
30
|
-
[
|
|
31
|
-
`Rotate existing keys`,
|
|
32
|
-
`generate key --rotate`
|
|
33
|
-
]
|
|
21
|
+
[`Generate new keys`, `generate key`],
|
|
22
|
+
[`Rotate existing keys`, `generate key --rotate`]
|
|
34
23
|
]
|
|
35
24
|
});
|
|
36
25
|
rotate = Option.Boolean(`--rotate`, false, {
|
|
@@ -40,6 +29,7 @@ class KeyGenerateCommand extends Command {
|
|
|
40
29
|
logger().info("generating keys for jwt token and adding to .env file");
|
|
41
30
|
const { publicKey, privateKey } = generateKeyPairSync("rsa", {
|
|
42
31
|
modulusLength: 2048,
|
|
32
|
+
// 2048-bit key is standard for RS256
|
|
43
33
|
publicKeyEncoding: {
|
|
44
34
|
type: "spki",
|
|
45
35
|
format: "pem"
|
|
@@ -55,10 +45,22 @@ class KeyGenerateCommand extends Command {
|
|
|
55
45
|
} catch {
|
|
56
46
|
}
|
|
57
47
|
let old_public_key = envfile.match(/^jwt_secret_public=(.*)/m);
|
|
58
|
-
envfile = this.addEnvParam(
|
|
59
|
-
|
|
48
|
+
envfile = this.addEnvParam(
|
|
49
|
+
envfile,
|
|
50
|
+
"jwt_secret_public",
|
|
51
|
+
this.stripPemHeaders(publicKey)
|
|
52
|
+
);
|
|
53
|
+
envfile = this.addEnvParam(
|
|
54
|
+
envfile,
|
|
55
|
+
"jwt_secret_private",
|
|
56
|
+
this.stripPemHeaders(privateKey)
|
|
57
|
+
);
|
|
60
58
|
if (this.rotate && old_public_key && old_public_key[1]) {
|
|
61
|
-
envfile = this.addEnvParam(
|
|
59
|
+
envfile = this.addEnvParam(
|
|
60
|
+
envfile,
|
|
61
|
+
"jwt_secret_public_retired",
|
|
62
|
+
old_public_key[1]
|
|
63
|
+
);
|
|
62
64
|
}
|
|
63
65
|
await fs.writeFile(path.join(process.cwd(), ".env"), envfile, "utf-8");
|
|
64
66
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/app/console/KeyGenerateCommand.
|
|
1
|
+
{"version":3,"sources":["../../../src/app/console/KeyGenerateCommand.mts"],"sourcesContent":["import { Command, Option } from \"clipanion\";\nimport { generateKeyPairSync } from \"crypto\";\nimport fs from \"fs/promises\";\nimport path from \"path\";\nimport { logger, cli } from \"../../facades.mjs\";\n\nexport class KeyGenerateCommand extends Command {\n static paths = [[`generate`, \"key\"]];\n\n static usage = Command.Usage({\n category: `Main`,\n description: `generate keys`,\n details: `\n This command generates RSA key pair for JWT signing.\n Use --rotate flag to preserve old public key.\n `,\n examples: [\n [`Generate new keys`, `generate key`],\n [`Rotate existing keys`, `generate key --rotate`],\n ],\n });\n\n rotate = Option.Boolean(`--rotate`, false, {\n description: `Rotate existing keys (backup old keys before replacement)`,\n });\n\n async execute() {\n logger().info(\"generating keys for jwt token and adding to .env file\");\n const { publicKey, privateKey } = generateKeyPairSync(\"rsa\", {\n modulusLength: 2048, // 2048-bit key is standard for RS256\n publicKeyEncoding: {\n type: \"spki\",\n format: \"pem\",\n },\n privateKeyEncoding: {\n type: \"pkcs8\",\n format: \"pem\",\n },\n });\n\n let envfile = \"\";\n try {\n envfile = await fs.readFile(path.join(process.cwd(), \".env\"), \"utf-8\");\n } catch {}\n let old_public_key = envfile.match(/^jwt_secret_public=(.*)/m);\n\n envfile = this.addEnvParam(\n envfile,\n \"jwt_secret_public\",\n this.stripPemHeaders(publicKey),\n );\n envfile = this.addEnvParam(\n envfile,\n \"jwt_secret_private\",\n this.stripPemHeaders(privateKey),\n );\n\n if (this.rotate && old_public_key && old_public_key[1]) {\n envfile = this.addEnvParam(\n envfile,\n \"jwt_secret_public_retired\",\n old_public_key[1],\n );\n }\n\n await fs.writeFile(path.join(process.cwd(), \".env\"), envfile, \"utf-8\");\n }\n\n addEnvParam(file: string, key: string, value: string) {\n let regex = new RegExp(`^${key}=.*`, \"gm\");\n file = file.replace(regex, `${key}=${value}`);\n const match = file.match(regex);\n\n if (!match) {\n file = file + `\\n${key}=${value}`;\n }\n return file;\n }\n\n stripPemHeaders(pem: string) {\n return pem\n .replace(/-----BEGIN [\\w\\s]+-----/g, \"\")\n .replace(/-----END [\\w\\s]+-----/g, \"\")\n .replace(/\\r?\\n|\\r/g, \"\");\n }\n}\n\ncli().register(KeyGenerateCommand);\n"],"mappings":";;AAAA,SAAS,SAAS,cAAc;AAChC,SAAS,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AClB;AAAA,IACF;AAEA,UAAM,GAAG,UAAU,KAAK,KAAK,QAAQ,IAAI,GAAG,MAAM,GAAG,SAAS,OAAO;AAAA,EACvE;AAAA,EAEA,YAAY,MAAc,KAAa,OAAe;AACpD,QAAI,QAAQ,IAAI,OAAO,IAAI,GAAG,OAAO,IAAI;AACzC,WAAO,KAAK,QAAQ,OAAO,GAAG,GAAG,IAAI,KAAK,EAAE;AAC5C,UAAM,QAAQ,KAAK,MAAM,KAAK;AAE9B,QAAI,CAAC,OAAO;AACV,aAAO,OAAO;AAAA,EAAK,GAAG,IAAI,KAAK;AAAA,IACjC;AACA,WAAO;AAAA,EACT;AAAA,EAEA,gBAAgB,KAAa;AAC3B,WAAO,IACJ,QAAQ,4BAA4B,EAAE,EACtC,QAAQ,0BAA0B,EAAE,EACpC,QAAQ,aAAa,EAAE;AAAA,EAC5B;AACF;AAEA,IAAI,EAAE,SAAS,kBAAkB;","names":[]}
|
|
@@ -11,19 +11,13 @@ class StartCommand extends Command {
|
|
|
11
11
|
scheduler = Option.Boolean(`--scheduler`, false);
|
|
12
12
|
http = Option.Boolean(`--http`, false);
|
|
13
13
|
all = Option.Boolean("--all", false);
|
|
14
|
-
static paths = [
|
|
15
|
-
[
|
|
16
|
-
`start`
|
|
17
|
-
]
|
|
18
|
-
];
|
|
14
|
+
static paths = [[`start`]];
|
|
19
15
|
async execute() {
|
|
20
|
-
if ([
|
|
21
|
-
this.
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
this.context.stdout.write(`No service was selected. please check -h for details
|
|
26
|
-
`);
|
|
16
|
+
if ([this.all, this.http, this.scheduler].filter((x) => x).length == 0) {
|
|
17
|
+
this.context.stdout.write(
|
|
18
|
+
`No service was selected. please check -h for details
|
|
19
|
+
`
|
|
20
|
+
);
|
|
27
21
|
return;
|
|
28
22
|
}
|
|
29
23
|
logger().info(`Starting Server
|
|
@@ -37,7 +31,9 @@ class StartCommand extends Command {
|
|
|
37
31
|
if (this.http || this.all) {
|
|
38
32
|
const server = httpServer();
|
|
39
33
|
await server.listen(config.get("port"), () => {
|
|
40
|
-
logger().info(
|
|
34
|
+
logger().info(
|
|
35
|
+
"Server is running on http://localhost:" + config.get("port")
|
|
36
|
+
);
|
|
41
37
|
});
|
|
42
38
|
}
|
|
43
39
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/app/console/StartCommand.
|
|
1
|
+
{"version":3,"sources":["../../../src/app/console/StartCommand.mts"],"sourcesContent":["import { Command, Option } from \"clipanion\";\nimport { config } from \"@devbro/neko-config\";\n\nimport { cli, httpServer, logger, scheduler } from \"../../facades.mjs\";\nimport { PostgresqlConnection } from \"@devbro/neko-sql\";\n\nexport class StartCommand extends Command {\n scheduler = Option.Boolean(`--scheduler`, false);\n http = Option.Boolean(`--http`, false);\n all = Option.Boolean(\"--all\", false);\n static paths = [[`start`]];\n\n async execute() {\n if ([this.all, this.http, this.scheduler].filter((x) => x).length == 0) {\n this.context.stdout.write(\n `No service was selected. please check -h for details\\n`,\n );\n return;\n }\n\n logger().info(`Starting Server\\n`);\n\n PostgresqlConnection.defaults.idleTimeoutMillis = 10000;\n\n if (this.scheduler || this.all) {\n logger().info(`starting scheduler\\n`);\n scheduler().start();\n }\n\n if (this.http || this.all) {\n const server = httpServer();\n await server.listen(config.get(\"port\"), () => {\n logger().info(\n \"Server is running on http://localhost:\" + config.get(\"port\"),\n );\n });\n }\n }\n}\n\ncli().register(StartCommand);\n"],"mappings":";;AAAA,SAAS,SAAS,cAAc;AAChC,SAAS,cAAc;AAEvB,SAAS,KAAK,YAAY,QAAQ,iBAAiB;AACnD,SAAS,4BAA4B;AAE9B,MAAM,qBAAqB,QAAQ;AAAA,EAN1C,OAM0C;AAAA;AAAA;AAAA,EACxC,YAAY,OAAO,QAAQ,eAAe,KAAK;AAAA,EAC/C,OAAO,OAAO,QAAQ,UAAU,KAAK;AAAA,EACrC,MAAM,OAAO,QAAQ,SAAS,KAAK;AAAA,EACnC,OAAO,QAAQ,CAAC,CAAC,OAAO,CAAC;AAAA,EAEzB,MAAM,UAAU;AACd,QAAI,CAAC,KAAK,KAAK,KAAK,MAAM,KAAK,SAAS,EAAE,OAAO,CAAC,MAAM,CAAC,EAAE,UAAU,GAAG;AACtE,WAAK,QAAQ,OAAO;AAAA,QAClB;AAAA;AAAA,MACF;AACA;AAAA,IACF;AAEA,WAAO,EAAE,KAAK;AAAA,CAAmB;AAEjC,yBAAqB,SAAS,oBAAoB;AAElD,QAAI,KAAK,aAAa,KAAK,KAAK;AAC9B,aAAO,EAAE,KAAK;AAAA,CAAsB;AACpC,gBAAU,EAAE,MAAM;AAAA,IACpB;AAEA,QAAI,KAAK,QAAQ,KAAK,KAAK;AACzB,YAAM,SAAS,WAAW;AAC1B,YAAM,OAAO,OAAO,OAAO,IAAI,MAAM,GAAG,MAAM;AAC5C,eAAO,EAAE;AAAA,UACP,2CAA2C,OAAO,IAAI,MAAM;AAAA,QAC9D;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF;AAEA,IAAI,EAAE,SAAS,YAAY;","names":[]}
|
|
@@ -14,43 +14,40 @@ class GenerateControllerCommand extends Command {
|
|
|
14
14
|
__name(this, "GenerateControllerCommand");
|
|
15
15
|
}
|
|
16
16
|
static paths = [
|
|
17
|
-
[
|
|
18
|
-
|
|
19
|
-
`controller`
|
|
20
|
-
],
|
|
21
|
-
[
|
|
22
|
-
`generate`,
|
|
23
|
-
`controller`
|
|
24
|
-
]
|
|
17
|
+
[`make`, `controller`],
|
|
18
|
+
[`generate`, `controller`]
|
|
25
19
|
];
|
|
26
|
-
name = Option.String({
|
|
27
|
-
required: true
|
|
28
|
-
});
|
|
20
|
+
name = Option.String({ required: true });
|
|
29
21
|
async execute() {
|
|
30
22
|
const rootDir = process.cwd();
|
|
31
23
|
const date = /* @__PURE__ */ new Date();
|
|
32
24
|
const year = date.getFullYear();
|
|
33
25
|
const month = String(date.getMonth() + 1).padStart(2, "0");
|
|
34
26
|
const day = String(date.getDate()).padStart(2, "0");
|
|
35
|
-
const secondsOfDay = String(
|
|
27
|
+
const secondsOfDay = String(
|
|
28
|
+
date.getHours() * 3600 + date.getMinutes() * 60 + date.getSeconds()
|
|
29
|
+
).padStart(5, "0");
|
|
36
30
|
const fixed_name = Case.snake(this.name);
|
|
37
31
|
const filename = `${Case.capital(this.name)}Controller.ts`;
|
|
38
32
|
this.context.stdout.write(`creating migration file ${filename}
|
|
39
33
|
`);
|
|
40
|
-
await fs.mkdir(config.get("migration.path"), {
|
|
41
|
-
recursive: true
|
|
42
|
-
});
|
|
34
|
+
await fs.mkdir(config.get("migration.path"), { recursive: true });
|
|
43
35
|
let dirname = typeof __dirname === "string" ? __dirname : void 0;
|
|
44
36
|
if (!dirname) {
|
|
45
37
|
dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
46
38
|
}
|
|
47
|
-
const compiledTemplate = handlebars.compile(
|
|
39
|
+
const compiledTemplate = handlebars.compile(
|
|
40
|
+
(await fs.readFile(path.join(dirname, "./controller.tpl"))).toString()
|
|
41
|
+
);
|
|
48
42
|
const template = await compiledTemplate({
|
|
49
43
|
className: Case.pascal(this.name),
|
|
50
44
|
classNameLower: Case.snake(this.name),
|
|
51
45
|
routeName: Case.kebab(pluralize(this.name))
|
|
52
46
|
});
|
|
53
|
-
await fs.writeFile(
|
|
47
|
+
await fs.writeFile(
|
|
48
|
+
path.join(rootDir, "src/app/controllers", filename),
|
|
49
|
+
template
|
|
50
|
+
);
|
|
54
51
|
}
|
|
55
52
|
}
|
|
56
53
|
cli().register(GenerateControllerCommand);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/app/console/generate/GenerateControllerCommand.
|
|
1
|
+
{"version":3,"sources":["../../../../src/app/console/generate/GenerateControllerCommand.mts"],"sourcesContent":["import { cli } from \"../../../facades.mjs\";\nimport { Command, Option } from \"clipanion\";\nimport { Case } from \"change-case-all\";\nimport path from \"path\";\nimport * as fs from \"fs/promises\";\nimport { config } from \"@devbro/neko-config\";\nimport handlebars from \"handlebars\";\nimport { fileURLToPath } from \"url\";\nimport pluralize from \"pluralize\";\n\nexport class GenerateControllerCommand extends Command {\n static paths = [\n [`make`, `controller`],\n [`generate`, `controller`],\n ];\n\n name = Option.String({ required: true });\n\n async execute() {\n const rootDir = process.cwd();\n\n const date = new Date();\n const year = date.getFullYear();\n const month = String(date.getMonth() + 1).padStart(2, \"0\");\n const day = String(date.getDate()).padStart(2, \"0\");\n const secondsOfDay = String(\n date.getHours() * 3600 + date.getMinutes() * 60 + date.getSeconds(),\n ).padStart(5, \"0\");\n\n const fixed_name = Case.snake(this.name);\n const filename = `${Case.capital(this.name)}Controller.ts`;\n this.context.stdout.write(`creating migration file ${filename}\\n`);\n\n await fs.mkdir(config.get(\"migration.path\"), { recursive: true });\n\n let dirname = typeof __dirname === \"string\" ? __dirname : undefined;\n if (!dirname) {\n dirname = path.dirname(fileURLToPath(import.meta.url));\n }\n\n const compiledTemplate = handlebars.compile(\n (await fs.readFile(path.join(dirname, \"./controller.tpl\"))).toString(),\n );\n const template = await compiledTemplate({\n className: Case.pascal(this.name),\n classNameLower: Case.snake(this.name),\n routeName: Case.kebab(pluralize(this.name)),\n });\n\n await fs.writeFile(\n path.join(rootDir, \"src/app/controllers\", filename),\n template,\n );\n }\n}\n\ncli().register(GenerateControllerCommand);\n"],"mappings":";;AAAA,SAAS,WAAW;AACpB,SAAS,SAAS,cAAc;AAChC,SAAS,YAAY;AACrB,OAAO,UAAU;AACjB,YAAY,QAAQ;AACpB,SAAS,cAAc;AACvB,OAAO,gBAAgB;AACvB,SAAS,qBAAqB;AAC9B,OAAO,eAAe;AAEf,MAAM,kCAAkC,QAAQ;AAAA,EAVvD,OAUuD;AAAA;AAAA;AAAA,EACrD,OAAO,QAAQ;AAAA,IACb,CAAC,QAAQ,YAAY;AAAA,IACrB,CAAC,YAAY,YAAY;AAAA,EAC3B;AAAA,EAEA,OAAO,OAAO,OAAO,EAAE,UA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 @@
|
|
|
1
|
-
export * from "./GenerateControllerCommand";
|
|
1
|
+
export * from "./GenerateControllerCommand.mjs";
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/app/console/generate/index.
|
|
1
|
+
{"version":3,"sources":["../../../../src/app/console/generate/index.mts"],"sourcesContent":["export * from \"./GenerateControllerCommand.mjs\";\n"],"mappings":"AAAA,cAAc;","names":[]}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export * from "./migrate";
|
|
2
|
-
export * from "./StartCommand";
|
|
3
|
-
export * from "./DefaultCommand";
|
|
4
|
-
export * from "./KeyGenerateCommand";
|
|
5
|
-
export * from "./generate";
|
|
6
|
-
export * from "./project/CreateProjectCommand";
|
|
1
|
+
export * from "./migrate/index.mjs";
|
|
2
|
+
export * from "./StartCommand.mjs";
|
|
3
|
+
export * from "./DefaultCommand.mjs";
|
|
4
|
+
export * from "./KeyGenerateCommand.mjs";
|
|
5
|
+
export * from "./generate/index.mjs";
|
|
6
|
+
export * from "./project/CreateProjectCommand.mjs";
|
|
7
7
|
import { cli } from "../../facades.mjs";
|
|
8
|
-
import { CreateProjectCommand } from "./project/CreateProjectCommand";
|
|
8
|
+
import { CreateProjectCommand } from "./project/CreateProjectCommand.mjs";
|
|
9
9
|
cli().register(CreateProjectCommand);
|
|
10
10
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/app/console/index.
|
|
1
|
+
{"version":3,"sources":["../../../src/app/console/index.mts"],"sourcesContent":["export * from \"./migrate/index.mjs\";\nexport * from \"./StartCommand.mjs\";\nexport * from \"./DefaultCommand.mjs\";\nexport * from \"./KeyGenerateCommand.mjs\";\nexport * from \"./generate/index.mjs\";\nexport * from \"./project/CreateProjectCommand.mjs\";\n\nimport { cli } from \"../../facades.mjs\";\nimport { CreateProjectCommand } from \"./project/CreateProjectCommand.mjs\";\n\ncli().register(CreateProjectCommand);\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAEd,SAAS,WAAW;AACpB,SAAS,4BAA4B;AAErC,IAAI,EAAE,SAAS,oBAAoB;","names":[]}
|
|
@@ -13,41 +13,38 @@ class GenerateMigrateCommand extends Command {
|
|
|
13
13
|
__name(this, "GenerateMigrateCommand");
|
|
14
14
|
}
|
|
15
15
|
static paths = [
|
|
16
|
-
[
|
|
17
|
-
|
|
18
|
-
`migrate`
|
|
19
|
-
],
|
|
20
|
-
[
|
|
21
|
-
"generate",
|
|
22
|
-
"migration"
|
|
23
|
-
]
|
|
16
|
+
[`generate`, `migrate`],
|
|
17
|
+
["generate", "migration"]
|
|
24
18
|
];
|
|
25
|
-
name = Option.String({
|
|
26
|
-
required: true
|
|
27
|
-
});
|
|
19
|
+
name = Option.String({ required: true });
|
|
28
20
|
async execute() {
|
|
29
21
|
const date = /* @__PURE__ */ new Date();
|
|
30
22
|
const year = date.getFullYear();
|
|
31
23
|
const month = String(date.getMonth() + 1).padStart(2, "0");
|
|
32
24
|
const day = String(date.getDate()).padStart(2, "0");
|
|
33
|
-
const secondsOfDay = String(
|
|
25
|
+
const secondsOfDay = String(
|
|
26
|
+
date.getHours() * 3600 + date.getMinutes() * 60 + date.getSeconds()
|
|
27
|
+
).padStart(5, "0");
|
|
34
28
|
const fixed_name = Case.snake(this.name);
|
|
35
29
|
const filename = `${year}_${month}_${day}_${secondsOfDay}_${fixed_name}.ts`;
|
|
36
30
|
this.context.stdout.write(`creating migration file ${filename}
|
|
37
31
|
`);
|
|
38
|
-
await fs.mkdir(config.get("migration.path"), {
|
|
39
|
-
recursive: true
|
|
40
|
-
});
|
|
32
|
+
await fs.mkdir(config.get("migration.path"), { recursive: true });
|
|
41
33
|
let dirname = typeof __dirname === "string" ? __dirname : void 0;
|
|
42
34
|
if (!dirname) {
|
|
43
35
|
dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
44
36
|
}
|
|
45
|
-
const compiledTemplate = handlebars.compile(
|
|
37
|
+
const compiledTemplate = handlebars.compile(
|
|
38
|
+
(await fs.readFile(path.join(dirname, "./make_migration.tpl"))).toString()
|
|
39
|
+
);
|
|
46
40
|
const template = await compiledTemplate({
|
|
47
41
|
className: Case.pascal(this.name) + "Migration",
|
|
48
42
|
tableName: Case.snake(this.name)
|
|
49
43
|
});
|
|
50
|
-
await fs.writeFile(
|
|
44
|
+
await fs.writeFile(
|
|
45
|
+
path.join(config.get("migration.path"), filename),
|
|
46
|
+
template
|
|
47
|
+
);
|
|
51
48
|
}
|
|
52
49
|
}
|
|
53
50
|
cli().register(GenerateMigrateCommand);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/app/console/migrate/GenerateMigrateCommand.
|
|
1
|
+
{"version":3,"sources":["../../../../src/app/console/migrate/GenerateMigrateCommand.mts"],"sourcesContent":["import { cli } from \"../../../facades.mjs\";\nimport { Command, Option } from \"clipanion\";\nimport { Case } from \"change-case-all\";\nimport path from \"path\";\nimport * as fs from \"fs/promises\";\nimport { config } from \"@devbro/neko-config\";\nimport handlebars from \"handlebars\";\nimport { fileURLToPath } from \"url\";\nimport { table } from \"console\";\n\nexport class GenerateMigrateCommand extends Command {\n static paths = [\n [`generate`, `migrate`],\n [\"generate\", \"migration\"],\n ];\n\n name = Option.String({ required: true });\n\n async execute() {\n const date = new Date();\n const year = date.getFullYear();\n const month = String(date.getMonth() + 1).padStart(2, \"0\");\n const day = String(date.getDate()).padStart(2, \"0\");\n const secondsOfDay = String(\n date.getHours() * 3600 + date.getMinutes() * 60 + date.getSeconds(),\n ).padStart(5, \"0\");\n\n const fixed_name = Case.snake(this.name);\n const filename = `${year}_${month}_${day}_${secondsOfDay}_${fixed_name}.ts`;\n this.context.stdout.write(`creating migration file ${filename}\\n`);\n\n await fs.mkdir(config.get(\"migration.path\"), { recursive: true });\n\n let dirname = typeof __dirname === \"string\" ? __dirname : undefined;\n if (!dirname) {\n dirname = path.dirname(fileURLToPath(import.meta.url));\n }\n\n const compiledTemplate = handlebars.compile(\n (\n await fs.readFile(path.join(dirname, \"./make_migration.tpl\"))\n ).toString(),\n );\n const template = await compiledTemplate({\n className: Case.pascal(this.name) + \"Migration\",\n tableName: Case.snake(this.name),\n });\n\n await fs.writeFile(\n path.join(config.get(\"migration.path\"), filename),\n template,\n );\n }\n}\n\ncli().register(GenerateMigrateCommand);\n"],"mappings":";;AAAA,SAAS,WAAW;AACpB,SAAS,SAAS,cAAc;AAChC,SAAS,YAAY;AACrB,OAAO,UAAU;AACjB,YAAY,QAAQ;AACpB,SAAS,cAAc;AACvB,OAAO,gBAAgB;AACvB,SAAS,qBAAqB;AAGvB,MAAM,+BAA+B,QAAQ;AAAA,EAVpD,OAUoD;AAAA;AAAA;AAAA,EAClD,OAAO,QAAQ;AAAA,IACb,CAAC,YAAY,SAAS;AAAA,IACtB,CAAC,YAAY,WAAW;AAAA,EAC1B;AAAA,EAEA,OAAO,OAAO,OAAO,EAAE,UAAU,KAAK,CAAC;AAAA,EAEvC,MAAM,UAAU;AACd,UAAM,OAAO,oBAAI,KAAK;AACtB,UAAM,OAAO,KAAK,YAAY;AAC9B,UAAM,QAAQ,OAAO,KAAK,SAAS,IAAI,CAAC,EAAE,SAAS,GAAG,GAAG;AACzD,UAAM,MAAM,OAAO,KAAK,QAAQ,CAAC,EAAE,SAAS,GAAG,GAAG;AAClD,UAAM,eAAe;AAAA,MACnB,KAAK,SAAS,IAAI,OAAO,KAAK,WAAW,IAAI,KAAK,KAAK,WAAW;AAAA,IACpE,EAAE,SAAS,GAAG,GAAG;AAEjB,UAAM,aAAa,KAAK,MAAM,KAAK,IAAI;AACvC,UAAM,WAAW,GAAG,IAAI,IAAI,KAAK,IAAI,GAAG,IAAI,YAAY,IAAI,UAAU;AACtE,SAAK,QAAQ,OAAO,MAAM,2BAA2B,QAAQ;AAAA,CAAI;AAEjE,UAAM,GAAG,MAAM,OAAO,IAAI,gBAAgB,GAAG,EAAE,WAAW,KAAK,CAAC;AAEhE,QAAI,UAAU,OAAO,cAAc,WAAW,YAAY;AAC1D,QAAI,CAAC,SAAS;AACZ,gBAAU,KAAK,QAAQ,cAAc,YAAY,GAAG,CAAC;AAAA,IACvD;AAEA,UAAM,mBAAmB,WAAW;AAAA,OAEhC,MAAM,GAAG,SAAS,KAAK,KAAK,SAAS,sBAAsB,CAAC,GAC5D,SAAS;AAAA,IACb;AACA,UAAM,WAAW,MAAM,iBAAiB;AAAA,MACtC,WAAW,KAAK,OAAO,KAAK,IAAI,IAAI;AAAA,MACpC,WAAW,KAAK,MAAM,KAAK,IAAI;AAAA,IACjC,CAAC;AAED,UAAM,GAAG;AAAA,MACP,KAAK,KAAK,OAAO,IAAI,gBAAgB,GAAG,QAAQ;AAAA,MAChD;AAAA,IACF;AAAA,EACF;AACF;AAEA,IAAI,EAAE,SAAS,sBAAsB;","names":[]}
|
|
@@ -10,11 +10,7 @@ class MigrateCommand extends Command {
|
|
|
10
10
|
static {
|
|
11
11
|
__name(this, "MigrateCommand");
|
|
12
12
|
}
|
|
13
|
-
static paths = [
|
|
14
|
-
[
|
|
15
|
-
`migrate`
|
|
16
|
-
]
|
|
17
|
-
];
|
|
13
|
+
static paths = [[`migrate`]];
|
|
18
14
|
fresh = Option.Boolean("--fresh", false);
|
|
19
15
|
async execute() {
|
|
20
16
|
await context_provider.run(async () => {
|
|
@@ -62,7 +58,9 @@ class MigrateCommand extends Command {
|
|
|
62
58
|
bindings: []
|
|
63
59
|
});
|
|
64
60
|
const completed_migrations = migrations.map((r) => r.filename);
|
|
65
|
-
const pending_migrations = files.filter(
|
|
61
|
+
const pending_migrations = files.filter(
|
|
62
|
+
(file) => !completed_migrations.includes(file)
|
|
63
|
+
);
|
|
66
64
|
let migrated_count = 0;
|
|
67
65
|
for (const class_to_migrate of pending_migrations) {
|
|
68
66
|
logger().info(`migrating up ${class_to_migrate}`);
|
|
@@ -71,10 +69,7 @@ class MigrateCommand extends Command {
|
|
|
71
69
|
await c.up(db.getSchema());
|
|
72
70
|
await db.runQuery({
|
|
73
71
|
sql: "insert into migrations (filename, batch) values ($1,$2)",
|
|
74
|
-
bindings: [
|
|
75
|
-
class_to_migrate,
|
|
76
|
-
batch_number
|
|
77
|
-
]
|
|
72
|
+
bindings: [class_to_migrate, batch_number]
|
|
78
73
|
});
|
|
79
74
|
migrated_count++;
|
|
80
75
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/app/console/migrate/MigrateCommand.
|
|
1
|
+
{"version":3,"sources":["../../../../src/app/console/migrate/MigrateCommand.mts"],"sourcesContent":["import { cli, db as database, logger } from \"../../../facades.mjs\";\nimport { Command, Option } from \"clipanion\";\nimport { Blueprint } from \"@devbro/neko-sql\";\nimport { context_provider } from \"@devbro/neko-context\";\nimport path from \"path\";\nimport fs from \"fs/promises\";\nimport { config } from \"@devbro/neko-config\";\nimport { Migration } from \"@devbro/neko-sql\";\n\nexport class MigrateCommand extends Command {\n static paths = [[`migrate`]];\n\n fresh = Option.Boolean(\"--fresh\", false);\n\n async execute() {\n await context_provider.run(async () => {\n // this.context.stdout.write(`Hello Migrate Command!\\n`);\n const db = database();\n const schema = db.getSchema();\n\n if (this.fresh) {\n logger().info(\"dropping all tables!!\");\n let retry = true;\n let retry_count = 0;\n while (retry && retry_count < 10) {\n retry = false;\n retry_count++;\n const tables = await schema.tables();\n for (const table of tables) {\n logger().info(`dropping table ${table.name}`);\n try {\n await schema.dropTable(table.name);\n } catch {\n logger().info(`failed to drop ${table.name}`);\n retry = true;\n }\n }\n }\n }\n\n //create migration table if not exists\n if (!(await schema.tableExists(\"migrations\"))) {\n await schema.createTable(\"migrations\", (blueprint: Blueprint) => {\n blueprint.id();\n blueprint.timestamps();\n blueprint.string(\"filename\");\n blueprint.integer(\"batch\");\n });\n }\n\n const migrationsDir = config.get(\"migration.path\");\n let files: string[] = [];\n\n const dirEntries = await fs.readdir(migrationsDir);\n files = dirEntries\n .filter((entry) => entry.endsWith(\".ts\") || entry.endsWith(\".js\"))\n .sort();\n let batch_number = await db.runQuery({\n sql: \"select max(batch) as next_batch from migrations\",\n bindings: [],\n });\n batch_number = batch_number[0].next_batch || 0;\n batch_number++;\n\n const migrations = await db.runQuery({\n sql: \"select * from migrations order by created_at ASC\",\n bindings: [],\n });\n\n const completed_migrations = migrations.map((r: any) => r.filename);\n const pending_migrations = files.filter(\n (file) => !completed_migrations.includes(file),\n );\n\n let migrated_count = 0;\n for (const class_to_migrate of pending_migrations) {\n logger().info(`migrating up ${class_to_migrate}`);\n const ClassToMigrate = (\n await import(path.join(migrationsDir, class_to_migrate))\n ).default;\n const c: Migration = new ClassToMigrate();\n await c.up(db.getSchema());\n await db.runQuery({\n sql: \"insert into migrations (filename, batch) values ($1,$2)\",\n bindings: [class_to_migrate, batch_number],\n });\n migrated_count++;\n }\n\n if (migrated_count === 0) {\n logger().warn(\"no migrations to run!\");\n return;\n }\n\n logger().info(`migrated ${migrated_count} migrations successfully!`);\n });\n }\n}\n\ncli().register(MigrateCommand);\n"],"mappings":";;AAAA,SAAS,KAAK,MAAM,UAAU,cAAc;AAC5C,SAAS,SAAS,cAAc;AAEhC,SAAS,wBAAwB;AACjC,OAAO,UAAU;AACjB,OAAO,QAAQ;AACf,SAAS,cAAc;AAGhB,MAAM,uBAAuB,QAAQ;AAAA,EAT5C,OAS4C;AAAA;AAAA;AAAA,EAC1C,OAAO,QAAQ,CAAC,CAAC,SAAS,CAAC;AAAA,EAE3B,QAAQ,OAAO,QAAQ,WAAW,KAAK;AAAA,EAEvC,MAAM,UAAU;AACd,UAAM,iBAAiB,IAAI,YAAY;AAErC,YAAM,KAAK,SAAS;AACpB,YAAM,SAAS,GAAG,UAAU;AAE5B,UAAI,KAAK,OAAO;AACd,eAAO,EAAE,KAAK,uBAAuB;AACrC,YAAI,QAAQ;AACZ,YAAI,cAAc;AAClB,eAAO,SAAS,cAAc,IAAI;AAChC,kBAAQ;AACR;A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,eAAe,gBAAgB,IACtD;AACF,cAAM,IAAe,IAAI,eAAe;AACxC,cAAM,EAAE,GAAG,GAAG,UAAU,CAAC;AACzB,cAAM,GAAG,SAAS;AAAA,UAChB,KAAK;AAAA,UACL,UAAU,CAAC,kBAAkB,YAAY;AAAA,QAC3C,CAAC;AACD;AAAA,MACF;AAEA,UAAI,mBAAmB,GAAG;AACxB,eAAO,EAAE,KAAK,uBAAuB;AACrC;AAAA,MACF;AAEA,aAAO,EAAE,KAAK,YAAY,cAAc,2BAA2B;AAAA,IACrE,CAAC;AAAA,EACH;AACF;AAEA,IAAI,EAAE,SAAS,cAAc;","names":[]}
|
|
@@ -11,12 +11,7 @@ class MigrateRollbackCommand extends Command {
|
|
|
11
11
|
static {
|
|
12
12
|
__name(this, "MigrateRollbackCommand");
|
|
13
13
|
}
|
|
14
|
-
static paths = [
|
|
15
|
-
[
|
|
16
|
-
`migrate`,
|
|
17
|
-
"rollback"
|
|
18
|
-
]
|
|
19
|
-
];
|
|
14
|
+
static paths = [[`migrate`, "rollback"]];
|
|
20
15
|
steps = Option.String(`--steps`, {
|
|
21
16
|
description: `how many migrations to rollback`,
|
|
22
17
|
validator: t.isNumber()
|
|
@@ -42,9 +37,7 @@ class MigrateRollbackCommand extends Command {
|
|
|
42
37
|
await c.down(db.getSchema());
|
|
43
38
|
await db.runQuery({
|
|
44
39
|
sql: "delete from migrations where id = $1",
|
|
45
|
-
bindings: [
|
|
46
|
-
migration.id
|
|
47
|
-
]
|
|
40
|
+
bindings: [migration.id]
|
|
48
41
|
});
|
|
49
42
|
}
|
|
50
43
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/app/console/migrate/MigrateRollbackCommand.
|
|
1
|
+
{"version":3,"sources":["../../../../src/app/console/migrate/MigrateRollbackCommand.mts"],"sourcesContent":["import { cli, db as database } from \"../../../facades.mjs\";\nimport { Command, Option } from \"clipanion\";\nimport { context_provider } from \"@devbro/neko-context\";\nimport path from \"path\";\nimport fs from \"fs/promises\";\nimport { config } from \"@devbro/neko-config\";\nimport { Migration } from \"@devbro/neko-sql\";\nimport * as t from \"typanion\";\n\nexport class MigrateRollbackCommand extends Command {\n static paths = [[`migrate`, \"rollback\"]];\n\n steps = Option.String(`--steps`, {\n description: `how many migrations to rollback`,\n validator: t.isNumber(),\n });\n\n async execute() {\n await context_provider.run(async () => {\n // this.context.stdout.write(`Hello Migrate Command!\\n`);\n const db = database();\n const schema = db.getSchema();\n\n const migrationsDir = config.get(\"migration.path\");\n let files: string[] = [];\n\n const dirEntries = await fs.readdir(migrationsDir);\n files = dirEntries.filter((entry) => entry.endsWith(\".ts\")).sort();\n\n const migrations = await db.runQuery({\n sql: \"select * from migrations order by created_at DESC\",\n bindings: [],\n });\n\n const count = 0;\n for (const migration of migrations) {\n const class_to_migrate = migration.filename;\n this.context.stdout.write(`rolling back ${class_to_migrate}`);\n\n const ClassToMigrate = (\n await import(path.join(migrationsDir, class_to_migrate))\n ).default;\n\n const c: Migration = new ClassToMigrate();\n await c.down(db.getSchema());\n await db.runQuery({\n sql: \"delete from migrations where id = $1\",\n bindings: [migration.id],\n });\n }\n });\n }\n}\n\ncli().register(MigrateRollbackCommand);\n"],"mappings":";;AAAA,SAAS,KAAK,MAAM,gBAAgB;AACpC,SAAS,SAAS,cAAc;AAChC,SAAS,wBAAwB;AACjC,OAAO,UAAU;AACjB,OAAO,QAAQ;AACf,SAAS,cAAc;AAEvB,YAAY,OAAO;AAEZ,MAAM,+BAA+B,QAAQ;AAAA,EATpD,OASoD;AAAA;AAAA;AAAA,EAClD,OAAO,QAAQ,CAAC,CAAC,WAAW,UAAU,CAAC;AAAA,EAEvC,QAAQ,OAAO,OAAO,WAAW;AAAA,IAC/B,aAAa;AAAA,IACb,WAAW,EAAE,SAAS;AAAA,EACxB,CAAC;AAAA,EAED,MAAM,UAAU;AACd,UAAM,iBAAiB,IAAI,YAAY;AAErC,YAAM,KAAK,SAAS;AACpB,YAAM,SAAS,GAAG,UAAU;AAE5B,YAAM,gBAAgB,OAAO,IAAI,gBAAgB;AACjD,UAAI,QAAkB,CAAC;AAEvB,YAAM,aAAa,MAAM,GAAG,QAAQ,aAAa;AACjD,cAAQ,WAAW,OAAO,CAAC,UAAU,MAAM,SAAS,KAAK,CAAC,EAAE,KAAK;AAEjE,YAAM,aAAa,MAAM,GAAG,SAAS;AAAA,QACnC,KAAK;AAAA,QACL,UAAU,CAAC;AAAA,MACb,CAAC;AAED,YAAM,QAAQ;AACd,iBAAW,aAAa,YAAY;AAClC,cAAM,mBAAmB,UAAU;AACnC,aAAK,QAAQ,OAAO,MAAM,gBAAgB,gBAAgB,EAAE;AAE5D,cAAM,kBACJ,MAAM,OAAO,KAAK,KAAK,eAAe,gBAAgB,IACtD;AAEF,cAAM,IAAe,IAAI,eAAe;AACxC,cAAM,EAAE,KAAK,GAAG,UAAU,CAAC;AAC3B,cAAM,GAAG,SAAS;AAAA,UAChB,KAAK;AAAA,UACL,UAAU,CAAC,UAAU,EAAE;AAAA,QACzB,CAAC;AAAA,MACH;AAAA,IACF,CAAC;AAAA,EACH;AACF;AAEA,IAAI,EAAE,SAAS,sBAAsB;","names":[]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from "./MigrateCommand";
|
|
2
|
-
export * from "./GenerateMigrateCommand";
|
|
3
|
-
export * from "./MigrateRollbackCommand";
|
|
1
|
+
export * from "./MigrateCommand.mjs";
|
|
2
|
+
export * from "./GenerateMigrateCommand.mjs";
|
|
3
|
+
export * from "./MigrateRollbackCommand.mjs";
|
|
4
4
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/app/console/migrate/index.
|
|
1
|
+
{"version":3,"sources":["../../../../src/app/console/migrate/index.mts"],"sourcesContent":["export * from \"./MigrateCommand.mjs\";\nexport * from \"./GenerateMigrateCommand.mjs\";\nexport * from \"./MigrateRollbackCommand.mjs\";\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
|
|
@@ -11,12 +11,7 @@ class CreateProjectCommand extends Command {
|
|
|
11
11
|
static {
|
|
12
12
|
__name(this, "CreateProjectCommand");
|
|
13
13
|
}
|
|
14
|
-
static paths = [
|
|
15
|
-
[
|
|
16
|
-
`create`,
|
|
17
|
-
`project`
|
|
18
|
-
]
|
|
19
|
-
];
|
|
14
|
+
static paths = [[`create`, `project`]];
|
|
20
15
|
static usage = Command.Usage({
|
|
21
16
|
category: `Project`,
|
|
22
17
|
description: `Create a new project`,
|
|
@@ -35,9 +30,7 @@ class CreateProjectCommand extends Command {
|
|
|
35
30
|
]
|
|
36
31
|
]
|
|
37
32
|
});
|
|
38
|
-
projectPath = Option.String("--path", {
|
|
39
|
-
required: true
|
|
40
|
-
});
|
|
33
|
+
projectPath = Option.String("--path", { required: true });
|
|
41
34
|
git = Option.Boolean(`--git`, false, {
|
|
42
35
|
description: `Initialize a git repository in the new project`
|
|
43
36
|
});
|
|
@@ -60,9 +53,7 @@ class CreateProjectCommand extends Command {
|
|
|
60
53
|
return 1;
|
|
61
54
|
} catch {
|
|
62
55
|
}
|
|
63
|
-
await fs.mkdir(projectPath, {
|
|
64
|
-
recursive: true
|
|
65
|
-
});
|
|
56
|
+
await fs.mkdir(projectPath, { recursive: true });
|
|
66
57
|
console.log(`Created project directory at: ${projectPath}`);
|
|
67
58
|
const dirname = typeof __dirname === "undefined" ? path.dirname(fileURLToPath(import.meta.url)) : __dirname;
|
|
68
59
|
let basePath = path.join(dirname, `./base_project`);
|
|
@@ -80,9 +71,12 @@ class CreateProjectCommand extends Command {
|
|
|
80
71
|
console.log(`Updated package.json with project name: ${packageJson.name}`);
|
|
81
72
|
if (this.git) {
|
|
82
73
|
try {
|
|
83
|
-
execSync(
|
|
84
|
-
|
|
85
|
-
|
|
74
|
+
execSync(
|
|
75
|
+
'git init; git add --all; git commit --allow-empty -m "chore: first commit for pashmak"',
|
|
76
|
+
{
|
|
77
|
+
cwd: projectPath
|
|
78
|
+
}
|
|
79
|
+
);
|
|
86
80
|
} catch (error) {
|
|
87
81
|
console.error(`Failed to create project.`, error);
|
|
88
82
|
return 1;
|
|
@@ -90,26 +84,26 @@ class CreateProjectCommand extends Command {
|
|
|
90
84
|
}
|
|
91
85
|
}
|
|
92
86
|
async processTplFolder(src, dest, data = {}) {
|
|
93
|
-
const files = await fs.readdir(src, {
|
|
94
|
-
withFileTypes: true
|
|
95
|
-
});
|
|
87
|
+
const files = await fs.readdir(src, { withFileTypes: true });
|
|
96
88
|
for (const file of files) {
|
|
97
89
|
const srcPath = path.join(src, file.name);
|
|
98
90
|
const destPath = file.isFile() && file.name.endsWith(".tpl") ? path.join(dest, file.name.substring(0, file.name.length - 4)) : path.join(dest, file.name);
|
|
99
91
|
if (file.isDirectory()) {
|
|
100
|
-
await fs.mkdir(destPath, {
|
|
101
|
-
recursive: true
|
|
102
|
-
});
|
|
92
|
+
await fs.mkdir(destPath, { recursive: true });
|
|
103
93
|
await this.processTplFolder(srcPath, destPath, data);
|
|
104
94
|
} else if (file.name.endsWith(".tpl")) {
|
|
105
95
|
await this.processTplFile(srcPath, destPath, {});
|
|
106
96
|
} else {
|
|
107
|
-
throw new Error(
|
|
97
|
+
throw new Error(
|
|
98
|
+
"unexpected non tpl file: " + srcPath + " " + file.name
|
|
99
|
+
);
|
|
108
100
|
}
|
|
109
101
|
}
|
|
110
102
|
}
|
|
111
103
|
async processTplFile(src, dest, data = {}) {
|
|
112
|
-
const compiledTemplate = handlebars.compile(
|
|
104
|
+
const compiledTemplate = handlebars.compile(
|
|
105
|
+
(await fs.readFile(src)).toString()
|
|
106
|
+
);
|
|
113
107
|
const template = await compiledTemplate(data);
|
|
114
108
|
await fs.writeFile(dest, template);
|
|
115
109
|
}
|