create-arkos 1.2.15-beta.1 → 1.2.15-beta.2
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/index.js +27 -32
- package/dist/index.js.map +1 -1
- package/dist/utils/helpers/hbs-tester.helpers.js +13 -18
- package/dist/utils/helpers/hbs-tester.helpers.js.map +1 -1
- package/dist/utils/helpers/index.js +4 -12
- package/dist/utils/helpers/index.js.map +1 -1
- package/dist/utils/helpers/npm.helpers.js +4 -9
- package/dist/utils/helpers/npm.helpers.js.map +1 -1
- package/dist/utils/project-config-inquirer.js +24 -28
- package/dist/utils/project-config-inquirer.js.map +1 -1
- package/dist/utils/template-compiler.js +13 -18
- package/dist/utils/template-compiler.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,52 +1,47 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const handlebars_1 = __importDefault(require("handlebars"));
|
|
14
|
-
const helpers_1 = require("./utils/helpers");
|
|
15
|
-
const npm_helpers_1 = require("./utils/helpers/npm.helpers");
|
|
16
|
-
handlebars_1.default.registerHelper("eq", (a, b) => a === b);
|
|
17
|
-
handlebars_1.default.registerHelper("neq", (a, b) => a !== b);
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import chalk from "chalk";
|
|
5
|
+
import { execSync } from "child_process";
|
|
6
|
+
import projectConfigInquirer from "./utils/project-config-inquirer";
|
|
7
|
+
import templateCompiler from "./utils/template-compiler";
|
|
8
|
+
import Handlebars from "handlebars";
|
|
9
|
+
import { getProcjetPackageJsonDependecies } from "./utils/helpers";
|
|
10
|
+
import { detectPackageManagerFromUserAgent } from "./utils/helpers/npm.helpers";
|
|
11
|
+
Handlebars.registerHelper("eq", (a, b) => a === b);
|
|
12
|
+
Handlebars.registerHelper("neq", (a, b) => a !== b);
|
|
18
13
|
async function main() {
|
|
19
|
-
const config = await
|
|
14
|
+
const config = await projectConfigInquirer.run();
|
|
20
15
|
const argProjectName = config.argProjectName;
|
|
21
16
|
const projectPath = config.projectPath;
|
|
22
|
-
|
|
23
|
-
console.info(`\nCreating a new ${
|
|
24
|
-
const templatesDir =
|
|
25
|
-
await
|
|
17
|
+
fs.mkdirSync(projectPath, { recursive: true });
|
|
18
|
+
console.info(`\nCreating a new ${chalk.bold(chalk.cyan("Arkos.js"))} project under ${chalk.green(`./${config.projectName}`)}`);
|
|
19
|
+
const templatesDir = path.join(__dirname, `../templates/basic`);
|
|
20
|
+
await templateCompiler.compile(templatesDir, config);
|
|
26
21
|
process.chdir(projectPath);
|
|
27
|
-
const packageManager =
|
|
28
|
-
const { dependencies, devDependencies } =
|
|
29
|
-
console.info(
|
|
22
|
+
const packageManager = detectPackageManagerFromUserAgent();
|
|
23
|
+
const { dependencies, devDependencies } = getProcjetPackageJsonDependecies(projectPath);
|
|
24
|
+
console.info(chalk.cyan(chalk.bold("\ndependencies:")));
|
|
30
25
|
dependencies.forEach((dependency) => console.info(`- ${dependency}`));
|
|
31
|
-
console.info(
|
|
26
|
+
console.info(chalk.cyan(chalk.bold("\ndevDependencies:")));
|
|
32
27
|
devDependencies.forEach((devDependency) => console.info(`- ${devDependency}`));
|
|
33
|
-
console.info(
|
|
28
|
+
console.info(chalk.bold("\nInstalling dependencies..."));
|
|
34
29
|
console.info(`Using ${packageManager}.\n`);
|
|
35
|
-
|
|
30
|
+
execSync(`${packageManager} install`, { stdio: "inherit" });
|
|
36
31
|
process.chdir(projectPath);
|
|
37
32
|
console.info("\nRunning npx prisma generate...");
|
|
38
|
-
|
|
33
|
+
execSync(`npx prisma generate`, { stdio: "inherit" });
|
|
39
34
|
console.info(`
|
|
40
|
-
${
|
|
35
|
+
${chalk.bold(chalk.cyan("Arkos.js"))} project created successfully!
|
|
41
36
|
|
|
42
|
-
${
|
|
37
|
+
${chalk.bold("Next Steps:")}
|
|
43
38
|
${argProjectName === "."
|
|
44
39
|
? `1. cd ${config.projectName}
|
|
45
|
-
2. setup your ${
|
|
40
|
+
2. setup your ${chalk.cyan("DATABASE_URL")} under .env
|
|
46
41
|
3. npx prisma db push
|
|
47
42
|
4. ${packageManager} run dev
|
|
48
43
|
`
|
|
49
|
-
: `1. setup your ${
|
|
44
|
+
: `1. setup your ${chalk.cyan("DATABASE_URL")} under .env
|
|
50
45
|
2. npx prisma db push
|
|
51
46
|
3. ${packageManager} run dev
|
|
52
47
|
`}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,qBAAqB,MAAM,iCAAiC,CAAC;AACpE,OAAO,gBAAgB,MAAM,2BAA2B,CAAC;AACzD,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,gCAAgC,EAAE,MAAM,iBAAiB,CAAC;AACnE,OAAO,EAAE,iCAAiC,EAAE,MAAM,6BAA6B,CAAC;AAEhF,UAAU,CAAC,cAAc,CAAC,IAAI,EAAE,CAAC,CAAM,EAAE,CAAM,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;AAC7D,UAAU,CAAC,cAAc,CAAC,KAAK,EAAE,CAAC,CAAM,EAAE,CAAM,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;AAE9D,KAAK,UAAU,IAAI;IACjB,MAAM,MA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AAI,CAAC,KAAK,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAC,CAAC;IACzD,OAAO,CAAC,IAAI,CAAC,SAAS,cAAc,KAAK,CAAC,CAAC;IAE3C,QAAQ,CAAC,GAAG,cAAc,UAAU,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;IAE5D,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;IAC3B,OAAO,CAAC,IAAI,CAAC,kCAAkC,CAAC,CAAC;IACjD,QAAQ,CAAC,qBAAqB,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;IAEtD,OAAO,CAAC,IAAI,CAAC;IACX,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;;IAElC,KAAK,CAAC,IAAI,CAAC,aAAa,CAAC;IAEzB,cAAc,KAAK,GAAG;QACpB,CAAC,CAAC,SAAS,MAAM,CAAC,WAAW;kBACjB,KAAK,CAAC,IAAI,CAAC,cAAc,CAAC;;OAErC,cAAc;CACpB;QACK,CAAC,CAAC,iBAAiB,KAAK,CAAC,IAAI,CAAC,cAAc,CAAC;;OAE5C,cAAc;CAEnB;KACG,CAAC,CAAC;AACP,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC","sourcesContent":["#!/usr/bin/env node\nimport fs from \"fs\";\nimport path from \"path\";\nimport chalk from \"chalk\";\nimport { execSync } from \"child_process\";\nimport projectConfigInquirer from \"./utils/project-config-inquirer\";\nimport templateCompiler from \"./utils/template-compiler\";\nimport Handlebars from \"handlebars\";\nimport { getProcjetPackageJsonDependecies } from \"./utils/helpers\";\nimport { detectPackageManagerFromUserAgent } from \"./utils/helpers/npm.helpers\";\n\nHandlebars.registerHelper(\"eq\", (a: any, b: any) => a === b);\nHandlebars.registerHelper(\"neq\", (a: any, b: any) => a !== b);\n\nasync function main() {\n const config = await projectConfigInquirer.run();\n const argProjectName = config.argProjectName;\n\n const projectPath = config.projectPath;\n\n fs.mkdirSync(projectPath, { recursive: true });\n\n console.info(\n `\\nCreating a new ${chalk.bold(chalk.cyan(\"Arkos.js\"))} project under ${chalk.green(`./${config.projectName}`)}`\n );\n\n const templatesDir = path.join(__dirname, `../templates/basic`);\n await templateCompiler.compile(templatesDir, config);\n\n process.chdir(projectPath);\n\n const packageManager = detectPackageManagerFromUserAgent();\n const { dependencies, devDependencies } =\n getProcjetPackageJsonDependecies(projectPath);\n\n console.info(chalk.cyan(chalk.bold(\"\\ndependencies:\")));\n dependencies.forEach((dependency) => console.info(`- ${dependency}`));\n\n console.info(chalk.cyan(chalk.bold(\"\\ndevDependencies:\")));\n devDependencies.forEach((devDependency) =>\n console.info(`- ${devDependency}`)\n );\n\n console.info(chalk.bold(\"\\nInstalling dependencies...\"));\n console.info(`Using ${packageManager}.\\n`);\n\n execSync(`${packageManager} install`, { stdio: \"inherit\" });\n\n process.chdir(projectPath);\n console.info(\"\\nRunning npx prisma generate...\");\n execSync(`npx prisma generate`, { stdio: \"inherit\" });\n\n console.info(`\n ${chalk.bold(chalk.cyan(\"Arkos.js\"))} project created successfully!\n\n ${chalk.bold(\"Next Steps:\")}\n ${\n argProjectName === \".\"\n ? `1. cd ${config.projectName}\n 2. setup your ${chalk.cyan(\"DATABASE_URL\")} under .env\n 3. npx prisma db push\n 4. ${packageManager} run dev\n`\n : `1. setup your ${chalk.cyan(\"DATABASE_URL\")} under .env\n 2. npx prisma db push\n 3. ${packageManager} run dev\n`\n }\n `);\n}\n\nmain().catch(console.error);\n"]}
|
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const fs_1 = __importDefault(require("fs"));
|
|
7
|
-
const path_1 = __importDefault(require("path"));
|
|
8
|
-
const handlebars_1 = __importDefault(require("handlebars"));
|
|
9
|
-
handlebars_1.default.registerHelper("eq", (a, b) => a === b);
|
|
10
|
-
handlebars_1.default.registerHelper("neq", (a, b) => a !== b);
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import handlebars from "handlebars";
|
|
4
|
+
handlebars.registerHelper("eq", (a, b) => a === b);
|
|
5
|
+
handlebars.registerHelper("neq", (a, b) => a !== b);
|
|
11
6
|
(() => {
|
|
12
7
|
const templatesDir = `${process.cwd()}/cache/handlebars/templates`;
|
|
13
8
|
const outputDir = `${process.cwd()}/cache/handlebars/output`;
|
|
@@ -30,22 +25,22 @@ handlebars_1.default.registerHelper("neq", (a, b) => a !== b);
|
|
|
30
25
|
projectPath: outputDir,
|
|
31
26
|
};
|
|
32
27
|
function processTemplates(dir, relativeDir = "") {
|
|
33
|
-
|
|
34
|
-
const fullPath =
|
|
35
|
-
const relativePath =
|
|
28
|
+
fs.readdirSync(dir, { withFileTypes: true }).forEach(async (dirent) => {
|
|
29
|
+
const fullPath = path.join(dir, dirent.name);
|
|
30
|
+
const relativePath = path.join(relativeDir, dirent.name);
|
|
36
31
|
if (dirent.isDirectory()) {
|
|
37
32
|
processTemplates(fullPath, relativePath);
|
|
38
33
|
}
|
|
39
34
|
else if (dirent.name.endsWith(".hbs")) {
|
|
40
35
|
const templatePath = fullPath;
|
|
41
|
-
const template =
|
|
36
|
+
const template = handlebars.compile(fs.readFileSync(templatePath, "utf8"));
|
|
42
37
|
const content = template(config);
|
|
43
38
|
const ext = config.typescript ? ".ts" : ".js";
|
|
44
|
-
let outputPath =
|
|
39
|
+
let outputPath = path.join(outputDir, relativePath.replace(".hbs", ""));
|
|
45
40
|
if (dirent.name.endsWith(".ts.hbs"))
|
|
46
|
-
outputPath =
|
|
47
|
-
|
|
48
|
-
|
|
41
|
+
outputPath = path.join(outputDir, relativePath.replace(".ts.hbs", ext));
|
|
42
|
+
fs.mkdirSync(path.dirname(outputPath), { recursive: true });
|
|
43
|
+
fs.writeFileSync(outputPath, content);
|
|
49
44
|
}
|
|
50
45
|
});
|
|
51
46
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hbs-tester.helpers.js","sourceRoot":"","sources":["../../../src/utils/helpers/hbs-tester.helpers.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"hbs-tester.helpers.js","sourceRoot":"","sources":["../../../src/utils/helpers/hbs-tester.helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,UAAU,MAAM,YAAY,CAAC;AAEpC,UAAU,CAAC,cAAc,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;AACnD,UAAU,CAAC,cAAc,CAAC,KAAK,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;AAEpD,CAAC,GAAG,EAAE;IACJ,MAAM,YAAY,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,6BAA6B,CAAC;IACnE,MAAM,SAAS,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,0BAA0B,CAAC;IAC7D,MAAM,MAAM,GAAkB;QAC5B,WAAW,EAAE,eAAe;QAC5B,UAAU,EAAE,IAAI;QAChB,UAAU,EAAE;YACV,IAAI,EAAE,KAAK;SACZ;QACD,cAAc,EAAE;YACd,IAAI,EAAE,SAAS;YACf,aAAa,EAAE,OAAO;YACtB,aAAa,EAAE,IAAI;SACpB;QACD,MAAM,EAAE;YACN,QAAQ,EAAE,SAAS;YACnB,cAAc,EAAE,sBAAsB;YACtC,YAAY,EAAE,sBAAsB;SACrC;QACD,WAAW,EAAE,SAAS;KACvB,CAAC;IAEF,SAAS,gBAAgB,CAAC,GAAW,EAAE,WAAW,GAAG,EAAE;QACrD,EAAE,CAAC,WAAW,CAAC,GAAG,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,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,CAAC;AACjC,CAAC,CAAC,EAAE,CAAC","sourcesContent":["import fs from \"fs\";\nimport path from \"path\";\nimport handlebars from \"handlebars\";\nimport { ProjectConfig } from \"../project-config-inquirer\";\nhandlebars.registerHelper(\"eq\", (a, b) => a === b);\nhandlebars.registerHelper(\"neq\", (a, b) => a !== b);\n\n(() => {\n const templatesDir = `${process.cwd()}/cache/handlebars/templates`;\n const outputDir = `${process.cwd()}/cache/handlebars/output`;\n const config: ProjectConfig = {\n projectName: \"arkos-project\",\n typescript: true,\n validation: {\n type: \"zod\",\n },\n authentication: {\n type: \"dynamic\",\n usernameField: \"email\",\n multipleRoles: true,\n },\n prisma: {\n provider: \"mongodb\",\n idDatabaseType: \"@db @default(uuid())\",\n defaultDBurl: \"@db @default(uuid())\",\n },\n projectPath: outputDir,\n };\n\n function processTemplates(dir: string, relativeDir = \"\") {\n fs.readdirSync(dir, { withFileTypes: true }).forEach(async (dirent) => {\n const fullPath = path.join(dir, dirent.name);\n const relativePath = path.join(relativeDir, dirent.name);\n\n if (dirent.isDirectory()) {\n processTemplates(fullPath, relativePath);\n } else if (dirent.name.endsWith(\".hbs\")) {\n const templatePath = fullPath;\n const template = handlebars.compile(\n fs.readFileSync(templatePath, \"utf8\")\n );\n\n const content = template(config);\n const ext = config.typescript ? \".ts\" : \".js\";\n\n let outputPath = path.join(outputDir, relativePath.replace(\".hbs\", \"\"));\n if (dirent.name.endsWith(\".ts.hbs\"))\n outputPath = path.join(\n outputDir,\n relativePath.replace(\".ts.hbs\", ext)\n );\n\n fs.mkdirSync(path.dirname(outputPath), { recursive: true });\n fs.writeFileSync(outputPath, content);\n }\n });\n }\n\n processTemplates(templatesDir);\n})();\n"]}
|
|
@@ -1,20 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getProcjetPackageJsonDependecies = exports.getLatestVersion = void 0;
|
|
7
|
-
const fs_1 = __importDefault(require("fs"));
|
|
8
|
-
async function getLatestVersion(packageName) {
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
export async function getLatestVersion(packageName) {
|
|
9
3
|
const res = await fetch(`https://registry.npmjs.org/${packageName}`);
|
|
10
4
|
if (!res.ok)
|
|
11
5
|
throw new Error(`Failed to fetch: ${res.status}`);
|
|
12
6
|
const data = await res.json();
|
|
13
7
|
return data["dist-tags"].latest;
|
|
14
8
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const content = fs_1.default.readFileSync(`${projectPath}/package.json`, {
|
|
9
|
+
export function getProcjetPackageJsonDependecies(projectPath) {
|
|
10
|
+
const content = fs.readFileSync(`${projectPath}/package.json`, {
|
|
18
11
|
encoding: "utf8",
|
|
19
12
|
});
|
|
20
13
|
const packageJson = JSON.parse(content);
|
|
@@ -22,5 +15,4 @@ function getProcjetPackageJsonDependecies(projectPath) {
|
|
|
22
15
|
const devDependencies = Object.keys(packageJson.devDependencies);
|
|
23
16
|
return { dependencies, devDependencies };
|
|
24
17
|
}
|
|
25
|
-
exports.getProcjetPackageJsonDependecies = getProcjetPackageJsonDependecies;
|
|
26
18
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/helpers/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/helpers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,WAAmB;IACxD,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,8BAA8B,WAAW,EAAE,CAAC,CAAC;IACrE,IAAI,CAAC,GAAG,CAAC,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,oBAAoB,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC;IAE/D,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;IAC9B,OAAO,IAAI,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC;AAClC,CAAC;AAED,MAAM,UAAU,gCAAgC,CAAC,WAAmB;IAIlE,MAAM,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,GAAG,WAAW,eAAe,EAAE;QAC7D,QAAQ,EAAE,MAAM;KACjB,CAAC,CAAC;IAEH,MAAM,WAAW,GAGb,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACxB,MAAM,YAAY,GAAG,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC;IAC3D,MAAM,eAAe,GAAG,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,eAAe,CAAC,CAAC;IAEjE,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,CAAC;AAC3C,CAAC","sourcesContent":["import fs from \"fs\";\n\nexport async function getLatestVersion(packageName: string) {\n const res = await fetch(`https://registry.npmjs.org/${packageName}`);\n if (!res.ok) throw new Error(`Failed to fetch: ${res.status}`);\n\n const data = await res.json();\n return data[\"dist-tags\"].latest;\n}\n\nexport function getProcjetPackageJsonDependecies(projectPath: string): {\n dependencies: string[];\n devDependencies: string[];\n} {\n const content = fs.readFileSync(`${projectPath}/package.json`, {\n encoding: \"utf8\",\n });\n\n const packageJson: {\n dependencies: Record<string, string>;\n devDependencies: Record<string, string>;\n } = JSON.parse(content);\n const dependencies = Object.keys(packageJson.dependencies);\n const devDependencies = Object.keys(packageJson.devDependencies);\n\n return { dependencies, devDependencies };\n}\n"]}
|
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const child_process_1 = require("child_process");
|
|
5
|
-
function getNpmPackageVersion(name = "arkos") {
|
|
6
|
-
const version = (0, child_process_1.execSync)(`npm view ${name} version`).toString().trim();
|
|
1
|
+
import { execSync } from "child_process";
|
|
2
|
+
export function getNpmPackageVersion(name = "arkos") {
|
|
3
|
+
const version = execSync(`npm view ${name} version`).toString().trim();
|
|
7
4
|
return version;
|
|
8
5
|
}
|
|
9
|
-
|
|
10
|
-
function detectPackageManagerFromUserAgent() {
|
|
6
|
+
export function detectPackageManagerFromUserAgent() {
|
|
11
7
|
const userAgent = process.env.npm_config_user_agent || "";
|
|
12
8
|
if (!userAgent)
|
|
13
9
|
return "npm";
|
|
@@ -27,5 +23,4 @@ function detectPackageManagerFromUserAgent() {
|
|
|
27
23
|
return "deno";
|
|
28
24
|
return "npm";
|
|
29
25
|
}
|
|
30
|
-
exports.detectPackageManagerFromUserAgent = detectPackageManagerFromUserAgent;
|
|
31
26
|
//# sourceMappingURL=npm.helpers.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"npm.helpers.js","sourceRoot":"","sources":["../../../src/utils/helpers/npm.helpers.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"npm.helpers.js","sourceRoot":"","sources":["../../../src/utils/helpers/npm.helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAQzC,MAAM,UAAU,oBAAoB,CAAC,OAAe,OAAO;IACzD,MAAM,OAAO,GAAG,QAAQ,CAAC,YAAY,IAAI,UAAU,CAAC,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,CAAC;IACvE,OAAO,OAAO,CAAC;AACjB,CAAC;AAQD,MAAM,UAAU,iCAAiC;IAC/C,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,qBAAqB,IAAI,EAAE,CAAC;IAE1D,IAAI,CAAC,SAAS;QAAE,OAAO,KAAK,CAAC;IAC7B,IAAI,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC;QAAE,OAAO,MAAM,CAAC;IAC9C,IAAI,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC;QAAE,OAAO,MAAM,CAAC;IAC9C,IAAI,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAC5C,IAAI,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAC5C,IAAI,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC;QAAE,OAAO,MAAM,CAAC;IAC9C,IAAI,SAAS,CAAC,QAAQ,CAAC,UAAU,CAAC;QAAE,OAAO,UAAU,CAAC;IACtD,IAAI,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC;QAAE,OAAO,MAAM,CAAC;IAE9C,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import { execSync } from \"child_process\";\n\n/**\n * Helps getting npm packages latest version\n *\n * @param {striong} name - name of the npm package (defaults: arkos)\n * @returns {string} version - the package latest version\n * */\nexport function getNpmPackageVersion(name: string = \"arkos\"): string {\n const version = execSync(`npm view ${name} version`).toString().trim();\n return version;\n}\n\n/**\n * Helps getting the current package manager from user agent\n *\n * @returns {string} the package manager\n * @default \"npm\"\n */\nexport function detectPackageManagerFromUserAgent(): string {\n const userAgent = process.env.npm_config_user_agent || \"\";\n\n if (!userAgent) return \"npm\";\n if (userAgent.includes(\"pnpm\")) return \"pnpm\";\n if (userAgent.includes(\"yarn\")) return \"yarn\";\n if (userAgent.includes(\"npm\")) return \"npm\";\n if (userAgent.includes(\"bun\")) return \"bun\";\n if (userAgent.includes(\"cnpm\")) return \"cnpm\";\n if (userAgent.includes(\"corepack\")) return \"corepack\";\n if (userAgent.includes(\"deno\")) return \"deno\";\n\n return \"npm\";\n}\n"]}
|
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const path_1 = __importDefault(require("path"));
|
|
7
|
-
const inquirer_1 = __importDefault(require("inquirer"));
|
|
8
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
1
|
+
import path from "path";
|
|
2
|
+
import inquirer from "inquirer";
|
|
3
|
+
import chalk from "chalk";
|
|
9
4
|
class ProjectConfigInquirer {
|
|
5
|
+
config;
|
|
10
6
|
constructor() {
|
|
11
7
|
this.config = {};
|
|
12
8
|
}
|
|
@@ -17,18 +13,18 @@ class ProjectConfigInquirer {
|
|
|
17
13
|
await this.promptValidation();
|
|
18
14
|
await this.promptAuthentication();
|
|
19
15
|
if (this.config.projectName === ".") {
|
|
20
|
-
this.config.projectName =
|
|
21
|
-
this.config.projectPath =
|
|
16
|
+
this.config.projectName = path.basename(process.cwd());
|
|
17
|
+
this.config.projectPath = path.resolve(process.cwd());
|
|
22
18
|
}
|
|
23
19
|
else
|
|
24
|
-
this.config.projectPath =
|
|
20
|
+
this.config.projectPath = path.resolve(process.cwd(), this.config.projectName);
|
|
25
21
|
return this.config;
|
|
26
22
|
}
|
|
27
23
|
async promptProjectName() {
|
|
28
24
|
let projectName = process?.argv?.[2];
|
|
29
25
|
this.config.argProjectName = process?.argv?.[2];
|
|
30
26
|
if (!projectName) {
|
|
31
|
-
const result = await
|
|
27
|
+
const result = await inquirer.prompt([
|
|
32
28
|
{
|
|
33
29
|
type: "input",
|
|
34
30
|
name: "projectName",
|
|
@@ -42,7 +38,7 @@ class ProjectConfigInquirer {
|
|
|
42
38
|
else {
|
|
43
39
|
const validation = this.validateProjectName(projectName);
|
|
44
40
|
if (validation !== true) {
|
|
45
|
-
console.error(
|
|
41
|
+
console.error(chalk.red(`\nError: ${validation}`));
|
|
46
42
|
process.exit(1);
|
|
47
43
|
}
|
|
48
44
|
}
|
|
@@ -73,22 +69,22 @@ class ProjectConfigInquirer {
|
|
|
73
69
|
return true;
|
|
74
70
|
}
|
|
75
71
|
async promptTypescript() {
|
|
76
|
-
const { typescript } = await
|
|
72
|
+
const { typescript } = await inquirer.prompt([
|
|
77
73
|
{
|
|
78
74
|
type: "confirm",
|
|
79
75
|
name: "typescript",
|
|
80
|
-
message: `Would you like to use ${
|
|
76
|
+
message: `Would you like to use ${chalk.cyan("TypeScript")}?`,
|
|
81
77
|
default: false,
|
|
82
78
|
},
|
|
83
79
|
]);
|
|
84
80
|
this.config.typescript = typescript;
|
|
85
81
|
}
|
|
86
82
|
async promptPrismaProvider() {
|
|
87
|
-
const { prismaProvider } = await
|
|
83
|
+
const { prismaProvider } = await inquirer.prompt([
|
|
88
84
|
{
|
|
89
85
|
type: "list",
|
|
90
86
|
name: "prismaProvider",
|
|
91
|
-
message: `What db provider will be used for ${
|
|
87
|
+
message: `What db provider will be used for ${chalk.cyan("Prisma")}?`,
|
|
92
88
|
choices: [
|
|
93
89
|
"postgresql",
|
|
94
90
|
"mongodb",
|
|
@@ -137,18 +133,18 @@ class ProjectConfigInquirer {
|
|
|
137
133
|
};
|
|
138
134
|
}
|
|
139
135
|
async promptValidation() {
|
|
140
|
-
const { useValidation } = await
|
|
136
|
+
const { useValidation } = await inquirer.prompt([
|
|
141
137
|
{
|
|
142
138
|
type: "confirm",
|
|
143
139
|
name: "useValidation",
|
|
144
|
-
message: `Would you like to set up ${
|
|
140
|
+
message: `Would you like to set up ${chalk.cyan("Validation")}?`,
|
|
145
141
|
default: true,
|
|
146
142
|
},
|
|
147
143
|
]);
|
|
148
144
|
if (useValidation) {
|
|
149
145
|
let validationTypeResponse = { validationType: "zod" };
|
|
150
146
|
if (this.config.typescript)
|
|
151
|
-
validationTypeResponse = await
|
|
147
|
+
validationTypeResponse = await inquirer.prompt([
|
|
152
148
|
{
|
|
153
149
|
type: "list",
|
|
154
150
|
name: "validationType",
|
|
@@ -157,7 +153,7 @@ class ProjectConfigInquirer {
|
|
|
157
153
|
},
|
|
158
154
|
]);
|
|
159
155
|
else {
|
|
160
|
-
console.info(`${
|
|
156
|
+
console.info(`${chalk.bold(chalk.green("?"))} Validation library set to ${chalk.cyan("zod")} (class-validator is not supported on JavaScript).`);
|
|
161
157
|
}
|
|
162
158
|
this.config.validation = {
|
|
163
159
|
type: validationTypeResponse.validationType,
|
|
@@ -167,16 +163,16 @@ class ProjectConfigInquirer {
|
|
|
167
163
|
}
|
|
168
164
|
}
|
|
169
165
|
async promptAuthentication() {
|
|
170
|
-
const { useAuthentication } = await
|
|
166
|
+
const { useAuthentication } = await inquirer.prompt([
|
|
171
167
|
{
|
|
172
168
|
type: "confirm",
|
|
173
169
|
name: "useAuthentication",
|
|
174
|
-
message: `Would you like to set up ${
|
|
170
|
+
message: `Would you like to set up ${chalk.cyan("Authentication")}?`,
|
|
175
171
|
default: true,
|
|
176
172
|
},
|
|
177
173
|
]);
|
|
178
174
|
if (useAuthentication) {
|
|
179
|
-
const { authenticationType } = await
|
|
175
|
+
const { authenticationType } = await inquirer.prompt([
|
|
180
176
|
{
|
|
181
177
|
type: "list",
|
|
182
178
|
name: "authenticationType",
|
|
@@ -184,7 +180,7 @@ class ProjectConfigInquirer {
|
|
|
184
180
|
choices: ["static", "dynamic", "define later"],
|
|
185
181
|
},
|
|
186
182
|
]);
|
|
187
|
-
const { usernameField } = await
|
|
183
|
+
const { usernameField } = await inquirer.prompt([
|
|
188
184
|
{
|
|
189
185
|
type: "list",
|
|
190
186
|
name: "usernameField",
|
|
@@ -200,12 +196,12 @@ class ProjectConfigInquirer {
|
|
|
200
196
|
if (authenticationType !== "define later" ||
|
|
201
197
|
(this.config.prisma.provider !== "sqlite" &&
|
|
202
198
|
authenticationType !== "static")) {
|
|
203
|
-
const { multipleRoles } = await
|
|
199
|
+
const { multipleRoles } = await inquirer.prompt([
|
|
204
200
|
{
|
|
205
201
|
type: "confirm",
|
|
206
202
|
name: "multipleRoles",
|
|
207
203
|
default: true,
|
|
208
|
-
message: `Would you like to use authentication with ${
|
|
204
|
+
message: `Would you like to use authentication with ${chalk.cyan("Multiple Roles")}?`,
|
|
209
205
|
},
|
|
210
206
|
]);
|
|
211
207
|
this.config.authentication = {
|
|
@@ -220,5 +216,5 @@ class ProjectConfigInquirer {
|
|
|
220
216
|
}
|
|
221
217
|
}
|
|
222
218
|
const projectConfigInquirer = new ProjectConfigInquirer();
|
|
223
|
-
|
|
219
|
+
export default projectConfigInquirer;
|
|
224
220
|
//# sourceMappingURL=project-config-inquirer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project-config-inquirer.js","sourceRoot":"","sources":["../../src/utils/project-config-inquirer.ts"],"names":[],"mappings":";;;;;AAAA,gDAAwB;AACxB,wDAAgC;AAChC,kDAA0B;AA4B1B,MAAM,qBAAqB;IAGzB;QACE,IAAI,CAAC,MAAM,GAAG,EAAmB,CAAC;IACpC,CAAC;IAED,KAAK,CAAC,GAAG;QACP,MAAM,IAAI,CAAC,iBAAiB,EAAE,CAAC;QAC/B,MAAM,IAAI,CAAC,gBAAgB,EAAE,CAAC;QAC9B,MAAM,IAAI,CAAC,oBAAoB,EAAE,CAAC;QAClC,MAAM,IAAI,CAAC,gBAAgB,EAAE,CAAC;QAC9B,MAAM,IAAI,CAAC,oBAAoB,EAAE,CAAC;QAGlC,IAAI,IAAI,CAAC,MAAM,CAAC,WAAW,KAAK,GAAG,EAAE;YACnC,IAAI,CAAC,MAAM,CAAC,WAAW,GAAG,cAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;YACvD,IAAI,CAAC,MAAM,CAAC,WAAW,GAAG,cAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;SACvD;;YACC,IAAI,CAAC,MAAM,CAAC,WAAW,GAAG,cAAI,CAAC,OAAO,CACpC,OAAO,CAAC,GAAG,EAAE,EACb,IAAI,CAAC,MAAM,CAAC,WAAW,CACxB,CAAC;QAEJ,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAEO,KAAK,CAAC,iBAAiB;QAC7B,IAAI,WAAW,GAAG,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;QACrC,IAAI,CAAC,MAAM,CAAC,cAAc,GAAG,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;QAEhD,IA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C,cAAc,GAAG;gBAC3B,IAAI,EAAE,kBAAkB;gBACxB,aAAa,EACX,aAAa,KAAK,cAAc,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,aAAa;gBAC7D,aAAa,EAAE,KAAK;aACrB,CAAC;YAEF,IACE,kBAAkB,KAAK,cAAc;gBACrC,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,KAAK,QAAQ;oBACvC,kBAAkB,KAAK,QAAQ,CAAC,EAClC;gBACA,MAAM,EAAE,aAAa,EAAE,GAAG,MAAM,kBAAQ,CAAC,MAAM,CAAC;oBAC9C;wBACE,IAAI,EAAE,SAAS;wBACf,IAAI,EAAE,eAAe;wBACrB,OAAO,EAAE,IAAI;wBACb,OAAO,EAAE,6CAA6C,eAAK,CAAC,IAAI,CAAC,gBAAgB,CAAC,GAAG;qBACtF;iBACF,CAAC,CAAC;gBAEH,IAAI,CAAC,MAAM,CAAC,cAAc,GAAG;oBAC3B,GAAG,IAAI,CAAC,MAAM,CAAC,cAAc;oBAC7B,aAAa;iBACd,CAAC;aACH;iBAAM,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,KAAK,QAAQ,EAAE;gBACnD,OAAO,CAAC,IAAI,CACV,0HAA0H,CAC3H,CAAC;aACH;SACF;IACH,CAAC;CACF;AAED,MAAM,qBAAqB,GAAG,IAAI,qBAAqB,EAAE,CAAC;AAE1D,kBAAe,qBAAqB,CAAC","sourcesContent":["import path from \"path\";\nimport inquirer from \"inquirer\";\nimport chalk from \"chalk\";\n\nexport interface ProjectConfig {\n projectName: string;\n argProjectName?: string;\n typescript: boolean;\n validation: {\n type?: \"zod\" | \"class-validator\";\n };\n authentication: {\n type?: \"static\" | \"dynamic\" | \"define later\";\n usernameField?: \"username\" | \"email\" | \"custom\";\n multipleRoles: boolean;\n };\n prisma: {\n provider:\n | \"postgresql\"\n | \"mysql\"\n | \"sqlite\"\n | \"sqlserver\"\n | \"cockroachdb\"\n | \"mongodb\";\n idDatabaseType: string;\n defaultDBurl: string;\n };\n projectPath: string;\n}\n\nclass ProjectConfigInquirer {\n private config: ProjectConfig;\n\n constructor() {\n this.config = {} as ProjectConfig;\n }\n\n async run() {\n await this.promptProjectName();\n await this.promptTypescript();\n await this.promptPrismaProvider();\n await this.promptValidation();\n await this.promptAuthentication();\n\n // If user passed \".\", use current directory name\n if (this.config.projectName === \".\") {\n this.config.projectName = path.basename(process.cwd());\n this.config.projectPath = path.resolve(process.cwd());\n } else\n this.config.projectPath = path.resolve(\n process.cwd(),\n this.config.projectName\n );\n\n return this.config;\n }\n\n private async promptProjectName() {\n let projectName = process?.argv?.[2];\n this.config.argProjectName = process?.argv?.[2];\n\n if (!projectName) {\n const result = await inquirer.prompt([\n {\n type: \"input\",\n name: \"projectName\",\n message: \"What is the name of your project?\",\n default: \"my-arkos-project\",\n validate: this.validateProjectName,\n },\n ]);\n projectName = result.projectName;\n } else {\n // Validate the project name from command line args\n const validation = this.validateProjectName(projectName);\n if (validation !== true) {\n console.error(chalk.red(`\\nError: ${validation}`));\n process.exit(1);\n }\n }\n\n this.config.projectName = projectName;\n }\n\n private validateProjectName(input: string): boolean | string {\n if (input === \".\") return true;\n\n if (!input || input.length === 0) {\n return \"Project name cannot be empty\";\n }\n\n // Check for valid characters (letters, numbers, hyphens, underscores)\n if (!/^[a-zA-Z0-9_-]+$/.test(input)) {\n return \"Project name can only contain letters, numbers, hyphens, and underscores\";\n }\n\n // Check if it starts with a letter or number (not hyphen or underscore)\n if (!/^[a-zA-Z0-9]/.test(input)) {\n return \"Project name must start with a letter or number\";\n }\n\n // Check if it ends with a letter or number (not hyphen or underscore)\n if (!/[a-zA-Z0-9]$/.test(input)) {\n return \"Project name must end with a letter or number\";\n }\n\n // Check length (reasonable limits)\n if (input.length > 50) {\n return \"Project name must be 50 characters or less\";\n }\n\n // Check for reserved names\n const reservedNames = [\"node_modules\"];\n if (reservedNames.includes(input.toLowerCase())) {\n return \"Project name cannot be a reserved name\";\n }\n\n return true;\n }\n\n private async promptTypescript() {\n const { typescript } = await inquirer.prompt([\n {\n type: \"confirm\",\n name: \"typescript\",\n message: `Would you like to use ${chalk.cyan(\"TypeScript\")}?`,\n default: false,\n },\n ]);\n this.config.typescript = typescript;\n }\n\n private async promptPrismaProvider() {\n const { prismaProvider } = await inquirer.prompt([\n {\n type: \"list\",\n name: \"prismaProvider\",\n message: `What db provider will be used for ${chalk.cyan(\"Prisma\")}?`,\n choices: [\n \"postgresql\",\n \"mongodb\",\n \"mysql\",\n \"sqlite\",\n \"sqlserver\",\n \"cockroachdb\",\n ],\n },\n ]);\n\n // Set the correct idDatabaseType based on provider\n let idDatabaseType: string;\n let defaultDBurl: string;\n\n switch (prismaProvider) {\n case \"mongodb\":\n idDatabaseType = '@id @default(auto()) @map(\"_id\") @db.ObjectId';\n defaultDBurl = `mongodb://localhost:27017/${this.config.projectName}`;\n break;\n case \"sqlite\":\n idDatabaseType = \"@id @default(cuid())\";\n defaultDBurl = \"file:../../file.db\";\n break;\n case \"mysql\":\n idDatabaseType = \"@id @default(uuid())\";\n defaultDBurl = `mysql://username:password@localhost:3306/${this.config.projectName}`;\n break;\n case \"postgresql\":\n idDatabaseType = \"@id @default(uuid())\";\n defaultDBurl = `postgresql://username:password@localhost:5432/${this.config.projectName}`;\n break;\n case \"sqlserver\":\n idDatabaseType = \"@id @default(uuid())\";\n defaultDBurl = `sqlserver://localhost:1433;database=${this.config.projectName};username=sa;password=password;encrypt=DANGER_PLAINTEXT`;\n break;\n case \"cockroachdb\":\n idDatabaseType = \"@id @default(uuid())\";\n defaultDBurl = `postgresql://username:password@localhost:26257/${this.config.projectName}?sslmode=require`;\n break;\n default:\n idDatabaseType = \"@id @default(uuid())\";\n defaultDBurl = `postgresql://username:password@localhost:5432/${this.config.projectName}`;\n }\n\n this.config.prisma = {\n provider: prismaProvider,\n idDatabaseType: idDatabaseType,\n defaultDBurl: defaultDBurl,\n };\n }\n\n private async promptValidation() {\n const { useValidation } = await inquirer.prompt([\n {\n type: \"confirm\",\n name: \"useValidation\",\n message: `Would you like to set up ${chalk.cyan(\"Validation\")}?`,\n default: true,\n },\n ]);\n\n if (useValidation) {\n let validationTypeResponse: {\n validationType: \"zod\" | \"class-validator\";\n } = { validationType: \"zod\" };\n\n if (this.config.typescript)\n validationTypeResponse = await inquirer.prompt([\n {\n type: \"list\",\n name: \"validationType\",\n message: \"Choose validation library:\",\n choices: [\"zod\", \"class-validator\"],\n },\n ]);\n else {\n console.info(\n `${chalk.bold(chalk.green(\"?\"))} Validation library set to ${chalk.cyan(\"zod\")} (class-validator is not supported on JavaScript).`\n );\n }\n this.config.validation = {\n type: validationTypeResponse.validationType,\n };\n } else if (!this.config.typescript) {\n }\n }\n\n private async promptAuthentication() {\n const { useAuthentication } = await inquirer.prompt([\n {\n type: \"confirm\",\n name: \"useAuthentication\",\n message: `Would you like to set up ${chalk.cyan(\"Authentication\")}?`,\n default: true,\n },\n ]);\n\n if (useAuthentication) {\n const { authenticationType } = await inquirer.prompt([\n {\n type: \"list\",\n name: \"authenticationType\",\n message: \"Choose authentication type:\",\n choices: [\"static\", \"dynamic\", \"define later\"],\n },\n ]);\n\n const { usernameField } = await inquirer.prompt([\n {\n type: \"list\",\n name: \"usernameField\",\n message: \"Choose default username field for login:\",\n choices: [\"email\", \"username\", \"define later\"],\n },\n ]);\n\n this.config.authentication = {\n type: authenticationType,\n usernameField:\n usernameField === \"define later\" ? \"custom\" : usernameField,\n multipleRoles: false,\n };\n\n if (\n authenticationType !== \"define later\" ||\n (this.config.prisma.provider !== \"sqlite\" &&\n authenticationType !== \"static\")\n ) {\n const { multipleRoles } = await inquirer.prompt([\n {\n type: \"confirm\",\n name: \"multipleRoles\",\n default: true,\n message: `Would you like to use authentication with ${chalk.cyan(\"Multiple Roles\")}?`,\n },\n ]);\n\n this.config.authentication = {\n ...this.config.authentication,\n multipleRoles,\n };\n } else if (this.config.prisma.provider === \"sqlite\") {\n console.info(\n `\\nSkipping multiple roles option because it is not supported with sqlite prisma provider and static authentication mode.`\n );\n }\n }\n }\n}\n\nconst projectConfigInquirer = new ProjectConfigInquirer();\n\nexport default projectConfigInquirer;\n"]}
|
|
1
|
+
{"version":3,"file":"project-config-inquirer.js","sourceRoot":"","sources":["../../src/utils/project-config-inquirer.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,KAAK,MAAM,OAAO,CAAC;AA4B1B,MAAM,qBAAqB;IACjB,MAAM,CAAgB;IAE9B;QACE,IAAI,CAAC,MAAM,GAAG,EAAmB,CAAC;IACpC,CAAC;IAED,KAAK,CAAC,GAAG;QACP,MAAM,IAAI,CAAC,iBAAiB,EAAE,CAAC;QAC/B,MAAM,IAAI,CAAC,gBAAgB,EAAE,CAAC;QAC9B,MAAM,IAAI,CAAC,oBAAoB,EAAE,CAAC;QAClC,MAAM,IAAI,CAAC,gBAAgB,EAAE,CAAC;QAC9B,MAAM,IAAI,CAAC,oBAAoB,EAAE,CAAC;QAGlC,IAAI,IAAI,CAAC,MAAM,CAAC,WAAW,KAAK,GAAG,EAAE;YACnC,IAAI,CAAC,MAAM,CAAC,WAAW,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;YACvD,IAAI,CAAC,MAAM,CAAC,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;SACvD;;YACC,IAAI,CAAC,MAAM,CAAC,WAAW,GAAG,IAAI,CAAC,OAAO,CACpC,OAAO,CAAC,GAAG,EAAE,EACb,IAAI,CAAC,MAAM,CAAC,WAAW,CACxB,CAAC;QAEJ,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAEO,KAAK,CAAC,iBAAiB;QAC7B,IAAI,WAAW,GAAG,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;QACrC,IAAI,CA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AAU,EAAE,cAAc,CAAC;iBAC/C;aACF,CAAC,CAAC;YAEH,IAAI,CAAC,MAAM,CAAC,cAAc,GAAG;gBAC3B,IAAI,EAAE,kBAAkB;gBACxB,aAAa,EACX,aAAa,KAAK,cAAc,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,aAAa;gBAC7D,aAAa,EAAE,KAAK;aACrB,CAAC;YAEF,IACE,kBAAkB,KAAK,cAAc;gBACrC,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,KAAK,QAAQ;oBACvC,kBAAkB,KAAK,QAAQ,CAAC,EAClC;gBACA,MAAM,EAAE,aAAa,EAAE,GAAG,MAAM,QAAQ,CAAC,MAAM,CAAC;oBAC9C;wBACE,IAAI,EAAE,SAAS;wBACf,IAAI,EAAE,eAAe;wBACrB,OAAO,EAAE,IAAI;wBACb,OAAO,EAAE,6CAA6C,KAAK,CAAC,IAAI,CAAC,gBAAgB,CAAC,GAAG;qBACtF;iBACF,CAAC,CAAC;gBAEH,IAAI,CAAC,MAAM,CAAC,cAAc,GAAG;oBAC3B,GAAG,IAAI,CAAC,MAAM,CAAC,cAAc;oBAC7B,aAAa;iBACd,CAAC;aACH;iBAAM,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,KAAK,QAAQ,EAAE;gBACnD,OAAO,CAAC,IAAI,CACV,0HAA0H,CAC3H,CAAC;aACH;SACF;IACH,CAAC;CACF;AAED,MAAM,qBAAqB,GAAG,IAAI,qBAAqB,EAAE,CAAC;AAE1D,eAAe,qBAAqB,CAAC","sourcesContent":["import path from \"path\";\nimport inquirer from \"inquirer\";\nimport chalk from \"chalk\";\n\nexport interface ProjectConfig {\n projectName: string;\n argProjectName?: string;\n typescript: boolean;\n validation: {\n type?: \"zod\" | \"class-validator\";\n };\n authentication: {\n type?: \"static\" | \"dynamic\" | \"define later\";\n usernameField?: \"username\" | \"email\" | \"custom\";\n multipleRoles: boolean;\n };\n prisma: {\n provider:\n | \"postgresql\"\n | \"mysql\"\n | \"sqlite\"\n | \"sqlserver\"\n | \"cockroachdb\"\n | \"mongodb\";\n idDatabaseType: string;\n defaultDBurl: string;\n };\n projectPath: string;\n}\n\nclass ProjectConfigInquirer {\n private config: ProjectConfig;\n\n constructor() {\n this.config = {} as ProjectConfig;\n }\n\n async run() {\n await this.promptProjectName();\n await this.promptTypescript();\n await this.promptPrismaProvider();\n await this.promptValidation();\n await this.promptAuthentication();\n\n // If user passed \".\", use current directory name\n if (this.config.projectName === \".\") {\n this.config.projectName = path.basename(process.cwd());\n this.config.projectPath = path.resolve(process.cwd());\n } else\n this.config.projectPath = path.resolve(\n process.cwd(),\n this.config.projectName\n );\n\n return this.config;\n }\n\n private async promptProjectName() {\n let projectName = process?.argv?.[2];\n this.config.argProjectName = process?.argv?.[2];\n\n if (!projectName) {\n const result = await inquirer.prompt([\n {\n type: \"input\",\n name: \"projectName\",\n message: \"What is the name of your project?\",\n default: \"my-arkos-project\",\n validate: this.validateProjectName,\n },\n ]);\n projectName = result.projectName;\n } else {\n // Validate the project name from command line args\n const validation = this.validateProjectName(projectName);\n if (validation !== true) {\n console.error(chalk.red(`\\nError: ${validation}`));\n process.exit(1);\n }\n }\n\n this.config.projectName = projectName;\n }\n\n private validateProjectName(input: string): boolean | string {\n if (input === \".\") return true;\n\n if (!input || input.length === 0) {\n return \"Project name cannot be empty\";\n }\n\n // Check for valid characters (letters, numbers, hyphens, underscores)\n if (!/^[a-zA-Z0-9_-]+$/.test(input)) {\n return \"Project name can only contain letters, numbers, hyphens, and underscores\";\n }\n\n // Check if it starts with a letter or number (not hyphen or underscore)\n if (!/^[a-zA-Z0-9]/.test(input)) {\n return \"Project name must start with a letter or number\";\n }\n\n // Check if it ends with a letter or number (not hyphen or underscore)\n if (!/[a-zA-Z0-9]$/.test(input)) {\n return \"Project name must end with a letter or number\";\n }\n\n // Check length (reasonable limits)\n if (input.length > 50) {\n return \"Project name must be 50 characters or less\";\n }\n\n // Check for reserved names\n const reservedNames = [\"node_modules\"];\n if (reservedNames.includes(input.toLowerCase())) {\n return \"Project name cannot be a reserved name\";\n }\n\n return true;\n }\n\n private async promptTypescript() {\n const { typescript } = await inquirer.prompt([\n {\n type: \"confirm\",\n name: \"typescript\",\n message: `Would you like to use ${chalk.cyan(\"TypeScript\")}?`,\n default: false,\n },\n ]);\n this.config.typescript = typescript;\n }\n\n private async promptPrismaProvider() {\n const { prismaProvider } = await inquirer.prompt([\n {\n type: \"list\",\n name: \"prismaProvider\",\n message: `What db provider will be used for ${chalk.cyan(\"Prisma\")}?`,\n choices: [\n \"postgresql\",\n \"mongodb\",\n \"mysql\",\n \"sqlite\",\n \"sqlserver\",\n \"cockroachdb\",\n ],\n },\n ]);\n\n // Set the correct idDatabaseType based on provider\n let idDatabaseType: string;\n let defaultDBurl: string;\n\n switch (prismaProvider) {\n case \"mongodb\":\n idDatabaseType = '@id @default(auto()) @map(\"_id\") @db.ObjectId';\n defaultDBurl = `mongodb://localhost:27017/${this.config.projectName}`;\n break;\n case \"sqlite\":\n idDatabaseType = \"@id @default(cuid())\";\n defaultDBurl = \"file:../../file.db\";\n break;\n case \"mysql\":\n idDatabaseType = \"@id @default(uuid())\";\n defaultDBurl = `mysql://username:password@localhost:3306/${this.config.projectName}`;\n break;\n case \"postgresql\":\n idDatabaseType = \"@id @default(uuid())\";\n defaultDBurl = `postgresql://username:password@localhost:5432/${this.config.projectName}`;\n break;\n case \"sqlserver\":\n idDatabaseType = \"@id @default(uuid())\";\n defaultDBurl = `sqlserver://localhost:1433;database=${this.config.projectName};username=sa;password=password;encrypt=DANGER_PLAINTEXT`;\n break;\n case \"cockroachdb\":\n idDatabaseType = \"@id @default(uuid())\";\n defaultDBurl = `postgresql://username:password@localhost:26257/${this.config.projectName}?sslmode=require`;\n break;\n default:\n idDatabaseType = \"@id @default(uuid())\";\n defaultDBurl = `postgresql://username:password@localhost:5432/${this.config.projectName}`;\n }\n\n this.config.prisma = {\n provider: prismaProvider,\n idDatabaseType: idDatabaseType,\n defaultDBurl: defaultDBurl,\n };\n }\n\n private async promptValidation() {\n const { useValidation } = await inquirer.prompt([\n {\n type: \"confirm\",\n name: \"useValidation\",\n message: `Would you like to set up ${chalk.cyan(\"Validation\")}?`,\n default: true,\n },\n ]);\n\n if (useValidation) {\n let validationTypeResponse: {\n validationType: \"zod\" | \"class-validator\";\n } = { validationType: \"zod\" };\n\n if (this.config.typescript)\n validationTypeResponse = await inquirer.prompt([\n {\n type: \"list\",\n name: \"validationType\",\n message: \"Choose validation library:\",\n choices: [\"zod\", \"class-validator\"],\n },\n ]);\n else {\n console.info(\n `${chalk.bold(chalk.green(\"?\"))} Validation library set to ${chalk.cyan(\"zod\")} (class-validator is not supported on JavaScript).`\n );\n }\n this.config.validation = {\n type: validationTypeResponse.validationType,\n };\n } else if (!this.config.typescript) {\n }\n }\n\n private async promptAuthentication() {\n const { useAuthentication } = await inquirer.prompt([\n {\n type: \"confirm\",\n name: \"useAuthentication\",\n message: `Would you like to set up ${chalk.cyan(\"Authentication\")}?`,\n default: true,\n },\n ]);\n\n if (useAuthentication) {\n const { authenticationType } = await inquirer.prompt([\n {\n type: \"list\",\n name: \"authenticationType\",\n message: \"Choose authentication type:\",\n choices: [\"static\", \"dynamic\", \"define later\"],\n },\n ]);\n\n const { usernameField } = await inquirer.prompt([\n {\n type: \"list\",\n name: \"usernameField\",\n message: \"Choose default username field for login:\",\n choices: [\"email\", \"username\", \"define later\"],\n },\n ]);\n\n this.config.authentication = {\n type: authenticationType,\n usernameField:\n usernameField === \"define later\" ? \"custom\" : usernameField,\n multipleRoles: false,\n };\n\n if (\n authenticationType !== \"define later\" ||\n (this.config.prisma.provider !== \"sqlite\" &&\n authenticationType !== \"static\")\n ) {\n const { multipleRoles } = await inquirer.prompt([\n {\n type: \"confirm\",\n name: \"multipleRoles\",\n default: true,\n message: `Would you like to use authentication with ${chalk.cyan(\"Multiple Roles\")}?`,\n },\n ]);\n\n this.config.authentication = {\n ...this.config.authentication,\n multipleRoles,\n };\n } else if (this.config.prisma.provider === \"sqlite\") {\n console.info(\n `\\nSkipping multiple roles option because it is not supported with sqlite prisma provider and static authentication mode.`\n );\n }\n }\n }\n}\n\nconst projectConfigInquirer = new ProjectConfigInquirer();\n\nexport default projectConfigInquirer;\n"]}
|
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const path_1 = __importDefault(require("path"));
|
|
7
|
-
const fs_1 = __importDefault(require("fs"));
|
|
8
|
-
const handlebars_1 = __importDefault(require("handlebars"));
|
|
1
|
+
import path from "path";
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
import handlebars from "handlebars";
|
|
9
4
|
class TemplateCompiler {
|
|
10
5
|
async canCompileAuthenticationTemplates(config) {
|
|
11
6
|
return !!config.authentication;
|
|
@@ -89,25 +84,25 @@ class TemplateCompiler {
|
|
|
89
84
|
const isTypescript = config.typescript;
|
|
90
85
|
const filesToBeSkipped = this.filesToBeSkipped(config);
|
|
91
86
|
function processTemplates(dir, relativeDir = "") {
|
|
92
|
-
|
|
87
|
+
fs.readdirSync(dir, { withFileTypes: true }).forEach(async (dirent) => {
|
|
93
88
|
if (filesToBeSkipped.includes(dirent.name))
|
|
94
89
|
return;
|
|
95
|
-
const fullPath =
|
|
96
|
-
const relativePath =
|
|
90
|
+
const fullPath = path.join(dir, dirent.name);
|
|
91
|
+
const relativePath = path.join(relativeDir, dirent.name);
|
|
97
92
|
if (dirent.isDirectory()) {
|
|
98
93
|
processTemplates(fullPath, relativePath);
|
|
99
94
|
}
|
|
100
95
|
else if (dirent.name.endsWith(".hbs")) {
|
|
101
96
|
const templatePath = fullPath;
|
|
102
|
-
const template =
|
|
103
|
-
let arkosCurrentVersion = "
|
|
97
|
+
const template = handlebars.compile(fs.readFileSync(templatePath, "utf8"));
|
|
98
|
+
let arkosCurrentVersion = "{{arkosCurrentVersion}}";
|
|
104
99
|
const content = template({ ...config, arkosCurrentVersion });
|
|
105
100
|
const ext = isTypescript ? ".ts" : ".js";
|
|
106
|
-
let outputPath =
|
|
101
|
+
let outputPath = path.join(outputDir, relativePath.replace(".hbs", ""));
|
|
107
102
|
if (dirent.name.endsWith(".ts.hbs"))
|
|
108
|
-
outputPath =
|
|
109
|
-
|
|
110
|
-
|
|
103
|
+
outputPath = path.join(outputDir, relativePath.replace(".ts.hbs", ext));
|
|
104
|
+
fs.mkdirSync(path.dirname(outputPath), { recursive: true });
|
|
105
|
+
fs.writeFileSync(outputPath, content);
|
|
111
106
|
}
|
|
112
107
|
});
|
|
113
108
|
}
|
|
@@ -115,5 +110,5 @@ class TemplateCompiler {
|
|
|
115
110
|
}
|
|
116
111
|
}
|
|
117
112
|
const templateCompiler = new TemplateCompiler();
|
|
118
|
-
|
|
113
|
+
export default templateCompiler;
|
|
119
114
|
//# sourceMappingURL=template-compiler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"template-compiler.js","sourceRoot":"","sources":["../../src/utils/template-compiler.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"template-compiler.js","sourceRoot":"","sources":["../../src/utils/template-compiler.ts"],"names":[],"mappings":"AACA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,UAAU,MAAM,YAAY,CAAC;AAGpC,MAAM,gBAAgB;IACpB,KAAK,CAAC,iCAAiC,CAAC,MAAqB;QAC3D,OAAO,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC;IACjC,CAAC;IAED,gBAAgB,CAAC,MAAqB;QACpC,MAAM,KAAK,GAAa,EAAE,CAAC;QAC3B,MAAM,qBAAqB,GAAG,CAAC,iBAAiB,CAAC,CAAC;QAElD,MAAM,sBAAsB,GAAG;YAC7B,4BAA4B;YAC5B,sBAAsB;YACtB,sBAAsB;SACvB,CAAC;QAEF,MAAM,wBAAwB,GA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AAI,gBAAgB,EAAE,CAAC;AAEhD,eAAe,gBAAgB,CAAC","sourcesContent":["import { ProjectConfig } from \"./project-config-inquirer\";\nimport path from \"path\";\nimport fs from \"fs\";\nimport handlebars from \"handlebars\";\nimport { getNpmPackageVersion } from \"./helpers/npm.helpers\";\n\nclass TemplateCompiler {\n async canCompileAuthenticationTemplates(config: ProjectConfig) {\n return !!config.authentication;\n }\n\n filesToBeSkipped(config: ProjectConfig) {\n const files: string[] = [];\n const authSharedPrismaFiles = [\"user.prisma.hbs\"];\n\n const dynamicAuthPrismaFiles = [\n \"auth-permission.prisma.hbs\",\n \"auth-role.prisma.hbs\",\n \"user-role.prisma.hbs\",\n ];\n\n const sharedAuthZodSchemaFiles = [\n \"login.schema.ts.hbs\",\n \"signup.schema.ts.hbs\",\n \"update-password.schema.ts.hbs\",\n \"update-me.schema.ts.hbs\",\n ];\n\n const dynamicAuthZodSchemaFiles = [\n \"create-auth-permission.schema.ts.hbs\",\n \"update-auth-permission.schema.ts.hbs\",\n \"create-auth-role.schema.ts.hbs\",\n \"update-auth-role.schema.ts.hbs\",\n ];\n\n const userZodSchemaFiles = [\n \"create-user.schema.ts.hbs\",\n \"update-user.schema.ts.hbs\",\n ];\n\n const userClassValidatorDtoFiles = [\n \"create-user.dto.ts.hbs\",\n \"update-user.dto.ts.hbs\",\n ];\n\n const sharedAuthClassValidatorDtoFiles = [\n \"login.dto.ts.hbs\",\n \"signup.dto.ts.hbs\",\n \"update-password.dto.ts.hbs\",\n \"update-me.dto.ts.hbs\",\n ];\n\n const dynamicAuthClassValidatorDtoFiles = [\n \"create-auth-permission.dto.ts.hbs\",\n \"update-auth-permission.dto.ts.hbs\",\n \"create-auth-role.dto.ts.hbs\",\n \"update-auth-role.dto.ts.hbs\",\n ];\n\n const authModuleComponents = [\n \"auth.middlewares.ts.hbs\",\n \"auth.query.ts.hbs\",\n ];\n\n const authPermissionModuleComponents = [\n \"auth-permission.auth.ts.hbs\",\n \"auth-permission.query.ts.hbs\",\n \"auth-permission.service.ts.hbs\",\n ];\n\n const authRoleModuleComponents = [\n \"auth-role.auth.ts.hbs\",\n \"auth-role.query.ts.hbs\",\n \"auth-role.service.ts.hbs\",\n ];\n\n const userModuleComponents = [\n \"user.middlewares.ts.hbs\",\n \"user.query.ts.hbs\",\n \"user.service.ts.hbs\",\n \"user.auth.ts.hbs\",\n ];\n\n // Ignoring auth relation files when auth is set to define later\n if (config.authentication?.type === \"define later\")\n files.push(\n ...authSharedPrismaFiles,\n ...dynamicAuthPrismaFiles,\n ...sharedAuthZodSchemaFiles,\n ...dynamicAuthZodSchemaFiles,\n ...sharedAuthClassValidatorDtoFiles,\n ...dynamicAuthClassValidatorDtoFiles,\n ...userModuleComponents,\n ...authModuleComponents,\n ...authPermissionModuleComponents,\n ...authRoleModuleComponents\n );\n\n // Ignoring files that are not required on static authentication\n if (config.authentication?.type === \"static\")\n files.push(\n ...dynamicAuthPrismaFiles,\n ...dynamicAuthZodSchemaFiles,\n ...dynamicAuthClassValidatorDtoFiles,\n ...authPermissionModuleComponents,\n ...authRoleModuleComponents\n );\n\n // Ignore zod related files when validation is class-validator\n if (config.validation.type !== \"zod\")\n files.push(\n ...sharedAuthZodSchemaFiles,\n ...dynamicAuthZodSchemaFiles,\n ...userZodSchemaFiles\n );\n\n // Ignore class-validator related files when validation is zod\n if (config.validation.type !== \"class-validator\")\n files.push(\n ...sharedAuthClassValidatorDtoFiles,\n ...dynamicAuthClassValidatorDtoFiles,\n ...userClassValidatorDtoFiles\n );\n\n // Ignoring typescript related files when typescript false\n if (!config.typescript) files.push(...[\"tsconfig.json.hbs\"]);\n\n // Ignoring javascript related files when typescript true\n if (config?.typescript) files.push(...[\"jsconfig.json.hbs\"]);\n\n return files;\n }\n /**\n * Compiles the Arkos.js project with handlebars templates\n *\n * @param templatesDir {string} templates location\n * @param config {ProjectConfig} the project configuration\n * @returns void\n * */\n async compile(templatesDir: string, config: ProjectConfig) {\n const outputDir = config.projectPath;\n const isTypescript = config.typescript;\n const filesToBeSkipped = this.filesToBeSkipped(config);\n\n function processTemplates(dir: string, relativeDir = \"\") {\n fs.readdirSync(dir, { withFileTypes: true }).forEach(async (dirent) => {\n if (filesToBeSkipped.includes(dirent.name)) return;\n\n const fullPath = path.join(dir, dirent.name);\n const relativePath = path.join(relativeDir, dirent.name);\n\n if (dirent.isDirectory()) {\n processTemplates(fullPath, relativePath);\n } else if (dirent.name.endsWith(\".hbs\")) {\n const templatePath = fullPath;\n const template = handlebars.compile(\n fs.readFileSync(templatePath, \"utf8\")\n );\n\n let arkosCurrentVersion = \"{{arkosCurrentVersion}}\";\n\n const content = template({ ...config, arkosCurrentVersion });\n const ext = isTypescript ? \".ts\" : \".js\";\n\n let outputPath = path.join(\n outputDir,\n relativePath.replace(\".hbs\", \"\")\n );\n if (dirent.name.endsWith(\".ts.hbs\"))\n outputPath = path.join(\n outputDir,\n relativePath.replace(\".ts.hbs\", ext)\n );\n\n fs.mkdirSync(path.dirname(outputPath), { recursive: true });\n fs.writeFileSync(outputPath, content);\n }\n });\n }\n\n processTemplates(templatesDir);\n }\n}\n\nconst templateCompiler = new TemplateCompiler();\n\nexport default templateCompiler;\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-arkos",
|
|
3
|
-
"version": "1.2.15-beta.
|
|
3
|
+
"version": "1.2.15-beta.2",
|
|
4
4
|
"description": "CLI for creating Arkos.js projects, see docs at www.arkosjs.com",
|
|
5
5
|
"bin": {
|
|
6
6
|
"create-arkos": "./dist/index.js"
|
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
"scripts": {
|
|
9
9
|
"build": "rimraf dist && tsc",
|
|
10
10
|
"dev": "ts-node src/index.ts",
|
|
11
|
-
"
|
|
12
|
-
"
|
|
11
|
+
"postbuilda": "ts-node scripts/postbuild/index.ts",
|
|
12
|
+
"postpublisha": "ts-node scripts/postpublish/index.ts",
|
|
13
13
|
"test:hbs": "ts-node src/utils/helpers/hbs-tester.helpers.ts",
|
|
14
14
|
"prepublishOnlyBak": "pnpm build",
|
|
15
15
|
"publish": "ts-node scripts/postbuild/index.ts && pnpm build && npm publish --tag latest"
|