Skip to content
This repository has been archived by the owner on Apr 1, 2023. It is now read-only.

Commit

Permalink
feat: update deps and default template to latest; switch to using mic…
Browse files Browse the repository at this point in the history
…robundle instead of rollup directly
  • Loading branch information
transitive-bullshit committed Mar 30, 2020
1 parent ac06cb9 commit 73da50f
Show file tree
Hide file tree
Showing 26 changed files with 206 additions and 2,905 deletions.
4 changes: 1 addition & 3 deletions .eslintrc
@@ -1,5 +1,3 @@
{
"extends": [
"standard"
]
"extends": ["standard"]
}
2 changes: 1 addition & 1 deletion index.test.js
Expand Up @@ -4,7 +4,7 @@ const { test } = require('ava')
const execa = require('execa')

test('--help', async (t) => {
const { stdout } = await execa('./index.js', [ '--help' ])
const { stdout } = await execa('./index.js', ['--help'])
t.true(stdout.length > 0)
t.true(/create-react-library/.test(stdout))
})
34 changes: 24 additions & 10 deletions lib/cli.js
Expand Up @@ -18,14 +18,27 @@ module.exports = async () => {
.version(version)
.usage('[options] [package-name]')
.option('-d, --desc <string>', 'package description')
.option('-a, --author <string>', 'author\'s github handle', defaults.author)
.option('-a, --author <string>', "author's github handle", defaults.author)
.option('-l, --license <string>', 'package license', defaults.license)
.option('-r, --repo <string>', 'package repo path')
.option('-g, --no-git', 'generate without git init')
.option('-m, --manager <npm|yarn>', 'package manager to use', /^(npm|yarn)$/, defaults.manager)
.option('-t, --template <default|typescript>', 'package template to use', /^(default|typescript|custom)$/, defaults.template)
.option(
'-m, --manager <npm|yarn>',
'package manager to use',
/^(npm|yarn)$/,
defaults.manager
)
.option(
'-t, --template <default|typescript>',
'package template to use',
/^(default|typescript|custom)$/,
defaults.template
)
.option('-p, --template-path <string>', 'custom package template path')
.option('-s, --skip-prompts', 'skip all prompts (must provide package-name via cli)')
.option(
'-s, --skip-prompts',
'skip all prompts (must provide package-name via cli)'
)
.parse(process.argv)

const opts = {
Expand Down Expand Up @@ -65,14 +78,15 @@ To get started, in one tab, run:
$ ${chalk.cyan(`cd ${params.shortName} && ${params.manager} start`)}
And in another tab, run the create-react-app dev server:
$ ${chalk.cyan(`cd ${path.join(params.shortName, 'example')} && ${params.manager} start`)}
$ ${chalk.cyan(
`cd ${path.join(params.shortName, 'example')} && ${params.manager} start`
)}
`)

return dest
}

module.exports()
.catch((err) => {
console.error(err)
process.exit(1)
})
module.exports().catch((err) => {
console.error(err)
process.exit(1)
})
46 changes: 17 additions & 29 deletions lib/create-library.js
Expand Up @@ -11,18 +11,10 @@ const pEachSeries = require('p-each-series')

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

const templateBlacklist = new Set([
'example/public/favicon.ico'
])
const templateBlacklist = new Set(['example/public/favicon.ico'])

module.exports = async (info) => {
const {
manager,
template,
name,
templatePath,
git
} = info
const { manager, template, name, templatePath, git } = info

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

const source = template === 'custom'
? path.join(process.cwd(), templatePath)
: path.join(__dirname, '..', 'template', template)
const source =
template === 'custom'
? path.join(process.cwd(), templatePath)
: path.join(__dirname, '..', 'template', template)
const files = await globby(source, {
dot: true
})
Expand All @@ -54,6 +47,7 @@ module.exports = async (info) => {

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

module.exports.copyTemplateFile = async (opts) => {
const {
file,
source,
dest,
info
} = opts
const { file, source, dest, info } = opts

const fileRelativePath = path.relative(source, file)
const destFilePath = path.join(dest, fileRelativePath)
Expand All @@ -88,7 +77,7 @@ module.exports.copyTemplateFile = async (opts) => {
const template = handlebars.compile(fs.readFileSync(file, 'utf8'))
const content = template({
...info,
yarn: (info.manager === 'yarn')
yarn: info.manager === 'yarn'
})

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

module.exports.initPackageManager = async (opts) => {
const {
dest,
info
} = opts
const { dest, info } = opts

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

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

module.exports.initGitRepo = async (opts) => {
const {
dest
} = opts
const { dest } = opts

const gitIgnorePath = path.join(dest, '.gitignore')
fs.writeFileSync(gitIgnorePath, `
fs.writeFileSync(
gitIgnorePath,
`
# See https://help.github.com/ignore-files/ for more about ignoring files.
# dependencies
Expand All @@ -153,7 +139,9 @@ dist
npm-debug.log*
yarn-debug.log*
yarn-error.log*
`, 'utf8')
`,
'utf8'
)

const cmd = `git init && git add . && git commit -m "init ${pkg.name}@${pkg.version}"`
return execa.shell(cmd, { cwd: dest })
Expand Down
4 changes: 2 additions & 2 deletions lib/get-default-library-params.js
Expand Up @@ -10,7 +10,7 @@ const config = require('./config')
module.exports = async () => {
const defaults = {
name: '',
description: '',
description: 'React module created with Create React Library',
author: config.get('author'),
repo: (info) => `${info.author}/${info.name}`,
license: config.get('license', 'MIT'),
Expand Down Expand Up @@ -48,7 +48,7 @@ module.exports = async () => {
if (!config.get('template')) {
config.set('template', defaults.template)
}
} catch (err) { }
} catch (err) {}

return defaults
}
27 changes: 15 additions & 12 deletions lib/prompt-library-params.js
Expand Up @@ -14,7 +14,9 @@ module.exports = async (opts) => {

if (opts.skipPrompts) {
if (!opts.name) {
throw new Error('invalid input; you must pass a package name with --skip-prompts')
throw new Error(
'invalid input; you must pass a package name with --skip-prompts'
)
}

Object.keys(opts).forEach((key) => {
Expand Down Expand Up @@ -45,7 +47,7 @@ module.exports = async (opts) => {
{
type: 'input',
name: 'author',
message: 'Author\'s GitHub Handle',
message: "Author's GitHub Handle",
default: opts.author
},
{
Expand All @@ -64,14 +66,14 @@ module.exports = async (opts) => {
type: 'list',
name: 'manager',
message: 'Package Manager',
choices: [ 'npm', 'yarn' ],
choices: ['npm', 'yarn'],
default: opts.manager
},
{
type: 'list',
name: 'template',
message: 'Template',
choices: [ 'default', 'typescript', 'custom' ],
choices: ['default', 'typescript', 'custom'],
default: opts.template
},
{
Expand All @@ -80,15 +82,16 @@ module.exports = async (opts) => {
message: 'Template Path',
default: opts.templatePath,
when: ({ template }) => template === 'custom',
validate: input => new Promise(resolve => {
const fullPath = path.resolve(process.cwd(), input)
fs.stat(fullPath, (err, stats) => {
if (err) {
return resolve(`Cannot resolve directory at: ${fullPath}`)
}
resolve(true)
validate: (input) =>
new Promise((resolve) => {
const fullPath = path.resolve(process.cwd(), input)
fs.stat(fullPath, (err, stats) => {
if (err) {
return resolve(`Cannot resolve directory at: ${fullPath}`)
}
resolve(true)
})
})
})
}
])

Expand Down
9 changes: 5 additions & 4 deletions lib/prompt-library-params.test.js
Expand Up @@ -16,10 +16,11 @@ const opts = {
git: true
}

test('passed options are returned when skipPrompts is true', async t => {
const result = await promptLibraryParams(Object.assign({}, opts, { skipPrompts: true }))
Object.entries(opts).forEach(opt => {
// console.log(`comparing passed in option ${opt[0]}:${opt[1]} to returned option ${result[opt[0]]}`)
test('passed options are returned when skipPrompts is true', async (t) => {
const result = await promptLibraryParams(
Object.assign({}, opts, { skipPrompts: true })
)
Object.entries(opts).forEach((opt) => {
t.is(opt[1], result[opt[0]])
})
})
13 changes: 3 additions & 10 deletions readme.md
Expand Up @@ -4,14 +4,12 @@
[![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)


## Intro

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


## Features

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


## Notice

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.

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.

## Install globally

This package requires `node >= 4`, but we recommend `node >= 8`.
This package requires `node >= 10`.

```bash
npm install -g create-react-library
Expand All @@ -58,6 +54,7 @@ create-react-library
```

Answer some basic prompts about your module, and then the CLI will perform the following steps:

- copy over the template
- install dependencies via yarn or npm
- link packages together for local development
Expand All @@ -69,7 +66,6 @@ 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 (ideally using two tabs).
Expand All @@ -92,7 +88,6 @@ Now, anytime you make a change to your library in `src/` or to the example app's

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


#### Publishing to npm

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

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.


#### Deploying to Github Pages

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

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.


## License

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

0 comments on commit 73da50f

Please sign in to comment.