-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(new-workspace): Create a sandbox to create new workpaces
- Loading branch information
Showing
10 changed files
with
100 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#!/usr/bin/env node | ||
'use strict'; | ||
|
||
const { execSync } = require('child_process'); | ||
const { dirSync } = require('tmp'); | ||
const { lt } = require('semver'); | ||
const path = require('path'); | ||
|
||
const ngNewArgs = process.argv.slice(2); | ||
const collection = ( | ||
ngNewArgs.find(arg => arg.startsWith('--collection=')) || | ||
'--collection=@schematics/angular' | ||
).replace('--collection=', ''); | ||
|
||
try { | ||
// check the correct version of the NPM is installed | ||
const output = execSync('npm --version').toString(); | ||
if (lt(output, '5.0.0')) { | ||
console.error( | ||
'To create a workspace you must have NPM >= 5.0.0 installed.' | ||
); | ||
process.exit(1); | ||
} | ||
} catch (e) { | ||
throw new Error('Cannot find npm. Do you have node installed?'); | ||
} | ||
|
||
const tmpDir = dirSync().name; | ||
|
||
console.log(`npm init -y`); | ||
execSync('npm init -y', { cwd: tmpDir, stdio: [0, 1, 2] }); | ||
console.log(`npm install @angular/cli@latest`); | ||
execSync('npm install @angular/cli@latest', { | ||
cwd: tmpDir, | ||
stdio: [0, 1, 2] | ||
}); | ||
|
||
if (collection !== '@schematics/angular') { | ||
console.log(`npm install ${collection}@latest`); | ||
execSync(`npm install ${collection}@latest`, { | ||
cwd: tmpDir, | ||
stdio: [0, 1, 2] | ||
}); | ||
} | ||
|
||
console.log(`ng new ${ngNewArgs.join(' ')}`); | ||
execSync( | ||
`${path.join(tmpDir, 'node_modules', '.bin', 'ng')} new ${ngNewArgs.join( | ||
' ' | ||
)} --no-interactive`, | ||
{ | ||
stdio: [0, 1, 2] | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
@IF EXIST "%~dp0\node.exe" ( | ||
"%~dp0\node.exe" "%~dp0\new-workspace" %* | ||
) ELSE ( | ||
@SETLOCAL | ||
@SET PATHEXT=%PATHEXT:;.JS;=;% | ||
node "%~dp0\new-workspace" %* | ||
) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.