Skip to content

Commit d3ef57d

Browse files
committed
Version 0.0.2
- changed file permissions to 644 - added babel transform class properties plugin - added eslint plugin to go with babel plugin - added babelrc to package.json - added some binary font and image filetypes to the file loader - changed webpack build to production
1 parent 3febf99 commit d3ef57d

File tree

4 files changed

+84
-88
lines changed

4 files changed

+84
-88
lines changed

args.js

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
module.exports = {
22
dependencies: [
3-
'i',
4-
'react',
5-
'react-dom',
6-
'prop-types',
7-
'webpack',
8-
'css-loader',
9-
'style-loader',
10-
'file-loader',
3+
"i",
4+
"react",
5+
"react-dom",
6+
"webpack",
7+
"prop-types",
8+
"css-loader",
9+
"style-loader",
10+
"file-loader"
1111
],
1212
devDependencies: [
13-
'i',
14-
'--save-dev',
15-
'babel-cli',
16-
'babel-core',
17-
'babel-loader',
18-
'babel-plugin-transform-object-rest-spread',
19-
'babel-plugin-transform-react-jsx',
20-
'babel-preset-env',
21-
],
13+
"i",
14+
"--save-dev",
15+
"babel-cli",
16+
"babel-core",
17+
"babel-loader",
18+
"babel-plugin-transform-object-rest-spread",
19+
"babel-plugin-transform-react-jsx",
20+
"babel-preset-env",
21+
"babel-plugin-transform-class-properties",
22+
"eslint-plugin-class-property"
23+
]
2224
};

index.js

Lines changed: 36 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,54 @@
11
#! /usr/local/bin/node
22

3-
const { spawn } = require('child_process');
4-
const fs = require('fs');
3+
const { spawn } = require("child_process");
4+
const fs = require("fs");
55

6-
const colors = require('colors');
7-
const commandLineArgs = require('command-line-args');
8-
const getUsage = require('command-line-usage');
6+
const colors = require("colors");
7+
const commandLineArgs = require("command-line-args");
8+
const getUsage = require("command-line-usage");
99

1010
const {
1111
babelrc,
1212
gitignore,
1313
index,
1414
packageJSON,
15-
webpackConfig,
16-
} = require('./templates');
17-
const { dependencies, devDependencies } = require('./args');
15+
webpackConfig
16+
} = require("./templates");
17+
const { dependencies, devDependencies } = require("./args");
1818

1919
// define the flags that are needed for this tool.
20-
const optionDefinitions = [{ name: 'help', alias: 'h', type: Boolean }];
20+
const optionDefinitions = [{ name: "help", alias: "h", type: Boolean }];
2121

2222
// define the usage sections
2323
const sections = [
2424
{
25-
header: 'create-react-npm-component',
26-
content: 'generates a skeleton project for a react component to upload to npm',
25+
header: "create-react-npm-component",
26+
content: "generates a skeleton project for a react component to upload to npm"
2727
},
2828
{
29-
header: 'Usage',
30-
content: ['$ create-react-npm-component [project-name]'],
29+
header: "Usage",
30+
content: ["$ create-react-npm-component [project-name]"]
3131
},
3232
{
33-
header: 'Options',
33+
header: "Options",
3434
optionList: [
3535
{
36-
name: 'help',
37-
alias: 'h',
38-
description: 'Print this usage guide.',
39-
},
40-
],
41-
},
36+
name: "help",
37+
alias: "h",
38+
description: "Print this usage guide."
39+
}
40+
]
41+
}
4242
];
4343

4444
const Do = (cmd, args, callback) => {
45-
const p = spawn(cmd, args, { stdio: ['pipe', 'pipe', 'pipe'] });
45+
const p = spawn(cmd, args, { stdio: ["pipe", "pipe", "pipe"] });
4646

4747
p.stdout.pipe(process.stdout);
4848
p.stderr.pipe(process.stderr);
4949
process.stdin.pipe(p.stdin);
5050

51-
p.on('close', () => {
51+
p.on("close", () => {
5252
if (callback) {
5353
callback();
5454
}
@@ -69,21 +69,21 @@ const Main = () => {
6969

7070
fs.mkdirSync(project);
7171
process.chdir(project);
72-
fs.mkdirSync('build');
73-
fs.mkdirSync('src');
72+
fs.mkdirSync("build");
73+
fs.mkdirSync("src");
7474

7575
// write some boilerplate files...
76-
console.log(colors.green('\nwriting boilerplate files...'));
77-
const files = [babelrc, gitignore, webpackConfig, index, packageJSON];
78-
files.forEach((file) => {
76+
console.log(colors.green("\nwriting boilerplate files..."));
77+
const files = [gitignore, webpackConfig, index, packageJSON];
78+
files.forEach(file => {
7979
let f;
80-
if (typeof file.content === 'object') {
80+
if (typeof file.content === "object") {
8181
f = JSON.stringify(file.content);
8282
} else {
8383
f = file.content;
8484
}
8585

86-
fs.writeFile(`./${file.name}`, f, { mode: '755' }, (err) => {
86+
fs.writeFile(`./${file.name}`, f, { mode: "644" }, err => {
8787
if (err) {
8888
console.log(`error writing ${file.name}`);
8989
console.log(err);
@@ -92,24 +92,20 @@ const Main = () => {
9292
});
9393

9494
// start and run the user through npm init...
95-
console.log(
96-
colors.green(
97-
'\nstarting npm init...(you should put src/index.js as the main entrypoint)',
98-
),
99-
);
100-
Do('npm', ['init'], () => {
95+
console.log(colors.green("\nstarting npm init..."));
96+
Do("npm", ["init"], () => {
10197
// install dependencies...
10298
console.log(
103-
colors.green('\ninstalling npm dependencies, this may take a while...'),
99+
colors.green("\ninstalling npm dependencies, this may take a while...")
104100
);
105-
Do('npm', dependencies, () => {
101+
Do("npm", dependencies, () => {
106102
// install dev dependencies...
107103
console.log(
108-
colors.green('\ninstalling dev dependencies, this may take a while...'),
104+
colors.green("\ninstalling dev dependencies, this may take a while...")
109105
);
110-
Do('npm', devDependencies, () => {
106+
Do("npm", devDependencies, () => {
111107
console.log(`\n[ ${project} ] created successfully`);
112-
console.log('press any key to exit');
108+
console.log("press any key to exit");
113109
});
114110
});
115111
});

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "create-react-npm-component",
3-
"version": "0.0.1",
3+
"version": "0.0.2",
44
"description": "quickly create react component skeleton for upload to npm",
55
"main": "index.js",
66
"bin": {
@@ -20,6 +20,7 @@
2020
"distribute"
2121
],
2222
"author": "Jeff Willette",
23+
"repository": "https://github.com/deltaskelta/create-react-npm-component",
2324
"license": "MIT",
2425
"dependencies": {
2526
"colors": "^1.1.2",

templates.js

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,13 @@
11
module.exports = {
2-
// the babelrc file which needs to be written in main
3-
babelrc: {
4-
name: '.babelrc',
5-
content: {
6-
presets: ['env'],
7-
plugins: ['transform-object-rest-spread', 'transform-react-jsx'],
8-
},
9-
},
10-
112
// gitignore written in main
123
gitignore: {
13-
name: '.gitignore',
14-
content: 'node_modules/',
4+
name: ".gitignore",
5+
content: "node_modules/"
156
},
167

178
// webpackConfig written in main
189
webpackConfig: {
19-
name: 'webpack.config.js',
10+
name: "webpack.config.js",
2011
content: `var path = require('path');
2112
module.exports = {
2213
entry: './src/index.js',
@@ -33,17 +24,15 @@ module.exports = {
3324
exclude: /(node_modules|bower_components|build)/,
3425
use: {
3526
loader: 'babel-loader',
36-
options: {
37-
presets: ['env']
38-
}
27+
options: {},
3928
}
4029
},
4130
{
4231
test: /\.css$/,
4332
use: [ 'style-loader', 'css-loader' ]
4433
},
4534
{
46-
test: /\.(png|jpg|gif)$/,
35+
test: /\.(png|jpg|gif|eot|svg|ttf|woff|woff2)$/,
4736
use: [
4837
{
4938
loader: 'file-loader',
@@ -56,11 +45,11 @@ module.exports = {
5645
externals: {
5746
'react': 'commonjs react' // this line is just to use the React dependency of our parent-testing-project instead of using our own React.
5847
}
59-
};`,
48+
};`
6049
},
6150

6251
index: {
63-
name: 'src/index.js',
52+
name: "src/index.js",
6453
content: `import React from 'react';
6554
6655
class MyComponent extends React.Component {
@@ -70,25 +59,33 @@ class MyComponent extends React.Component {
7059
);
7160
}
7261
}
73-
export default MyComponent;`,
62+
export default MyComponent;`
7463
},
7564

7665
packageJSON: {
77-
name: 'package.json',
66+
name: "package.json",
7867
content: {
79-
name: '',
80-
version: '0.1.0',
81-
description: '',
82-
main: 'build/index.js',
68+
name: "",
69+
version: "0.1.0",
70+
description: "",
71+
main: "build/index.js",
8372
scripts: {
8473
test: 'echo "Error: no test specified" && exit 1',
85-
start: 'webpack --watch',
86-
build: 'webpack',
74+
start: "webpack --watch",
75+
build: "webpack -p"
8776
},
8877
author: {
89-
name: '',
90-
email: '',
78+
name: "",
79+
email: ""
9180
},
92-
},
93-
},
81+
babel: {
82+
presets: ["env"],
83+
plugins: [
84+
"transform-object-rest-spread",
85+
"transform-react-jsx",
86+
"transform-class-properties"
87+
]
88+
}
89+
}
90+
}
9491
};

0 commit comments

Comments
 (0)