diff --git a/e2e/schematics/application.test.ts b/e2e/schematics/application.test.ts index 9308ae55e5..93c9b16176 100644 --- a/e2e/schematics/application.test.ts +++ b/e2e/schematics/application.test.ts @@ -1,7 +1,7 @@ import { newApp, newLib, newProject, runCLI, updateFile } from '../utils'; describe('Nrwl Workspace', () => { - it( + fit( 'should work', () => { newProject(); diff --git a/package.json b/package.json index fc330e7d12..20b1e1d6b9 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", diff --git a/packages/schematics/bin/create-nx-workspace.ts b/packages/schematics/bin/create-nx-workspace.ts new file mode 100644 index 0000000000..b0c3f636ea --- /dev/null +++ b/packages/schematics/bin/create-nx-workspace.ts @@ -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] +}); diff --git a/packages/schematics/package.json b/packages/schematics/package.json index 1e03e20cac..2860601886 100644 --- a/packages/schematics/package.json +++ b/packages/schematics/package.json @@ -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" + } } diff --git a/packages/schematics/src/collection/application/application.spec.ts b/packages/schematics/src/collection/application/application.spec.ts index c529ae5c4f..42533acc65 100644 --- a/packages/schematics/src/collection/application/application.spec.ts +++ b/packages/schematics/src/collection/application/application.spec.ts @@ -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', diff --git a/packages/schematics/src/collection/application/files/__directory__/.angular_cli.tgz b/packages/schematics/src/collection/application/files/__directory__/.angular_cli.tgz new file mode 100644 index 0000000000..7a76d96b47 Binary files /dev/null and b/packages/schematics/src/collection/application/files/__directory__/.angular_cli.tgz differ diff --git a/packages/schematics/src/collection/application/files/__directory__/package.json b/packages/schematics/src/collection/application/files/__directory__/package.json index 95b00cb3c5..c96f2354ea 100644 --- a/packages/schematics/src/collection/application/files/__directory__/package.json +++ b/packages/schematics/src/collection/application/files/__directory__/package.json @@ -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", @@ -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 %>" } diff --git a/packages/schematics/src/collection/utility/lib-versions.ts b/packages/schematics/src/collection/utility/lib-versions.ts index 405a5d7909..d0649c3441 100644 --- a/packages/schematics/src/collection/utility/lib-versions.ts +++ b/packages/schematics/src/collection/utility/lib-versions.ts @@ -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'; diff --git a/scripts/copy-clis.sh b/scripts/copy-clis.sh deleted file mode 100755 index 38afdb89fb..0000000000 --- a/scripts/copy-clis.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env bash - -rm -rf ./node_modules/clis -mkdir ./node_modules/clis -cp -rf ./node_modules/@angular/cli ./node_modules/clis/standard diff --git a/yarn.lock b/yarn.lock index daa711ca28..950620f44d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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" @@ -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" @@ -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: