Skip to content

Commit

Permalink
fix(schematics): added Store workspace schematics
Browse files Browse the repository at this point in the history
  • Loading branch information
xmlking committed Oct 1, 2018
1 parent 14b44c0 commit 29a7fbe
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 22 deletions.
3 changes: 2 additions & 1 deletion PLAYBOOK.md
Expand Up @@ -392,7 +392,8 @@ ng g component containers/ledDemo --project=experiments --dry-run
# generate workspace-schematic `store`
ng g workspace-schematic store
# run workspace-schematic `store`
npm run workspace-schematic store models/sumo -- --type=model --project=grid --dry-run
# *** always delete ./dist folder when you change schematic implementation ***
npm run workspace-schematic store models/sumoDemo -- --project=grid --dry-run
```

### Install
Expand Down
6 changes: 0 additions & 6 deletions tools/schematics/store/_files/__name__.store.ts

This file was deleted.

@@ -0,0 +1,5 @@
export class <%= classify(name) %>State {
constructor() {

}
}
62 changes: 53 additions & 9 deletions tools/schematics/store/index.ts
@@ -1,13 +1,57 @@
import { chain, externalSchematic, Rule } from '@angular-devkit/schematics';
import {
apply,
branchAndMerge,
chain,
mergeWith,
move,
Rule,
SchematicContext,
SchematicsException,
template,
Tree,
url,
} from '@angular-devkit/schematics';
import { strings } from '@angular-devkit/core';

import { Schema as featureOptions } from './schema';

import { getWorkspace } from '@schematics/angular/utility/config';
import { parseName } from '@schematics/angular/utility/parse-name';
import { buildDefaultPath } from '@schematics/angular/utility/project';
import { findModuleFromOptions } from '@schematics/angular/utility/find-module';
import { validateName } from '@schematics/angular/utility//validation';

export default function store(options: featureOptions): Rule {
return chain([
externalSchematic('@nrwl/schematics', 'class',
options)
// {
// name: options.name,
// project: options.project,
// }),
]);
return (host: Tree, context: SchematicContext) => {
const workspace = getWorkspace(host);
if (!options.project) {
throw new SchematicsException('Option (project) is required.');
}
const project = workspace.projects[options.project];

if (options.path === undefined) {
options.path = buildDefaultPath(project);
}

options.module = findModuleFromOptions(host, options);

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

validateName(options.name);
console.log(options);

const templateSource = apply(url('./_files'), [
template({
...strings,
...options,
}),
// move(parsedPath.path),
]);

const rule = chain([branchAndMerge(chain([mergeWith(templateSource)]))]);

return rule(host, context);
};
}
9 changes: 3 additions & 6 deletions tools/schematics/store/schema.d.ts
@@ -1,11 +1,8 @@
export interface Schema {
name: string;
/**
* Target apps
*/
projects?: string;
/**
* dry run
*/
dryRun?: boolean;
path?: string;
project?: string;
module?: string;
}

0 comments on commit 29a7fbe

Please sign in to comment.