Skip to content

Commit

Permalink
chore: update plop template to use typescript
Browse files Browse the repository at this point in the history
Now that we want to use typescript, update plopfile to use typescript
and not javascript. Along with, add tsconfig, tslint and related.
  • Loading branch information
swashata committed Oct 7, 2018
1 parent 83f42dc commit 4e41353
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 11 deletions.
5 changes: 3 additions & 2 deletions packages/babel-preset-base/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,5 +172,6 @@ This package has the same `npm scripts` as this monorepo. These should be run
using `lerna run <script>`. More information can be found under [CONTRIBUTION.md](../../CONTRIBUTION.md).

- `build`: Use babel to build for nodejs 8.6+. Files inside `src` are compiled and put under `lib`. All type definitions are stripped and individual type declaration files are created.
- `test`: Run tests using jest.
- `lint`: Run linter using tslint.
- `prepare`: Run `build` after `yarn` and before `publish`.
- `lint`: Lint all files using tslint.
- `test`: Run tests on files using jest.
5 changes: 3 additions & 2 deletions packages/scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ npm i @wpackio/scripts
This package has the same `npm scripts` as this monorepo. These should be run
using `lerna run <script>`. More information can be found under [CONTRIBUTION.md](../../CONTRIBUTION.md).

- `build`: Use babel to build for nodejs 8.6+. Files inside `src` are compiled and put under `lib`.
- `build`: Use babel to build for nodejs 8.6+. Files inside `src` are compiled and put under `lib`. All type definitions are stripped and individual type declaration files are created.
- `prepare`: Run `build` after `yarn` and before `publish`.
- `watch`: Watch for changes in `src` and build in `lib`.
- `lint`: Lint all files using tslint.
- `test`: Run tests on files using jest.
5 changes: 3 additions & 2 deletions plop-templates/package/README.md.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ npm i @wpackio/{{kebabCase name}}
This package has the same `npm scripts` as this monorepo. These should be run
using `lerna run <script>`. More information can be found under [CONTRIBUTION.md](../../CONTRIBUTION.md).
- `build`: Use babel to build for nodejs 8.6+. Files inside `src` are compiled and put under `lib`.
- `build`: Use babel to build for nodejs 8.6+. Files inside `src` are compiled and put under `lib`. All type definitions are stripped and individual type declaration files are created.
- `prepare`: Run `build` after `yarn` and before `publish`.
- `watch`: Watch for changes in `src` and build in `lib`.
- `lint`: Lint all files using tslint.
- `test`: Run tests on files using jest.
8 changes: 8 additions & 0 deletions plop-templates/package/jest.config.js.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const base = require('../../jest.base');
const pkg = require('./package.json');

module.exports = {
...base,
name: pkg.name,
displayName: pkg.name,
};
12 changes: 9 additions & 3 deletions plop-templates/package/package.json.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,15 @@
"lib"
],
"scripts": {
"build": "babel src --out-dir lib --ignore **/__tests__",
"prepare": "cross-env NODE_ENV=production yarn build",
"watch": "babel -w src --out-dir lib --ignore **/__tests__"
"clean": "rimraf './lib'",
"type-check": "tsc --noEmit",
"type-check:watch": "yarn type-check --watch",
"build:js": "babel ./src --out-dir lib --extensions '.ts,.tsx'",
"build:types": "tsc --emitDeclarationOnly",
"build": "yarn clean && yarn build:types && yarn build:js",
"lint": "tslint --project './tsconfig.json'",
"test": "jest --color",
"prepare": "cross-env NODE_ENV=production yarn build"
},
"publishConfig": {
"access": "public"
Expand Down
12 changes: 12 additions & 0 deletions plop-templates/package/tsconfig.json.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "./lib" /* Redirect output structure to the directory. */,
"rootDir": "./src" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
},
"exclude": [
"__mocks__/**",
"__tests__/**",
"lib/**"
]
}
3 changes: 3 additions & 0 deletions plop-templates/package/tslint.json.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": ["../../tslint.json"]
}
22 changes: 20 additions & 2 deletions plopfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports = plop => {
{
type: 'input',
name: 'name',
message: 'name of the package under the scope @wpw',
message: 'name of the package under the scope @wpackio',
},
{
type: 'input',
Expand All @@ -38,7 +38,7 @@ module.exports = plop => {
// Add src
{
type: 'add',
path: 'packages/{{kebabCase name}}/src/index.js',
path: 'packages/{{kebabCase name}}/src/index.ts',
},
// Add .npmignore
{
Expand All @@ -58,6 +58,24 @@ module.exports = plop => {
path: 'packages/{{kebabCase name}}/README.md',
templateFile: 'plop-templates/package/README.md.hbs',
},
// Add jest.config.js
{
type: 'add',
path: 'packages/{{kebabCase name}}/jest.config.js',
templateFile: 'plop-templates/package/jest.config.js.hbs',
},
// Add tsconfig.json
{
type: 'add',
path: 'packages/{{kebabCase name}}/tsconfig.json',
templateFile: 'plop-templates/package/tsconfig.json.hbs',
},
// Add tslint.json
{
type: 'add',
path: 'packages/{{kebabCase name}}/tslint.json',
templateFile: 'plop-templates/package/tslint.json.hbs',
},
],
});
};

0 comments on commit 4e41353

Please sign in to comment.