create-arkos 0.0.14 → 0.0.16
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/create-arkos/src/utils/project-config-inquirer.js +1 -1
- package/dist/create-arkos/src/utils/project-config-inquirer.js.map +1 -1
- package/dist/create-arkos/src/utils/template-compiler.js +4 -4
- package/dist/create-arkos/src/utils/template-compiler.js.map +1 -1
- package/package.json +2 -2
- package/dist/index.d.mts +0 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -346
- package/dist/index.mjs +0 -325
|
@@ -120,7 +120,7 @@ class ProjectConfigInquirer {
|
|
|
120
120
|
break;
|
|
121
121
|
case "sqlite":
|
|
122
122
|
idDatabaseType = "@id @default(cuid())";
|
|
123
|
-
defaultDBurl = "file:../
|
|
123
|
+
defaultDBurl = "file:../file.db";
|
|
124
124
|
break;
|
|
125
125
|
case "mysql":
|
|
126
126
|
idDatabaseType = "@id @default(uuid())";
|
|
@@ -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;AA2B1B,MAAM,qBAAqB;IAGzB;QACE,IAAI,CAAC,MAAM,GAAG,EAAmB,CAAC;IACpC,CAAC;IAEK,GAAG;;YACP,MAAM,IAAI,CAAC,iBAAiB,EAAE,CAAC;YAC/B,MAAM,IAAI,CAAC,gBAAgB,EAAE,CAAC;YAC9B,MAAM,IAAI,CAAC,oBAAoB,EAAE,CAAC;YAClC,MAAM,IAAI,CAAC,gBAAgB,EAAE,CAAC;YAC9B,MAAM,IAAI,CAAC,oBAAoB,EAAE,CAAC;YAElC,MAAM,WAAW,GAAG,cAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;YACzE,IAA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CAAC,CAAC;oBAEH,MAAM,EAAE,aAAa,EAAE,GAAG,MAAM,kBAAQ,CAAC,MAAM,CAAC;wBAC9C;4BACE,IAAI,EAAE,MAAM;4BACZ,IAAI,EAAE,eAAe;4BACrB,OAAO,EAAE,0CAA0C;4BACnD,OAAO,EAAE,CAAC,OAAO,EAAE,UAAU,EAAE,cAAc,CAAC;yBAC/C;qBACF,CAAC,CAAC;oBAEH,IAAI,CAAC,MAAM,CAAC,cAAc,GAAG;wBAC3B,IAAI,EAAE,kBAAkB;wBACxB,aAAa,EACX,aAAa,KAAK,cAAc,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,aAAa;wBAC7D,aAAa;qBACd,CAAC;iBACH;qBAAM,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,KAAK,QAAQ,EAAE;oBACnD,OAAO,CAAC,IAAI,CACV,+DAA+D,CAChE,CAAC;iBACH;aACF;QACH,CAAC;KAAA;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 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 const projectPath = path.resolve(process.cwd(), this.config.projectName);\n this.config.projectPath = projectPath;\n\n return this.config;\n }\n\n private async promptProjectName() {\n let projectName = process.argv[2];\n\n // If user passed \".\", use current directory name\n if (projectName === \".\") {\n projectName = path.basename(process.cwd());\n }\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(`Error: ${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 || 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:../database.db\"; // Goes to root dir, not prisma folder\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 const { validationType } = await inquirer.prompt([\n {\n type: \"list\",\n name: \"validationType\",\n message: \"Choose validation library:\",\n choices: [\"zod\", \"class-validator\"],\n },\n ]);\n this.config.validation = {\n type: validationType,\n };\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 if (\n authenticationType !== \"define later\" &&\n this.config.prisma.provider !== \"sqlite\"\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 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,\n };\n } else if (this.config.prisma.provider === \"sqlite\") {\n console.info(\n `Skipping multiple roles options because provider is sqlite...`\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,gDAAwB;AACxB,wDAAgC;AAChC,kDAA0B;AA2B1B,MAAM,qBAAqB;IAGzB;QACE,IAAI,CAAC,MAAM,GAAG,EAAmB,CAAC;IACpC,CAAC;IAEK,GAAG;;YACP,MAAM,IAAI,CAAC,iBAAiB,EAAE,CAAC;YAC/B,MAAM,IAAI,CAAC,gBAAgB,EAAE,CAAC;YAC9B,MAAM,IAAI,CAAC,oBAAoB,EAAE,CAAC;YAClC,MAAM,IAAI,CAAC,gBAAgB,EAAE,CAAC;YAC9B,MAAM,IAAI,CAAC,oBAAoB,EAAE,CAAC;YAElC,MAAM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AE,eAAe;4BACrB,OAAO,EAAE,IAAI;4BACb,OAAO,EAAE,6CAA6C,eAAK,CAAC,IAAI,CAAC,gBAAgB,CAAC,GAAG;yBACtF;qBACF,CAAC,CAAC;oBAEH,MAAM,EAAE,aAAa,EAAE,GAAG,MAAM,kBAAQ,CAAC,MAAM,CAAC;wBAC9C;4BACE,IAAI,EAAE,MAAM;4BACZ,IAAI,EAAE,eAAe;4BACrB,OAAO,EAAE,0CAA0C;4BACnD,OAAO,EAAE,CAAC,OAAO,EAAE,UAAU,EAAE,cAAc,CAAC;yBAC/C;qBACF,CAAC,CAAC;oBAEH,IAAI,CAAC,MAAM,CAAC,cAAc,GAAG;wBAC3B,IAAI,EAAE,kBAAkB;wBACxB,aAAa,EACX,aAAa,KAAK,cAAc,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,aAAa;wBAC7D,aAAa;qBACd,CAAC;iBACH;qBAAM,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,KAAK,QAAQ,EAAE;oBACnD,OAAO,CAAC,IAAI,CACV,+DAA+D,CAChE,CAAC;iBACH;aACF;QACH,CAAC;KAAA;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 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 const projectPath = path.resolve(process.cwd(), this.config.projectName);\n this.config.projectPath = projectPath;\n\n return this.config;\n }\n\n private async promptProjectName() {\n let projectName = process.argv[2];\n\n // If user passed \".\", use current directory name\n if (projectName === \".\") {\n projectName = path.basename(process.cwd());\n }\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(`Error: ${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 || 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 const { validationType } = await inquirer.prompt([\n {\n type: \"list\",\n name: \"validationType\",\n message: \"Choose validation library:\",\n choices: [\"zod\", \"class-validator\"],\n },\n ]);\n this.config.validation = {\n type: validationType,\n };\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 if (\n authenticationType !== \"define later\" &&\n this.config.prisma.provider !== \"sqlite\"\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 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,\n };\n } else if (this.config.prisma.provider === \"sqlite\") {\n console.info(\n `Skipping multiple roles options because provider is sqlite...`\n );\n }\n }\n }\n}\n\nconst projectConfigInquirer = new ProjectConfigInquirer();\n\nexport default projectConfigInquirer;\n"]}
|
|
@@ -23,11 +23,11 @@ class TemplateCompiler {
|
|
|
23
23
|
});
|
|
24
24
|
}
|
|
25
25
|
filesToBeSkipped(config) {
|
|
26
|
-
var _a;
|
|
26
|
+
var _a, _b;
|
|
27
27
|
const files = [];
|
|
28
|
-
if (config.authentication.type === "define later")
|
|
28
|
+
if (((_a = config.authentication) === null || _a === void 0 ? void 0 : _a.type) === "define later")
|
|
29
29
|
files.push(...["user.prisma.hbs"]);
|
|
30
|
-
if (((
|
|
30
|
+
if (((_b = config.authentication) === null || _b === void 0 ? void 0 : _b.type) === "static")
|
|
31
31
|
files.push(...[
|
|
32
32
|
"auth-role.prisma.hbs",
|
|
33
33
|
"auth-permission.prisma.hbs",
|
|
@@ -35,7 +35,7 @@ class TemplateCompiler {
|
|
|
35
35
|
]);
|
|
36
36
|
if (!config.typescript)
|
|
37
37
|
files.push(...["tsconfig.json.hbs"]);
|
|
38
|
-
if (config.typescript)
|
|
38
|
+
if (config === null || config === void 0 ? void 0 : config.typescript)
|
|
39
39
|
files.push(...["jsconfig.json.hbs"]);
|
|
40
40
|
return files;
|
|
41
41
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"template-compiler.js","sourceRoot":"","sources":["../../../../src/utils/template-compiler.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AACA,gDAAwB;AACxB,4CAAoB;AACpB,4DAAoC;AACpC,uDAA6D;AAE7D,MAAM,gBAAgB;IACd,iCAAiC,CAAC,MAAqB;;YAC3D,OAAO,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC;QACjC,CAAC;KAAA;IAED,gBAAgB,CAAC,MAAqB;;QACpC,MAAM,KAAK,GAAa,EAAE,CAAC;QAE3B,IAAI,MAAM,CAAC,cAAc,
|
|
1
|
+
{"version":3,"file":"template-compiler.js","sourceRoot":"","sources":["../../../../src/utils/template-compiler.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AACA,gDAAwB;AACxB,4CAAoB;AACpB,4DAAoC;AACpC,uDAA6D;AAE7D,MAAM,gBAAgB;IACd,iCAAiC,CAAC,MAAqB;;YAC3D,OAAO,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC;QACjC,CAAC;KAAA;IAED,gBAAgB,CAAC,MAAqB;;QACpC,MAAM,KAAK,GAAa,EAAE,CAAC;QAE3B,IAAI,CAAA,MAAA,MAAM,CAAC,cAAc,0CAAE,IAAI,MAAK,cAAc;YAChD,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC,CAAC;QAErC,IAAI,CAAA,MAAA,MAAM,CAAC,cAAc,0CAAE,IAAI,MAA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,CAAC;wBAC9B,MAAM,QAAQ,GAAG,oBAAU,CAAC,OAAO,CACjC,YAAE,CAAC,YAAY,CAAC,YAAY,EAAE,MAAM,CAAC,CACtC,CAAC;wBAEF,IAAI,mBAAmB,GAAG,IAAA,kCAAoB,EAAC,OAAO,CAAC,CAAC;wBAExD,MAAM,OAAO,GAAG,QAAQ,iCAAM,MAAM,KAAE,mBAAmB,IAAG,CAAC;wBAC7D,MAAM,GAAG,GAAG,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC;wBAEzC,IAAI,UAAU,GAAG,cAAI,CAAC,IAAI,CACxB,SAAS,EACT,YAAY,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CACjC,CAAC;wBACF,IAAI,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC;4BACjC,UAAU,GAAG,cAAI,CAAC,IAAI,CACpB,SAAS,EACT,YAAY,CAAC,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC,CACrC,CAAC;wBAEJ,YAAE,CAAC,SAAS,CAAC,cAAI,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;wBAC5D,YAAE,CAAC,aAAa,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;qBACvC;gBACH,CAAC,CAAA,CAAC,CAAC;YACL,CAAC;YAED,gBAAgB,CAAC,YAAY,CAAC,CAAC;QACjC,CAAC;KAAA;CACF;AAED,MAAM,gBAAgB,GAAG,IAAI,gBAAgB,EAAE,CAAC;AAEhD,kBAAe,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\n if (config.authentication?.type === \"define later\")\n files.push(...[\"user.prisma.hbs\"]);\n\n if (config.authentication?.type === \"static\")\n files.push(\n ...[\n \"auth-role.prisma.hbs\",\n \"auth-permission.prisma.hbs\",\n \"user-role.prisma.hbs\",\n ]\n );\n\n if (!config.typescript) files.push(...[\"tsconfig.json.hbs\"]);\n\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 = getNpmPackageVersion(\"arkos\");\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,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-arkos",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.16",
|
|
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"
|
|
7
7
|
},
|
|
8
8
|
"scripts": {
|
|
9
|
-
"build": "tsc",
|
|
9
|
+
"build": "rimraf dist && tsc",
|
|
10
10
|
"dev": "ts-node src/index.ts",
|
|
11
11
|
"test:hbs": "ts-node src/utils/helpers/hbs-tester.helpers.ts",
|
|
12
12
|
"prebuild": "pnpm --filter @arkos/shared build",
|
package/dist/index.d.mts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
package/dist/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
package/dist/index.js
DELETED
|
@@ -1,346 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
var __create = Object.create;
|
|
4
|
-
var __defProp = Object.defineProperty;
|
|
5
|
-
var __defProps = Object.defineProperties;
|
|
6
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
8
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
9
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
10
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
11
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
13
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
14
|
-
var __spreadValues = (a, b) => {
|
|
15
|
-
for (var prop in b || (b = {}))
|
|
16
|
-
if (__hasOwnProp.call(b, prop))
|
|
17
|
-
__defNormalProp(a, prop, b[prop]);
|
|
18
|
-
if (__getOwnPropSymbols)
|
|
19
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
20
|
-
if (__propIsEnum.call(b, prop))
|
|
21
|
-
__defNormalProp(a, prop, b[prop]);
|
|
22
|
-
}
|
|
23
|
-
return a;
|
|
24
|
-
};
|
|
25
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
26
|
-
var __copyProps = (to, from, except, desc) => {
|
|
27
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
28
|
-
for (let key of __getOwnPropNames(from))
|
|
29
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
30
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
31
|
-
}
|
|
32
|
-
return to;
|
|
33
|
-
};
|
|
34
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
35
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
36
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
37
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
38
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
39
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
40
|
-
mod
|
|
41
|
-
));
|
|
42
|
-
var __async = (__this, __arguments, generator) => {
|
|
43
|
-
return new Promise((resolve, reject) => {
|
|
44
|
-
var fulfilled = (value) => {
|
|
45
|
-
try {
|
|
46
|
-
step(generator.next(value));
|
|
47
|
-
} catch (e) {
|
|
48
|
-
reject(e);
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
var rejected = (value) => {
|
|
52
|
-
try {
|
|
53
|
-
step(generator.throw(value));
|
|
54
|
-
} catch (e) {
|
|
55
|
-
reject(e);
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
59
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
60
|
-
});
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
// src/index.ts
|
|
64
|
-
var import_fs2 = __toESM(require("fs"));
|
|
65
|
-
var import_path3 = __toESM(require("path"));
|
|
66
|
-
var import_chalk2 = __toESM(require("chalk"));
|
|
67
|
-
var import_child_process = require("child_process");
|
|
68
|
-
|
|
69
|
-
// src/utils/project-config-inquirer.ts
|
|
70
|
-
var import_path = __toESM(require("path"));
|
|
71
|
-
var import_inquirer = __toESM(require("inquirer"));
|
|
72
|
-
var import_chalk = __toESM(require("chalk"));
|
|
73
|
-
var ProjectConfigInquirer = class {
|
|
74
|
-
constructor() {
|
|
75
|
-
this.config = {};
|
|
76
|
-
}
|
|
77
|
-
run() {
|
|
78
|
-
return __async(this, null, function* () {
|
|
79
|
-
yield this.promptProjectName();
|
|
80
|
-
yield this.promptTypescript();
|
|
81
|
-
yield this.promptPrismaProvider();
|
|
82
|
-
yield this.promptValidation();
|
|
83
|
-
yield this.promptAuthentication();
|
|
84
|
-
const projectPath = import_path.default.resolve(process.cwd(), this.config.projectName);
|
|
85
|
-
this.config.projectPath = projectPath;
|
|
86
|
-
return this.config;
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
promptProjectName() {
|
|
90
|
-
return __async(this, null, function* () {
|
|
91
|
-
let projectName = process.argv[2];
|
|
92
|
-
if (!projectName) {
|
|
93
|
-
const result = yield import_inquirer.default.prompt([
|
|
94
|
-
{
|
|
95
|
-
type: "input",
|
|
96
|
-
name: "projectName",
|
|
97
|
-
message: "What is the name of your project?",
|
|
98
|
-
default: "my-arkos-project",
|
|
99
|
-
validate: (input) => input.length > 0 ? true : "Project name cannot be empty"
|
|
100
|
-
}
|
|
101
|
-
]);
|
|
102
|
-
projectName = result.projectName;
|
|
103
|
-
}
|
|
104
|
-
this.config.projectName = projectName;
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
promptTypescript() {
|
|
108
|
-
return __async(this, null, function* () {
|
|
109
|
-
const { typescript } = yield import_inquirer.default.prompt([
|
|
110
|
-
{
|
|
111
|
-
type: "confirm",
|
|
112
|
-
name: "typescript",
|
|
113
|
-
message: `Would you like to use ${import_chalk.default.cyan("TypeScript")}?`,
|
|
114
|
-
default: false
|
|
115
|
-
}
|
|
116
|
-
]);
|
|
117
|
-
this.config.typescript = typescript;
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
promptPrismaProvider() {
|
|
121
|
-
return __async(this, null, function* () {
|
|
122
|
-
const { prismaProvider } = yield import_inquirer.default.prompt([
|
|
123
|
-
{
|
|
124
|
-
type: "list",
|
|
125
|
-
name: "prismaProvider",
|
|
126
|
-
message: `What db provider will be used for ${import_chalk.default.cyan("Prisma")}?`,
|
|
127
|
-
choices: [
|
|
128
|
-
"postgresql",
|
|
129
|
-
"mongodb",
|
|
130
|
-
"mysql",
|
|
131
|
-
"sqlite",
|
|
132
|
-
"sqlserver",
|
|
133
|
-
"cockroachdb"
|
|
134
|
-
]
|
|
135
|
-
}
|
|
136
|
-
]);
|
|
137
|
-
let idDatabaseType;
|
|
138
|
-
switch (prismaProvider) {
|
|
139
|
-
case "mongodb":
|
|
140
|
-
idDatabaseType = '@id @default(auto()) @map("_id") @db.ObjectId';
|
|
141
|
-
break;
|
|
142
|
-
case "sqlite":
|
|
143
|
-
idDatabaseType = "@id @default(cuid())";
|
|
144
|
-
break;
|
|
145
|
-
default:
|
|
146
|
-
idDatabaseType = "@id @default(uuid())";
|
|
147
|
-
}
|
|
148
|
-
this.config.prisma = {
|
|
149
|
-
provider: prismaProvider,
|
|
150
|
-
idDatabaseType
|
|
151
|
-
};
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
promptValidation() {
|
|
155
|
-
return __async(this, null, function* () {
|
|
156
|
-
const { useValidation } = yield import_inquirer.default.prompt([
|
|
157
|
-
{
|
|
158
|
-
type: "confirm",
|
|
159
|
-
name: "useValidation",
|
|
160
|
-
message: `Would you like to set up ${import_chalk.default.cyan("Validation")}?`,
|
|
161
|
-
default: true
|
|
162
|
-
}
|
|
163
|
-
]);
|
|
164
|
-
if (useValidation) {
|
|
165
|
-
const { validationType } = yield import_inquirer.default.prompt([
|
|
166
|
-
{
|
|
167
|
-
type: "list",
|
|
168
|
-
name: "validationType",
|
|
169
|
-
message: "Choose validation library:",
|
|
170
|
-
choices: ["zod", "class-validator"]
|
|
171
|
-
}
|
|
172
|
-
]);
|
|
173
|
-
this.config.validation = {
|
|
174
|
-
type: validationType
|
|
175
|
-
};
|
|
176
|
-
}
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
promptAuthentication() {
|
|
180
|
-
return __async(this, null, function* () {
|
|
181
|
-
const { useAuthentication } = yield import_inquirer.default.prompt([
|
|
182
|
-
{
|
|
183
|
-
type: "confirm",
|
|
184
|
-
name: "useAuthentication",
|
|
185
|
-
message: `Would you like to set up ${import_chalk.default.cyan("Authentication")}?`,
|
|
186
|
-
default: true
|
|
187
|
-
}
|
|
188
|
-
]);
|
|
189
|
-
if (useAuthentication) {
|
|
190
|
-
const { authenticationType } = yield import_inquirer.default.prompt([
|
|
191
|
-
{
|
|
192
|
-
type: "list",
|
|
193
|
-
name: "authenticationType",
|
|
194
|
-
message: "Choose authentication type:",
|
|
195
|
-
choices: ["static", "dynamic", "define later"]
|
|
196
|
-
}
|
|
197
|
-
]);
|
|
198
|
-
if (authenticationType !== "define later") {
|
|
199
|
-
const { multipleRoles } = yield import_inquirer.default.prompt([
|
|
200
|
-
{
|
|
201
|
-
type: "confirm",
|
|
202
|
-
name: "multipleRoles",
|
|
203
|
-
default: true,
|
|
204
|
-
message: `Would you like to use authentication with ${import_chalk.default.cyan("Multiple Roles")}?`
|
|
205
|
-
}
|
|
206
|
-
]);
|
|
207
|
-
const { usernameField } = yield import_inquirer.default.prompt([
|
|
208
|
-
{
|
|
209
|
-
type: "list",
|
|
210
|
-
name: "usernameField",
|
|
211
|
-
message: "Choose default username field for login:",
|
|
212
|
-
choices: ["email", "username", "define later"]
|
|
213
|
-
}
|
|
214
|
-
]);
|
|
215
|
-
this.config.authentication = {
|
|
216
|
-
type: authenticationType,
|
|
217
|
-
usernameField: usernameField === "define later" ? "custom" : usernameField,
|
|
218
|
-
multipleRoles
|
|
219
|
-
};
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
};
|
|
225
|
-
var projectConfigInquirer = new ProjectConfigInquirer();
|
|
226
|
-
var project_config_inquirer_default = projectConfigInquirer;
|
|
227
|
-
|
|
228
|
-
// src/utils/template-compiler.ts
|
|
229
|
-
var import_path2 = __toESM(require("path"));
|
|
230
|
-
var import_fs = __toESM(require("fs"));
|
|
231
|
-
var import_handlebars = __toESM(require("handlebars"));
|
|
232
|
-
var TemplateCompiler = class {
|
|
233
|
-
canCompileAuthenticationTemplates(config) {
|
|
234
|
-
return __async(this, null, function* () {
|
|
235
|
-
return !!config.authentication;
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
|
-
filesToBeSkipped(config) {
|
|
239
|
-
var _a;
|
|
240
|
-
const files = [];
|
|
241
|
-
if (config.authentication.type !== "define later")
|
|
242
|
-
files.concat(["user.prisma.hbs"]);
|
|
243
|
-
if (((_a = config.authentication) == null ? void 0 : _a.type) === "static")
|
|
244
|
-
files.concat(["auth-role.prisma.hbs", "auth-permission.prisma.hbs"]);
|
|
245
|
-
if (!config.typescript) files.concat(["tsconfig.json.hbs"]);
|
|
246
|
-
return files;
|
|
247
|
-
}
|
|
248
|
-
/**
|
|
249
|
-
* Compiles the Arkos.js project with handlebars templates
|
|
250
|
-
*
|
|
251
|
-
* @param templatesDir {string} templates location
|
|
252
|
-
* @param config {ProjectConfig} the project configuration
|
|
253
|
-
* @returns void
|
|
254
|
-
* */
|
|
255
|
-
compile(templatesDir, config) {
|
|
256
|
-
return __async(this, null, function* () {
|
|
257
|
-
const outputDir = config.projectPath;
|
|
258
|
-
const isTypescript = config.typescript;
|
|
259
|
-
const filesToBeSkipped = this.filesToBeSkipped(config);
|
|
260
|
-
function processTemplates(dir, relativeDir = "") {
|
|
261
|
-
import_fs.default.readdirSync(dir, { withFileTypes: true }).forEach((dirent) => __async(null, null, function* () {
|
|
262
|
-
if (filesToBeSkipped.includes(dirent.name)) return;
|
|
263
|
-
const fullPath = import_path2.default.join(dir, dirent.name);
|
|
264
|
-
const relativePath = import_path2.default.join(relativeDir, dirent.name);
|
|
265
|
-
if (dirent.isDirectory()) {
|
|
266
|
-
processTemplates(fullPath, relativePath);
|
|
267
|
-
} else if (dirent.name.endsWith(".hbs")) {
|
|
268
|
-
const templatePath = fullPath;
|
|
269
|
-
const template = import_handlebars.default.compile(
|
|
270
|
-
import_fs.default.readFileSync(templatePath, "utf8")
|
|
271
|
-
);
|
|
272
|
-
let arkosLatestVersion = "1.0.0";
|
|
273
|
-
const content = template(__spreadProps(__spreadValues({}, config), { arkosLatestVersion }));
|
|
274
|
-
const ext = isTypescript ? ".ts" : ".js";
|
|
275
|
-
let outputPath = import_path2.default.join(
|
|
276
|
-
outputDir,
|
|
277
|
-
relativePath.replace(".hbs", "")
|
|
278
|
-
);
|
|
279
|
-
if (dirent.name.endsWith(".ts.hbs"))
|
|
280
|
-
outputPath = import_path2.default.join(
|
|
281
|
-
outputDir,
|
|
282
|
-
relativePath.replace(".ts.hbs", ext)
|
|
283
|
-
);
|
|
284
|
-
import_fs.default.mkdirSync(import_path2.default.dirname(outputPath), { recursive: true });
|
|
285
|
-
import_fs.default.writeFileSync(outputPath, content);
|
|
286
|
-
}
|
|
287
|
-
}));
|
|
288
|
-
}
|
|
289
|
-
processTemplates(templatesDir);
|
|
290
|
-
});
|
|
291
|
-
}
|
|
292
|
-
};
|
|
293
|
-
var templateCompiler = new TemplateCompiler();
|
|
294
|
-
var template_compiler_default = templateCompiler;
|
|
295
|
-
|
|
296
|
-
// src/index.ts
|
|
297
|
-
var import_handlebars2 = __toESM(require("handlebars"));
|
|
298
|
-
|
|
299
|
-
// ../shared/src/utils/helpers/user-agent.helpers.ts
|
|
300
|
-
function detectPackageManagerFromUserAgent() {
|
|
301
|
-
const userAgent = process.env.npm_config_user_agent || "";
|
|
302
|
-
if (!userAgent) return "npm";
|
|
303
|
-
if (userAgent.includes("pnpm")) return "pnpm";
|
|
304
|
-
if (userAgent.includes("yarn")) return "yarn";
|
|
305
|
-
if (userAgent.includes("npm")) return "npm";
|
|
306
|
-
if (userAgent.includes("bun")) return "bun";
|
|
307
|
-
if (userAgent.includes("cnpm")) return "cnpm";
|
|
308
|
-
if (userAgent.includes("corepack")) return "corepack";
|
|
309
|
-
if (userAgent.includes("deno")) return "deno";
|
|
310
|
-
return "npm";
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
// src/index.ts
|
|
314
|
-
import_handlebars2.default.registerHelper("eq", (a, b) => a === b);
|
|
315
|
-
import_handlebars2.default.registerHelper("neq", (a, b) => a !== b);
|
|
316
|
-
function main() {
|
|
317
|
-
return __async(this, null, function* () {
|
|
318
|
-
const config = yield project_config_inquirer_default.run();
|
|
319
|
-
const projectPath = config.projectPath;
|
|
320
|
-
import_fs2.default.mkdirSync(projectPath, { recursive: true });
|
|
321
|
-
console.info(
|
|
322
|
-
`
|
|
323
|
-
Creating a new ${import_chalk2.default.bold(import_chalk2.default.cyan("Arkos.js"))} project in ${import_chalk2.default.green(`./${config.projectName}`)}`
|
|
324
|
-
);
|
|
325
|
-
const templatesDir = import_path3.default.join(__dirname, `../templates/basic`);
|
|
326
|
-
yield template_compiler_default.compile(templatesDir, config);
|
|
327
|
-
process.chdir(projectPath);
|
|
328
|
-
const packageManager = detectPackageManagerFromUserAgent();
|
|
329
|
-
console.info("\nInstalling dependencies...");
|
|
330
|
-
console.info(`
|
|
331
|
-
Using ${packageManager}.
|
|
332
|
-
`);
|
|
333
|
-
(0, import_child_process.execSync)(`${packageManager} install`, { stdio: "inherit" });
|
|
334
|
-
console.info(`
|
|
335
|
-
${import_chalk2.default.bold(import_chalk2.default.cyan("Arkos.js"))} project created successfully!
|
|
336
|
-
|
|
337
|
-
Next steps:
|
|
338
|
-
1. cd ${config.projectName}
|
|
339
|
-
2. setup your ${import_chalk2.default.cyan("DATABASE_URL")} under .env
|
|
340
|
-
3. npx prisma db push
|
|
341
|
-
4. npx prisma generate
|
|
342
|
-
5. npm run dev
|
|
343
|
-
`);
|
|
344
|
-
});
|
|
345
|
-
}
|
|
346
|
-
main().catch(console.error);
|
package/dist/index.mjs
DELETED
|
@@ -1,325 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __defProps = Object.defineProperties;
|
|
4
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
5
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
8
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
-
var __spreadValues = (a, b) => {
|
|
10
|
-
for (var prop in b || (b = {}))
|
|
11
|
-
if (__hasOwnProp.call(b, prop))
|
|
12
|
-
__defNormalProp(a, prop, b[prop]);
|
|
13
|
-
if (__getOwnPropSymbols)
|
|
14
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
15
|
-
if (__propIsEnum.call(b, prop))
|
|
16
|
-
__defNormalProp(a, prop, b[prop]);
|
|
17
|
-
}
|
|
18
|
-
return a;
|
|
19
|
-
};
|
|
20
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
21
|
-
var __async = (__this, __arguments, generator) => {
|
|
22
|
-
return new Promise((resolve, reject) => {
|
|
23
|
-
var fulfilled = (value) => {
|
|
24
|
-
try {
|
|
25
|
-
step(generator.next(value));
|
|
26
|
-
} catch (e) {
|
|
27
|
-
reject(e);
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
var rejected = (value) => {
|
|
31
|
-
try {
|
|
32
|
-
step(generator.throw(value));
|
|
33
|
-
} catch (e) {
|
|
34
|
-
reject(e);
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
38
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
39
|
-
});
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
// src/index.ts
|
|
43
|
-
import fs2 from "fs";
|
|
44
|
-
import path3 from "path";
|
|
45
|
-
import chalk2 from "chalk";
|
|
46
|
-
import { execSync } from "child_process";
|
|
47
|
-
|
|
48
|
-
// src/utils/project-config-inquirer.ts
|
|
49
|
-
import path from "path";
|
|
50
|
-
import inquirer from "inquirer";
|
|
51
|
-
import chalk from "chalk";
|
|
52
|
-
var ProjectConfigInquirer = class {
|
|
53
|
-
constructor() {
|
|
54
|
-
this.config = {};
|
|
55
|
-
}
|
|
56
|
-
run() {
|
|
57
|
-
return __async(this, null, function* () {
|
|
58
|
-
yield this.promptProjectName();
|
|
59
|
-
yield this.promptTypescript();
|
|
60
|
-
yield this.promptPrismaProvider();
|
|
61
|
-
yield this.promptValidation();
|
|
62
|
-
yield this.promptAuthentication();
|
|
63
|
-
const projectPath = path.resolve(process.cwd(), this.config.projectName);
|
|
64
|
-
this.config.projectPath = projectPath;
|
|
65
|
-
return this.config;
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
promptProjectName() {
|
|
69
|
-
return __async(this, null, function* () {
|
|
70
|
-
let projectName = process.argv[2];
|
|
71
|
-
if (!projectName) {
|
|
72
|
-
const result = yield inquirer.prompt([
|
|
73
|
-
{
|
|
74
|
-
type: "input",
|
|
75
|
-
name: "projectName",
|
|
76
|
-
message: "What is the name of your project?",
|
|
77
|
-
default: "my-arkos-project",
|
|
78
|
-
validate: (input) => input.length > 0 ? true : "Project name cannot be empty"
|
|
79
|
-
}
|
|
80
|
-
]);
|
|
81
|
-
projectName = result.projectName;
|
|
82
|
-
}
|
|
83
|
-
this.config.projectName = projectName;
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
promptTypescript() {
|
|
87
|
-
return __async(this, null, function* () {
|
|
88
|
-
const { typescript } = yield inquirer.prompt([
|
|
89
|
-
{
|
|
90
|
-
type: "confirm",
|
|
91
|
-
name: "typescript",
|
|
92
|
-
message: `Would you like to use ${chalk.cyan("TypeScript")}?`,
|
|
93
|
-
default: false
|
|
94
|
-
}
|
|
95
|
-
]);
|
|
96
|
-
this.config.typescript = typescript;
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
promptPrismaProvider() {
|
|
100
|
-
return __async(this, null, function* () {
|
|
101
|
-
const { prismaProvider } = yield inquirer.prompt([
|
|
102
|
-
{
|
|
103
|
-
type: "list",
|
|
104
|
-
name: "prismaProvider",
|
|
105
|
-
message: `What db provider will be used for ${chalk.cyan("Prisma")}?`,
|
|
106
|
-
choices: [
|
|
107
|
-
"postgresql",
|
|
108
|
-
"mongodb",
|
|
109
|
-
"mysql",
|
|
110
|
-
"sqlite",
|
|
111
|
-
"sqlserver",
|
|
112
|
-
"cockroachdb"
|
|
113
|
-
]
|
|
114
|
-
}
|
|
115
|
-
]);
|
|
116
|
-
let idDatabaseType;
|
|
117
|
-
switch (prismaProvider) {
|
|
118
|
-
case "mongodb":
|
|
119
|
-
idDatabaseType = '@id @default(auto()) @map("_id") @db.ObjectId';
|
|
120
|
-
break;
|
|
121
|
-
case "sqlite":
|
|
122
|
-
idDatabaseType = "@id @default(cuid())";
|
|
123
|
-
break;
|
|
124
|
-
default:
|
|
125
|
-
idDatabaseType = "@id @default(uuid())";
|
|
126
|
-
}
|
|
127
|
-
this.config.prisma = {
|
|
128
|
-
provider: prismaProvider,
|
|
129
|
-
idDatabaseType
|
|
130
|
-
};
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
promptValidation() {
|
|
134
|
-
return __async(this, null, function* () {
|
|
135
|
-
const { useValidation } = yield inquirer.prompt([
|
|
136
|
-
{
|
|
137
|
-
type: "confirm",
|
|
138
|
-
name: "useValidation",
|
|
139
|
-
message: `Would you like to set up ${chalk.cyan("Validation")}?`,
|
|
140
|
-
default: true
|
|
141
|
-
}
|
|
142
|
-
]);
|
|
143
|
-
if (useValidation) {
|
|
144
|
-
const { validationType } = yield inquirer.prompt([
|
|
145
|
-
{
|
|
146
|
-
type: "list",
|
|
147
|
-
name: "validationType",
|
|
148
|
-
message: "Choose validation library:",
|
|
149
|
-
choices: ["zod", "class-validator"]
|
|
150
|
-
}
|
|
151
|
-
]);
|
|
152
|
-
this.config.validation = {
|
|
153
|
-
type: validationType
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
promptAuthentication() {
|
|
159
|
-
return __async(this, null, function* () {
|
|
160
|
-
const { useAuthentication } = yield inquirer.prompt([
|
|
161
|
-
{
|
|
162
|
-
type: "confirm",
|
|
163
|
-
name: "useAuthentication",
|
|
164
|
-
message: `Would you like to set up ${chalk.cyan("Authentication")}?`,
|
|
165
|
-
default: true
|
|
166
|
-
}
|
|
167
|
-
]);
|
|
168
|
-
if (useAuthentication) {
|
|
169
|
-
const { authenticationType } = yield inquirer.prompt([
|
|
170
|
-
{
|
|
171
|
-
type: "list",
|
|
172
|
-
name: "authenticationType",
|
|
173
|
-
message: "Choose authentication type:",
|
|
174
|
-
choices: ["static", "dynamic", "define later"]
|
|
175
|
-
}
|
|
176
|
-
]);
|
|
177
|
-
if (authenticationType !== "define later") {
|
|
178
|
-
const { multipleRoles } = yield inquirer.prompt([
|
|
179
|
-
{
|
|
180
|
-
type: "confirm",
|
|
181
|
-
name: "multipleRoles",
|
|
182
|
-
default: true,
|
|
183
|
-
message: `Would you like to use authentication with ${chalk.cyan("Multiple Roles")}?`
|
|
184
|
-
}
|
|
185
|
-
]);
|
|
186
|
-
const { usernameField } = yield inquirer.prompt([
|
|
187
|
-
{
|
|
188
|
-
type: "list",
|
|
189
|
-
name: "usernameField",
|
|
190
|
-
message: "Choose default username field for login:",
|
|
191
|
-
choices: ["email", "username", "define later"]
|
|
192
|
-
}
|
|
193
|
-
]);
|
|
194
|
-
this.config.authentication = {
|
|
195
|
-
type: authenticationType,
|
|
196
|
-
usernameField: usernameField === "define later" ? "custom" : usernameField,
|
|
197
|
-
multipleRoles
|
|
198
|
-
};
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
|
-
};
|
|
204
|
-
var projectConfigInquirer = new ProjectConfigInquirer();
|
|
205
|
-
var project_config_inquirer_default = projectConfigInquirer;
|
|
206
|
-
|
|
207
|
-
// src/utils/template-compiler.ts
|
|
208
|
-
import path2 from "path";
|
|
209
|
-
import fs from "fs";
|
|
210
|
-
import handlebars from "handlebars";
|
|
211
|
-
var TemplateCompiler = class {
|
|
212
|
-
canCompileAuthenticationTemplates(config) {
|
|
213
|
-
return __async(this, null, function* () {
|
|
214
|
-
return !!config.authentication;
|
|
215
|
-
});
|
|
216
|
-
}
|
|
217
|
-
filesToBeSkipped(config) {
|
|
218
|
-
var _a;
|
|
219
|
-
const files = [];
|
|
220
|
-
if (config.authentication.type !== "define later")
|
|
221
|
-
files.concat(["user.prisma.hbs"]);
|
|
222
|
-
if (((_a = config.authentication) == null ? void 0 : _a.type) === "static")
|
|
223
|
-
files.concat(["auth-role.prisma.hbs", "auth-permission.prisma.hbs"]);
|
|
224
|
-
if (!config.typescript) files.concat(["tsconfig.json.hbs"]);
|
|
225
|
-
return files;
|
|
226
|
-
}
|
|
227
|
-
/**
|
|
228
|
-
* Compiles the Arkos.js project with handlebars templates
|
|
229
|
-
*
|
|
230
|
-
* @param templatesDir {string} templates location
|
|
231
|
-
* @param config {ProjectConfig} the project configuration
|
|
232
|
-
* @returns void
|
|
233
|
-
* */
|
|
234
|
-
compile(templatesDir, config) {
|
|
235
|
-
return __async(this, null, function* () {
|
|
236
|
-
const outputDir = config.projectPath;
|
|
237
|
-
const isTypescript = config.typescript;
|
|
238
|
-
const filesToBeSkipped = this.filesToBeSkipped(config);
|
|
239
|
-
function processTemplates(dir, relativeDir = "") {
|
|
240
|
-
fs.readdirSync(dir, { withFileTypes: true }).forEach((dirent) => __async(null, null, function* () {
|
|
241
|
-
if (filesToBeSkipped.includes(dirent.name)) return;
|
|
242
|
-
const fullPath = path2.join(dir, dirent.name);
|
|
243
|
-
const relativePath = path2.join(relativeDir, dirent.name);
|
|
244
|
-
if (dirent.isDirectory()) {
|
|
245
|
-
processTemplates(fullPath, relativePath);
|
|
246
|
-
} else if (dirent.name.endsWith(".hbs")) {
|
|
247
|
-
const templatePath = fullPath;
|
|
248
|
-
const template = handlebars.compile(
|
|
249
|
-
fs.readFileSync(templatePath, "utf8")
|
|
250
|
-
);
|
|
251
|
-
let arkosLatestVersion = "1.0.0";
|
|
252
|
-
const content = template(__spreadProps(__spreadValues({}, config), { arkosLatestVersion }));
|
|
253
|
-
const ext = isTypescript ? ".ts" : ".js";
|
|
254
|
-
let outputPath = path2.join(
|
|
255
|
-
outputDir,
|
|
256
|
-
relativePath.replace(".hbs", "")
|
|
257
|
-
);
|
|
258
|
-
if (dirent.name.endsWith(".ts.hbs"))
|
|
259
|
-
outputPath = path2.join(
|
|
260
|
-
outputDir,
|
|
261
|
-
relativePath.replace(".ts.hbs", ext)
|
|
262
|
-
);
|
|
263
|
-
fs.mkdirSync(path2.dirname(outputPath), { recursive: true });
|
|
264
|
-
fs.writeFileSync(outputPath, content);
|
|
265
|
-
}
|
|
266
|
-
}));
|
|
267
|
-
}
|
|
268
|
-
processTemplates(templatesDir);
|
|
269
|
-
});
|
|
270
|
-
}
|
|
271
|
-
};
|
|
272
|
-
var templateCompiler = new TemplateCompiler();
|
|
273
|
-
var template_compiler_default = templateCompiler;
|
|
274
|
-
|
|
275
|
-
// src/index.ts
|
|
276
|
-
import Handlebars from "handlebars";
|
|
277
|
-
|
|
278
|
-
// ../shared/src/utils/helpers/user-agent.helpers.ts
|
|
279
|
-
function detectPackageManagerFromUserAgent() {
|
|
280
|
-
const userAgent = process.env.npm_config_user_agent || "";
|
|
281
|
-
if (!userAgent) return "npm";
|
|
282
|
-
if (userAgent.includes("pnpm")) return "pnpm";
|
|
283
|
-
if (userAgent.includes("yarn")) return "yarn";
|
|
284
|
-
if (userAgent.includes("npm")) return "npm";
|
|
285
|
-
if (userAgent.includes("bun")) return "bun";
|
|
286
|
-
if (userAgent.includes("cnpm")) return "cnpm";
|
|
287
|
-
if (userAgent.includes("corepack")) return "corepack";
|
|
288
|
-
if (userAgent.includes("deno")) return "deno";
|
|
289
|
-
return "npm";
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
// src/index.ts
|
|
293
|
-
Handlebars.registerHelper("eq", (a, b) => a === b);
|
|
294
|
-
Handlebars.registerHelper("neq", (a, b) => a !== b);
|
|
295
|
-
function main() {
|
|
296
|
-
return __async(this, null, function* () {
|
|
297
|
-
const config = yield project_config_inquirer_default.run();
|
|
298
|
-
const projectPath = config.projectPath;
|
|
299
|
-
fs2.mkdirSync(projectPath, { recursive: true });
|
|
300
|
-
console.info(
|
|
301
|
-
`
|
|
302
|
-
Creating a new ${chalk2.bold(chalk2.cyan("Arkos.js"))} project in ${chalk2.green(`./${config.projectName}`)}`
|
|
303
|
-
);
|
|
304
|
-
const templatesDir = path3.join(__dirname, `../templates/basic`);
|
|
305
|
-
yield template_compiler_default.compile(templatesDir, config);
|
|
306
|
-
process.chdir(projectPath);
|
|
307
|
-
const packageManager = detectPackageManagerFromUserAgent();
|
|
308
|
-
console.info("\nInstalling dependencies...");
|
|
309
|
-
console.info(`
|
|
310
|
-
Using ${packageManager}.
|
|
311
|
-
`);
|
|
312
|
-
execSync(`${packageManager} install`, { stdio: "inherit" });
|
|
313
|
-
console.info(`
|
|
314
|
-
${chalk2.bold(chalk2.cyan("Arkos.js"))} project created successfully!
|
|
315
|
-
|
|
316
|
-
Next steps:
|
|
317
|
-
1. cd ${config.projectName}
|
|
318
|
-
2. setup your ${chalk2.cyan("DATABASE_URL")} under .env
|
|
319
|
-
3. npx prisma db push
|
|
320
|
-
4. npx prisma generate
|
|
321
|
-
5. npm run dev
|
|
322
|
-
`);
|
|
323
|
-
});
|
|
324
|
-
}
|
|
325
|
-
main().catch(console.error);
|