Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 77659d7

Browse files
authored
Merge pull request #127 from sulco/feature/sandbox-schematics
add sandbox schematics #73
2 parents 9d9295e + 573ec71 commit 77659d7

File tree

7 files changed

+120
-16
lines changed

7 files changed

+120
-16
lines changed

‎packages/angular-playground/package-lock.json‎

Lines changed: 13 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/angular-playground/package.json‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@
5858
"zone.js": ">=0.8.26"
5959
},
6060
"dependencies": {
61-
"@angular-devkit/core": "^0.7.1",
62-
"@angular-devkit/schematics": "^0.7.1",
63-
"@schematics/angular": "^0.7.1",
61+
"@angular-devkit/core": "^0.7.3",
62+
"@angular-devkit/schematics": "^0.7.3",
63+
"@schematics/angular": "^0.7.3",
6464
"async": "^2.6.0",
6565
"chalk": "^2.4.1",
6666
"commander": "^2.15.1",

‎packages/angular-playground/schematics/src/collection.json‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
{
22
"$schema": "../node_modules/@angular-devkit/schematics/collection-schema.json",
33
"schematics": {
4+
"sandbox": {
5+
"description": "Creates a sandbox file for component in given path",
6+
"factory": "./sandbox",
7+
"schema": "./sandbox/schema.json"
8+
},
49
"ng-add": {
510
"description": "Adds Angular Playground to an application",
611
"factory": "./ng-add"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { sandboxOf } from 'angular-playground';
2+
import { <%= classify(name) %>Component } from './<%= name %>.component';
3+
4+
export default sandboxOf(<%= classify(name) %>Component)
5+
.add('default', {
6+
template: `<<%= selector %>></<%= selector %>>`
7+
});
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import {
2+
apply,
3+
branchAndMerge,
4+
chain,
5+
mergeWith,
6+
move,
7+
Rule,
8+
SchematicContext,
9+
template,
10+
Tree,
11+
url
12+
} from '@angular-devkit/schematics';
13+
import { strings } from '@angular-devkit/core';
14+
import { getProject, getProjectPath } from '../utils/project';
15+
import { Schema } from './schema';
16+
import { parseName } from '@schematics/angular/utility/parse-name';
17+
18+
export default function sandbox(options: Schema): Rule {
19+
return (host: Tree, context: SchematicContext) => {
20+
if (options.path === undefined) {
21+
options.path = getProjectPath(host, options);
22+
}
23+
24+
const parsedPath = parseName(options.path, options.name);
25+
options.name = parsedPath.name;
26+
options.path = parsedPath.path;
27+
28+
const targetPath = options.flat
29+
? options.path
30+
: `${options.path}/${options.name}`;
31+
32+
const prefix = getProject(host, {}).prefix;
33+
const selector = `${prefix}-${options.name}`;
34+
35+
const templateSource = apply(url('./files'), [
36+
template({
37+
...strings,
38+
selector,
39+
...options,
40+
}),
41+
move(targetPath),
42+
]);
43+
44+
return chain([
45+
branchAndMerge(mergeWith(templateSource))
46+
])(host, context);
47+
}
48+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"$schema": "http://json-schema.org/schema",
3+
"id": "SchematicsPlaygroundSandbox",
4+
"title": "Angular Playground's Sandbox",
5+
"type": "object",
6+
"properties": {
7+
"name": {
8+
"description": "The name of the component to add the sandbox to.",
9+
"type": "string",
10+
"$default": {
11+
"$source": "argv",
12+
"index": 0
13+
}
14+
},
15+
"path": {
16+
"type": "string",
17+
"format": "path",
18+
"description": "The path to create the sandbox.",
19+
"visible": false
20+
},
21+
"flat": {
22+
"type": "boolean",
23+
"description": "Flag to indicate if a dir is created.",
24+
"default": false
25+
}
26+
},
27+
"required": []
28+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
export interface Schema {
2+
/**
3+
* The name of the component.
4+
*/
5+
name: string;
6+
7+
/**
8+
* The path to create the sandbox.
9+
*/
10+
path?: string;
11+
12+
/**
13+
* Should the sandbox be created in the component's directory.
14+
*/
15+
flat: boolean;
16+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /