1
0
Fork 0

use node-compat-require instead of webpack for node >= 4 support; update dependencies

This commit is contained in:
Travis Fischer 2018-05-06 19:01:46 -04:00 committed by Joost De Cock
parent fa8df25694
commit dd83df8f4e
10 changed files with 1327 additions and 10673 deletions

View file

@ -1,8 +1,7 @@
language: node_js
cache: yarn
node_js:
- 9
- 8
cache:
yarn: true
directories:
- node_modules
- 6
- 4

View file

@ -1,52 +1,5 @@
#!/usr/bin/env node
'use strict'
require('util.promisify/shim')()
const meow = require('meow')
const getLibraryDefaults = require('./lib/get-library-defaults')
const createLibrary = require('./lib/create-library')
const promptLibraryInfo = require('./lib/prompt-library-info')
module.exports = async () => {
const defaults = await getLibraryDefaults()
const info = await promptLibraryInfo(defaults)
await createLibrary(info)
return info
}
if (!module.parent) {
meow(`
Usage
$ create-react-library
`)
module.exports()
.then((info) => {
console.log(`
Your module has been created at ${info.dest}.
To get started, in one tab, run:
$ cd ${info.name} && ${info.manager} start
And in another tab, run the create-react-app devserver:
$ cd ${info.name}/example && ${info.manager} start
`)
if (info.manager === 'npm') {
console.log(`
Because you're using npm, you'll need to publish a dummy version of ${info.name} first before you can "npm link" your package into the example app.
`)
}
process.exit(0)
})
.catch((err) => {
console.error(err)
process.exit(1)
})
}
const compatRequire = require('node-compat-require')
compatRequire('./lib', { node: '>= 8' })

View file

@ -88,8 +88,6 @@ module.exports.initPackageManager = async (opts) => {
info
} = opts
const example = path.join(dest, 'example')
const commands = [
{
cmd: `${info.manager} install`,
@ -99,13 +97,7 @@ module.exports.initPackageManager = async (opts) => {
cmd: `${info.manager} link`,
cwd: dest
}
].concat(info.manager === 'yarn' ? [
{
cmd: `${info.manager}`,
cwd: example
}
] : [ ]
)
]
return pEachSeries(commands, async ({ cmd, cwd }) => {
return execa.shell(cmd, { cwd })

View file

@ -2,6 +2,7 @@
const { test } = require('ava')
const execa = require('execa')
const path = require('path')
const rmfr = require('rmfr')
const createLibrary = require('./create-library')
@ -36,18 +37,26 @@ const tests = [
tests.forEach((info) => {
test.serial(`creating "${info.name}" using ${info.manager}`, async (t) => {
console.log(`creating "${info.name}" using ${info.manager}...`)
let ret
// ensure library is created successfully
const root = await createLibrary(info)
t.truthy(root.indexOf(info.shortName) >= 0)
// ensure yarn runs successfully
let ret = await execa.shell('yarn', { cwd: root })
// ensure yarn runs successfully in src/
ret = await execa.shell('yarn', { cwd: root })
t.is(ret.code, 0)
// ensure jest tests pass
ret = await execa.shell('yarn test', { cwd: root })
t.is(ret.code, 0)
if (info.manager === 'yarn') {
// ensure yarn runs successfully in example/
ret = await execa.shell('yarn install', { cwd: path.join(root, 'example') })
t.is(ret.code, 0)
}
// ensure git is initialized properly
ret = await execa.shell('git status', { cwd: root })
t.is(ret.code, 0)

View file

@ -0,0 +1,48 @@
#!/usr/bin/env node
'use strict'
const meow = require('meow')
const getLibraryDefaults = require('./get-library-defaults')
const createLibrary = require('./create-library')
const promptLibraryInfo = require('./prompt-library-info')
module.exports = async () => {
const defaults = await getLibraryDefaults()
const info = await promptLibraryInfo(defaults)
await createLibrary(info)
return info
}
meow(`
Usage
$ create-react-library
`)
module.exports()
.then((info) => {
console.log(`
Your module has been created at ${info.dest}.
To get started, in one tab, run:
$ cd ${info.name} && ${info.manager} start
And in another tab, run the create-react-app devserver:
$ cd ${info.name}/example && ${info.manager} start
`)
if (info.manager === 'npm') {
console.log(`
Because you're using npm, you'll need to publish a dummy version of ${info.name} first before you can "npm link" your package into the example app.
`)
}
process.exit(0)
})
.catch((err) => {
console.error(err)
process.exit(1)
})

File diff suppressed because it is too large Load diff

View file

@ -4,20 +4,16 @@
"description": "CLI for easily bootstrapping modern react libraries",
"repository": "transitive-bullshit/create-react-library",
"author": "Travis Fischer <travis@automagical.ai>",
"main": "dist/index.js",
"module": "index.js",
"jsnext:main": "index.js",
"main": "index.js",
"license": "MIT",
"bin": {
"create-react-library": "index.js"
},
"scripts": {
"test": "ava -v && standard *.js lib/*.js",
"dev": "webpack -w",
"build": "webpack"
"test": "ava -v && standard *.js lib/*.js"
},
"engines": {
"node": ">=8"
"node": ">=4"
},
"keywords": [
"react",
@ -34,36 +30,24 @@
"dependencies": {
"conf": "^1.4.0",
"cp-file": "^5.0.0",
"execa": "^0.9.0",
"execa": "^0.10.0",
"git-config-path": "^1.0.1",
"github-username": "^4.1.0",
"globby": "^8.0.1",
"handlebars": "^4.0.11",
"inquirer": "^3",
"inquirer": "^5.2.0",
"make-dir": "^1.2.0",
"meow": "^4.0.0",
"ora": "^2.0.0",
"meow": "^5.0.0",
"node-compat-require": "^1.0.3",
"ora": "^2.1.0",
"p-each-series": "^1.0.0",
"parse-git-config": "^2.0.0",
"util.promisify": "^1.0.0",
"parse-git-config": "^2.0.2",
"validate-npm-package-name": "^3.0.0",
"which": "^1.3.0"
},
"devDependencies": {
"ava": "^0.25.0",
"babel-core": "6.26.0",
"babel-eslint": "8.0.1",
"babel-loader": "7.1.2",
"babel-plugin-transform-async-to-generator": "6.24.1",
"babel-plugin-transform-flow-comments": "6.22.0",
"babel-plugin-transform-runtime": "6.23.0",
"babel-preset-env": "1.6.0",
"babel-preset-stage-0": "^6.24.1",
"babel-runtime": "^6.26.0",
"rmfr": "^2.0.0",
"shebang-loader": "0.0.1",
"standard": "^11.0.0",
"webpack": "3.6.0",
"webpack-node-externals": "1.6.0"
"standard": "^11.0.1"
}
}

View file

@ -4,6 +4,7 @@
[![NPM](https://img.shields.io/npm/v/create-react-library.svg)](https://www.npmjs.com/package/create-react-library) [![Build Status](https://travis-ci.org/transitive-bullshit/create-react-library.svg?branch=master)](https://travis-ci.org/transitive-bullshit/create-react-library) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
## Intro
**The purpose of this CLI is to make publishing your own React components as simple as possible.**
@ -14,6 +15,7 @@
The CLI is based on this [boilerplate](https://github.com/transitive-bullshit/react-modern-library-boilerplate), which you can optionally read about [here](https://hackernoon.com/publishing-baller-react-modules-2b039d84bce7).
## Features
- Easy-to-use CLI
@ -28,12 +30,16 @@ The CLI is based on this [boilerplate](https://github.com/transitive-bullshit/re
- Sourcemap creation
- Thorough documentation :heart_eyes:
## Install
This package requires `node >= 4`, but we recommend `node >= 8`.
```bash
npm install -g create-react-library
```
## Creating a New Module
```bash
@ -52,6 +58,7 @@ At this point, your new module should resemble this screenshot and is all setup
<img width="600" src="https://cdn.rawgit.com/transitive-bullshit/create-react-library/master/media/tree.svg">
</p>
## Development
Local development is broken into two parts.
@ -77,6 +84,7 @@ Now, anytime you make a change to your component in `src/` or to the example app
Note: if you're using yarn, there is no need to use `yarn link`, as the generated module's example includes a local-link by default.
#### NPM Stuffs
The only difference when publishing your component to **npm** is to make sure you add any npm modules you want as peer dependencies are properly marked as `peerDependencies` in `package.json`. The rollup config will automatically recognize them as peer dependencies and not try to bundle them in your module.
@ -88,6 +96,7 @@ Then publish as per usual.
npm publish
```
#### Github Pages
Deploying the example to github pages is simple. We create a production build of our example `create-react-app` that showcases your library and then run `gh-pages` to deploy the resulting bundle. This can be done as follows:
@ -96,6 +105,7 @@ Deploying the example to github pages is simple. We create a production build of
npm run deploy
```
## Examples
### Multiple Named Exports
@ -106,6 +116,7 @@ Here is a [branch](https://github.com/transitive-bullshit/react-modern-library-b
Here is a [branch](https://github.com/transitive-bullshit/react-modern-library-boilerplate/tree/feature/material-ui) which demonstrates how to make use of a relatively complicated peer dependency, [material-ui](https://github.com/mui-org/material-ui). It shows the power of [rollup-plugin-peer-deps-external](https://www.npmjs.com/package/rollup-plugin-peer-deps-external) which makes it a breeze to create reusable modules that include complicated material-ui subcomponents without having them bundled as a part of your module.
## License
MIT © [Travis Fischer](https://github.com/transitive-bullshit)

View file

@ -1,65 +0,0 @@
/**
* Transpiles the CLI to ES5 in order to support node >= 4.
*
* Note: we use Webpack to compile the CLI, but the generated template still
* uses Rollup for compiling libraries. We don't judge between the two, but
* rather try to use the best tool for the job.
*/
'use strict'
const nodeExternals = require('webpack-node-externals')
const path = require('path')
const webpack = require('webpack')
module.exports = {
target: 'node',
node: {
__dirname: false,
__filename: false,
process: false
},
entry: [
'./index.js'
],
output: {
path: path.join(__dirname, 'dist'),
filename: 'index.js'
},
externals: [
nodeExternals()
],
plugins: [
new webpack.BannerPlugin({
banner: '#!/usr/bin/env node',
raw: true
})
],
module: {
loaders: [
{
test: /.js$/,
exclude: /node_modules/,
loaders: [
{
loader: 'shebang-loader'
},
{
loader: 'babel-loader',
query: {
babelrc: false,
plugins: [
'transform-async-to-generator',
'transform-runtime'
],
presets: [
'env',
'stage-0'
]
}
}
]
}
]
}
}

File diff suppressed because it is too large Load diff