create-es-module
Advanced tools
Comparing version 0.1.6 to 0.1.7
{ | ||
"name": "create-es-module", | ||
"version": "0.1.6", | ||
"version": "0.1.7", | ||
"description": "Helper to create es module", | ||
"keywords": [ | ||
"ecmascript", | ||
"export", | ||
"import", | ||
"init", | ||
"create", | ||
"es", | ||
"module" | ||
], | ||
"bin": { | ||
@@ -6,0 +15,0 @@ "create-es-module": "./src/index.js" |
@@ -6,15 +6,56 @@ # create-es-module | ||
`Yarn`: | ||
``` | ||
yarn create es-module my-module | ||
``` | ||
yarn add create-es-module --global | ||
`NPM`: | ||
``` | ||
npm init es-module my-module | ||
``` | ||
`NPX`: | ||
``` | ||
npx create-es-module my-module | ||
cd my-module | ||
yarn build | ||
``` | ||
``` | ||
yarn create es-module my-module | ||
cd my-module | ||
yarn build | ||
It will create `my-module` folder with the default structure. | ||
## Build | ||
`yarn build` or `npm run build` | ||
Builds the module for production to the `build` folder. | ||
## Test | ||
`yarn test` or `npm test` | ||
## Publish | ||
It will publish the module to `npm`. | ||
By default files in `build` folder is whitelisted to be included in the package. | ||
For more information about list of files in the package visit https://docs.npmjs.com/files/package.json#files. | ||
## Add `flow` | ||
You need to add `flow-bin` as dev dependency and run `init` command. | ||
``` | ||
yarn add flow-bin --dev | ||
npx flow --init | ||
``` | ||
## Add `react` and use JSX | ||
You need to add `react` as dependency | ||
``` | ||
yarn add react | ||
``` | ||
## What’s Included? | ||
- React, JSX, ES6 and Flow syntax support. | ||
- Unit test | ||
- module build and cjs build | ||
## | ||
## TODO | ||
- make react optional | ||
## Credits | ||
Credit to [create-react-app](https://github.com/facebook/create-react-app). | ||
## License | ||
MIT |
@@ -16,5 +16,3 @@ const chalk = require('chalk'); | ||
console.error( | ||
`Could not create a project called ${chalk.red( | ||
`"${appName}"` | ||
)} because of npm naming restrictions:` | ||
`Could not create a project called ${chalk.red(`"${appName}"`)} because of npm naming restrictions:` | ||
); | ||
@@ -21,0 +19,0 @@ printValidationResults(validationResult.errors); |
@@ -5,36 +5,13 @@ const fs = require('fs-extra'); | ||
module.exports = function copyTemplateFiles(root) { | ||
fs.copySync( | ||
require.resolve('./templates/.editorconfig'), | ||
path.join(root, '.editorconfig') | ||
); | ||
fs.copySync(require.resolve('./templates/.editorconfig'), path.join(root, '.editorconfig')); | ||
fs.copySync( | ||
require.resolve('./templates/.flowconfig'), | ||
path.join(root, '.flowconfig') | ||
); | ||
fs.copySync(require.resolve('./templates/.gitignore'), path.join(root, '.gitignore')); | ||
fs.copySync( | ||
require.resolve('./templates/.gitignore'), | ||
path.join(root, '.gitignore') | ||
); | ||
fs.copySync(require.resolve('./templates/babel.config.js'), path.join(root, 'babel.config.js')); | ||
fs.copySync( | ||
require.resolve('./templates/babel.config.js'), | ||
path.join(root, 'babel.config.js') | ||
); | ||
fs.copySync(require.resolve('./templates/README.md'), path.join(root, 'README.md')); | ||
fs.copySync( | ||
require.resolve('./templates/README.md'), | ||
path.join(root, 'README.md') | ||
); | ||
fs.copySync(require.resolve('./templates/index.js'), path.join(root, 'src/index.js')); | ||
fs.copySync( | ||
require.resolve('./templates/index.js'), | ||
path.join(root, 'src/index.js') | ||
); | ||
fs.copySync( | ||
require.resolve('./templates/index.test.js'), | ||
path.join(root, 'src/index.test.js') | ||
); | ||
fs.copySync(require.resolve('./templates/index.test.js'), path.join(root, 'src/index.test.js')); | ||
}; |
@@ -15,3 +15,3 @@ #!/usr/bin/env node | ||
let projectName; | ||
let projectName = ''; | ||
@@ -32,5 +32,3 @@ const program = new commander.Command(packageJson.name) | ||
.on('--help', () => { | ||
console.log( | ||
` Only ${chalk.green('<project-directory>')} is required.` | ||
); | ||
console.log(` Only ${chalk.green('<project-directory>')} is required.`); | ||
}) | ||
@@ -41,14 +39,8 @@ .parse(process.argv); | ||
console.error('Please specify the project directory:'); | ||
console.log( | ||
` ${chalk.cyan(program.name())} ${chalk.green('<project-directory>')}` | ||
); | ||
console.log(` ${chalk.cyan(program.name())} ${chalk.green('<project-directory>')}`); | ||
console.log(); | ||
console.log('For example:'); | ||
console.log( | ||
` ${chalk.cyan(program.name())} ${chalk.green('my-es-module')}` | ||
); | ||
console.log(` ${chalk.cyan(program.name())} ${chalk.green('my-es-module')}`); | ||
console.log(); | ||
console.log( | ||
`Run ${chalk.cyan(`${program.name()} --help`)} to see all options.` | ||
); | ||
console.log(`Run ${chalk.cyan(`${program.name()} --help`)} to see all options.`); | ||
process.exit(1); | ||
@@ -73,2 +65,3 @@ } | ||
module: 'build/esm/index.js', | ||
files: ['build/**/*'], | ||
scripts: { | ||
@@ -79,13 +72,8 @@ test: 'jest', | ||
build: 'npm run build:cjs && npm run build:esm', | ||
'build:esm': | ||
'BABEL_ENV=esm babel src --out-dir build/esm/ --ignore "src/**/*.test.js"', | ||
'build:cjs': | ||
'BABEL_ENV=cjs babel src --out-dir build/cjs/ --ignore "src/**/*.test.js"', | ||
'build:esm': 'BABEL_ENV=esm babel src --out-dir build/esm/ --ignore "src/**/*.test.js"', | ||
'build:cjs': 'BABEL_ENV=cjs babel src --out-dir build/cjs/ --ignore "src/**/*.test.js"', | ||
}, | ||
}; | ||
fs.writeFileSync( | ||
path.join(root, 'package.json'), | ||
JSON.stringify(modulePackageJson, null, 2) + os.EOL | ||
); | ||
fs.writeFileSync(path.join(root, 'package.json'), JSON.stringify(modulePackageJson, null, 2) + os.EOL); | ||
@@ -106,3 +94,2 @@ copyTemplateFiles(root); | ||
'@babel/preset-react', | ||
'flow-bin', | ||
'jest', | ||
@@ -109,0 +96,0 @@ 'rimraf', |
const chalk = require('chalk'); | ||
const spawn = require('cross-spawn'); | ||
module.exports = function installDependencies( | ||
root, | ||
useYarn, | ||
usePnp, | ||
dependencies, | ||
verbose, | ||
isOnline | ||
) { | ||
module.exports = function installDependencies(root, useYarn, usePnp, dependencies, verbose, isOnline) { | ||
return new Promise((resolve, reject) => { | ||
@@ -17,3 +10,3 @@ let command; | ||
command = 'yarnpkg'; | ||
args = ['add', '--exact', '--dev']; | ||
args = ['add', '--dev']; | ||
if (!isOnline) { | ||
@@ -37,5 +30,3 @@ args.push('--offline'); | ||
console.log(chalk.yellow('You appear to be offline.')); | ||
console.log( | ||
chalk.yellow('Falling back to the local Yarn cache.') | ||
); | ||
console.log(chalk.yellow('Falling back to the local Yarn cache.')); | ||
console.log(); | ||
@@ -45,15 +36,7 @@ } | ||
command = 'npm'; | ||
args = [ | ||
'install', | ||
'--save', | ||
'--save-exact', | ||
'--loglevel', | ||
'error', | ||
].concat(dependencies); | ||
args = ['install', '--save-dev', '--loglevel', 'error'].concat(dependencies); | ||
if (usePnp) { | ||
console.log(chalk.yellow("NPM doesn't support PnP.")); | ||
console.log( | ||
chalk.yellow('Falling back to the regular installs.') | ||
); | ||
console.log(chalk.yellow('Falling back to the regular installs.')); | ||
console.log(); | ||
@@ -60,0 +43,0 @@ } |
@@ -5,7 +5,3 @@ const fs = require('fs-extra'); | ||
const errorLogFilePatterns = [ | ||
'npm-debug.log', | ||
'yarn-error.log', | ||
'yarn-debug.log', | ||
]; | ||
const errorLogFilePatterns = ['npm-debug.log', 'yarn-error.log', 'yarn-debug.log']; | ||
@@ -38,15 +34,6 @@ const validFiles = [ | ||
// Don't treat log files from previous installation as conflicts | ||
.filter( | ||
file => | ||
!errorLogFilePatterns.some( | ||
pattern => file.indexOf(pattern) === 0 | ||
) | ||
); | ||
.filter(file => !errorLogFilePatterns.some(pattern => file.indexOf(pattern) === 0)); | ||
if (conflicts.length > 0) { | ||
console.log( | ||
`The directory ${chalk.green( | ||
name | ||
)} contains files that could conflict:` | ||
); | ||
console.log(`The directory ${chalk.green(name)} contains files that could conflict:`); | ||
console.log(); | ||
@@ -57,5 +44,3 @@ for (const file of conflicts) { | ||
console.log(); | ||
console.log( | ||
'Either try using a new directory name, or remove the files listed above.' | ||
); | ||
console.log('Either try using a new directory name, or remove the files listed above.'); | ||
@@ -62,0 +47,0 @@ return false; |
@@ -1,6 +0,2 @@ | ||
const presets = [ | ||
['@babel/preset-env'], | ||
'@babel/preset-react', | ||
'@babel/preset-flow', | ||
]; | ||
const presets = [['@babel/preset-env'], '@babel/preset-react', '@babel/preset-flow']; | ||
@@ -21,7 +17,4 @@ if (process.env['BABEL_ENV'] === 'esm') { | ||
const plugins = [ | ||
'@babel/plugin-transform-runtime', | ||
'@babel/plugin-proposal-class-properties', | ||
]; | ||
const plugins = ['@babel/plugin-transform-runtime', '@babel/plugin-proposal-class-properties']; | ||
module.exports = {presets, plugins}; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12778
61
240