Skip to content

Commit

Permalink
fix(@angular/cli): fix new to work with custom collections
Browse files Browse the repository at this point in the history
  • Loading branch information
vsavkin authored and hansl committed Sep 13, 2017
1 parent 30e54cd commit 645e56b
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 2 deletions.
6 changes: 5 additions & 1 deletion packages/@angular/cli/commands/new.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,11 @@ const NewCommand = Command.extend({
`);
}

commandOptions.collectionName = this.getCollectionName(rawArgs);
if (commandOptions.collection) {
commandOptions.collectionName = commandOptions.collection;
} else {
commandOptions.collectionName = this.getCollectionName(rawArgs);
}

const initCommand = new InitCommand({
ui: this.ui,
Expand Down
12 changes: 11 additions & 1 deletion tests/acceptance/new.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@ describe('Acceptance: ng new', function () {
jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;

spyOn(console, 'error');
// symlink custom collections to node_modules, so we can use with ng new
// it is a bit dirty, but bootstrap-local tricks won't work here
fs.symlinkSync(`${process.cwd()}/tests/collections/@custom`, `./node_modules/@custom`, 'dir');

tmp.setup('./tmp')
.then(() => process.chdir('./tmp'))
.then(() => done());
}, 10000);

afterEach((done) => {
fs.unlinkSync(path.join(__dirname, '/../../node_modules/@custom'));
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
tmp.teardown('./tmp').then(() => done());
});
Expand Down Expand Up @@ -172,6 +176,12 @@ describe('Acceptance: ng new', function () {
expect(pkgJson.devDependencies['@angular/cli']).toMatch(/\d+\.\d+\.\d+/);
})
.then(done, done.fail);
})
});

it('should support passing a custom collection', (done) => {
return ng(['new', 'foo', '--collection=@custom/application', '--skip-install', '--skip-git']).then(() => {
expect(() => fs.readFileSync('emptyapp', 'utf8')).not.toThrow();
})
.then(done, done.fail);
});
});
11 changes: 11 additions & 0 deletions tests/collections/@custom/application/collection.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "@custom/application",
"version": "0.1",
"schematics": {
"application": {
"factory": "./index.js",
"schema": "./schema.json",
"description": "Create an empty application"
}
}
}
Empty file.
6 changes: 6 additions & 0 deletions tests/collections/@custom/application/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const s = require('@angular-devkit/schematics');

exports.default = function(options) {
return s.chain([s.mergeWith(s.apply(
s.url('./files'), [s.template({}), s.move(options.name)]))]);
};
4 changes: 4 additions & 0 deletions tests/collections/@custom/application/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "empty-app",
"schematics": "./collection.json"
}
13 changes: 13 additions & 0 deletions tests/collections/@custom/application/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"$schema": "http://json-schema.org/schema",
"id": "EmptyApp",
"title": "Angular Bazel Workspace Options Schema",
"type": "object",
"properties": {
"name": {
"type": "string"
}
},
"required": [
]
}

0 comments on commit 645e56b

Please sign in to comment.