Skip to content

Commit 426f3ee

Browse files
transpile to es5 for node >= 4 support
1 parent 206da41 commit 426f3ee

File tree

7 files changed

+1411
-100
lines changed

7 files changed

+1411
-100
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ language: node_js
22
node_js:
33
- 9
44
- 8
5+
- 6
6+
- 4
57
cache:
68
yarn: true
79
directories:

index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
#!/usr/bin/env node
21
'use strict'
32

3+
require('util.promisify/shim')()
4+
45
const meow = require('meow')
56

67
const getLibraryDefaults = require('./lib/get-library-defaults')

lib/create-library.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

3-
const consolidate = require('consolidate')
3+
const handlebars = require('handlebars')
44
const execa = require('execa')
55
const fs = require('fs')
66
const globby = require('globby')
@@ -70,7 +70,8 @@ module.exports.copyTemplateFile = async (opts) => {
7070
const destFilePath = path.join(dest, fileRelativePath)
7171
const destFileDir = path.parse(destFilePath).dir
7272

73-
const content = await consolidate.handlebars(file, {
73+
const template = handlebars.compile(fs.readFileSync(file, 'utf8'))
74+
const content = template({
7475
...info,
7576
yarn: (info.manager === 'yarn')
7677
})

lib/prompt-library-info.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict'
22

33
const inquirer = require('inquirer')
4-
const isValidNpmName = require('is-valid-npm-name')
4+
const validateNpmName = require('validate-npm-package-name')
55

66
const config = require('./config')
77

@@ -12,7 +12,7 @@ module.exports = async (defaults) => {
1212
name: 'name',
1313
message: 'Package Name',
1414
validate: (name) => {
15-
return name && name.length && isValidNpmName(name)
15+
return name && validateNpmName(name).validForNewPackages
1616
}
1717
},
1818
{

package.json

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,21 @@
44
"description": "CLI for easily bootstrapping modern react libraries",
55
"repository": "transitive-bullshit/create-react-library",
66
"author": "Travis Fischer <travis@automagical.ai>",
7-
"main": "index.js",
7+
"main": "dist/index.js",
8+
"module": "index.js",
9+
"jsnext:main": "index.js",
810
"license": "MIT",
911
"bin": {
10-
"create-react-library": "index.js"
12+
"create-react-library": "dist/index.js"
1113
},
1214
"scripts": {
13-
"test": "ava -v && standard *.js lib/*.js"
15+
"test": "ava -v && standard *.js lib/*.js",
16+
"dev": "webpack -w",
17+
"prepare": "yarn run build",
18+
"build": "webpack"
1419
},
1520
"engines": {
16-
"node": ">=8"
21+
"node": ">=4"
1722
},
1823
"keywords": [
1924
"react",
@@ -29,25 +34,36 @@
2934
],
3035
"dependencies": {
3136
"conf": "^1.4.0",
32-
"consolidate": "^0.15.0",
3337
"cp-file": "^5.0.0",
3438
"execa": "^0.9.0",
3539
"git-config-path": "^1.0.1",
3640
"github-username": "^4.1.0",
3741
"globby": "^8.0.1",
3842
"handlebars": "^4.0.11",
39-
"inquirer": "^5.1.0",
40-
"is-valid-npm-name": "^0.0.4",
43+
"inquirer": "^3",
4144
"make-dir": "^1.2.0",
4245
"meow": "^4.0.0",
4346
"ora": "^2.0.0",
4447
"p-each-series": "^1.0.0",
4548
"parse-git-config": "^2.0.0",
49+
"util.promisify": "^1.0.0",
50+
"validate-npm-package-name": "^3.0.0",
4651
"which": "^1.3.0"
4752
},
4853
"devDependencies": {
4954
"ava": "^0.25.0",
55+
"babel-core": "6.26.0",
56+
"babel-eslint": "8.0.1",
57+
"babel-loader": "7.1.2",
58+
"babel-plugin-transform-async-to-generator": "6.24.1",
59+
"babel-plugin-transform-flow-comments": "6.22.0",
60+
"babel-plugin-transform-runtime": "6.23.0",
61+
"babel-preset-env": "1.6.0",
62+
"babel-preset-stage-0": "^6.24.1",
5063
"rmfr": "^2.0.0",
51-
"standard": "^11.0.0"
64+
"shebang-loader": "0.0.1",
65+
"standard": "^11.0.0",
66+
"webpack": "3.6.0",
67+
"webpack-node-externals": "1.6.0"
5268
}
5369
}

webpack.config.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/**
2+
* Transpiles create-react-library CLI to ES5 in order to support node >= 4.
3+
*
4+
* Note: we use Webpack to compile the CLI, but the generated template still
5+
* uses Rollup for compiling the library. We don't judge between the two, but
6+
* rather try to use the best tool for the job.
7+
*/
8+
9+
'use strict'
10+
11+
const nodeExternals = require('webpack-node-externals')
12+
const path = require('path')
13+
14+
module.exports = {
15+
target: 'node',
16+
node: {
17+
__dirname: false,
18+
__filename: false,
19+
process: false
20+
},
21+
entry: [
22+
'./index.js'
23+
],
24+
output: {
25+
path: path.join(__dirname, 'dist'),
26+
filename: 'index.js'
27+
},
28+
externals: [
29+
nodeExternals()
30+
],
31+
module: {
32+
loaders: [
33+
{
34+
loader: 'babel-loader',
35+
test: /.js$/,
36+
exclude: /node_modules/,
37+
query: {
38+
babelrc: false,
39+
plugins: [
40+
'transform-async-to-generator',
41+
'transform-runtime'
42+
],
43+
presets: [
44+
'env',
45+
'stage-0'
46+
]
47+
}
48+
}
49+
]
50+
}
51+
}

0 commit comments

Comments
 (0)