1
1
#! /usr/local/bin/node
2
2
3
- const { spawn } = require ( ' child_process' ) ;
4
- const fs = require ( 'fs' ) ;
3
+ const { spawn } = require ( " child_process" ) ;
4
+ const fs = require ( "fs" ) ;
5
5
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" ) ;
9
9
10
10
const {
11
11
babelrc,
12
12
gitignore,
13
13
index,
14
14
packageJSON,
15
- webpackConfig,
16
- } = require ( ' ./templates' ) ;
17
- const { dependencies, devDependencies } = require ( ' ./args' ) ;
15
+ webpackConfig
16
+ } = require ( " ./templates" ) ;
17
+ const { dependencies, devDependencies } = require ( " ./args" ) ;
18
18
19
19
// 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 } ] ;
21
21
22
22
// define the usage sections
23
23
const sections = [
24
24
{
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"
27
27
} ,
28
28
{
29
- header : ' Usage' ,
30
- content : [ ' $ create-react-npm-component [project-name]' ] ,
29
+ header : " Usage" ,
30
+ content : [ " $ create-react-npm-component [project-name]" ]
31
31
} ,
32
32
{
33
- header : ' Options' ,
33
+ header : " Options" ,
34
34
optionList : [
35
35
{
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
+ }
42
42
] ;
43
43
44
44
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" ] } ) ;
46
46
47
47
p . stdout . pipe ( process . stdout ) ;
48
48
p . stderr . pipe ( process . stderr ) ;
49
49
process . stdin . pipe ( p . stdin ) ;
50
50
51
- p . on ( ' close' , ( ) => {
51
+ p . on ( " close" , ( ) => {
52
52
if ( callback ) {
53
53
callback ( ) ;
54
54
}
@@ -69,21 +69,21 @@ const Main = () => {
69
69
70
70
fs . mkdirSync ( project ) ;
71
71
process . chdir ( project ) ;
72
- fs . mkdirSync ( ' build' ) ;
73
- fs . mkdirSync ( ' src' ) ;
72
+ fs . mkdirSync ( " build" ) ;
73
+ fs . mkdirSync ( " src" ) ;
74
74
75
75
// 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 => {
79
79
let f ;
80
- if ( typeof file . content === ' object' ) {
80
+ if ( typeof file . content === " object" ) {
81
81
f = JSON . stringify ( file . content ) ;
82
82
} else {
83
83
f = file . content ;
84
84
}
85
85
86
- fs . writeFile ( `./${ file . name } ` , f , { mode : '755' } , ( err ) => {
86
+ fs . writeFile ( `./${ file . name } ` , f , { mode : "644" } , err => {
87
87
if ( err ) {
88
88
console . log ( `error writing ${ file . name } ` ) ;
89
89
console . log ( err ) ;
@@ -92,24 +92,20 @@ const Main = () => {
92
92
} ) ;
93
93
94
94
// 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" ] , ( ) => {
101
97
// install dependencies...
102
98
console . log (
103
- colors . green ( ' \ninstalling npm dependencies, this may take a while...' ) ,
99
+ colors . green ( " \ninstalling npm dependencies, this may take a while..." )
104
100
) ;
105
- Do ( ' npm' , dependencies , ( ) => {
101
+ Do ( " npm" , dependencies , ( ) => {
106
102
// install dev dependencies...
107
103
console . log (
108
- colors . green ( ' \ninstalling dev dependencies, this may take a while...' ) ,
104
+ colors . green ( " \ninstalling dev dependencies, this may take a while..." )
109
105
) ;
110
- Do ( ' npm' , devDependencies , ( ) => {
106
+ Do ( " npm" , devDependencies , ( ) => {
111
107
console . log ( `\n[ ${ project } ] created successfully` ) ;
112
- console . log ( ' press any key to exit' ) ;
108
+ console . log ( " press any key to exit" ) ;
113
109
} ) ;
114
110
} ) ;
115
111
} ) ;
0 commit comments