Skip to content

Commit

Permalink
feat(schematics): schematics fisrt commit
Browse files Browse the repository at this point in the history
  • Loading branch information
walkerkay committed Jul 4, 2020
1 parent 0983f9b commit fe36263
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/gantt/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
{
"name": "@worktile/gantt",
"version": "0.0.21",
"schematics": "./schematics/collection.json",
"scripts": {
"build": "../../node_modules/.bin/tsc -p tsconfig.schematics.json",
"copy:schemas": "cp --parents schematics/*/schema.json ../../dist/gantt/",
"copy:files": "cp --parents -p schematics/*/files/** ../../dist/gantt/",
"copy:collection": "cp schematics/collection.json ../../dist/gantt/schematics/collection.json",
"postbuild": "npm run copy:schemas && npm run copy:files && npm run copy:collection"
},
"peerDependencies": {
"@angular/common": "^8.2.14",
"@angular/core": "^8.2.14"
Expand Down
14 changes: 14 additions & 0 deletions packages/gantt/schematics/collection.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"$schema": "../../../node_modules/@angular-devkit/schematics/collection-schema.json",
"schematics": {
"ng-add": {
"description": "Add my library to the project.",
"factory": "./ng-add/index#ngAdd"
},
"my-service": {
"description": "Generate a service in the project.",
"factory": "./my-service/index#myService",
"schema": "./my-service/schema.json"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';

@Injectable({
providedIn: 'root'
})
export class <%= classify(name) %>Service {
constructor(private http: HttpClient) { }
}
20 changes: 20 additions & 0 deletions packages/gantt/schematics/my-service/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Rule, Tree, SchematicsException, apply, url, applyTemplates, move, chain, mergeWith } from '@angular-devkit/schematics';

import { strings, normalize, experimental } from '@angular-devkit/core';

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

export function myService(options: MyServiceSchema): Rule {
return (tree: Tree) => {
const workspaceConfig = tree.read('/angular.json');
if (!workspaceConfig) {
throw new SchematicsException('Could not find Angular workspace configuration');
}

// convert workspace to string
const workspaceContent = workspaceConfig.toString();

// parse workspace string into JSON object
const workspace: experimental.workspace.WorkspaceSchema = JSON.parse(workspaceContent);
};
}
26 changes: 26 additions & 0 deletions packages/gantt/schematics/my-service/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"$schema": "http://json-schema.org/schema",
"id": "SchematicsMyService",
"title": "My Service Schema",
"type": "object",
"properties": {
"name": {
"description": "The name of the service.",
"type": "string"
},
"path": {
"type": "string",
"format": "path",
"description": "The path to create the service.",
"visible": false
},
"project": {
"type": "string",
"description": "The name of the project.",
"$default": {
"$source": "projectName"
}
}
},
"required": ["name"]
}
10 changes: 10 additions & 0 deletions packages/gantt/schematics/my-service/schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export interface Schema {
// The name of the service.
name: string;

// The path to create the service.
path?: string;

// The name of the project.
project?: string;
}
10 changes: 10 additions & 0 deletions packages/gantt/schematics/ng-add/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Rule, SchematicContext, Tree } from '@angular-devkit/schematics';
import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks';

// Just return the tree
export function ngAdd(_options: any): Rule {
return (tree: Tree, _context: SchematicContext) => {
_context.addTask(new NodePackageInstallTask());
return tree;
};
}
25 changes: 25 additions & 0 deletions packages/gantt/tsconfig.schematics.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"compilerOptions": {
"baseUrl": ".",
"lib": ["es2018", "dom"],
"declaration": true,
"module": "commonjs",
"moduleResolution": "node",
"noEmitOnError": true,
"noFallthroughCasesInSwitch": true,
"noImplicitAny": true,
"noImplicitThis": true,
"noUnusedParameters": true,
"noUnusedLocals": true,
"rootDir": "schematics",
"outDir": "../../dist/gantt/schematics",
"skipDefaultLibCheck": true,
"skipLibCheck": true,
"sourceMap": true,
"strictNullChecks": true,
"target": "es6",
"types": ["jasmine", "node"]
},
"include": ["schematics/**/*"],
"exclude": ["schematics/*/files/**/*"]
}

0 comments on commit fe36263

Please sign in to comment.