Skip to content

Commit 73da50f

Browse files
feat: update deps and default template to latest; switch to using microbundle instead of rollup directly
1 parent ac06cb9 commit 73da50f

26 files changed

+206
-2905
lines changed

.eslintrc

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
{
2-
"extends": [
3-
"standard"
4-
]
2+
"extends": ["standard"]
53
}

index.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const { test } = require('ava')
44
const execa = require('execa')
55

66
test('--help', async (t) => {
7-
const { stdout } = await execa('./index.js', [ '--help' ])
7+
const { stdout } = await execa('./index.js', ['--help'])
88
t.true(stdout.length > 0)
99
t.true(/create-react-library/.test(stdout))
1010
})

lib/cli.js

+24-10
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,27 @@ module.exports = async () => {
1818
.version(version)
1919
.usage('[options] [package-name]')
2020
.option('-d, --desc <string>', 'package description')
21-
.option('-a, --author <string>', 'author\'s github handle', defaults.author)
21+
.option('-a, --author <string>', "author's github handle", defaults.author)
2222
.option('-l, --license <string>', 'package license', defaults.license)
2323
.option('-r, --repo <string>', 'package repo path')
2424
.option('-g, --no-git', 'generate without git init')
25-
.option('-m, --manager <npm|yarn>', 'package manager to use', /^(npm|yarn)$/, defaults.manager)
26-
.option('-t, --template <default|typescript>', 'package template to use', /^(default|typescript|custom)$/, defaults.template)
25+
.option(
26+
'-m, --manager <npm|yarn>',
27+
'package manager to use',
28+
/^(npm|yarn)$/,
29+
defaults.manager
30+
)
31+
.option(
32+
'-t, --template <default|typescript>',
33+
'package template to use',
34+
/^(default|typescript|custom)$/,
35+
defaults.template
36+
)
2737
.option('-p, --template-path <string>', 'custom package template path')
28-
.option('-s, --skip-prompts', 'skip all prompts (must provide package-name via cli)')
38+
.option(
39+
'-s, --skip-prompts',
40+
'skip all prompts (must provide package-name via cli)'
41+
)
2942
.parse(process.argv)
3043

3144
const opts = {
@@ -65,14 +78,15 @@ To get started, in one tab, run:
6578
$ ${chalk.cyan(`cd ${params.shortName} && ${params.manager} start`)}
6679
6780
And in another tab, run the create-react-app dev server:
68-
$ ${chalk.cyan(`cd ${path.join(params.shortName, 'example')} && ${params.manager} start`)}
81+
$ ${chalk.cyan(
82+
`cd ${path.join(params.shortName, 'example')} && ${params.manager} start`
83+
)}
6984
`)
7085

7186
return dest
7287
}
7388

74-
module.exports()
75-
.catch((err) => {
76-
console.error(err)
77-
process.exit(1)
78-
})
89+
module.exports().catch((err) => {
90+
console.error(err)
91+
process.exit(1)
92+
})

lib/create-library.js

+17-29
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,10 @@ const pEachSeries = require('p-each-series')
1111

1212
const pkg = require('../package')
1313

14-
const templateBlacklist = new Set([
15-
'example/public/favicon.ico'
16-
])
14+
const templateBlacklist = new Set(['example/public/favicon.ico'])
1715

1816
module.exports = async (info) => {
19-
const {
20-
manager,
21-
template,
22-
name,
23-
templatePath,
24-
git
25-
} = info
17+
const { manager, template, name, templatePath, git } = info
2618

2719
// handle scoped package names
2820
const parts = name.split('/')
@@ -32,9 +24,10 @@ module.exports = async (info) => {
3224
info.dest = dest
3325
await mkdirp(dest)
3426

35-
const source = template === 'custom'
36-
? path.join(process.cwd(), templatePath)
37-
: path.join(__dirname, '..', 'template', template)
27+
const source =
28+
template === 'custom'
29+
? path.join(process.cwd(), templatePath)
30+
: path.join(__dirname, '..', 'template', template)
3831
const files = await globby(source, {
3932
dot: true
4033
})
@@ -54,6 +47,7 @@ module.exports = async (info) => {
5447

5548
{
5649
const promise = module.exports.initPackageManager({ dest, info })
50+
console.log('Initializing npm dependencies. This will take a minute.')
5751
ora.promise(promise, `Running ${manager} install and ${manager} link`)
5852
await promise
5953
}
@@ -68,12 +62,7 @@ module.exports = async (info) => {
6862
}
6963

7064
module.exports.copyTemplateFile = async (opts) => {
71-
const {
72-
file,
73-
source,
74-
dest,
75-
info
76-
} = opts
65+
const { file, source, dest, info } = opts
7766

7867
const fileRelativePath = path.relative(source, file)
7968
const destFilePath = path.join(dest, fileRelativePath)
@@ -88,7 +77,7 @@ module.exports.copyTemplateFile = async (opts) => {
8877
const template = handlebars.compile(fs.readFileSync(file, 'utf8'))
8978
const content = template({
9079
...info,
91-
yarn: (info.manager === 'yarn')
80+
yarn: info.manager === 'yarn'
9281
})
9382

9483
fs.writeFileSync(destFilePath, content, 'utf8')
@@ -98,10 +87,7 @@ module.exports.copyTemplateFile = async (opts) => {
9887
}
9988

10089
module.exports.initPackageManager = async (opts) => {
101-
const {
102-
dest,
103-
info
104-
} = opts
90+
const { dest, info } = opts
10591

10692
const example = path.join(dest, 'example')
10793

@@ -126,12 +112,12 @@ module.exports.initPackageManager = async (opts) => {
126112
}
127113

128114
module.exports.initGitRepo = async (opts) => {
129-
const {
130-
dest
131-
} = opts
115+
const { dest } = opts
132116

133117
const gitIgnorePath = path.join(dest, '.gitignore')
134-
fs.writeFileSync(gitIgnorePath, `
118+
fs.writeFileSync(
119+
gitIgnorePath,
120+
`
135121
# See https://help.github.com/ignore-files/ for more about ignoring files.
136122
137123
# dependencies
@@ -153,7 +139,9 @@ dist
153139
npm-debug.log*
154140
yarn-debug.log*
155141
yarn-error.log*
156-
`, 'utf8')
142+
`,
143+
'utf8'
144+
)
157145

158146
const cmd = `git init && git add . && git commit -m "init ${pkg.name}@${pkg.version}"`
159147
return execa.shell(cmd, { cwd: dest })

lib/get-default-library-params.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const config = require('./config')
1010
module.exports = async () => {
1111
const defaults = {
1212
name: '',
13-
description: '',
13+
description: 'React module created with Create React Library',
1414
author: config.get('author'),
1515
repo: (info) => `${info.author}/${info.name}`,
1616
license: config.get('license', 'MIT'),
@@ -48,7 +48,7 @@ module.exports = async () => {
4848
if (!config.get('template')) {
4949
config.set('template', defaults.template)
5050
}
51-
} catch (err) { }
51+
} catch (err) {}
5252

5353
return defaults
5454
}

lib/prompt-library-params.js

+15-12
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ module.exports = async (opts) => {
1414

1515
if (opts.skipPrompts) {
1616
if (!opts.name) {
17-
throw new Error('invalid input; you must pass a package name with --skip-prompts')
17+
throw new Error(
18+
'invalid input; you must pass a package name with --skip-prompts'
19+
)
1820
}
1921

2022
Object.keys(opts).forEach((key) => {
@@ -45,7 +47,7 @@ module.exports = async (opts) => {
4547
{
4648
type: 'input',
4749
name: 'author',
48-
message: 'Author\'s GitHub Handle',
50+
message: "Author's GitHub Handle",
4951
default: opts.author
5052
},
5153
{
@@ -64,14 +66,14 @@ module.exports = async (opts) => {
6466
type: 'list',
6567
name: 'manager',
6668
message: 'Package Manager',
67-
choices: [ 'npm', 'yarn' ],
69+
choices: ['npm', 'yarn'],
6870
default: opts.manager
6971
},
7072
{
7173
type: 'list',
7274
name: 'template',
7375
message: 'Template',
74-
choices: [ 'default', 'typescript', 'custom' ],
76+
choices: ['default', 'typescript', 'custom'],
7577
default: opts.template
7678
},
7779
{
@@ -80,15 +82,16 @@ module.exports = async (opts) => {
8082
message: 'Template Path',
8183
default: opts.templatePath,
8284
when: ({ template }) => template === 'custom',
83-
validate: input => new Promise(resolve => {
84-
const fullPath = path.resolve(process.cwd(), input)
85-
fs.stat(fullPath, (err, stats) => {
86-
if (err) {
87-
return resolve(`Cannot resolve directory at: ${fullPath}`)
88-
}
89-
resolve(true)
85+
validate: (input) =>
86+
new Promise((resolve) => {
87+
const fullPath = path.resolve(process.cwd(), input)
88+
fs.stat(fullPath, (err, stats) => {
89+
if (err) {
90+
return resolve(`Cannot resolve directory at: ${fullPath}`)
91+
}
92+
resolve(true)
93+
})
9094
})
91-
})
9295
}
9396
])
9497

lib/prompt-library-params.test.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ const opts = {
1616
git: true
1717
}
1818

19-
test('passed options are returned when skipPrompts is true', async t => {
20-
const result = await promptLibraryParams(Object.assign({}, opts, { skipPrompts: true }))
21-
Object.entries(opts).forEach(opt => {
22-
// console.log(`comparing passed in option ${opt[0]}:${opt[1]} to returned option ${result[opt[0]]}`)
19+
test('passed options are returned when skipPrompts is true', async (t) => {
20+
const result = await promptLibraryParams(
21+
Object.assign({}, opts, { skipPrompts: true })
22+
)
23+
Object.entries(opts).forEach((opt) => {
2324
t.is(opt[1], result[opt[0]])
2425
})
2526
})

readme.md

+3-10
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@
44
55
[![NPM](https://img.shields.io/npm/v/create-react-library.svg)](https://www.npmjs.com/package/create-react-library) [![Build Status](https://travis-ci.com/transitive-bullshit/create-react-library.svg?branch=master)](https://travis-ci.com/transitive-bullshit/create-react-library) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
66

7-
87
## Intro
98

109
<p align="center">
1110
<img width="600" src="https://cdn.rawgit.com/transitive-bullshit/create-react-library/master/media/demo.svg">
1211
</p>
1312

14-
1513
## Features
1614

1715
- Easy-to-use CLI
@@ -29,15 +27,13 @@
2927
- Thorough documentation :heart_eyes:
3028
- [Chinese docs](./readme.zh-CN.md) by [@monsterooo](https://github.com/monsterooo)
3129

32-
3330
## Notice
3431

35-
This is now an [OPEN Open Source](http://openopensource.org/) project. I am not able to invest a significant amount of time into maintaining CRL and so am looking for volunteers who would like to be active maintainers of the project. If you are interested, shoot me a note.
36-
32+
My open source efforts are now focused on [Saasify](https://github.com/saasify-sh/saasify), and I am not able to invest a significant amount of time into maintaining CRL anymore. I am looking for volunteers who would like to become active maintainers of the project. If you are interested, please shoot me a note.
3733

3834
## Install globally
3935

40-
This package requires `node >= 4`, but we recommend `node >= 8`.
36+
This package requires `node >= 10`.
4137

4238
```bash
4339
npm install -g create-react-library
@@ -58,6 +54,7 @@ create-react-library
5854
```
5955

6056
Answer some basic prompts about your module, and then the CLI will perform the following steps:
57+
6158
- copy over the template
6259
- install dependencies via yarn or npm
6360
- link packages together for local development
@@ -69,7 +66,6 @@ At this point, your new module should resemble this screenshot and is all setup
6966
<img width="600" src="https://cdn.rawgit.com/transitive-bullshit/create-react-library/master/media/tree.svg">
7067
</p>
7168

72-
7369
## Development
7470

7571
Local development is broken into two parts (ideally using two tabs).
@@ -92,7 +88,6 @@ Now, anytime you make a change to your library in `src/` or to the example app's
9288

9389
![](https://media.giphy.com/media/12NUbkX6p4xOO4/giphy.gif)
9490

95-
9691
#### Publishing to npm
9792

9893
```bash
@@ -103,7 +98,6 @@ This builds `cjs` and `es` versions of your module to `dist/` and then publishes
10398

10499
Make sure that any npm modules you want as peer dependencies are properly marked as `peerDependencies` in `package.json`. The rollup config will automatically recognize them as peers and not try to bundle them in your module.
105100

106-
107101
#### Deploying to Github Pages
108102

109103
```bash
@@ -153,7 +147,6 @@ Want to see a more completed list? Check out [Made with CRL](https://made-with-c
153147

154148
Want to add yours to the list? Submit an [PR](https://github.com/HurricaneInteractive/made-with-crl#adding-a-library) at the _Made with CRL_ repository.
155149

156-
157150
## License
158151

159152
MIT © [Travis Fischer](https://github.com/transitive-bullshit)

0 commit comments

Comments
 (0)