Skip to content

Commit 645e56b

Browse files
vsavkinhansl
authored andcommitted
fix(@angular/cli): fix new to work with custom collections
1 parent 30e54cd commit 645e56b

File tree

7 files changed

+50
-2
lines changed

7 files changed

+50
-2
lines changed

packages/@angular/cli/commands/new.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,11 @@ const NewCommand = Command.extend({
144144
`);
145145
}
146146

147-
commandOptions.collectionName = this.getCollectionName(rawArgs);
147+
if (commandOptions.collection) {
148+
commandOptions.collectionName = commandOptions.collection;
149+
} else {
150+
commandOptions.collectionName = this.getCollectionName(rawArgs);
151+
}
148152

149153
const initCommand = new InitCommand({
150154
ui: this.ui,

tests/acceptance/new.spec.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,17 @@ describe('Acceptance: ng new', function () {
1515
jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;
1616

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

1922
tmp.setup('./tmp')
2023
.then(() => process.chdir('./tmp'))
2124
.then(() => done());
2225
}, 10000);
2326

2427
afterEach((done) => {
28+
fs.unlinkSync(path.join(__dirname, '/../../node_modules/@custom'));
2529
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
2630
tmp.teardown('./tmp').then(() => done());
2731
});
@@ -172,6 +176,12 @@ describe('Acceptance: ng new', function () {
172176
expect(pkgJson.devDependencies['@angular/cli']).toMatch(/\d+\.\d+\.\d+/);
173177
})
174178
.then(done, done.fail);
175-
})
179+
});
176180

181+
it('should support passing a custom collection', (done) => {
182+
return ng(['new', 'foo', '--collection=@custom/application', '--skip-install', '--skip-git']).then(() => {
183+
expect(() => fs.readFileSync('emptyapp', 'utf8')).not.toThrow();
184+
})
185+
.then(done, done.fail);
186+
});
177187
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "@custom/application",
3+
"version": "0.1",
4+
"schematics": {
5+
"application": {
6+
"factory": "./index.js",
7+
"schema": "./schema.json",
8+
"description": "Create an empty application"
9+
}
10+
}
11+
}

tests/collections/@custom/application/files/emptyapp

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const s = require('@angular-devkit/schematics');
2+
3+
exports.default = function(options) {
4+
return s.chain([s.mergeWith(s.apply(
5+
s.url('./files'), [s.template({}), s.move(options.name)]))]);
6+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "empty-app",
3+
"schematics": "./collection.json"
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"$schema": "http://json-schema.org/schema",
3+
"id": "EmptyApp",
4+
"title": "Angular Bazel Workspace Options Schema",
5+
"type": "object",
6+
"properties": {
7+
"name": {
8+
"type": "string"
9+
}
10+
},
11+
"required": [
12+
]
13+
}

0 commit comments

Comments
 (0)