feat(schematics): replace install.sh with a more robust way of creating new workspaces
This commit is contained in:
parent
a7f06edf59
commit
f91b5309bd
@ -1,7 +1,7 @@
|
||||
import { newApp, newLib, newProject, runCLI, updateFile } from '../utils';
|
||||
|
||||
describe('Nrwl Workspace', () => {
|
||||
it(
|
||||
fit(
|
||||
'should work',
|
||||
() => {
|
||||
newProject();
|
||||
|
||||
@ -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",
|
||||
|
||||
54
packages/schematics/bin/create-nx-workspace.ts
Normal file
54
packages/schematics/bin/create-nx-workspace.ts
Normal file
@ -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]
|
||||
});
|
||||
@ -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"
|
||||
}
|
||||
}
|
||||
|
||||
@ -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',
|
||||
|
||||
Binary file not shown.
@ -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 %>"
|
||||
}
|
||||
|
||||
@ -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';
|
||||
|
||||
@ -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
|
||||
@ -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:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user