@expressots/cli 1.3.3 → 1.4.0

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.
@@ -2,12 +2,10 @@ import { provide } from "inversify-binding-decorators";
2
2
  import { randomUUID } from "node:crypto";
3
3
 
4
4
  @provide({{className}})
5
- class {{className}} {
6
- public id: string;
5
+ export class {{className}} {
6
+ id: string;
7
7
 
8
8
  constructor() {
9
9
  this.id = randomUUID();
10
10
  }
11
11
  }
12
-
13
- export { {{className}} };
@@ -0,0 +1,3 @@
1
+ import { CreateModule } from "@expressots/core";
2
+
3
+ export const {{moduleName}}Module = CreateModule([]);
@@ -1,6 +1,4 @@
1
1
  import { CreateModule } from "@expressots/core";
2
2
  import { {{className}}Controller } from "{{{path}}}";
3
3
 
4
- const {{moduleName}}Module = CreateModule([{{className}}Controller]);
5
-
6
- export { {{moduleName}}Module };
4
+ export const {{moduleName}}Module = CreateModule([{{className}}Controller]);
@@ -1,10 +1,4 @@
1
1
  import { provide } from "inversify-binding-decorators";
2
2
 
3
3
  @provide({{className}}Provider)
4
- class {{className}}Provider {
5
-
6
- constructor() {}
7
-
8
- }
9
-
10
- export { {{className}}Provider };
4
+ export class {{className}}Provider {}
@@ -2,13 +2,8 @@ import { provide } from "inversify-binding-decorators";
2
2
  import { I{{className}}RequestDTO, I{{className}}ResponseDTO } from "./{{fileName}}.dto";
3
3
 
4
4
  @provide({{className}}UseCase)
5
- class {{className}}UseCase {
6
-
7
- constructor() {}
8
-
9
- execute(id: string, payload: I{{className}}RequestDTO): I{{className}}ResponseDTO {
10
- return "your use case";
5
+ export class {{className}}UseCase {
6
+ execute(payload: I{{className}}RequestDTO): I{{className}}ResponseDTO {
7
+ return "Use Case";
11
8
  }
12
9
  }
13
-
14
- export { {{className}}UseCase };
@@ -2,13 +2,8 @@ import { provide } from "inversify-binding-decorators";
2
2
  import { I{{className}}RequestDTO, I{{className}}ResponseDTO } from "./{{fileName}}.dto";
3
3
 
4
4
  @provide({{className}}UseCase)
5
- class {{className}}UseCase {
6
-
7
- constructor() {}
8
-
5
+ export class {{className}}UseCase {
9
6
  execute(payload: I{{className}}RequestDTO): I{{className}}ResponseDTO {
10
- return "your use case";
7
+ return "Use Case";
11
8
  }
12
- }
13
-
14
- export { {{className}}UseCase };
9
+ }
@@ -1,13 +1,8 @@
1
1
  import { provide } from "inversify-binding-decorators";
2
2
 
3
3
  @provide({{className}}UseCase)
4
- class {{className}}UseCase {
5
-
6
- constructor() {}
7
-
8
- execute(): string {
9
- return "your use case";
4
+ export class {{className}}UseCase {
5
+ execute() {
6
+ return "Use Case";
10
7
  }
11
8
  }
12
-
13
- export { {{className}}UseCase };
package/bin/new/cli.js CHANGED
@@ -3,6 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createProject = void 0;
4
4
  const form_1 = require("./form");
5
5
  const createProject = () => {
6
+ const packageManagers = ["npm", "yarn", "pnpm"];
7
+ if (process.platform !== "win32") {
8
+ packageManagers.push("bun");
9
+ }
6
10
  return {
7
11
  command: "new <project-name> [package-manager] [template] [directory]",
8
12
  describe: "Create a new project",
@@ -21,7 +25,7 @@ const createProject = () => {
21
25
  .option("package-manager", {
22
26
  describe: "The package manager to use",
23
27
  type: "string",
24
- choices: ["npm", "yarn", "pnpm"],
28
+ choices: packageManagers,
25
29
  alias: "p",
26
30
  })
27
31
  .option("directory", {
@@ -33,8 +37,12 @@ const createProject = () => {
33
37
  .implies("template", "package-manager");
34
38
  return yargs;
35
39
  },
36
- handler: async ({ projectName, packageManager, template, directory }) => {
37
- return await (0, form_1.projectForm)(projectName, [packageManager, template, directory]);
40
+ handler: async ({ projectName, packageManager, template, directory, }) => {
41
+ return await (0, form_1.projectForm)(projectName, [
42
+ packageManager,
43
+ template,
44
+ directory,
45
+ ]);
38
46
  },
39
47
  };
40
48
  };
package/bin/new/form.js CHANGED
@@ -73,7 +73,10 @@ const projectForm = async (projectName, args) => {
73
73
  // Resolving the argument order problem
74
74
  for (const arg of args) {
75
75
  if (args.length >= 3) {
76
- if (arg === "npm" || arg === "yarn" || arg === "pnpm") {
76
+ if (arg === "npm" ||
77
+ arg === "yarn" ||
78
+ arg === "pnpm" ||
79
+ arg === "bun") {
77
80
  packageManager = arg;
78
81
  }
79
82
  else if (arg === "non-opinionated" || arg === "opinionated") {
@@ -107,7 +110,7 @@ const projectForm = async (projectName, args) => {
107
110
  type: "list",
108
111
  name: "packageManager",
109
112
  message: "Package manager",
110
- choices: ["npm", "yarn", "pnpm"],
113
+ choices: ["npm", "yarn", "pnpm", "bun"],
111
114
  },
112
115
  {
113
116
  type: "list",
@@ -141,10 +144,17 @@ const projectForm = async (projectName, args) => {
141
144
  Opinionated: "opinionated",
142
145
  };
143
146
  if (answer.confirm) {
147
+ // Check if package manager is bun and OS is Windows
148
+ if (answer.packageManager === "bun" && process.platform === "win32") {
149
+ (0, cli_ui_1.printError)("bun is not supported on Windows. Please use", "npm, yarn or pnpm");
150
+ process.exit(1);
151
+ }
144
152
  await checkIfPackageManagerExists(answer.packageManager);
145
153
  console.log("\n");
146
154
  const progressBar = new cli_progress_1.SingleBar({
147
- format: "Progress |" + chalk_1.default.green("{bar}") + "| {percentage}% || {doing}",
155
+ format: "Progress |" +
156
+ chalk_1.default.green("{bar}") +
157
+ "| {percentage}% || {doing}",
148
158
  hideCursor: true,
149
159
  }, cli_progress_1.Presets.shades_classic);
150
160
  progressBar.start(100, 0, {
@@ -188,6 +198,9 @@ const projectForm = async (projectName, args) => {
188
198
  case "pnpm":
189
199
  console.log(chalk_1.default.bold.gray("$ pnpm run dev"));
190
200
  break;
201
+ case "bun":
202
+ console.log(chalk_1.default.bold.gray("$ bun dev"));
203
+ break;
191
204
  }
192
205
  console.log("\n");
193
206
  console.log(chalk_1.default.bold.green((0, center_text_1.centerText)("Happy coding!")));
@@ -6,11 +6,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.addControllerToModule = void 0;
7
7
  const node_fs_1 = __importDefault(require("node:fs"));
8
8
  async function addControllerToModule(filePath, controllerName, controllerPath) {
9
- const fileContent = await node_fs_1.default.promises.readFile(filePath, 'utf8');
9
+ const fileContent = await node_fs_1.default.promises.readFile(filePath, "utf8");
10
10
  const imports = [];
11
11
  const notImports = [];
12
- fileContent.split('\n').forEach((line) => {
13
- if (line.startsWith('import')) {
12
+ fileContent.split("\n").forEach((line) => {
13
+ if (line.startsWith("import")) {
14
14
  imports.push(line);
15
15
  }
16
16
  else {
@@ -27,14 +27,20 @@ async function addControllerToModule(filePath, controllerName, controllerPath) {
27
27
  if (!moduleDeclarationMatch) {
28
28
  return;
29
29
  }
30
- const controllers = moduleDeclarationMatch[1].trim().split(',').map((c) => c.trim()).filter((c) => c);
30
+ const controllers = moduleDeclarationMatch[1]
31
+ .trim()
32
+ .split(",")
33
+ .map((c) => c.trim())
34
+ .filter((c) => c);
31
35
  if (controllers.includes(controllerName)) {
32
36
  return;
33
37
  }
34
38
  controllers.push(controllerName);
35
- const newControllers = controllers.join(', ');
39
+ const newControllers = controllers.join(", ");
36
40
  const newModuleDeclaration = `CreateModule([${newControllers}]`;
37
- const newFileContent = [...imports, ...notImports].join('\n').replace(moduleDeclarationRegex, newModuleDeclaration);
38
- await node_fs_1.default.promises.writeFile(filePath, newFileContent, 'utf8');
41
+ const newFileContent = [...imports, ...notImports]
42
+ .join("\n")
43
+ .replace(moduleDeclarationRegex, newModuleDeclaration);
44
+ await node_fs_1.default.promises.writeFile(filePath, newFileContent, "utf8");
39
45
  }
40
46
  exports.addControllerToModule = addControllerToModule;
@@ -14,14 +14,17 @@ async function validateAppContainer() {
14
14
  const { sourceRoot } = await compiler_1.default.loadConfig();
15
15
  const imports = [];
16
16
  const notImports = [];
17
- const path = (0, glob_1.globSync)(`./${sourceRoot}/${APP_CONTAINER}`, { absolute: true, ignore: '**/node_modules/**' });
17
+ const path = (0, glob_1.globSync)(`./${sourceRoot}/${APP_CONTAINER}`, {
18
+ absolute: true,
19
+ ignore: "**/node_modules/**",
20
+ });
18
21
  if (!path.length) {
19
- (0, cli_ui_1.printError)('Module not added to Container. Container file not found!', APP_CONTAINER);
22
+ (0, cli_ui_1.printError)("Module not added to Container. Container file not found!", APP_CONTAINER);
20
23
  process.exit(1);
21
24
  }
22
- const fileContent = await node_fs_1.default.promises.readFile(path[0], 'utf8');
23
- fileContent.split('\n').forEach((line) => {
24
- if (line.startsWith('import')) {
25
+ const fileContent = await node_fs_1.default.promises.readFile(path[0], "utf8");
26
+ fileContent.split("\n").forEach((line) => {
27
+ if (line.startsWith("import")) {
25
28
  imports.push(line);
26
29
  }
27
30
  else {
@@ -32,17 +35,21 @@ async function validateAppContainer() {
32
35
  const moduleDeclarationRegex = /.create\(\s*\[([\s\S]*?)]/;
33
36
  const moduleDeclarationMatch = fileContent.match(moduleDeclarationRegex);
34
37
  if (!moduleDeclarationMatch) {
35
- (0, cli_ui_1.printError)('Container format incorrect!', APP_CONTAINER);
38
+ (0, cli_ui_1.printError)("Container format incorrect!", APP_CONTAINER);
36
39
  process.exit(1);
37
40
  }
38
- const modules = moduleDeclarationMatch[1].trim().split(',').filter((m) => m.trim() !== "").map((m) => m.trim());
41
+ const modules = moduleDeclarationMatch[1]
42
+ .trim()
43
+ .split(",")
44
+ .filter((m) => m.trim() !== "")
45
+ .map((m) => m.trim());
39
46
  return {
40
47
  regex: moduleDeclarationRegex,
41
48
  path: path[0],
42
49
  content: moduleDeclarationMatch,
43
50
  modules,
44
51
  imports,
45
- notImports
52
+ notImports,
46
53
  };
47
54
  }
48
55
  async function addModuleToContainer(name, modulePath, path) {
@@ -59,7 +66,7 @@ async function addModuleToContainer(name, modulePath, path) {
59
66
  let newImport = "";
60
67
  const modulePathRegex = /^[^/]=$/;
61
68
  if (!modulePathRegex.test(modulePath)) {
62
- if (path.split('/').length > 1) {
69
+ if (path.split("/").length > 1) {
63
70
  newImport = `import { ${moduleName}Module } from "${usecaseDir}${modulePath}/${name}.module";`;
64
71
  }
65
72
  else {
@@ -69,16 +76,21 @@ async function addModuleToContainer(name, modulePath, path) {
69
76
  else {
70
77
  newImport = `import { ${moduleName}Module } from "${usecaseDir}${name}/${name}.module";`;
71
78
  }
72
- if (containerData.imports.includes(newImport) && containerData.modules.includes(`${moduleName}Module`)) {
79
+ if (containerData.imports.includes(newImport) &&
80
+ containerData.modules.includes(`${moduleName}Module`)) {
73
81
  return;
74
82
  }
75
83
  containerData.imports.push(newImport);
76
84
  containerData.modules.push(`${moduleName}Module`);
77
- const newModule = containerData.modules.join(', ');
85
+ const newModule = containerData.modules.join(", ");
78
86
  const newModuleDeclaration = `.create([${newModule}]`;
79
- const newFileContent = [...containerData.imports, ...containerData.notImports]
80
- .join('\n').replace(containerData.regex, newModuleDeclaration);
87
+ const newFileContent = [
88
+ ...containerData.imports,
89
+ ...containerData.notImports,
90
+ ]
91
+ .join("\n")
92
+ .replace(containerData.regex, newModuleDeclaration);
81
93
  console.log(" ", chalk_1.default.greenBright(`[container]`.padEnd(14)), chalk_1.default.bold.white(`${moduleName}Module added to ${APP_CONTAINER}! ✔️`));
82
- await node_fs_1.default.promises.writeFile(containerData.path, newFileContent, 'utf8');
94
+ await node_fs_1.default.promises.writeFile(containerData.path, newFileContent, "utf8");
83
95
  }
84
96
  exports.addModuleToContainer = addModuleToContainer;
@@ -4,7 +4,7 @@ exports.centerText = void 0;
4
4
  function centerText(text) {
5
5
  const terminalWidth = process.stdout.columns;
6
6
  const padding = Math.floor((terminalWidth - text.length) / 2);
7
- const centeredText = ' '.repeat(padding) + text;
7
+ const centeredText = " ".repeat(padding) + text;
8
8
  return centeredText;
9
9
  }
10
10
  exports.centerText = centerText;
@@ -18,9 +18,9 @@ async function verifyIfFileExists(path) {
18
18
  default: true,
19
19
  },
20
20
  ]);
21
- const fileName = path.split('/').pop();
21
+ const fileName = path.split("/").pop();
22
22
  if (!answer.confirm) {
23
- (0, cli_ui_1.printError)('File not created!', fileName);
23
+ (0, cli_ui_1.printError)("File not created!", fileName);
24
24
  process.exit(1);
25
25
  }
26
26
  }
package/package.json CHANGED
@@ -1,141 +1,151 @@
1
1
  {
2
- "name": "@expressots/cli",
3
- "version": "1.3.3",
4
- "description": "Expressots CLI - modern, fast, lightweight nodejs web framework (@cli)",
5
- "author": "Richard Zampieri",
6
- "license": "MIT",
7
- "bugs": {
8
- "url": "https://github.com/expressots/expressots-cli/issues"
9
- },
10
- "bin": {
11
- "expressots": "bin/cli.js"
12
- },
13
- "engines": {
14
- "node": ">=18.10.0"
15
- },
16
- "funding": {
17
- "type": "github",
18
- "url": "https://github.com/sponsors/expressots"
19
- },
20
- "repository": {
21
- "type": "git",
22
- "url": "https://github.com/expressots/expressots-cli"
23
- },
24
- "homepage": "https://expresso-ts.com",
25
- "publishConfig": {
26
- "access": "public"
27
- },
28
- "keywords": [
29
- "ExpressoTS",
30
- "CLI",
31
- "Scaffolding"
32
- ],
33
- "scripts": {
34
- "start:build": "npm run build && npm run start",
35
- "start": "node ./bin/cli.js",
36
- "start:dev": "tsnd ./src/cli.ts",
37
- "build": "npm run clean && tsc -p tsconfig.json && yarn cp:templates && chmod +x ./bin/cli.js",
38
- "cp:templates": "cp -r ./src/generate/templates ./bin/generate/templates",
39
- "clean": "rimraf ./bin",
40
- "lint": "eslint .eslintrc.js --ext .ts,.tsx,.js,.jsx .",
41
- "release": "release-it",
42
- "prepare": "husky install"
43
- },
44
- "dependencies": {
45
- "@expressots/boost-ts": "^1.1.1",
46
- "chalk-animation": "^1",
47
- "cli-progress": "^3.11.2",
48
- "degit": "^2.8.4",
49
- "glob": "^10.2.6",
50
- "inquirer": "^8.0.0",
51
- "mustache": "^4.2.0",
52
- "ts-node": "^10.9.1",
53
- "yargs": "^17.6.2"
54
- },
55
- "devDependencies": {
56
- "@types/chalk-animation": "^1.6.1",
57
- "@types/cli-progress": "^3.11.0",
58
- "@types/degit": "^2.8.3",
59
- "@types/inquirer": "^9.0.3",
60
- "@types/mustache": "^4.2.2",
61
- "@types/node": "^18.11.19",
62
- "@types/yargs": "^17.0.22",
63
- "@typescript-eslint/eslint-plugin": "^5.53.0",
64
- "@typescript-eslint/parser": "^5.53.0",
65
- "chalk": "^4.1.2",
66
- "eslint": "^8.34.0",
67
- "eslint-config-prettier": "^8.6.0",
68
- "eslint-plugin-prettier": "^4.2.1",
69
- "husky": "^8.0.3",
70
- "prettier": "^2.8.4",
71
- "release-it": "^15.6.0",
72
- "rimraf": "^4.1.2",
73
- "ts-node-dev": "^2.0.0",
74
- "typescript": "^4.9.5"
75
- },
76
- "release-it": {
77
- "git": {
78
- "commitMessage": "chore: release v${version}"
79
- },
80
- "github": {
81
- "release": true
82
- },
83
- "npm": {
84
- "publish": false
85
- },
86
- "plugins": {
87
- "@release-it/conventional-changelog": {
88
- "infile": "CHANGELOG.md",
89
- "preset": {
90
- "name": "conventionalcommits",
91
- "types": [
92
- {
93
- "type": "feat",
94
- "section": "Features"
95
- },
96
- {
97
- "type": "fix",
98
- "section": "Bug Fixes"
99
- },
100
- {
101
- "type": "perf",
102
- "section": "Performance Improvements"
103
- },
104
- {
105
- "type": "revert",
106
- "section": "Reverts"
107
- },
108
- {
109
- "type": "docs",
110
- "section": "Documentation"
111
- },
112
- {
113
- "type": "style",
114
- "section": "Styles"
115
- },
116
- {
117
- "type": "refactor",
118
- "section": "Code Refactoring"
119
- },
120
- {
121
- "type": "test",
122
- "section": "Tests"
123
- },
124
- {
125
- "type": "build",
126
- "section": "Build System"
127
- },
128
- {
129
- "type": "ci",
130
- "section": "Continuous Integrations"
131
- },
132
- {
133
- "type": "chore",
134
- "hidden": true
135
- }
136
- ]
137
- }
138
- }
139
- }
140
- }
2
+ "name": "@expressots/cli",
3
+ "version": "1.4.0",
4
+ "description": "Expressots CLI - modern, fast, lightweight nodejs web framework (@cli)",
5
+ "author": "Richard Zampieri",
6
+ "license": "MIT",
7
+ "bugs": {
8
+ "url": "https://github.com/expressots/expressots-cli/issues"
9
+ },
10
+ "bin": {
11
+ "expressots": "bin/cli.js"
12
+ },
13
+ "engines": {
14
+ "node": ">=18.10.0"
15
+ },
16
+ "funding": {
17
+ "type": "github",
18
+ "url": "https://github.com/sponsors/expressots"
19
+ },
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "https://github.com/expressots/expressots-cli"
23
+ },
24
+ "homepage": "https://expresso-ts.com",
25
+ "publishConfig": {
26
+ "access": "public"
27
+ },
28
+ "keywords": [
29
+ "ExpressoTS",
30
+ "CLI",
31
+ "Scaffolding"
32
+ ],
33
+ "scripts": {
34
+ "prepare": "husky install",
35
+ "start:build": "npm run build && npm run start",
36
+ "start": "node ./bin/cli.js",
37
+ "start:dev": "tsnd ./src/cli.ts",
38
+ "build": "npm run clean && tsc -p tsconfig.json && yarn cp:templates && chmod +x ./bin/cli.js",
39
+ "cp:templates": "cp -r ./src/generate/templates ./bin/generate/templates",
40
+ "clean": "rimraf ./bin",
41
+ "format": "prettier --write \"./src/**/*.ts\" --cache",
42
+ "lint": "eslint \"./src/**/*.ts\"",
43
+ "lint:fix": "eslint \"./src/**/*.ts\" --fix",
44
+ "release": "release-it",
45
+ "test": "vitest run",
46
+ "test:watch": "vitest",
47
+ "test:coverage": "vitest run --coverage"
48
+ },
49
+ "dependencies": {
50
+ "@expressots/boost-ts": "1.1.1",
51
+ "chalk-animation": "2.0.3",
52
+ "cli-progress": "3.11.2",
53
+ "degit": "2.8.4",
54
+ "glob": "10.2.6",
55
+ "inquirer": "8.0.0",
56
+ "mustache": "4.2.0",
57
+ "ts-node": "10.9.1",
58
+ "yargs": "17.6.2"
59
+ },
60
+ "devDependencies": {
61
+ "@commitlint/cli": "^17.7.1",
62
+ "@commitlint/config-conventional": "^17.7.0",
63
+ "@release-it/conventional-changelog": "^7.0.1",
64
+ "@types/chalk-animation": "^1.6.1",
65
+ "@types/cli-progress": "^3.11.0",
66
+ "@types/degit": "^2.8.3",
67
+ "@types/inquirer": "^9.0.3",
68
+ "@types/mustache": "^4.2.2",
69
+ "@types/node": "^18.11.19",
70
+ "@types/yargs": "^17.0.22",
71
+ "@typescript-eslint/eslint-plugin": "^5.53.0",
72
+ "@typescript-eslint/parser": "^5.53.0",
73
+ "chalk": "^4.1.2",
74
+ "eslint": "^8.34.0",
75
+ "eslint-config-prettier": "^8.6.0",
76
+ "eslint-plugin-prettier": "^4.2.1",
77
+ "husky": "^8.0.3",
78
+ "prettier": "^2.8.4",
79
+ "release-it": "^16.1.5",
80
+ "rimraf": "^4.1.2",
81
+ "ts-node-dev": "^2.0.0",
82
+ "typescript": "^4.9.5",
83
+ "vite": "^4.4.9",
84
+ "vitest": "^0.34.4"
85
+ },
86
+ "release-it": {
87
+ "git": {
88
+ "commitMessage": "chore: release v${version}"
89
+ },
90
+ "github": {
91
+ "release": true
92
+ },
93
+ "npm": {
94
+ "publish": false
95
+ },
96
+ "plugins": {
97
+ "@release-it/conventional-changelog": {
98
+ "infile": "CHANGELOG.md",
99
+ "preset": {
100
+ "name": "conventionalcommits",
101
+ "types": [
102
+ {
103
+ "type": "feat",
104
+ "section": "Features"
105
+ },
106
+ {
107
+ "type": "fix",
108
+ "section": "Bug Fixes"
109
+ },
110
+ {
111
+ "type": "perf",
112
+ "section": "Performance Improvements"
113
+ },
114
+ {
115
+ "type": "revert",
116
+ "section": "Reverts"
117
+ },
118
+ {
119
+ "type": "docs",
120
+ "section": "Documentation"
121
+ },
122
+ {
123
+ "type": "style",
124
+ "section": "Styles"
125
+ },
126
+ {
127
+ "type": "refactor",
128
+ "section": "Code Refactoring"
129
+ },
130
+ {
131
+ "type": "test",
132
+ "section": "Tests"
133
+ },
134
+ {
135
+ "type": "build",
136
+ "section": "Build System"
137
+ },
138
+ {
139
+ "type": "ci",
140
+ "section": "Continuous Integrations"
141
+ },
142
+ {
143
+ "type": "chore",
144
+ "hidden": true
145
+ }
146
+ ]
147
+ }
148
+ }
149
+ }
150
+ }
141
151
  }