@@ -4,29 +4,34 @@ const fs = require('fs');
44const copySync = require ( 'fs-extra' ) . copySync ;
55const path = require ( 'path' ) ;
66const chalk = require ( 'chalk' ) ;
7- const spawnSync = require ( 'child_process' ) . spawnSync ;
7+ const spawn = require ( 'cross-spawn' ) ;
88const argv = require ( 'minimist' ) ( process . argv . slice ( 2 ) ) ;
99const commands = argv . _ ;
1010
11+ const isWindows = process . platform === 'win32' ;
12+
1113if ( commands . length === 0 || commands [ 0 ] === '' ) {
12- console . error ( '\nUsage: elm-app create <project-directory>' ) ;
14+ console . log ( ) ;
15+ console . error ( 'Usage: elm-app create <project-directory>' ) ;
1316 process . exit ( 1 ) ;
1417}
1518
1619createElmApp ( commands [ 0 ] ) ;
1720
1821function createElmApp ( name ) {
19- console . log ( '\nCreating ' + name + ' project...\n' ) ;
22+ console . log ( ) ;
23+ console . log ( 'Creating ' + name + ' project...' ) ;
24+ console . log ( ) ;
2025
21- const root = path . resolve ( name . toString ( ) ) ;
26+ const appRoot = path . resolve ( name . toString ( ) ) ;
2227 const template = path . join ( __dirname , '../template' ) ;
2328
2429 if ( ! fs . existsSync ( name ) ) {
2530 try {
26- copySync ( template , root ) ;
31+ copySync ( template , appRoot ) ;
2732 fs . renameSync (
28- path . resolve ( root , 'gitignore' ) ,
29- path . resolve ( root , '.gitignore' )
33+ path . resolve ( appRoot , 'gitignore' ) ,
34+ path . resolve ( appRoot , '.gitignore' )
3035 ) ;
3136 } catch ( err ) {
3237 console . log ( err ) ;
@@ -37,28 +42,33 @@ function createElmApp(name) {
3742 process . exit ( 1 ) ;
3843 }
3944
40- process . chdir ( root ) ;
41-
4245 // Run initial `elm make`
43- const spawnElmPkgResult = spawnSync (
46+ const spawnElmPkgResult = spawn . sync (
4447 path . resolve ( __dirname , '../node_modules/.bin/elm' ) ,
4548 // Run elm-make to install the dependencies.
4649 [ 'make' , 'src/Main.elm' , '--output=/dev/null' ] ,
47- { stdio : 'inherit' }
50+ { stdio : 'inherit' , cwd : appRoot }
4851 ) ;
4952
5053 if ( spawnElmPkgResult . status !== 0 ) {
51- console . log ( chalk . red ( '\nFailed to install elm packages' ) ) ;
52- console . log ( '\nPlease, make sure you have internet connection!' ) ;
53- console . log (
54- '\nIn case if you are running Unix OS, you might look in to this issue:'
55- ) ;
56- console . log ( '\n https://github.com/halfzebra/create-elm-app/issues/10' ) ;
54+ console . log ( ) ;
55+ console . log ( chalk . red ( 'Failed to install elm packages' ) ) ;
56+ console . log ( ) ;
57+ console . log ( 'Please, make sure you have internet connection!' ) ;
58+ if ( ! isWindows ) {
59+ console . log ( ) ;
60+ console . log (
61+ 'In case if you are running Unix OS, you might look in to this issue:'
62+ ) ;
63+ console . log ( ) ;
64+ console . log ( ' https://github.com/halfzebra/create-elm-app/issues/10' ) ;
65+ }
5766 process . exit ( 1 ) ;
5867 }
5968
69+ console . log ( ) ;
6070 console . log (
61- chalk . green ( '\nProject is successfully created in `' + root + '`.' )
71+ chalk . green ( 'Project is successfully created in `' + appRoot + '`.' )
6272 ) ;
6373 console . log ( ) ;
6474 console . log ( 'Inside that directory, you can run several commands:' ) ;
0 commit comments