From 260ca394f66da80426941ab5157b152dd7a21213 Mon Sep 17 00:00:00 2001 From: Faris Tangastani Date: Mon, 4 Mar 2019 11:06:49 +0100 Subject: [PATCH] feat: added nodemon create/readme and updated package updated package spacing --- .npmignore | 2 +- README.md | 6 +++--- package.json | 12 +++++------ src/create/createSetup.ts | 5 ++++- src/create/dependencies.ts | 41 +++++++++++++++++++------------------- src/create/nodemon.ts | 28 ++++++++++++++++++++++++++ src/types/spinner.type.ts | 16 +++++++-------- templates/nodemon.json | 13 ++++++++++++ tslint.json | 1 + 9 files changed, 85 insertions(+), 39 deletions(-) create mode 100644 src/create/nodemon.ts create mode 100644 templates/nodemon.json diff --git a/.npmignore b/.npmignore index 2158953..c195501 100644 --- a/.npmignore +++ b/.npmignore @@ -1,7 +1,7 @@ # Relevant files !lib/** -## Unrelevant files +## Irrelevant files src/** .gitignore CODE_OF_CONDUCT.md diff --git a/README.md b/README.md index 8a094c5..de04bb6 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ Liftr is a quick project-starter/pseudo-framework CLI, built on [express](https: Install Liftr as a global CLI. ```shell - npm install -g liftr +npm install -g liftr cd @@ -64,9 +64,9 @@ git push origin my-fix Lastly, open a pull request on Github. -The following npm script are available +The following npm scripts are available -Before you run `npm start`, make sure you didn't installed the `liftr` package globally. If you did, run `npm uninstall -g liftr` and run `npm start`, otherwise you will get an npm error. +Before you run `npm start`, make sure you didn't install the `liftr` package globally. If you did, run `npm uninstall -g liftr` and run `npm start`, otherwise you will get an npm error. - `npm start` - create build, install globally and run liftr - `npm run build` - create build diff --git a/package.json b/package.json index 25f75fb..f6581b3 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "liftr", - "version": "1.2.1", - "description": "A scaffolding CLI for Node.js/Typescript API's and Projects", + "version": "1.3.0", + "description": "Liftr is a scaffolding CLI for Node.js/Typescript APIs and Projects", "author": "Faris Tangastani", "license": "ISC", "main": "./lib/index.js", @@ -34,17 +34,17 @@ "fs-extra": "^7.0.1", "minimist": "^1.2.0", "npm": "^6.7.0", - "ora": "^3.1.0", + "ora": "^3.2.0", "path": "^0.12.7" }, "devDependencies": { "@types/minimist": "^1.2.0", - "@types/node": "^10.12.10", + "@types/node": "^10.12.29", "nodemon": "^1.18.7", "ts-loader": "^5.3.3", "ts-node": "^7.0.1", "tscov": "^1.3.3", - "tslint": "^5.11.0", - "typescript": "^3.3.1" + "tslint": "^5.13.1", + "typescript": "^3.3.3333" } } diff --git a/src/create/createSetup.ts b/src/create/createSetup.ts index c2d4107..c13e7d2 100644 --- a/src/create/createSetup.ts +++ b/src/create/createSetup.ts @@ -7,9 +7,10 @@ import { dependencies } from './dependencies'; import { createConfig } from './createConfig'; import { createExampleApi } from './createExampleApi'; import { Spinner } from '../types/spinner.type'; +import { createNodemonConfig } from './nodemon'; export const createSetup = async (setupName: string) => { - const spinner: Spinner = ora('Setting up Scaffold project').start(); + const spinner: Spinner = ora('Setting up Liftr project').start(); spinner.spinner = 'moon'; let timeout: any; @@ -37,10 +38,12 @@ export const createSetup = async (setupName: string) => { const setupServer: string = process.cwd() + `/${setupName}/src/server.ts`; const setupApp: string = process.cwd() + `/${setupName}/src/app.ts`; const setupConfig: string = process.cwd() + `/${setupName}/tsconfig.json`; + const setupNodemon: string = process.cwd() + `/${setupName}/nodemon.json`; const liftrProject: any = util.promisify(createExampleApi); liftrProject(setupName, spinner) .then(createConfig(setupConfig)) + .then(createNodemonConfig(setupNodemon)) .then(createServer(setupServer)) .then(createApp(setupApp)) .then(dependencies(setupName, spinner)); diff --git a/src/create/dependencies.ts b/src/create/dependencies.ts index 3117b64..abf3dbe 100644 --- a/src/create/dependencies.ts +++ b/src/create/dependencies.ts @@ -1,10 +1,10 @@ -import fs from 'fs-extra' -import { Spinner } from '../types/spinner.type' -import chalk from 'chalk' -const { exec } = require('child_process') +import fs from 'fs-extra'; +import { Spinner } from '../types/spinner.type'; +import chalk from 'chalk'; +const { exec } = require('child_process'); export const dependencies = async (setupName: string, spinner: Spinner) => { - const setupPackageJson = process.cwd() + `/${setupName}/package.json` + const setupPackageJson = process.cwd() + `/${setupName}/package.json`; const packageJson: () => void = () => { const fileContent = ` @@ -15,6 +15,7 @@ export const dependencies = async (setupName: string, spinner: Spinner) => { "main": "server.js", "scripts": { "start": "ts-node -r tsconfig-paths/register src/server.ts", + "dev": "nodemon", "build": "tsc -p ." }, "author": "", @@ -31,30 +32,30 @@ export const dependencies = async (setupName: string, spinner: Spinner) => { "nodemon": "^1.18.7" } } -` - fs.writeFile(setupPackageJson, fileContent, err => { - if (err) throw err - }) - } +`; + fs.writeFile(setupPackageJson, fileContent, (err) => { + if (err) throw err; + }); + }; try { - await packageJson() + await packageJson(); await exec( `cd ${setupName} && npm install `, (error: Error, stdout: string, stderr: string) => { if (error) { - console.log(error) - return + console.log(error); + return; } - spinner.succeed(chalk.green(`Liftr is ready! cd into ${setupName} and run npm start.`)) + spinner.succeed(chalk.green(`Liftr is ready! cd into ${setupName} and run npm start.`)); spinner.info( chalk.blue( - `Make sure you have installed ts-node and typscript installed on your machine.`, + 'Make sure you have ts-node and typscript installed on your machine.', ), - ) - spinner.warn(chalk.yellow(`If not run: "npm i -g ts-node typescript".`)) + ); + spinner.warn(chalk.yellow('If not run: "npm i -g ts-node typescript".')); }, - ) + ); } catch (error) { - console.error(error) + console.error(error); } -} +}; diff --git a/src/create/nodemon.ts b/src/create/nodemon.ts new file mode 100644 index 0000000..afb9e13 --- /dev/null +++ b/src/create/nodemon.ts @@ -0,0 +1,28 @@ +import fs from 'fs-extra'; + +export const createNodemonConfig = (setupFilePath: string) => { + const fileContent = ` +{ + "ignore": [ + "**/*.test.ts", + "**/*.spec.ts", + ".git", + "node_modules" + ], + "watch": [ + "src" + ], + "exec": "ts-node -r tsconfig-paths/register src/server.ts", + "ext": "ts" +} +`; + let filePath: string; + if (setupFilePath) { + filePath = setupFilePath; + } else { + filePath = process.cwd() + '/nodemon.json'; + } + fs.writeFile(filePath, fileContent, (err) => { + if (err) throw err; + }); +}; diff --git a/src/types/spinner.type.ts b/src/types/spinner.type.ts index 13a54d0..87cec60 100644 --- a/src/types/spinner.type.ts +++ b/src/types/spinner.type.ts @@ -1,9 +1,9 @@ -export type Spinner = { - spinner: string - color: string - text: string - stop: Function - succeed: Function - info: Function - warn: Function +export interface Spinner { + spinner: string; + color: string; + text: string; + stop: Function; + succeed: Function; + info: Function; + warn: Function; } diff --git a/templates/nodemon.json b/templates/nodemon.json new file mode 100644 index 0000000..38eb412 --- /dev/null +++ b/templates/nodemon.json @@ -0,0 +1,13 @@ +{ + "ignore": [ + "**/*.test.ts", + "**/*.spec.ts", + ".git", + "node_modules" + ], + "watch": [ + "src" + ], + "exec": "ts-node -r tsconfig-paths/register src/server.ts", + "ext": "ts" + } diff --git a/tslint.json b/tslint.json index cb11ace..941927b 100644 --- a/tslint.json +++ b/tslint.json @@ -1,5 +1,6 @@ { "defaultSeverity": "error", + "indent": [true, "tabs", 2], "extends": [ "tslint:recommended" ],