@devbro/pashmak 0.1.0 → 0.1.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/app/console/generate/GenerateControllerCommand.js +5 -2
- package/dist/app/console/generate/GenerateControllerCommand.js.map +1 -1
- package/dist/app/console/index.js +3 -0
- package/dist/app/console/index.js.map +1 -1
- package/dist/app/console/project/CreateProjectCommand.d.ts +1 -0
- package/dist/app/console/project/CreateProjectCommand.js +28 -11
- package/dist/app/console/project/CreateProjectCommand.js.map +1 -1
- package/dist/bin/pashmak_cli.cjs +160 -0
- package/dist/bin/pashmak_cli.d.ts +2 -0
- package/dist/bin/pashmak_cli.js +14 -0
- package/dist/bin/pashmak_cli.js.map +1 -0
- package/package.json +3 -3
- package/dist/pashmak_cli.d.ts +0 -1
- package/dist/pashmak_cli.js +0 -9
- package/dist/pashmak_cli.js.map +0 -1
|
@@ -9,7 +9,6 @@ import { config } from "@devbro/neko-config";
|
|
|
9
9
|
import handlebars from "handlebars";
|
|
10
10
|
import { fileURLToPath } from "url";
|
|
11
11
|
import pluralize from "pluralize";
|
|
12
|
-
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
13
12
|
class GenerateControllerCommand extends Command {
|
|
14
13
|
static {
|
|
15
14
|
__name(this, "GenerateControllerCommand");
|
|
@@ -41,7 +40,11 @@ class GenerateControllerCommand extends Command {
|
|
|
41
40
|
await fs.mkdir(config.get("migration.path"), {
|
|
42
41
|
recursive: true
|
|
43
42
|
});
|
|
44
|
-
|
|
43
|
+
let dirname = __dirname;
|
|
44
|
+
if (!dirname) {
|
|
45
|
+
dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
46
|
+
}
|
|
47
|
+
const compiledTemplate = handlebars.compile((await fs.readFile(path.join(dirname, "./controller.tpl"))).toString());
|
|
45
48
|
const template = await compiledTemplate({
|
|
46
49
|
className: Case.pascal(this.name),
|
|
47
50
|
routeName: Case.kebab(pluralize(this.name))
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/app/console/generate/GenerateControllerCommand.ts"],"sourcesContent":["import { cli } from \"../../../facades\";\nimport { Command, Option } from \"clipanion\";\nimport { Case } from \"change-case-all\";\nimport path from \"path\";\nimport * as fs from \"fs/promises\";\nimport { config } from \"@devbro/neko-config\";\nimport handlebars from \"handlebars\";\nimport { fileURLToPath } from \"url\";\nimport pluralize from \"pluralize\";\n\
|
|
1
|
+
{"version":3,"sources":["../../../../src/app/console/generate/GenerateControllerCommand.ts"],"sourcesContent":["import { cli } from \"../../../facades\";\nimport { Command, Option } from \"clipanion\";\nimport { Case } from \"change-case-all\";\nimport path from \"path\";\nimport * as fs from \"fs/promises\";\nimport { config } from \"@devbro/neko-config\";\nimport handlebars from \"handlebars\";\nimport { fileURLToPath } from \"url\";\nimport pluralize from \"pluralize\";\n\nexport class GenerateControllerCommand extends Command {\n static paths = [\n [`make`, `controller`],\n [`generate`, `controller`],\n ];\n\n name = Option.String({ required: true });\n\n async execute() {\n const rootDir = process.cwd();\n\n const date = new Date();\n const year = date.getFullYear();\n const month = String(date.getMonth() + 1).padStart(2, \"0\");\n const day = String(date.getDate()).padStart(2, \"0\");\n const secondsOfDay = String(\n date.getHours() * 3600 + date.getMinutes() * 60 + date.getSeconds(),\n ).padStart(5, \"0\");\n\n const fixed_name = Case.snake(this.name);\n const filename = `${Case.capital(this.name)}Controller.ts`;\n this.context.stdout.write(`creating migration file ${filename}\\n`);\n\n await fs.mkdir(config.get(\"migration.path\"), { recursive: true });\n\n let dirname = __dirname;\n if (!dirname) {\n dirname = path.dirname(fileURLToPath(import.meta.url));\n }\n\n const compiledTemplate = handlebars.compile(\n (await fs.readFile(path.join(dirname, \"./controller.tpl\"))).toString(),\n );\n const template = await compiledTemplate({\n className: Case.pascal(this.name),\n routeName: Case.kebab(pluralize(this.name)),\n });\n\n await fs.writeFile(\n path.join(rootDir, \"src/app/controllers\", filename),\n template,\n );\n }\n}\n\ncli().register(Gener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CAAA,GAAsBO,SAAQ,CAAA;AAEtE,UAAMC,WAAW,MAAML,iBAAiB;MACtCM,WAAWhD,KAAKiD,OAAO,KAAKxC,IAAI;MAChCyC,WAAWlD,KAAKmD,MAAM7C,UAAU,KAAKG,IAAI,CAAA;IAC3C,CAAA;AAEA,UAAMP,GAAGkD,UACPnD,KAAK4C,KAAKhC,SAAS,uBAAuBkB,QAAAA,GAC1CgB,QAAAA;EAEJ;AACF;AAEAlD,IAAAA,EAAMwD,SAAS9C,yBAAAA;","names":["cli","Command","Option","Case","path","fs","config","handlebars","fileURLToPath","pluralize","GenerateControllerCommand","paths","name","String","required","execute","rootDir","process","cwd","date","Date","year","getFullYear","month","getMonth","padStart","day","getDate","secondsOfDay","getHours","getMinutes","getSeconds","fixed_name","snake","filename","capital","context","stdout","write","mkdir","get","recursive","dirname","__dirname","url","compiledTemplate","compile","readFile","join","toString","template","className","pascal","routeName","kebab","writeFile","register"]}
|
|
@@ -4,4 +4,7 @@ export * from "./DefaultCommand";
|
|
|
4
4
|
export * from "./KeyGenerateCommand";
|
|
5
5
|
export * from "./generate";
|
|
6
6
|
export * from "./project/CreateProjectCommand";
|
|
7
|
+
import { cli } from "../../facades";
|
|
8
|
+
import { CreateProjectCommand } from "./project/CreateProjectCommand";
|
|
9
|
+
cli().register(CreateProjectCommand);
|
|
7
10
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/app/console/index.ts"],"sourcesContent":["export * from \"./migrate\";\nexport * from \"./StartCommand\";\nexport * from \"./DefaultCommand\";\nexport * from \"./KeyGenerateCommand\";\nexport * from \"./generate\";\nexport * from \"./project/CreateProjectCommand\";\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/app/console/index.ts"],"sourcesContent":["export * from \"./migrate\";\nexport * from \"./StartCommand\";\nexport * from \"./DefaultCommand\";\nexport * from \"./KeyGenerateCommand\";\nexport * from \"./generate\";\nexport * from \"./project/CreateProjectCommand\";\n\nimport { cli } from \"../../facades\";\nimport { CreateProjectCommand } from \"./project/CreateProjectCommand\";\n\ncli().register(CreateProjectCommand);\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAEd,SAASA,WAAW;AACpB,SAASC,4BAA4B;AAErCD,IAAAA,EAAME,SAASD,oBAAAA;","names":["cli","CreateProjectCommand","register"]}
|
|
@@ -6,6 +6,7 @@ declare class CreateProjectCommand extends Command {
|
|
|
6
6
|
static usage: clipanion.Usage;
|
|
7
7
|
projectPath: string;
|
|
8
8
|
git: boolean;
|
|
9
|
+
folderExists(folderPath: string): Promise<boolean>;
|
|
9
10
|
execute(): Promise<1 | undefined>;
|
|
10
11
|
processTplFolder(src: string, dest: string, data?: any): Promise<void>;
|
|
11
12
|
processTplFile(src: string, dest: string, data?: any): Promise<void>;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
import { cli } from "../../../facades";
|
|
4
3
|
import { Command, Option } from "clipanion";
|
|
5
4
|
import { Case } from "change-case-all";
|
|
6
5
|
import path from "path";
|
|
@@ -8,7 +7,6 @@ import * as fs from "fs/promises";
|
|
|
8
7
|
import { fileURLToPath } from "url";
|
|
9
8
|
import handlebars from "handlebars";
|
|
10
9
|
import { execSync } from "child_process";
|
|
11
|
-
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
12
10
|
class CreateProjectCommand extends Command {
|
|
13
11
|
static {
|
|
14
12
|
__name(this, "CreateProjectCommand");
|
|
@@ -28,21 +26,32 @@ class CreateProjectCommand extends Command {
|
|
|
28
26
|
`,
|
|
29
27
|
examples: [
|
|
30
28
|
[
|
|
31
|
-
`Create a new project in
|
|
32
|
-
`create project my-project`
|
|
29
|
+
`Create a new project in specified directory`,
|
|
30
|
+
`create project --path /path/to/my-project --git`
|
|
33
31
|
],
|
|
34
32
|
[
|
|
35
|
-
`Create a new project at a specific path`,
|
|
36
|
-
`create project
|
|
33
|
+
`Create a new project at a specific path with git initialized`,
|
|
34
|
+
`create project --path /path/to/my-project --git`
|
|
37
35
|
]
|
|
38
36
|
]
|
|
39
37
|
});
|
|
40
|
-
projectPath = Option.String(
|
|
41
|
-
|
|
38
|
+
projectPath = Option.String("--path", {
|
|
39
|
+
required: true
|
|
42
40
|
});
|
|
43
41
|
git = Option.Boolean(`--git`, false, {
|
|
44
42
|
description: `Initialize a git repository in the new project`
|
|
45
43
|
});
|
|
44
|
+
async folderExists(folderPath) {
|
|
45
|
+
try {
|
|
46
|
+
const stats = await fs.stat(folderPath);
|
|
47
|
+
return stats.isDirectory();
|
|
48
|
+
} catch (error) {
|
|
49
|
+
if (error.code === "ENOENT") {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
throw error;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
46
55
|
async execute() {
|
|
47
56
|
const projectPath = path.join(this.projectPath);
|
|
48
57
|
try {
|
|
@@ -55,7 +64,16 @@ class CreateProjectCommand extends Command {
|
|
|
55
64
|
recursive: true
|
|
56
65
|
});
|
|
57
66
|
console.log(`Created project directory at: ${projectPath}`);
|
|
58
|
-
|
|
67
|
+
let dirname = __dirname;
|
|
68
|
+
if (!dirname) {
|
|
69
|
+
dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
70
|
+
}
|
|
71
|
+
let basePath = path.join(dirname, `./base_project`);
|
|
72
|
+
if (await this.folderExists(basePath) === false) {
|
|
73
|
+
basePath = path.join(dirname, `../app/console/project/base_project`);
|
|
74
|
+
}
|
|
75
|
+
console.log(`Using base project path: ${basePath}`);
|
|
76
|
+
const baseProjectPath = basePath;
|
|
59
77
|
await this.processTplFolder(baseProjectPath, projectPath, {});
|
|
60
78
|
console.log(`Copied base project files to: ${projectPath}`);
|
|
61
79
|
const packageJsonPath = path.join(projectPath, `package.json`);
|
|
@@ -89,7 +107,7 @@ class CreateProjectCommand extends Command {
|
|
|
89
107
|
} else if (file.name.endsWith(".tpl")) {
|
|
90
108
|
await this.processTplFile(srcPath, destPath, {});
|
|
91
109
|
} else {
|
|
92
|
-
throw new Error("unexpected non tpl file");
|
|
110
|
+
throw new Error("unexpected non tpl file: " + srcPath + " " + file.name);
|
|
93
111
|
}
|
|
94
112
|
}
|
|
95
113
|
}
|
|
@@ -99,7 +117,6 @@ class CreateProjectCommand extends Command {
|
|
|
99
117
|
await fs.writeFile(dest, template);
|
|
100
118
|
}
|
|
101
119
|
}
|
|
102
|
-
cli().register(CreateProjectCommand);
|
|
103
120
|
export {
|
|
104
121
|
CreateProjectCommand
|
|
105
122
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/app/console/project/CreateProjectCommand.ts"],"sourcesContent":["import { cli } from \"../../../facades\";\nimport { Command, Option } from \"clipanion\";\nimport { Case } from \"change-case-all\";\nimport path from \"path\";\nimport * as fs from \"fs/promises\";\nimport { fileURLToPath } from \"url\";\nimport handlebars from \"handlebars\";\nimport { execSync } from \"child_process\";\
|
|
1
|
+
{"version":3,"sources":["../../../../src/app/console/project/CreateProjectCommand.ts"],"sourcesContent":["import { cli } from \"../../../facades\";\nimport { Command, Option } from \"clipanion\";\nimport { Case } from \"change-case-all\";\nimport path from \"path\";\nimport * as fs from \"fs/promises\";\nimport { fileURLToPath } from \"url\";\nimport handlebars from \"handlebars\";\nimport { execSync } from \"child_process\";\n\nexport class CreateProjectCommand extends Command {\n static paths = [[`create`, `project`]];\n\n static usage = Command.Usage({\n category: `Project`,\n description: `Create a new project`,\n details: `\n This command creates a new project with the specified name at the given path.\n If no path is provided, the project will be created in the current directory.\n `,\n examples: [\n [\n `Create a new project in specified directory`,\n `create project --path /path/to/my-project --git`,\n ],\n [\n `Create a new project at a specific path with git initialized`,\n `create project --path /path/to/my-project --git`,\n ],\n ],\n });\n\n projectPath = Option.String(\"--path\", { required: true });\n\n git = Option.Boolean(`--git`, false, {\n description: `Initialize a git repository in the new project`,\n });\n\n async folderExists(folderPath: string): Promise<boolean> {\n try {\n const stats = await fs.stat(folderPath);\n return stats.isDirectory();\n } catch (error: any) {\n if (error.code === \"ENOENT\") {\n return false; // Folder does not exist\n }\n throw error; // Other errors (e.g., permission issues)\n }\n }\n\n async execute() {\n // Create the project directory path by joining the specified path and project name\n const projectPath = path.join(this.projectPath);\n // Check if directory already exists\n try {\n await fs.access(projectPath);\n console.error(`Error: Directory ${projectPath} already exists.`);\n return 1;\n } catch {\n // Directory doesn't exist, we can proceed\n }\n\n await fs.mkdir(projectPath, { recursive: true });\n console.log(`Created project directory at: ${projectPath}`);\n\n let dirname = __dirname;\n if (!dirname) {\n dirname = path.dirname(fileURLToPath(import.meta.url));\n }\n\n let basePath = path.join(dirname, `./base_project`);\n if ((await this.folderExists(basePath)) === false) {\n // we are running a compiled code that was bundled and the code is running from ./dist/bin/ folder.\n basePath = path.join(dirname, `../app/console/project/base_project`);\n }\n\n console.log(`Using base project path: ${basePath}`);\n //copy content of ./base_project to the new project directory\n const baseProjectPath = basePath;\n\n await this.processTplFolder(baseProjectPath, projectPath, {});\n console.log(`Copied base project files to: ${projectPath}`);\n\n //modify package.json with foldername\n const packageJsonPath = path.join(projectPath, `package.json`);\n const packageJson = JSON.parse(await fs.readFile(packageJsonPath, `utf-8`));\n packageJson.name = Case.snake(path.basename(projectPath));\n await fs.writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2));\n console.log(`Updated package.json with project name: ${packageJson.name}`);\n\n if (this.git) {\n try {\n execSync(\n 'git init; git add --all; git commit --allow-empty -m \"chore: first commit for pashmak\"',\n {\n cwd: projectPath,\n },\n );\n } catch (error) {\n console.error(`Failed to create project.`, error);\n return 1;\n }\n }\n }\n\n async processTplFolder(src: string, dest: string, data: any = {}) {\n const files = await fs.readdir(src, { withFileTypes: true });\n for (const file of files) {\n const srcPath = path.join(src, file.name);\n const destPath =\n file.isFile() && file.name.endsWith(\".tpl\")\n ? path.join(dest, file.name.substring(0, file.name.length - 4))\n : path.join(dest, file.name);\n\n if (file.isDirectory()) {\n await fs.mkdir(destPath, { recursive: true });\n await this.processTplFolder(srcPath, destPath, data);\n } else if (file.name.endsWith(\".tpl\")) {\n await this.processTplFile(srcPath, destPath, {});\n } else {\n throw new Error(\n \"unexpected non tpl file: \" + srcPath + \" \" + file.name,\n );\n }\n }\n }\n\n async processTplFile(src: string, dest: string, data: any = {}) {\n const compiledTemplate = handlebars.compile(\n (await fs.readFile(src)).toString(),\n );\n const template = await compiledTemplate(data);\n await fs.writeFile(dest, template);\n }\n}\n"],"mappings":";;AACA,SAASA,SAASC,cAAc;AAChC,SAASC,YAAY;AACrB,OAAOC,UAAU;AACjB,YAAYC,QAAQ;AACpB,SAASC,qBAAqB;AAC9B,OAAOC,gBAAgB;AACvB,SAASC,gBAAgB;AAElB,MAAMC,6BAA6BR,QAAAA;EAR1C,OAQ0CA;;;EACxC,OAAOS,QAAQ;IAAC;MAAC;MAAU;;;EAE3B,OAAOC,QAAQV,QAAQW,MAAM;IAC3BC,UAAU;IACVC,aAAa;IACbC,SAAS;;;;IAITC,UAAU;MACR;QACE;QACA;;MAEF;QACE;QACA;;;EAGN,CAAA;EAEAC,cAAcf,OAAOgB,OAAO,UAAU;IAAEC,UAAU;EAAK,CAAA;EAEvDC,MAAMlB,OAAOmB,QAAQ,SAAS,OAAO;IACnCP,aAAa;EACf,CAAA;EAEA,MAAMQ,aAAaC,YAAsC;AACvD,QAAI;AACF,YAAMC,QAAQ,MAAMnB,GAAGoB,KAAKF,UAAAA;AAC5B,aAAOC,MAAME,YAAW;IAC1B,SAASC,OAAY;AACnB,UAAIA,MAAMC,SAAS,UAAU;AAC3B,eAAO;MACT;AACA,YAAMD;IACR;EACF;EAEA,MAAME,UAAU;AAEd,UAAMZ,cAAcb,KAAK0B,KAAK,KAAKb,WAAW;AA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ChE,UAAMC,QAAQ,MAAMnD,GAAGoD,QAAQJ,KAAK;MAAEK,eAAe;IAAK,CAAA;AAC1D,eAAWC,QAAQH,OAAO;AACxB,YAAMI,UAAUxD,KAAK0B,KAAKuB,KAAKM,KAAKZ,IAAI;AACxC,YAAMc,WACJF,KAAKG,OAAM,KAAMH,KAAKZ,KAAKgB,SAAS,MAAA,IAChC3D,KAAK0B,KAAKwB,MAAMK,KAAKZ,KAAKiB,UAAU,GAAGL,KAAKZ,KAAKkB,SAAS,CAAA,CAAA,IAC1D7D,KAAK0B,KAAKwB,MAAMK,KAAKZ,IAAI;AAE/B,UAAIY,KAAKjC,YAAW,GAAI;AACtB,cAAMrB,GAAG4B,MAAM4B,UAAU;UAAE3B,WAAW;QAAK,CAAA;AAC3C,cAAM,KAAKO,iBAAiBmB,SAASC,UAAUN,IAAAA;MACjD,WAAWI,KAAKZ,KAAKgB,SAAS,MAAA,GAAS;AACrC,cAAM,KAAKG,eAAeN,SAASC,UAAU,CAAC,CAAA;MAChD,OAAO;AACL,cAAM,IAAIM,MACR,8BAA8BP,UAAU,MAAMD,KAAKZ,IAAI;MAE3D;IACF;EACF;EAEA,MAAMmB,eAAeb,KAAaC,MAAcC,OAAY,CAAC,GAAG;AAC9D,UAAMa,mBAAmB7D,WAAW8D,SACjC,MAAMhE,GAAGyC,SAASO,GAAAA,GAAMiB,SAAQ,CAAA;AAEnC,UAAMC,WAAW,MAAMH,iBAAiBb,IAAAA;AACxC,UAAMlD,GAAG6C,UAAUI,MAAMiB,QAAAA;EAC3B;AACF;","names":["Command","Option","Case","path","fs","fileURLToPath","handlebars","execSync","CreateProjectCommand","paths","usage","Usage","category","description","details","examples","projectPath","String","required","git","Boolean","folderExists","folderPath","stats","stat","isDirectory","error","code","execute","join","access","console","mkdir","recursive","log","dirname","__dirname","url","basePath","baseProjectPath","processTplFolder","packageJsonPath","packageJson","JSON","parse","readFile","name","snake","basename","writeFile","stringify","cwd","src","dest","data","files","readdir","withFileTypes","file","srcPath","destPath","isFile","endsWith","substring","length","processTplFile","Error","compiledTemplate","compile","toString","template"]}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
18
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
19
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
20
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
21
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
22
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
23
|
+
mod
|
|
24
|
+
));
|
|
25
|
+
|
|
26
|
+
// src/bin/pashmak_cli.ts
|
|
27
|
+
var import_clipanion2 = require("clipanion");
|
|
28
|
+
|
|
29
|
+
// src/app/console/project/CreateProjectCommand.ts
|
|
30
|
+
var import_clipanion = require("clipanion");
|
|
31
|
+
var import_change_case_all = require("change-case-all");
|
|
32
|
+
var import_path = __toESM(require("path"), 1);
|
|
33
|
+
var fs = __toESM(require("fs/promises"), 1);
|
|
34
|
+
var import_url = require("url");
|
|
35
|
+
var import_handlebars = __toESM(require("handlebars"), 1);
|
|
36
|
+
var import_child_process = require("child_process");
|
|
37
|
+
var import_meta = {};
|
|
38
|
+
var CreateProjectCommand = class extends import_clipanion.Command {
|
|
39
|
+
static {
|
|
40
|
+
__name(this, "CreateProjectCommand");
|
|
41
|
+
}
|
|
42
|
+
static paths = [
|
|
43
|
+
[
|
|
44
|
+
`create`,
|
|
45
|
+
`project`
|
|
46
|
+
]
|
|
47
|
+
];
|
|
48
|
+
static usage = import_clipanion.Command.Usage({
|
|
49
|
+
category: `Project`,
|
|
50
|
+
description: `Create a new project`,
|
|
51
|
+
details: `
|
|
52
|
+
This command creates a new project with the specified name at the given path.
|
|
53
|
+
If no path is provided, the project will be created in the current directory.
|
|
54
|
+
`,
|
|
55
|
+
examples: [
|
|
56
|
+
[
|
|
57
|
+
`Create a new project in specified directory`,
|
|
58
|
+
`create project --path /path/to/my-project --git`
|
|
59
|
+
],
|
|
60
|
+
[
|
|
61
|
+
`Create a new project at a specific path with git initialized`,
|
|
62
|
+
`create project --path /path/to/my-project --git`
|
|
63
|
+
]
|
|
64
|
+
]
|
|
65
|
+
});
|
|
66
|
+
projectPath = import_clipanion.Option.String("--path", {
|
|
67
|
+
required: true
|
|
68
|
+
});
|
|
69
|
+
git = import_clipanion.Option.Boolean(`--git`, false, {
|
|
70
|
+
description: `Initialize a git repository in the new project`
|
|
71
|
+
});
|
|
72
|
+
async folderExists(folderPath) {
|
|
73
|
+
try {
|
|
74
|
+
const stats = await fs.stat(folderPath);
|
|
75
|
+
return stats.isDirectory();
|
|
76
|
+
} catch (error) {
|
|
77
|
+
if (error.code === "ENOENT") {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
throw error;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
async execute() {
|
|
84
|
+
const projectPath = import_path.default.join(this.projectPath);
|
|
85
|
+
try {
|
|
86
|
+
await fs.access(projectPath);
|
|
87
|
+
console.error(`Error: Directory ${projectPath} already exists.`);
|
|
88
|
+
return 1;
|
|
89
|
+
} catch {
|
|
90
|
+
}
|
|
91
|
+
await fs.mkdir(projectPath, {
|
|
92
|
+
recursive: true
|
|
93
|
+
});
|
|
94
|
+
console.log(`Created project directory at: ${projectPath}`);
|
|
95
|
+
let dirname = __dirname;
|
|
96
|
+
if (!dirname) {
|
|
97
|
+
dirname = import_path.default.dirname((0, import_url.fileURLToPath)(import_meta.url));
|
|
98
|
+
}
|
|
99
|
+
let basePath = import_path.default.join(dirname, `./base_project`);
|
|
100
|
+
if (await this.folderExists(basePath) === false) {
|
|
101
|
+
basePath = import_path.default.join(dirname, `../app/console/project/base_project`);
|
|
102
|
+
}
|
|
103
|
+
console.log(`Using base project path: ${basePath}`);
|
|
104
|
+
const baseProjectPath = basePath;
|
|
105
|
+
await this.processTplFolder(baseProjectPath, projectPath, {});
|
|
106
|
+
console.log(`Copied base project files to: ${projectPath}`);
|
|
107
|
+
const packageJsonPath = import_path.default.join(projectPath, `package.json`);
|
|
108
|
+
const packageJson = JSON.parse(await fs.readFile(packageJsonPath, `utf-8`));
|
|
109
|
+
packageJson.name = import_change_case_all.Case.snake(import_path.default.basename(projectPath));
|
|
110
|
+
await fs.writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2));
|
|
111
|
+
console.log(`Updated package.json with project name: ${packageJson.name}`);
|
|
112
|
+
if (this.git) {
|
|
113
|
+
try {
|
|
114
|
+
(0, import_child_process.execSync)('git init; git add --all; git commit --allow-empty -m "chore: first commit for pashmak"', {
|
|
115
|
+
cwd: projectPath
|
|
116
|
+
});
|
|
117
|
+
} catch (error) {
|
|
118
|
+
console.error(`Failed to create project.`, error);
|
|
119
|
+
return 1;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
async processTplFolder(src, dest, data = {}) {
|
|
124
|
+
const files = await fs.readdir(src, {
|
|
125
|
+
withFileTypes: true
|
|
126
|
+
});
|
|
127
|
+
for (const file of files) {
|
|
128
|
+
const srcPath = import_path.default.join(src, file.name);
|
|
129
|
+
const destPath = file.isFile() && file.name.endsWith(".tpl") ? import_path.default.join(dest, file.name.substring(0, file.name.length - 4)) : import_path.default.join(dest, file.name);
|
|
130
|
+
if (file.isDirectory()) {
|
|
131
|
+
await fs.mkdir(destPath, {
|
|
132
|
+
recursive: true
|
|
133
|
+
});
|
|
134
|
+
await this.processTplFolder(srcPath, destPath, data);
|
|
135
|
+
} else if (file.name.endsWith(".tpl")) {
|
|
136
|
+
await this.processTplFile(srcPath, destPath, {});
|
|
137
|
+
} else {
|
|
138
|
+
throw new Error("unexpected non tpl file: " + srcPath + " " + file.name);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
async processTplFile(src, dest, data = {}) {
|
|
143
|
+
const compiledTemplate = import_handlebars.default.compile((await fs.readFile(src)).toString());
|
|
144
|
+
const template = await compiledTemplate(data);
|
|
145
|
+
await fs.writeFile(dest, template);
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
// src/bin/pashmak_cli.ts
|
|
150
|
+
var [node, app, ...args] = process.argv;
|
|
151
|
+
var cli = new import_clipanion2.Cli({
|
|
152
|
+
binaryLabel: `Pashmak CLI`,
|
|
153
|
+
binaryName: `${node} ${app}`,
|
|
154
|
+
binaryVersion: `1.0.0`
|
|
155
|
+
});
|
|
156
|
+
cli.register(CreateProjectCommand);
|
|
157
|
+
cli.runExit(args).then(() => {
|
|
158
|
+
}).catch((err) => {
|
|
159
|
+
console.error(err);
|
|
160
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Cli } from "clipanion";
|
|
2
|
+
const [node, app, ...args] = process.argv;
|
|
3
|
+
let cli = new Cli({
|
|
4
|
+
binaryLabel: `Pashmak CLI`,
|
|
5
|
+
binaryName: `${node} ${app}`,
|
|
6
|
+
binaryVersion: `1.0.0`
|
|
7
|
+
});
|
|
8
|
+
import { CreateProjectCommand } from "../app/console/project/CreateProjectCommand";
|
|
9
|
+
cli.register(CreateProjectCommand);
|
|
10
|
+
cli.runExit(args).then(() => {
|
|
11
|
+
}).catch((err) => {
|
|
12
|
+
console.error(err);
|
|
13
|
+
});
|
|
14
|
+
//# sourceMappingURL=pashmak_cli.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/bin/pashmak_cli.ts"],"sourcesContent":["import { Cli } from \"clipanion\";\n\nconst [node, app, ...args] = process.argv;\nlet cli = new Cli({\n binaryLabel: `Pashmak CLI`,\n binaryName: `${node} ${app}`,\n binaryVersion: `1.0.0`,\n});\n\nimport { CreateProjectCommand } from \"../app/console/project/CreateProjectCommand\";\n\ncli.register(CreateProjectCommand);\n\ncli\n .runExit(args)\n .then(() => {})\n .catch((err: any) => {\n console.error(err);\n });\n"],"mappings":"AAAA,SAASA,WAAW;AAEpB,MAAM,CAACC,MAAMC,KAAK,GAAGC,IAAAA,IAAQC,QAAQC;AACrC,IAAIC,MAAM,IAAIN,IAAI;EAChBO,aAAa;EACbC,YAAY,GAAGP,IAAAA,IAAQC,GAAAA;EACvBO,eAAe;AACjB,CAAA;AAEA,SAASC,4BAA4B;AAErCJ,IAAIK,SAASD,oBAAAA;AAEbJ,IACGM,QAAQT,IAAAA,EACRU,KAAK,MAAA;AAAO,CAAA,EACZC,MAAM,CAACC,QAAAA;AACNC,UAAQC,MAAMF,GAAAA;AAChB,CAAA;","names":["Cli","node","app","args","process","argv","cli","binaryLabel","binaryName","binaryVersion","CreateProjectCommand","register","runExit","then","catch","err","console","error"]}
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@devbro/pashmak",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "testing application for the entire repo",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
8
8
|
"type": "module",
|
|
9
9
|
"bin": {
|
|
10
|
-
"pashmak": "./dist/pashmak_cli.js"
|
|
10
|
+
"pashmak": "./dist/bin/pashmak_cli.js"
|
|
11
11
|
},
|
|
12
12
|
"files": [
|
|
13
13
|
"dist"
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
"./package.json": "./package.json"
|
|
72
72
|
},
|
|
73
73
|
"scripts": {
|
|
74
|
-
"build": "tsup
|
|
74
|
+
"build": "tsup ",
|
|
75
75
|
"test": "jest",
|
|
76
76
|
"format": "eslint . --fix --ext ts,tsx --report-unused-disable-directives --max-warnings 0 ",
|
|
77
77
|
"prepare": "husky",
|
package/dist/pashmak_cli.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
package/dist/pashmak_cli.js
DELETED
package/dist/pashmak_cli.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/pashmak_cli.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport \"./app/console\";\nimport { logger, cli } from \"./facades\";\n\nconst [node, app, ...args] = process.argv;\ncli()\n .runExit(args)\n .then(() => {})\n .catch((err: any) => {\n logger().error(err);\n });\n"],"mappings":";AAEA,OAAO;AACP,SAASA,QAAQC,WAAW;AAE5B,MAAM,CAACC,MAAMC,KAAK,GAAGC,IAAAA,IAAQC,QAAQC;AACrCL,IAAAA,EACGM,QAAQH,IAAAA,EACRI,KAAK,MAAA;AAAO,CAAA,EACZC,MAAM,CAACC,QAAAA;AACNV,SAAAA,EAASW,MAAMD,GAAAA;AACjB,CAAA;","names":["logger","cli","node","app","args","process","argv","runExit","then","catch","err","error"]}
|