Skip to content

Commit

Permalink
feat(schematics): replace install.sh with a more robust way of creati…
Browse files Browse the repository at this point in the history
…ng new workspaces
  • Loading branch information
vsavkin committed Dec 17, 2017
1 parent a7f06ed commit f91b530
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 18 deletions.
2 changes: 1 addition & 1 deletion e2e/schematics/application.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { newApp, newLib, newProject, runCLI, updateFile } from '../utils';

describe('Nrwl Workspace', () => {
it(
fit(
'should work',
() => {
newProject();
Expand Down
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@
"test:nx": "yarn build && ./scripts/test_nx.sh",
"test": "yarn build && ./scripts/test_nx.sh && ./scripts/test_schematics.sh",
"checkformat": "./scripts/check-format.sh",
"publish_npm": "./scripts/publish.sh",
"postinstall": "./scripts/copy-clis.sh"
"publish_npm": "./scripts/publish.sh"
},
"dependencies": {
"jasmine-marbles": "0.1.0"
},
"devDependencies": {
"@angular/cli": "nrwl/fix-cli-build#release16",
"@angular/cli": "file:./packages/schematics/src/collection/application/files/__directory__/.angular_cli.tgz",
"@angular/common": "5.0.0",
"@angular/compiler": "5.0.0",
"@angular/compiler-cli": "5.0.0",
Expand All @@ -49,7 +48,9 @@
"rxjs": "^5.5.2",
"tslint": "5.7.0",
"typescript": "2.5.3",
"strip-json-comments": "2.0.1"
"strip-json-comments": "2.0.1",
"tmp": "0.0.33",
"semver": "5.4.1"
},
"author": "Victor Savkin",
"license": "MIT",
Expand Down
54 changes: 54 additions & 0 deletions packages/schematics/bin/create-nx-workspace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env node

import { execSync } from 'child_process';
import { dirSync } from 'tmp';
import { lt } from 'semver';
import { readFileSync, writeFileSync } from 'fs';
import * as path from 'path';

// check the correct version of the NPM is installed
const output = execSync('npm --version').toString();
if (lt(output, '5.0.0')) {
console.log('To create a workspace you must have NPM >= 5.0.0 installed.');
process.exit(1);
}

// check that the workspace name is passed in
if (process.argv.length < 3) {
console.error('Please provide a project name (e.g., create-nx-workspace nrwl-proj');
process.exit(1);
}

// creating the sandbox
console.log('Creating a sandbox with the CLI and Nx Schematics...');
const tmpDir = dirSync().name;
const nxVersion = JSON.parse(readFileSync(path.join(path.dirname(__dirname), 'package.json'), 'UTF-8')).version;
writeFileSync(
path.join(tmpDir, 'package.json'),
JSON.stringify({
dependencies: {
'@nrwl/schematics': nxVersion,
'@angular/cli': `file:${path.join(
path.dirname(__dirname),
'src',
'collection',
'application',
'files',
'__directory__',
'.angular_cli.tgz'
)}`
}
})
);

execSync('npm install --silent', { cwd: tmpDir, stdio: [0, 1, 2] });

// creating the app itself
const args = process.argv
.slice(2)
.map(a => `"${a}"`)
.join(' ');
console.log(`ng new ${args} --collection=@nrwl/schematics`);
execSync(`${path.join(tmpDir, 'node_modules', '.bin', 'ng')} new ${args} --collection=@nrwl/schematics`, {
stdio: [0, 1, 2]
});
9 changes: 8 additions & 1 deletion packages/schematics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,17 @@
"name": "@nrwl/schematics",
"version": "0.0.1",
"description": "Nrwl Extensions for Angular: Schematics",
"bin": {
"create-nx-workspace": "./bin/create-nx-workspace.js"
},
"main": "index.js",
"types": "index.d.js",
"peerDependencies" :{},
"author": "Victor Savkin",
"license": "MIT",
"schematics": "./src/collection.json"
"schematics": "./src/collection.json",
"dependencies": {
"tmp": "0.0.33",
"semver": "5.4.1"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ describe('application', () => {
it('should generate files', () => {
const tree = schematicRunner.runSchematic('application', { name: 'myApp', directory: 'my-app' }, appTree);
expect(tree.files).toEqual([
'/my-app/.angular_cli.tgz',
'/my-app/README.md',
'/my-app/.angular-cli.json',
'/my-app/.editorconfig',
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"@types/jasmine": "~2.5.53",
"@types/jasminewd2": "~2.0.2",
"@types/node": "~6.0.60",
"codelyzer": "~3.1.1",
"codelyzer": "^4.0.1",
"jasmine-core": "~2.6.2",
"jasmine-spec-reporter": "~4.1.0",
"karma": "~1.7.0",
Expand All @@ -51,7 +51,7 @@
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.1.2",
"ts-node": "~3.2.0",
"tslint": "~5.3.2",<% } %>
"tslint": "~5.7.0",<% } %>
"typescript": "<%= typescriptVersion %>",
"prettier": "<%= prettierVersion %>"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/schematics/src/collection/utility/lib-versions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const angularCliVersion = 'nrwl/fix-cli-build#release16';
export const angularCliVersion = 'file:.angular_cli.tgz';
export const angularVersion = '5.1.0';
export const angularJsVersion = '1.6.6';
export const ngrxVersion = '4.1.1';
Expand Down
5 changes: 0 additions & 5 deletions scripts/copy-clis.sh

This file was deleted.

8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
minimist "^1.2.0"
rxjs "^5.5.2"

"@angular/cli@nrwl/fix-cli-build#release16":
"@angular/cli@file:./packages/schematics/src/collection/application/files/__directory__/.angular_cli.tgz":
version "1.6.0"
resolved "https://codeload.github.com/nrwl/fix-cli-build/tar.gz/c75958e7f32f5997421fe6351f49367e5c43313a"
resolved "file:./packages/schematics/src/collection/application/files/__directory__/.angular_cli.tgz#5a19107a74a7454c97d6947508ca12e83a2bdc9d"
dependencies:
"@angular-devkit/build-optimizer" "~0.0.35"
"@angular-devkit/schematics" "~0.0.41"
Expand Down Expand Up @@ -5185,7 +5185,7 @@ selfsigned@^1.9.1:
dependencies:
node-forge "0.6.33"

"semver@2 || 3 || 4 || 5", semver@^5.1.0, semver@^5.3.0:
"semver@2 || 3 || 4 || 5", semver@5.4.1, semver@^5.1.0, semver@^5.3.0:
version "5.4.1"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.4.1.tgz#e059c09d8571f0540823733433505d3a2f00b18e"

Expand Down Expand Up @@ -5727,7 +5727,7 @@ tmp@0.0.31:
dependencies:
os-tmpdir "~1.0.1"

tmp@0.0.x:
tmp@0.0.33, tmp@0.0.x:
version "0.0.33"
resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.0.33.tgz#6d34335889768d21b2bcda0aa277ced3b1bfadf9"
dependencies:
Expand Down

0 comments on commit f91b530

Please sign in to comment.