Skip to content

Commit

Permalink
Merge pull request #307 from halfzebra/win-create-fix
Browse files Browse the repository at this point in the history
fix(create): Fix creation problems on Windows
  • Loading branch information
halfzebra authored Oct 1, 2018
2 parents 1766ea0 + 3868884 commit 55547b0
Showing 1 changed file with 28 additions and 18 deletions.
46 changes: 28 additions & 18 deletions scripts/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,34 @@ const fs = require('fs');
const copySync = require('fs-extra').copySync;
const path = require('path');
const chalk = require('chalk');
const spawnSync = require('child_process').spawnSync;
const spawn = require('cross-spawn');
const argv = require('minimist')(process.argv.slice(2));
const commands = argv._;

const isWindows = process.platform === 'win32';

if (commands.length === 0 || commands[0] === '') {
console.error('\nUsage: elm-app create <project-directory>');
console.log();
console.error('Usage: elm-app create <project-directory>');
process.exit(1);
}

createElmApp(commands[0]);

function createElmApp(name) {
console.log('\nCreating ' + name + ' project...\n');
console.log();
console.log('Creating ' + name + ' project...');
console.log();

const root = path.resolve(name.toString());
const appRoot = path.resolve(name.toString());
const template = path.join(__dirname, '../template');

if (!fs.existsSync(name)) {
try {
copySync(template, root);
copySync(template, appRoot);
fs.renameSync(
path.resolve(root, 'gitignore'),
path.resolve(root, '.gitignore')
path.resolve(appRoot, 'gitignore'),
path.resolve(appRoot, '.gitignore')
);
} catch (err) {
console.log(err);
Expand All @@ -37,28 +42,33 @@ function createElmApp(name) {
process.exit(1);
}

process.chdir(root);

// Run initial `elm make`
const spawnElmPkgResult = spawnSync(
const spawnElmPkgResult = spawn.sync(
path.resolve(__dirname, '../node_modules/.bin/elm'),
// Run elm-make to install the dependencies.
['make', 'src/Main.elm', '--output=/dev/null'],
{ stdio: 'inherit' }
{ stdio: 'inherit', cwd: appRoot }
);

if (spawnElmPkgResult.status !== 0) {
console.log(chalk.red('\nFailed to install elm packages'));
console.log('\nPlease, make sure you have internet connection!');
console.log(
'\nIn case if you are running Unix OS, you might look in to this issue:'
);
console.log('\n https://github.com/halfzebra/create-elm-app/issues/10');
console.log();
console.log(chalk.red('Failed to install elm packages'));
console.log();
console.log('Please, make sure you have internet connection!');
if (!isWindows) {
console.log();
console.log(
'In case if you are running Unix OS, you might look in to this issue:'
);
console.log();
console.log(' https://github.com/halfzebra/create-elm-app/issues/10');
}
process.exit(1);
}

console.log();
console.log(
chalk.green('\nProject is successfully created in `' + root + '`.')
chalk.green('Project is successfully created in `' + appRoot + '`.')
);
console.log();
console.log('Inside that directory, you can run several commands:');
Expand Down

0 comments on commit 55547b0

Please sign in to comment.