forked from angular/angular-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
5319428
commit a84bf55
Showing
10 changed files
with
154 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Copyright Google Inc. All Rights Reserved. | ||
# | ||
# Use of this source code is governed by an MIT-style license that can be | ||
# found in the LICENSE file at https://angular.io/license | ||
|
||
load("//tools:defaults.bzl", "pkg_npm", "ts_library") | ||
|
||
licenses(["notice"]) # MIT | ||
|
||
package(default_visibility = ["//visibility:public"]) | ||
|
||
ts_library( | ||
name = "create", | ||
package_name = "@angular/create", | ||
srcs = glob( | ||
["**/*.ts"], | ||
exclude = [ | ||
# NB: we need to exclude the nested node_modules that is laid out by yarn workspaces | ||
"node_modules/**", | ||
], | ||
), | ||
deps = [ | ||
"//packages/angular/cli:angular-cli", | ||
"@npm//@types/node", | ||
], | ||
) | ||
|
||
genrule( | ||
name = "license", | ||
srcs = ["//:LICENSE"], | ||
outs = ["LICENSE"], | ||
cmd = "cp $(execpath //:LICENSE) $@", | ||
) | ||
|
||
pkg_npm( | ||
name = "npm_package", | ||
deps = [ | ||
":README.md", | ||
":create", | ||
":license", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# `@angular/create` | ||
|
||
# Create an Angular CLI workspace | ||
|
||
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. | ||
|
||
# Usage | ||
|
||
NPM | ||
|
||
``` | ||
npm init @angular@latest [project-name] -- [...options] | ||
``` | ||
|
||
Yarn | ||
|
||
``` | ||
yarn create @angular [project-name] [...options] | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"name": "@angular/create", | ||
"version": "0.0.0-PLACEHOLDER", | ||
"description": "Scaffold an Angular CLI workspace.", | ||
"keywords": [ | ||
"angular", | ||
"angular-cli", | ||
"Angular CLI", | ||
"code generation", | ||
"schematics" | ||
], | ||
"bin": { | ||
"create": "./src/index.js" | ||
}, | ||
"dependencies": { | ||
"@angular/cli": "0.0.0-PLACEHOLDER" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/usr/bin/env node | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import { spawnSync } from 'child_process'; | ||
import { join } from 'path'; | ||
|
||
const binPath = join(require.resolve('@angular/cli/package.json'), '../bin/ng.js'); | ||
|
||
// Invoke ng new with any parameters provided. | ||
const { error } = spawnSync(process.execPath, [binPath, 'new', ...process.argv.slice(2)], { | ||
stdio: 'inherit', | ||
}); | ||
|
||
if (error) { | ||
// eslint-disable-next-line no-console | ||
console.error(error); | ||
process.exitCode = 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { join, resolve } from 'path'; | ||
import { expectFileToExist, rimraf } from '../../utils/fs'; | ||
import { getActivePackageManager } from '../../utils/packages'; | ||
import { silentNpm, silentYarn } from '../../utils/process'; | ||
|
||
export default async function () { | ||
const currentDirectory = process.cwd(); | ||
const newDirectory = resolve('../'); | ||
|
||
const projectName = 'test-project-create'; | ||
|
||
try { | ||
process.chdir(newDirectory); | ||
const packageManager = getActivePackageManager(); | ||
|
||
switch (packageManager) { | ||
case 'npm': | ||
await silentNpm('init', '@angular', projectName, '--', '--skip-install', '--style=scss'); | ||
|
||
break; | ||
case 'yarn': | ||
await silentYarn('create', '@angular', projectName, '--skip-install', '--style=scss'); | ||
|
||
break; | ||
default: | ||
throw new Error(`This test is not configured to use ${packageManager}.`); | ||
} | ||
|
||
await expectFileToExist(join(projectName, 'angular.json')); | ||
// Verify styles was create with correct extension. | ||
await expectFileToExist(join(projectName, 'src/styles.scss')); | ||
} finally { | ||
await rimraf(projectName); | ||
// Change directory back | ||
process.chdir(currentDirectory); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters