Skip to content

Commit fc506e0

Browse files
committed
feat(@angular/create): add support for yarn create and npm init
With this change we add support to scaffold an Angular workspace using `yarn create @angular` and `npm init @angular`. These shortcuts support all of the `ng-new` options. Closes angular#10339 and closes angular#14292
1 parent 5319428 commit fc506e0

File tree

10 files changed

+152
-2
lines changed

10 files changed

+152
-2
lines changed

.monorepo.json

+10
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@
1414
],
1515
"snapshotRepo": "angular/cli-builds"
1616
},
17+
"@angular/create": {
18+
"name": "Angular Create",
19+
"section": "Tooling",
20+
"links": [
21+
{
22+
"label": "README",
23+
"url": "/packages/angular/create/README.md"
24+
}
25+
]
26+
},
1727
"@angular/pwa": {
1828
"name": "Angular PWA Schematics",
1929
"section": "Schematics",

CONTRIBUTING.md

+1
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ The scope should be the name of the npm package affected as perceived by the per
212212
The following is the list of supported scopes:
213213
214214
* **@angular/cli**
215+
* **@angular/create**
215216
* **@angular/pwa**
216217
* **@angular-devkit/architect**
217218
* **@angular-devkit/architect-cli**

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ This is a monorepo which contains many tools and packages:
149149
| Project | Package | Version | Links |
150150
|---|---|---|---|
151151
**Angular CLI** | [`@angular/cli`](https://npmjs.com/package/@angular/cli) | [![latest](https://img.shields.io/npm/v/%40angular%2Fcli/latest.svg)](https://npmjs.com/package/@angular/cli) | [![README](https://img.shields.io/badge/README--green.svg)](/packages/angular/cli/README.md) [![snapshot](https://img.shields.io/badge/snapshot--blue.svg)](https://github.com/angular/cli-builds)
152+
**Angular Create** | [`@angular/create`](https://npmjs.com/package/@angular/create) | [![latest](https://img.shields.io/npm/v/%40angular%2Fcreate/latest.svg)](https://npmjs.com/package/@angular/create) | [![README](https://img.shields.io/badge/README--green.svg)](/packages/angular/create/README.md)
152153
**Architect CLI** | [`@angular-devkit/architect-cli`](https://npmjs.com/package/@angular-devkit/architect-cli) | [![latest](https://img.shields.io/npm/v/%40angular-devkit%2Farchitect-cli/latest.svg)](https://npmjs.com/package/@angular-devkit/architect-cli) | [![snapshot](https://img.shields.io/badge/snapshot--blue.svg)](https://github.com/angular/angular-devkit-architect-cli-builds)
153154
**Schematics CLI** | [`@angular-devkit/schematics-cli`](https://npmjs.com/package/@angular-devkit/schematics-cli) | [![latest](https://img.shields.io/npm/v/%40angular-devkit%2Fschematics-cli/latest.svg)](https://npmjs.com/package/@angular-devkit/schematics-cli) | [![snapshot](https://img.shields.io/badge/snapshot--blue.svg)](https://github.com/angular/angular-devkit-schematics-cli-builds)
154155

packages/angular/create/BUILD.bazel

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Copyright Google Inc. All Rights Reserved.
2+
#
3+
# Use of this source code is governed by an MIT-style license that can be
4+
# found in the LICENSE file at https://angular.io/license
5+
6+
load("//tools:defaults.bzl", "pkg_npm", "ts_library")
7+
8+
licenses(["notice"]) # MIT
9+
10+
package(default_visibility = ["//visibility:public"])
11+
12+
ts_library(
13+
name = "create",
14+
package_name = "@angular/create",
15+
srcs = glob(
16+
["**/*.ts"],
17+
exclude = [
18+
# NB: we need to exclude the nested node_modules that is laid out by yarn workspaces
19+
"node_modules/**",
20+
],
21+
),
22+
deps = [
23+
"//packages/angular/cli:angular-cli",
24+
"@npm//@types/node",
25+
],
26+
)
27+
28+
genrule(
29+
name = "license",
30+
srcs = ["//:LICENSE"],
31+
outs = ["LICENSE"],
32+
cmd = "cp $(execpath //:LICENSE) $@",
33+
)
34+
35+
pkg_npm(
36+
name = "npm_package",
37+
deps = [
38+
":README.md",
39+
":create",
40+
":license",
41+
],
42+
)

packages/angular/create/README.md

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# `@angular/create`
2+
3+
# Create an Angular CLI workspace
4+
5+
Scaffold an Angular CLI workspace without needing to install the Angular CLI globally. All of the [ng new](https://angular.io/cli/new) options and features are supported.
6+
7+
# Usage
8+
9+
NPM
10+
11+
```
12+
npm init @angular@latest [project-name] -- [...options]
13+
```
14+
15+
Yarn
16+
17+
```
18+
yarn create @angular [project-name] [...options]
19+
```

packages/angular/create/package.json

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "@angular/create",
3+
"version": "0.0.0-PLACEHOLDER",
4+
"description": "Scaffold an Angular CLI workspace.",
5+
"keywords": [
6+
"angular",
7+
"angular-cli",
8+
"Angular CLI",
9+
"code generation",
10+
"schematics"
11+
],
12+
"bin": {
13+
"create": "./src/index.js"
14+
},
15+
"dependencies": {
16+
"@angular/cli": "0.0.0-PLACEHOLDER"
17+
}
18+
}

packages/angular/create/src/index.ts

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env node
2+
/**
3+
* @license
4+
* Copyright Google LLC All Rights Reserved.
5+
*
6+
* Use of this source code is governed by an MIT-style license that can be
7+
* found in the LICENSE file at https://angular.io/license
8+
*/
9+
10+
import cli from '@angular/cli';
11+
import path from 'path';
12+
13+
// Invoke ng new with any parameters provided.
14+
void cli({ cliArgs: ['new', ...process.argv.slice(2)] })
15+
.then((exitCode) => {
16+
process.exitCode = exitCode;
17+
})
18+
.catch((e) => {
19+
// eslint-disable-next-line no-console
20+
console.error(e);
21+
process.exitCode = 1;
22+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { join, resolve } from 'path';
2+
import { expectFileToExist, rimraf } from '../../utils/fs';
3+
import { getActivePackageManager } from '../../utils/packages';
4+
import { silentNpm, silentYarn } from '../../utils/process';
5+
6+
export default async function () {
7+
const currentDirectory = process.cwd();
8+
const newDirectory = resolve('../');
9+
10+
const projectName = 'test-project-create';
11+
12+
try {
13+
process.chdir(newDirectory);
14+
const packageManager = getActivePackageManager();
15+
16+
switch (packageManager) {
17+
case 'npm':
18+
await silentNpm('init', '@angular', projectName, '--', '--skip-install', '--style=scss');
19+
20+
break;
21+
case 'yarn':
22+
await silentYarn('create', '@angular', projectName, '--skip-install', '--style=scss');
23+
24+
break;
25+
default:
26+
throw new Error(`This test is not configured to use ${packageManager}.`);
27+
}
28+
29+
await expectFileToExist(join(projectName, 'angular.json'));
30+
// Verify styles was create with correct extension.
31+
await expectFileToExist(join(projectName, 'src/styles.scss'));
32+
} finally {
33+
await rimraf(projectName);
34+
// Change directory back
35+
process.chdir(currentDirectory);
36+
}
37+
}

tests/legacy-cli/e2e/utils/project.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export async function prepareProjectForE2e(name: string) {
3939
const argv: yargsParser.Arguments = getGlobalVariable('argv');
4040

4141
await git('config', 'user.email', '[email protected]');
42-
await git('config', 'user.name', 'Angular CLI E2e');
42+
await git('config', 'user.name', 'Angular CLI E2E');
4343
await git('config', 'commit.gpgSign', 'false');
4444

4545
if (argv['ng-snapshots'] || argv['ng-tag']) {

tests/legacy-cli/verdaccio.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ uplinks:
1717
maxFreeSockets: 8
1818

1919
packages:
20-
'@angular/{cli,pwa}':
20+
'@angular/{create,cli,pwa}':
2121
access: $all
2222
publish: $all
2323

0 commit comments

Comments
 (0)