@avleon/cli 0.0.38 → 0.0.40

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.
Files changed (2) hide show
  1. package/dist/create.js +50 -26
  2. package/package.json +1 -1
package/dist/create.js CHANGED
@@ -40,11 +40,12 @@ exports.createApplication = createApplication;
40
40
  const fs_extra_1 = __importDefault(require("fs-extra"));
41
41
  const paths_1 = require("./paths");
42
42
  const prettier = __importStar(require("prettier"));
43
- const win32_1 = __importDefault(require("path/win32"));
43
+ const path_1 = __importDefault(require("path"));
44
44
  const os_1 = __importDefault(require("os"));
45
45
  const inquirer_1 = __importDefault(require("inquirer"));
46
46
  const child_process_1 = require("child_process");
47
47
  const util_1 = __importDefault(require("util"));
48
+ const lodash_1 = require("lodash");
48
49
  const execAsync = util_1.default.promisify(child_process_1.exec);
49
50
  const getShell = () => {
50
51
  if (os_1.default.platform() === 'win32') {
@@ -98,6 +99,7 @@ async function createApplication(fname, flags = {}) {
98
99
  // }
99
100
  await fs_extra_1.default.ensureDir(appPaths.root + "/src");
100
101
  await fs_extra_1.default.ensureDir(appPaths.root + "/src/controllers");
102
+ await fs_extra_1.default.ensureDir(appPaths.root + "/src/config");
101
103
  await fs_extra_1.default.ensureDir(appPaths.root + "/src/services");
102
104
  await fs_extra_1.default.ensureDir(appPaths.root + "/src/models");
103
105
  await fs_extra_1.default.ensureDir(appPaths.root + "/test");
@@ -122,22 +124,42 @@ export class HomeController{
122
124
  singleAttributePerLine: true,
123
125
  parser: "typescript",
124
126
  });
125
- await fs_extra_1.default.writeFile(win32_1.default.join(appPaths.src, "home.controller.ts"), formatHomeController);
127
+ await fs_extra_1.default.writeFile(path_1.default.join(appPaths.controllers, "home.controller.ts"), formatHomeController);
128
+ // openapi config file
129
+ const openapiConfigFile = `
130
+ import { AppConfig, Environment, IConfig } from "@avleon/core";
131
+
132
+ @AppConfig
133
+ export class OpenApiConfig implements IConfig {
134
+
135
+ config(env: Environment) {
136
+ return {
137
+ info: {
138
+ title: '${(0, lodash_1.capitalize)(fname)}',
139
+ version: '0.0.1',
140
+ },
141
+ }
142
+ }
143
+ }
144
+ `;
145
+ const formatConfigFile = await prettier.format(openapiConfigFile, {
146
+ singleQuote: true,
147
+ singleAttributePerLine: true,
148
+ parser: "typescript",
149
+ });
150
+ await fs_extra_1.default.writeFile(path_1.default.join(appPaths.configs, "openapi.config.ts"), formatConfigFile);
126
151
  // main file
127
152
  const mainFunc = `
128
- import {
129
- Avleon
130
- } from "@avleon/core";
131
- import { HomeController } from './home.controller';
153
+ import { Avleon } from '@avleon/core';
154
+ import { OpenApiConfig } from './config/openapi.config';
155
+ import { HomeController } from './controllers/home.controller';
132
156
 
133
157
 
134
158
  const app = Avleon.createApplication();
135
- app.useOpenApi({
136
- info:{
137
- title: '${fname} Api',
138
- version: '0.0.1'
139
- }
140
- });
159
+
160
+ if(app.isDevelopemtn()){
161
+ app.useOpenApi(OpenApiConfig);
162
+ }
141
163
 
142
164
  app.useControllers([ HomeController ]);
143
165
  app.useStaticFiles();
@@ -149,13 +171,14 @@ export default app;
149
171
  singleAttributePerLine: true,
150
172
  parser: "typescript",
151
173
  });
152
- await fs_extra_1.default.writeFile(win32_1.default.join(appPaths.src, "app.ts"), formatMainFunc);
174
+ await fs_extra_1.default.writeFile(path_1.default.join(appPaths.src, "app.ts"), formatMainFunc);
153
175
  // create serve.ts
154
176
  const serveFunc = `
155
177
  import app from "./app";
178
+ import { capitalize } from "lodash";
156
179
 
157
180
  async function start(){
158
- app.run();
181
+ app.run(); // default run on :4000
159
182
  }
160
183
 
161
184
  start();
@@ -165,7 +188,7 @@ start();
165
188
  singleAttributePerLine: true,
166
189
  parser: "typescript",
167
190
  });
168
- await fs_extra_1.default.writeFile(win32_1.default.join(appPaths.src, "serve.ts"), formatServeFunc);
191
+ await fs_extra_1.default.writeFile(path_1.default.join(appPaths.src, "serve.ts"), formatServeFunc);
169
192
  // create package.json
170
193
  const packageJson = `
171
194
  {
@@ -188,8 +211,8 @@ start();
188
211
  "keywords": ["avleon","nodejs","typescript"],
189
212
  "license": "ISC",
190
213
  "dependencies": {
191
- "@avleon/core": "^0.0.29",
192
- "@avleon/cli": "^0.0.37",
214
+ "@avleon/core": "^0.0.36",
215
+ "@avleon/cli": "^0.0.40",
193
216
  "class-transformer": "^0.5.1",
194
217
  "class-validator": "^0.14.1",
195
218
  "reflect-metadata": "^0.2.2"
@@ -218,7 +241,7 @@ start();
218
241
  const formattedPackageJson = await prettier.format(packageJson, {
219
242
  parser: "json",
220
243
  });
221
- await fs_extra_1.default.writeFile(win32_1.default.join(appPaths.root, "package.json"), formattedPackageJson);
244
+ await fs_extra_1.default.writeFile(path_1.default.join(appPaths.root, "package.json"), formattedPackageJson);
222
245
  const tsconfigJson = await prettier.format(`{
223
246
  "compilerOptions": {
224
247
  "target": "ES2017",
@@ -235,7 +258,13 @@ start();
235
258
  "include": ["src/**/*"],
236
259
  "exclude": ["node_modules", "dist"]
237
260
  }`, { parser: "json" });
238
- await fs_extra_1.default.writeFile(win32_1.default.join(appPaths.root, "tsconfig.json"), tsconfigJson);
261
+ await fs_extra_1.default.writeFile(path_1.default.join(appPaths.root, "tsconfig.json"), tsconfigJson);
262
+ const tsconfigBuildJson = await prettier.format(`{
263
+ "extends": "./tsconfig.json",
264
+ "exclude": ["node_modules","coverage", "test", "dist", "**/*spec.ts"]
265
+ }
266
+ `, { parser: "json" });
267
+ await fs_extra_1.default.writeFile(path_1.default.join(appPaths.root, "tsconfig.build.json"), tsconfigBuildJson);
239
268
  // write e2e-test.json
240
269
  const e2eJson = await prettier.format(`{
241
270
  "moduleFileExtensions": [
@@ -250,13 +279,8 @@ start();
250
279
  "^.+/\/\.(t|j)s$": "ts-jest"
251
280
  }
252
281
  }`, { parser: "json" });
253
- await fs_extra_1.default.writeFile(win32_1.default.join(appPaths.root, "test/e2e-spec.json"), e2eJson);
254
- await fs_extra_1.default.writeFile(win32_1.default.join(appPaths.root, ".gitignore"), `node_modules/\ndist/\n.env`);
255
- // create basic service
256
- // create basic controller
257
- // console.info("App created successfully. Run the following command to get start.");
258
- // console.log(`cd ${fname} && ${pm} install`);
259
- // console.log(pm == 'npm' ? `npm run start:dev` : `${pm} start:dev`);
282
+ await fs_extra_1.default.writeFile(path_1.default.join(appPaths.root, "test/e2e-spec.json"), e2eJson);
283
+ await fs_extra_1.default.writeFile(path_1.default.join(appPaths.root, ".gitignore"), `node_modules/\ndist/\n.env`);
260
284
  try {
261
285
  console.log(`Running ${pm} install...`);
262
286
  await execAsync(`cd ${fname}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@avleon/cli",
3
- "version": "0.0.38",
3
+ "version": "0.0.40",
4
4
  "bin": {
5
5
  "avleon": "./dist/cli.js"
6
6
  },