Skip to content

Commit

Permalink
fix(new-workspace): Create a sandbox to create new workpaces
Browse files Browse the repository at this point in the history
  • Loading branch information
mrmeku authored and vsavkin committed Feb 6, 2019
1 parent a50d3b8 commit be0722d
Show file tree
Hide file tree
Showing 10 changed files with 100 additions and 64 deletions.
4 changes: 2 additions & 2 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -198,15 +198,15 @@
"options": {
"externalDependencies": [
"electron",
"electron-updater",
"electron-updater",
"node-pty-prebuilt"
],
"outputPath": "dist/apps/electron",
"main": "apps/electron/src/main.ts",
"tsConfig": "apps/electron/tsconfig.app.json",
"assets": [
"apps/electron/src/package.json",
"apps/electron/src/assets/new-workspace",
"apps/electron/src/assets/new-workspace.cmd",
"apps/electron/src/assets"
]
},
Expand Down
54 changes: 54 additions & 0 deletions apps/electron/src/assets/new-workspace
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]
}
);
7 changes: 7 additions & 0 deletions apps/electron/src/assets/new-workspace.cmd
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" %*
)
7 changes: 0 additions & 7 deletions apps/electron/src/assets/ng.cmd

This file was deleted.

9 changes: 2 additions & 7 deletions apps/electron/src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,8 @@
"main": "main.js",
"license": "MIT",
"dependencies": {
"@angular/cli": "7.3.0",
"@nrwl/schematics": "7.5.1",
"@schematics/angular": "7.3.0",
"electron-updater": "3.1.2",
"semver": "5.6.0",
"tmp": "0.0.33",
"node-pty-prebuilt": "0.7.6"
},
"devDependencies": {
"electron": "2.0.14"
}
}
5 changes: 2 additions & 3 deletions apps/vscode/src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,8 @@
]
},
"dependencies": {
"@angular/cli": "7.3.0",
"@nrwl/schematics": "7.5.1",
"@schematics/angular": "7.3.0",
"semver": "5.6.0",
"tmp": "0.0.33",
"node-pty-prebuilt": "0.7.6"
}
}
18 changes: 11 additions & 7 deletions libs/server/src/lib/resolvers/mutation.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { readSettings, storeSettings } from '../api/read-settings';
import { commands, runCommand } from '../api/run-command';
import { SelectDirectory } from '../types';
import { findClosestNg, findExecutable, readJsonFile } from '../utils/utils';
import { platform } from 'os';

function disableInteractivePrompts(p: string) {
try {
Expand Down Expand Up @@ -62,16 +63,19 @@ export class MutationResolver {
try {
return runCommand(
'new',
__dirname,
'ng',
findClosestNg(__dirname),
p,
'new-workspace',
path.join(
__dirname,
'assets',
platform() === 'win32' ? 'new-workspace.cmd' : 'new-workspace'
),
[
'new',
name,
`--directory=${p}/${name}`,
`--directory=${name}`,
`--collection=${collection}`,
'--no-interactive',
...newCommand
...newCommand,
'--no-interactive'
],
this.pseudoTerminalFactory
);
Expand Down
32 changes: 17 additions & 15 deletions package-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,13 @@ function affected(affectedCommand) {
function electronBuilder(platform, dashP, extraFlags) {
return `electron-builder ${platform} -p ${dashP} ${
extraFlags ? extraFlags : ''
}`;
}`;
}

const ELECTRON_BUNDLE_PATH = join('dist', 'apps', 'electron');
const APPLICATION_BUNDLE_PATH = join('dist', 'apps', 'APPLICATION');

const assetMappings = {
'ng-cmd': {
from: join('tools', 'win', '.bin', 'ng.cmd'),
to: join(APPLICATION_BUNDLE_PATH, 'ng.cmd')
},
'node-pty-prebuilt': {
from: join('tools', 'win', 'node-pty-prebuilt', 'build', 'Release'),
to: join(
Expand Down Expand Up @@ -75,32 +71,38 @@ module.exports = {
scripts: {
dev: {
'copy-assets': {
electron: nps.series.nps('dev.copy-assets-base.electron'),
electron: nps.series(
'nps dev.copy-assets-base.electron',
`shx chmod 0755 ${join(
'dist',
'apps',
'electron',
'assets',
'new-workspace'
)}`
),
vscode: nps.series(
'nps dev.copy-assets-base.vscode',
`shx rm -rf ${assetMappings['node-pty-prebuilt'].to}]`,
`shx cp -rf ${assetMappings['node-pty-prebuilt'].from} ${
assetMappings['node-pty-prebuilt'].to
}`.replace(/APPLICATION/g, 'vscode')
}`.replace(/APPLICATION/g, 'vscode')
)
},
'copy-assets-base': electronOrVscode(
nps.concurrent({
schema: `shx cp ${assetMappings['schema'].from} ${
assetMappings['schema'].to
}`,
'ng-cmd': `shx cp ${assetMappings['ng-cmd'].from} ${
assetMappings['ng-cmd'].to
}`,
}`,
'server-assets': `shx cp -rf ${assetMappings['server-assets'].from} ${
assetMappings['server-assets'].to
}`,
}`,
readme: `shx cp ${assetMappings['readme'].from} ${
assetMappings['readme'].to
}`,
}`,
'extensions-schema': `shx cp ${
assetMappings['extensions-schema'].from
} ${assetMappings['extensions-schema'].to}`,
} ${assetMappings['extensions-schema'].to}`,
cli: 'node ./tools/scripts/patch-cli.js'
})
),
Expand Down Expand Up @@ -218,7 +220,7 @@ module.exports = {
: os.platform() === 'darwin'
? 'mac'
: 'linux'
} --dir -p never`
} --dir -p never`
}
}
};
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
"installerIcon": "icons/icon.ico",
"artifactName": "AngularConsole-Setup-${version}.${ext}"
},
"afterPack": "./tools/scripts/after-pack.js",
"publish": [
{
"provider": "github",
Expand All @@ -77,12 +76,14 @@
]
},
"dependencies": {
"@angular/cli": "7.3.0",
"@schematics/angular": "7.3.0",
"@nrwl/schematics": "7.5.1",
"semver": "5.6.0",
"tmp": "0.0.33",
"node-pty-prebuilt": "0.7.6"
},
"devDependencies": {
"@angular/cli": "7.3.0",
"@schematics/angular": "7.3.0",
"@nrwl/schematics": "7.5.1",
"@angular-devkit/build-angular": "0.11.4",
"@angular-devkit/build-ng-packagr": "0.11.4",
"@angular/animations": "7.2.0",
Expand All @@ -106,7 +107,6 @@
"@nrwl/angular-console-enterprise-frontend": "0.0.40",
"@nrwl/builders": "7.5.1",
"@nrwl/nx": "7.5.1",
"@nrwl/schematics": "7.5.1",
"@types/electron-store": "^1.3.0",
"@types/fontfaceobserver": "^0.0.6",
"@types/get-port": "^4.0.1",
Expand Down
18 changes: 0 additions & 18 deletions tools/scripts/after-pack.js

This file was deleted.

0 comments on commit be0722d

Please sign in to comment.