Skip to content

Commit

Permalink
feat: added nodemon create/readme and updated package
Browse files Browse the repository at this point in the history
updated package


spacing
  • Loading branch information
farisT committed Mar 4, 2019
1 parent 7934c59 commit 260ca39
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Relevant files
!lib/**

## Unrelevant files
## Irrelevant files
src/**
.gitignore
CODE_OF_CONDUCT.md
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <your-repo-location>

Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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"
}
}
5 changes: 4 additions & 1 deletion src/create/createSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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));
Expand Down
41 changes: 21 additions & 20 deletions src/create/dependencies.ts
Original file line number Diff line number Diff line change
@@ -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 = `
Expand All @@ -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": "",
Expand All @@ -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);
}
}
};
28 changes: 28 additions & 0 deletions src/create/nodemon.ts
Original file line number Diff line number Diff line change
@@ -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;
});
};
16 changes: 8 additions & 8 deletions src/types/spinner.type.ts
Original file line number Diff line number Diff line change
@@ -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;
}
13 changes: 13 additions & 0 deletions templates/nodemon.json
Original file line number Diff line number Diff line change
@@ -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"
}
1 change: 1 addition & 0 deletions tslint.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"defaultSeverity": "error",
"indent": [true, "tabs", 2],
"extends": [
"tslint:recommended"
],
Expand Down

0 comments on commit 260ca39

Please sign in to comment.