Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions packages/angular-playground/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions packages/angular-playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@
"zone.js": ">=0.8.26"
},
"dependencies": {
"@angular-devkit/core": "^0.7.1",
"@angular-devkit/schematics": "^0.7.1",
"@schematics/angular": "^0.7.1",
"@angular-devkit/core": "^0.7.3",
"@angular-devkit/schematics": "^0.7.3",
"@schematics/angular": "^0.7.3",
"async": "^2.6.0",
"chalk": "^2.4.1",
"commander": "^2.15.1",
Expand Down
5 changes: 5 additions & 0 deletions packages/angular-playground/schematics/src/collection.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
{
"$schema": "../node_modules/@angular-devkit/schematics/collection-schema.json",
"schematics": {
"sandbox": {
"description": "Creates a sandbox file for component in given path",
"factory": "./sandbox",
"schema": "./sandbox/schema.json"
},
"ng-add": {
"description": "Adds Angular Playground to an application",
"factory": "./ng-add"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { sandboxOf } from 'angular-playground';
import { <%= classify(name) %>Component } from './<%= name %>.component';

export default sandboxOf(<%= classify(name) %>Component)
.add('default', {
template: `<<%= selector %>></<%= selector %>>`
});
48 changes: 48 additions & 0 deletions packages/angular-playground/schematics/src/sandbox/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import {
apply,
branchAndMerge,
chain,
mergeWith,
move,
Rule,
SchematicContext,
template,
Tree,
url
} from '@angular-devkit/schematics';
import { strings } from '@angular-devkit/core';
import { getProject, getProjectPath } from '../utils/project';
import { Schema } from './schema';
import { parseName } from '@schematics/angular/utility/parse-name';

export default function sandbox(options: Schema): Rule {
return (host: Tree, context: SchematicContext) => {
if (options.path === undefined) {
options.path = getProjectPath(host, options);
}

const parsedPath = parseName(options.path, options.name);
options.name = parsedPath.name;
options.path = parsedPath.path;

const targetPath = options.flat
? options.path
: `${options.path}/${options.name}`;

const prefix = getProject(host, {}).prefix;
const selector = `${prefix}-${options.name}`;

const templateSource = apply(url('./files'), [
template({
...strings,
selector,
...options,
}),
move(targetPath),
]);

return chain([
branchAndMerge(mergeWith(templateSource))
])(host, context);
}
}
28 changes: 28 additions & 0 deletions packages/angular-playground/schematics/src/sandbox/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"$schema": "http://json-schema.org/schema",
"id": "SchematicsPlaygroundSandbox",
"title": "Angular Playground's Sandbox",
"type": "object",
"properties": {
"name": {
"description": "The name of the component to add the sandbox to.",
"type": "string",
"$default": {
"$source": "argv",
"index": 0
}
},
"path": {
"type": "string",
"format": "path",
"description": "The path to create the sandbox.",
"visible": false
},
"flat": {
"type": "boolean",
"description": "Flag to indicate if a dir is created.",
"default": false
}
},
"required": []
}
16 changes: 16 additions & 0 deletions packages/angular-playground/schematics/src/sandbox/schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export interface Schema {
/**
* The name of the component.
*/
name: string;

/**
* The path to create the sandbox.
*/
path?: string;

/**
* Should the sandbox be created in the component's directory.
*/
flat: boolean;
}