@avleon/cli 0.0.39 → 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 +42 -18
  2. package/package.json +1 -1
package/dist/create.js CHANGED
@@ -45,6 +45,7 @@ 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(path_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();
@@ -153,9 +175,10 @@ export default app;
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();
@@ -189,7 +212,7 @@ start();
189
212
  "license": "ISC",
190
213
  "dependencies": {
191
214
  "@avleon/core": "^0.0.36",
192
- "@avleon/cli": "^0.0.39",
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"
@@ -236,6 +259,12 @@ start();
236
259
  "exclude": ["node_modules", "dist"]
237
260
  }`, { parser: "json" });
238
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": [
@@ -252,11 +281,6 @@ start();
252
281
  }`, { parser: "json" });
253
282
  await fs_extra_1.default.writeFile(path_1.default.join(appPaths.root, "test/e2e-spec.json"), e2eJson);
254
283
  await fs_extra_1.default.writeFile(path_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`);
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.39",
3
+ "version": "0.0.40",
4
4
  "bin": {
5
5
  "avleon": "./dist/cli.js"
6
6
  },