create-arkos 1.2.16-test.5 → 1.3.0-beta.1
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 +6 -5
- package/dist/index.js.map +1 -1
- package/dist/utils/helpers/npm.helpers.js +2 -2
- package/dist/utils/helpers/npm.helpers.js.map +1 -1
- package/dist/utils/helpers/{index.js → package-json.helpers.js} +1 -1
- package/dist/utils/helpers/package-json.helpers.js.map +1 -0
- package/dist/utils/helpers/templates.helpers.js +7 -0
- package/dist/utils/helpers/templates.helpers.js.map +1 -0
- package/dist/utils/project-config-inquirer.js +17 -3
- package/dist/utils/project-config-inquirer.js.map +1 -1
- package/dist/utils/template-compiler.js +3 -1
- package/dist/utils/template-compiler.js.map +1 -1
- package/package.json +5 -2
- package/templates/basic/.env.hbs +1 -1
- package/templates/basic/__tests__/.env.hbs.test.ts +138 -0
- package/templates/basic/__tests__/.gitignore.hbs.test.ts +142 -0
- package/templates/basic/__tests__/arkos.config.ts.hbs.test.ts +110 -0
- package/templates/basic/__tests__/jsconfig.json.hbs.test.ts +115 -0
- package/templates/basic/__tests__/package.json.hbs.test.ts +183 -0
- package/templates/basic/__tests__/tsconfig.json.hbs.test.ts +143 -0
- package/templates/basic/docker-compose.yaml.hbs +0 -0
- package/templates/basic/package.json.hbs +2 -5
- package/templates/basic/prisma/schema/__tests__/auth-permission.prisma.hbs.test.ts +126 -0
- package/templates/basic/prisma/schema/__tests__/auth-role.prisma.hbs.test.ts +107 -0
- package/templates/basic/prisma/schema/__tests__/schema.prisma.hbs.test.ts +111 -0
- package/templates/basic/prisma/schema/__tests__/user-role.prisma.hbs.test.ts +158 -0
- package/templates/basic/prisma/schema/__tests__/user.prisma.hbs.test.ts +101 -0
- package/templates/basic/prisma/schema/auth-permission.prisma.hbs +0 -1
- package/templates/basic/prisma/schema/user.prisma.hbs +3 -1
- package/templates/basic/src/app.ts.hbs +5 -0
- package/templates/basic/src/modules/auth/auth.query.ts.hbs +2 -2
- package/templates/basic/src/modules/user/user.query.ts.hbs +4 -4
- package/templates/basic/tsconfig.json.hbs +1 -1
- package/dist/utils/helpers/hbs-tester.helpers.js +0 -49
- package/dist/utils/helpers/hbs-tester.helpers.js.map +0 -1
- package/dist/utils/helpers/index.js.map +0 -1
- package/dist/utils/helpers/template-processor.js +0 -2
- package/dist/utils/helpers/template-processor.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -5,14 +5,14 @@ import chalk from "chalk";
|
|
|
5
5
|
import { execSync } from "child_process";
|
|
6
6
|
import projectConfigInquirer from "./utils/project-config-inquirer.js";
|
|
7
7
|
import templateCompiler from "./utils/template-compiler.js";
|
|
8
|
-
import
|
|
9
|
-
import { getProcjetPackageJsonDependecies } from "./utils/helpers/
|
|
8
|
+
import handlebars from "handlebars";
|
|
9
|
+
import { getProcjetPackageJsonDependecies } from "./utils/helpers/package-json.helpers.js";
|
|
10
10
|
import { detectPackageManagerFromUserAgent } from "./utils/helpers/npm.helpers.js";
|
|
11
11
|
import { fileURLToPath } from "url";
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
handlebars.registerHelper("eq", (a, b) => a === b);
|
|
13
|
+
handlebars.registerHelper("neq", (a, b) => a !== b);
|
|
14
14
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
15
|
-
async function main() {
|
|
15
|
+
export async function main() {
|
|
16
16
|
const config = await projectConfigInquirer.run();
|
|
17
17
|
const argProjectName = config.argProjectName;
|
|
18
18
|
const projectPath = config.projectPath;
|
|
@@ -50,4 +50,5 @@ async function main() {
|
|
|
50
50
|
`);
|
|
51
51
|
}
|
|
52
52
|
main().catch(console.error);
|
|
53
|
+
export { handlebars };
|
|
53
54
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,O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C,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;MACT,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;;IAEpC,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;AAE5B,OAAO,EAAE,UAAU,EAAE,CAAC","sourcesContent":["#!/usr/bin/env node\nimport fs from \"fs\";\nimport path, { dirname } 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/package-json.helpers\";\nimport { detectPackageManagerFromUserAgent } from \"./utils/helpers/npm.helpers\";\nimport { fileURLToPath } from \"url\";\n\nhandlebars.registerHelper(\"eq\", (a: any, b: any) => a === b);\nhandlebars.registerHelper(\"neq\", (a: any, b: any) => a !== b);\n\nconst __dirname = dirname(fileURLToPath(import.meta.url));\n\nexport async 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 \\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\nexport { handlebars };\n"]}
|
|
@@ -11,8 +11,6 @@ export function detectPackageManagerFromUserAgent() {
|
|
|
11
11
|
return "pnpm";
|
|
12
12
|
if (userAgent.includes("yarn"))
|
|
13
13
|
return "yarn";
|
|
14
|
-
if (userAgent.includes("npm"))
|
|
15
|
-
return "npm";
|
|
16
14
|
if (userAgent.includes("bun"))
|
|
17
15
|
return "bun";
|
|
18
16
|
if (userAgent.includes("cnpm"))
|
|
@@ -21,6 +19,8 @@ export function detectPackageManagerFromUserAgent() {
|
|
|
21
19
|
return "corepack";
|
|
22
20
|
if (userAgent.includes("deno"))
|
|
23
21
|
return "deno";
|
|
22
|
+
if (userAgent.includes("npm"))
|
|
23
|
+
return "npm";
|
|
24
24
|
return "npm";
|
|
25
25
|
}
|
|
26
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":"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,
|
|
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,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;IAC9C,IAAI,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAE5C,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(\"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 if (userAgent.includes(\"npm\")) return \"npm\";\n\n return \"npm\";\n}\n"]}
|
|
@@ -15,4 +15,4 @@ export function getProcjetPackageJsonDependecies(projectPath) {
|
|
|
15
15
|
const devDependencies = Object.keys(packageJson.devDependencies);
|
|
16
16
|
return { dependencies, devDependencies };
|
|
17
17
|
}
|
|
18
|
-
//# sourceMappingURL=
|
|
18
|
+
//# sourceMappingURL=package-json.helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package-json.helpers.js","sourceRoot":"","sources":["../../../src/utils/helpers/package-json.helpers.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"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
import { handlebars } from "../../index.js";
|
|
4
|
+
export function renderTemplate(templatePath, context) {
|
|
5
|
+
return handlebars.compile(fs.readFileSync(path.join(process.cwd(), "templates", templatePath), "utf8"))(context);
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=templates.helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"templates.helpers.js","sourceRoot":"","sources":["../../../src/utils/helpers/templates.helpers.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAKnC,MAAM,UAAU,cAAc,CAC5B,YAAoB,EACpB,OAA4B;IAE5B,OAAO,UAAU,CAAC,OAAO,CACvB,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,WAAW,EAAE,YAAY,CAAC,EAAE,MAAM,CAAC,CAC7E,CAAC,OAAO,CAAC,CAAC;AACb,CAAC","sourcesContent":["import path from \"path\";\nimport fs from \"fs\";\nimport { handlebars } from \"../..\";\n\n/**\n * This one was added to help testing the hbs templates files.\n */\nexport function renderTemplate(\n templatePath: string,\n context: Record<string, any>\n) {\n return handlebars.compile(\n fs.readFileSync(path.join(process.cwd(), \"templates\", templatePath), \"utf8\")\n )(context);\n}\n"]}
|
|
@@ -12,6 +12,7 @@ class ProjectConfigInquirer {
|
|
|
12
12
|
await this.promptPrismaProvider();
|
|
13
13
|
await this.promptValidation();
|
|
14
14
|
await this.promptAuthentication();
|
|
15
|
+
await this.promptStrictRouting();
|
|
15
16
|
if (this.config.projectName === ".") {
|
|
16
17
|
this.config.projectName = path.basename(process.cwd());
|
|
17
18
|
this.config.projectPath = path.resolve(process.cwd());
|
|
@@ -193,9 +194,9 @@ class ProjectConfigInquirer {
|
|
|
193
194
|
usernameField: usernameField === "define later" ? "custom" : usernameField,
|
|
194
195
|
multipleRoles: false,
|
|
195
196
|
};
|
|
196
|
-
if (authenticationType !== "define later"
|
|
197
|
-
|
|
198
|
-
|
|
197
|
+
if (authenticationType !== "define later" &&
|
|
198
|
+
this.config.prisma.provider !== "sqlite" &&
|
|
199
|
+
authenticationType !== "static") {
|
|
199
200
|
const { multipleRoles } = await inquirer.prompt([
|
|
200
201
|
{
|
|
201
202
|
type: "confirm",
|
|
@@ -214,6 +215,19 @@ class ProjectConfigInquirer {
|
|
|
214
215
|
}
|
|
215
216
|
}
|
|
216
217
|
}
|
|
218
|
+
async promptStrictRouting() {
|
|
219
|
+
const { strictRouting } = await inquirer.prompt([
|
|
220
|
+
{
|
|
221
|
+
type: "confirm",
|
|
222
|
+
name: "strictRouting",
|
|
223
|
+
message: `Would you like to use ${chalk.cyan("Strict Routing")}?`,
|
|
224
|
+
default: false,
|
|
225
|
+
},
|
|
226
|
+
]);
|
|
227
|
+
this.config.routing = {
|
|
228
|
+
strict: strictRouting,
|
|
229
|
+
};
|
|
230
|
+
}
|
|
217
231
|
}
|
|
218
232
|
const projectConfigInquirer = new ProjectConfigInquirer();
|
|
219
233
|
export default projectConfigInquirer;
|
|
@@ -1 +1 @@
|
|
|
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,CA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C;gBAC9C;oBACE,IAAI,EAAE,MAAM;oBACZ,IAAI,EAAE,eAAe;oBACrB,OAAO,EAAE,0CAA0C;oBACnD,OAAO,EAAE,CAAC,OAAO,EAAE,UAAU,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(\n `${chalk.greenBright(\"?\")} Validation library set to zod (class-validator is not supported on JavaScript):`\n ),\n chalk.cyan(\"zod\")\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;AA+B1B,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;QAClC,MAAM,IAAI,CAAC,mBAAmB,EAAE,CAAC;QAGjC,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,I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AC;YAC9C;gBACE,IAAI,EAAE,SAAS;gBACf,IAAI,EAAE,eAAe;gBACrB,OAAO,EAAE,yBAAyB,KAAK,CAAC,IAAI,CAAC,gBAAgB,CAAC,GAAG;gBACjE,OAAO,EAAE,KAAK;aACf;SACF,CAAC,CAAC;QACH,IAAI,CAAC,MAAM,CAAC,OAAO,GAAG;YACpB,MAAM,EAAE,aAAa;SACtB,CAAC;IACJ,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 routing?: {\n strict?: boolean;\n };\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 await this.promptStrictRouting();\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(\n `${chalk.greenBright(\"?\")} Validation library set to zod (class-validator is not supported on JavaScript):`\n ),\n chalk.cyan(\"zod\")\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 private async promptStrictRouting() {\n const { strictRouting } = await inquirer.prompt([\n {\n type: \"confirm\",\n name: \"strictRouting\",\n message: `Would you like to use ${chalk.cyan(\"Strict Routing\")}?`,\n default: false,\n },\n ]);\n this.config.routing = {\n strict: strictRouting,\n };\n }\n}\n\nconst projectConfigInquirer = new ProjectConfigInquirer();\n\nexport default projectConfigInquirer;\n"]}
|
|
@@ -85,7 +85,9 @@ class TemplateCompiler {
|
|
|
85
85
|
const filesToBeSkipped = this.filesToBeSkipped(config);
|
|
86
86
|
function processTemplates(dir, relativeDir = "") {
|
|
87
87
|
fs.readdirSync(dir, { withFileTypes: true }).forEach(async (dirent) => {
|
|
88
|
-
if (filesToBeSkipped.includes(dirent.name)
|
|
88
|
+
if (filesToBeSkipped.includes(dirent.name) ||
|
|
89
|
+
dirent.name === "__tests__" ||
|
|
90
|
+
dirent.name?.includes(".test.ts"))
|
|
89
91
|
return;
|
|
90
92
|
const fullPath = path.join(dir, dirent.name);
|
|
91
93
|
const relativePath = path.join(relativeDir, dirent.name);
|
|
@@ -1 +1 @@
|
|
|
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;AAEpC,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,GAAG;YAC/B,qBAAqB;YACrB,sBAAsB;YACtB,+BAA+B;YAC/B,yBAAyB;SAC1B,CAAC;QAEF,MAAM,yBAAyB,GAAG;YAChC,sCAAsC;YACtC,sCAAsC;YACtC,gCAAgC;YAChC,gCAAgC;SACjC,CAAC;QAEF,MAAM,kBAAkB,GAAG;YACzB,2BAA2B;YAC3B,2BAA2B;SAC5B,CAAC;QAEF,MAAM,0BAA0B,GAAG;YACjC,wBAAwB;YACxB,wBAAwB;SACzB,CAAC;QAEF,MAAM,gCAAgC,GAAG;YACvC,kBAAkB;YAClB,mBAAmB;YACnB,4BAA4B;YAC5B,sBAAsB;SACvB,CAAC;QAEF,MAAM,iCAAiC,GAAG;YACxC,mCAAmC;YACnC,mCAAmC;YACnC,6BAA6B;YAC7B,6BAA6B;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D,eAAe,gBAAgB,CAAC","sourcesContent":["import { ProjectConfig } from \"./project-config-inquirer\";\nimport path from \"path\";\nimport fs from \"fs\";\nimport handlebars from \"handlebars\";\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 (\n filesToBeSkipped.includes(dirent.name) ||\n dirent.name === \"__tests__\" ||\n dirent.name?.includes(\".test.ts\")\n )\n 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,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-arkos",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0-beta.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "CLI for creating Arkos.js projects, see docs at www.arkosjs.com",
|
|
6
6
|
"bin": {
|
|
7
7
|
"create-arkos": "./dist/index.js"
|
|
8
8
|
},
|
|
9
9
|
"scripts": {
|
|
10
|
+
"test": "vitest --coverage",
|
|
10
11
|
"build": "rimraf dist && tsc",
|
|
11
12
|
"dev": "ts-node src/index.ts",
|
|
12
13
|
"postbuia": "ts-node scripts/postbuild/index.ts",
|
|
@@ -30,8 +31,10 @@
|
|
|
30
31
|
"devDependencies": {
|
|
31
32
|
"@types/inquirer": "^8.1.0",
|
|
32
33
|
"@types/node": "^16.18.126",
|
|
34
|
+
"@vitest/coverage-v8": "3.2.4",
|
|
33
35
|
"ts-node": "^10.9.2",
|
|
34
|
-
"typescript": "^4.9.5"
|
|
36
|
+
"typescript": "^4.9.5",
|
|
37
|
+
"vitest": "^3.2.4"
|
|
35
38
|
},
|
|
36
39
|
"dependencies": {
|
|
37
40
|
"@clack/prompts": "^0.11.0",
|
package/templates/basic/.env.hbs
CHANGED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
2
|
+
import { renderTemplate } from "../../../src/utils/helpers/templates.helpers";
|
|
3
|
+
|
|
4
|
+
describe("Environment variables template rendering", () => {
|
|
5
|
+
const templatePath = "basic/.env.hbs";
|
|
6
|
+
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
vi.clearAllMocks();
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it("should render the environment variables with the correct database URL", () => {
|
|
12
|
+
const databaseProviders = [
|
|
13
|
+
{
|
|
14
|
+
provider: "postgresql",
|
|
15
|
+
defaultDBurl: "postgresql://user:password@localhost:5432/mydb",
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
provider: "mysql",
|
|
19
|
+
defaultDBurl: "mysql://user:password@localhost:3306/mydb",
|
|
20
|
+
},
|
|
21
|
+
{ provider: "sqlite", defaultDBurl: "file:./dev.db" },
|
|
22
|
+
{ provider: "mongodb", defaultDBurl: "mongodb://localhost:27017/mydb" },
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
databaseProviders.forEach(({ provider, defaultDBurl }) => {
|
|
26
|
+
const context = {
|
|
27
|
+
prisma: {
|
|
28
|
+
provider,
|
|
29
|
+
defaultDBurl,
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const result = renderTemplate(templatePath, context);
|
|
34
|
+
|
|
35
|
+
expect(result).toContain("# Database connection");
|
|
36
|
+
expect(result).toContain(`DATABASE_URL=${defaultDBurl}`);
|
|
37
|
+
expect(result).toContain("# JWT secrets");
|
|
38
|
+
expect(result).toContain("JWT_SECRET=your-jwt-secret");
|
|
39
|
+
expect(result).toContain("JWT_EXPIRES_IN=90d");
|
|
40
|
+
expect(result).toContain("# Server configuration");
|
|
41
|
+
expect(result).toContain("PORT=8000");
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("should handle different database URL formats correctly", () => {
|
|
46
|
+
const testCases = [
|
|
47
|
+
{
|
|
48
|
+
provider: "postgresql",
|
|
49
|
+
defaultDBurl: "postgresql://user:password@localhost:5432/mydb",
|
|
50
|
+
expected: "DATABASE_URL=postgresql://user:password@localhost:5432/mydb",
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
provider: "sqlite",
|
|
54
|
+
defaultDBurl: "file:./dev.db",
|
|
55
|
+
expected: "DATABASE_URL=file:./dev.db",
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
provider: "mysql",
|
|
59
|
+
defaultDBurl: "mysql://user:password@localhost:3306/mydb?schema=public",
|
|
60
|
+
expected:
|
|
61
|
+
"DATABASE_URL=mysql://user:password@localhost:3306/mydb?schema",
|
|
62
|
+
},
|
|
63
|
+
];
|
|
64
|
+
|
|
65
|
+
testCases.forEach(({ provider, defaultDBurl, expected }) => {
|
|
66
|
+
const context = {
|
|
67
|
+
prisma: {
|
|
68
|
+
provider,
|
|
69
|
+
defaultDBurl,
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const result = renderTemplate(templatePath, context);
|
|
74
|
+
expect(result).toContain(expected);
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it("should render the complete template structure with all sections", () => {
|
|
79
|
+
const context = {
|
|
80
|
+
prisma: {
|
|
81
|
+
provider: "postgresql",
|
|
82
|
+
defaultDBurl: "postgresql://user:password@localhost:5432/mydb",
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const result = renderTemplate(templatePath, context);
|
|
87
|
+
|
|
88
|
+
// Check that all sections are present in the correct order
|
|
89
|
+
const lines = result.trim().split("\n");
|
|
90
|
+
|
|
91
|
+
expect(lines[0]).toBe("# Database connection");
|
|
92
|
+
expect(lines[1]).toBe(
|
|
93
|
+
"DATABASE_URL=postgresql://user:password@localhost:5432/mydb"
|
|
94
|
+
);
|
|
95
|
+
expect(lines[2]).toBe("");
|
|
96
|
+
expect(lines[3]).toBe("# JWT secrets");
|
|
97
|
+
expect(lines[4]).toBe("JWT_SECRET=your-jwt-secret");
|
|
98
|
+
expect(lines[5]).toBe("JWT_EXPIRES_IN=90d");
|
|
99
|
+
expect(lines[6]).toBe("");
|
|
100
|
+
expect(lines[7]).toBe("# Server configuration");
|
|
101
|
+
expect(lines[8]).toBe("PORT=8000");
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it("should not contain any unresolved template variables", () => {
|
|
105
|
+
const context = {
|
|
106
|
+
prisma: {
|
|
107
|
+
provider: "postgresql",
|
|
108
|
+
defaultDBurl: "postgresql://user:password@localhost:5432/mydb",
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
const result = renderTemplate(templatePath, context);
|
|
113
|
+
|
|
114
|
+
// Ensure no Handlebars variables are left in the output
|
|
115
|
+
expect(result).not.toContain("{{");
|
|
116
|
+
expect(result).not.toContain("}}");
|
|
117
|
+
expect(result).not.toContain("prisma.defaultDBurl");
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it("should handle missing context values gracefully", () => {
|
|
121
|
+
// Test with incomplete context
|
|
122
|
+
const context = {
|
|
123
|
+
prisma: {
|
|
124
|
+
// Missing defaultDBurl
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const result = renderTemplate(templatePath, context);
|
|
129
|
+
|
|
130
|
+
// Should still render the template structure
|
|
131
|
+
expect(result).toContain("# Database connection");
|
|
132
|
+
expect(result).toContain("DATABASE_URL="); // Empty value
|
|
133
|
+
expect(result).toContain("# JWT secrets");
|
|
134
|
+
expect(result).toContain("JWT_SECRET=your-jwt-secret");
|
|
135
|
+
expect(result).toContain("# Server configuration");
|
|
136
|
+
expect(result).toContain("PORT=8000");
|
|
137
|
+
});
|
|
138
|
+
});
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
2
|
+
import { renderTemplate } from "../../../src/utils/helpers/templates.helpers";
|
|
3
|
+
|
|
4
|
+
describe(".gitignore template rendering", () => {
|
|
5
|
+
const templatePath = "basic/.gitignore.hbs";
|
|
6
|
+
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
vi.clearAllMocks();
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it("should render the complete .gitignore content without modifications", () => {
|
|
12
|
+
const context = {}; // No variables needed for this template
|
|
13
|
+
|
|
14
|
+
const result = renderTemplate(templatePath, context);
|
|
15
|
+
|
|
16
|
+
// Check that all major sections are present
|
|
17
|
+
expect(result).toContain("# Dependencies");
|
|
18
|
+
expect(result).toContain("/node_modules");
|
|
19
|
+
expect(result).toContain(".pnp.js");
|
|
20
|
+
|
|
21
|
+
expect(result).toContain("# Environment files");
|
|
22
|
+
expect(result).toContain(".env");
|
|
23
|
+
expect(result).toContain(".env.local");
|
|
24
|
+
|
|
25
|
+
expect(result).toContain("# Build and output directories");
|
|
26
|
+
expect(result).toContain("/build");
|
|
27
|
+
expect(result).toContain("/dist");
|
|
28
|
+
|
|
29
|
+
expect(result).toContain("# Arkos.js' base uploads directory");
|
|
30
|
+
expect(result).toContain("/uploads");
|
|
31
|
+
|
|
32
|
+
expect(result).toContain("# TypeScript cache and declaration files");
|
|
33
|
+
expect(result).toContain("*.tsbuildinfo");
|
|
34
|
+
|
|
35
|
+
expect(result).toContain("# Logs");
|
|
36
|
+
expect(result).toContain("logs");
|
|
37
|
+
expect(result).toContain("*.log");
|
|
38
|
+
|
|
39
|
+
expect(result).toContain("# IDE and editor directories");
|
|
40
|
+
expect(result).toContain("/.idea");
|
|
41
|
+
expect(result).toContain("/.vscode");
|
|
42
|
+
|
|
43
|
+
expect(result).toContain("# OS files");
|
|
44
|
+
expect(result).toContain(".DS_Store");
|
|
45
|
+
expect(result).toContain("Thumbs.db");
|
|
46
|
+
|
|
47
|
+
expect(result).toContain("# Testing");
|
|
48
|
+
expect(result).toContain("/coverage");
|
|
49
|
+
expect(result).toContain("/.nyc_output");
|
|
50
|
+
|
|
51
|
+
expect(result).toContain("# Temporary files");
|
|
52
|
+
expect(result).toContain("*.tmp");
|
|
53
|
+
expect(result).toContain("*.temp");
|
|
54
|
+
|
|
55
|
+
expect(result).toContain("# Misc");
|
|
56
|
+
expect(result).toContain(".serverless/");
|
|
57
|
+
expect(result).toContain(".fusebox/");
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("should not contain any template variables", () => {
|
|
61
|
+
const context = {};
|
|
62
|
+
|
|
63
|
+
const result = renderTemplate(templatePath, context);
|
|
64
|
+
|
|
65
|
+
// Ensure no Handlebars variables are present
|
|
66
|
+
expect(result).not.toContain("{{");
|
|
67
|
+
expect(result).not.toContain("}}");
|
|
68
|
+
expect(result).not.toContain("#if");
|
|
69
|
+
expect(result).not.toContain("#unless");
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("should render the exact expected content", () => {
|
|
73
|
+
const context = {};
|
|
74
|
+
|
|
75
|
+
const result = renderTemplate(templatePath, context);
|
|
76
|
+
|
|
77
|
+
// Verify specific patterns are present
|
|
78
|
+
expect(result).toContain("package-lock.json");
|
|
79
|
+
expect(result).toContain("yarn.lock");
|
|
80
|
+
expect(result).toContain("pnpm-lock.yaml");
|
|
81
|
+
expect(result).toContain(".npm");
|
|
82
|
+
|
|
83
|
+
expect(result).toContain("*.env");
|
|
84
|
+
expect(result).toContain(".env.development");
|
|
85
|
+
expect(result).toContain(".env.test");
|
|
86
|
+
expect(result).toContain(".env.production");
|
|
87
|
+
|
|
88
|
+
expect(result).toContain("/.dist");
|
|
89
|
+
expect(result).toContain("/out");
|
|
90
|
+
expect(result).toContain("/.build");
|
|
91
|
+
|
|
92
|
+
expect(result).toContain("/src/**/*.js.map");
|
|
93
|
+
expect(result).toContain("/src/**/*.d.ts");
|
|
94
|
+
expect(result).toContain("/types/generated/*");
|
|
95
|
+
|
|
96
|
+
expect(result).toContain("npm-debug.log*");
|
|
97
|
+
expect(result).toContain("yarn-debug.log*");
|
|
98
|
+
expect(result).toContain("yarn-error.log*");
|
|
99
|
+
|
|
100
|
+
expect(result).toContain("*.swp");
|
|
101
|
+
expect(result).toContain("*.swo");
|
|
102
|
+
expect(result).toContain(".project");
|
|
103
|
+
|
|
104
|
+
expect(result).toContain("ehthumbs.db");
|
|
105
|
+
expect(result).toContain("Desktop.ini");
|
|
106
|
+
expect(result).toContain("$RECYCLE.BIN/");
|
|
107
|
+
|
|
108
|
+
expect(result).toContain("/cypress/screenshots");
|
|
109
|
+
expect(result).toContain("/cypress/videos");
|
|
110
|
+
expect(result).toContain("/.jest-cache");
|
|
111
|
+
|
|
112
|
+
expect(result).toContain(".cache/");
|
|
113
|
+
expect(result).toContain(".eslintcache");
|
|
114
|
+
expect(result).toContain(".stylelintcache");
|
|
115
|
+
|
|
116
|
+
expect(result).toContain(".dynamodb/");
|
|
117
|
+
expect(result).toContain(".webpack/");
|
|
118
|
+
expect(result).toContain(".next/");
|
|
119
|
+
expect(result).toContain(".nuxt/");
|
|
120
|
+
expect(result).toContain(".docz/");
|
|
121
|
+
expect(result).toContain(".vercel");
|
|
122
|
+
|
|
123
|
+
expect(result).toContain("*.db");
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it("should handle empty context without errors", () => {
|
|
127
|
+
const context = {};
|
|
128
|
+
|
|
129
|
+
expect(() => {
|
|
130
|
+
renderTemplate(templatePath, context);
|
|
131
|
+
}).not.toThrow();
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it("should return a string with multiple lines", () => {
|
|
135
|
+
const context = {};
|
|
136
|
+
|
|
137
|
+
const result = renderTemplate(templatePath, context);
|
|
138
|
+
|
|
139
|
+
expect(typeof result).toBe("string");
|
|
140
|
+
expect(result.split("\n").length).toBeGreaterThan(50); // Should have many lines
|
|
141
|
+
});
|
|
142
|
+
});
|