-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(schematics): schematics fisrt commit
- Loading branch information
Showing
8 changed files
with
122 additions
and
0 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
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" | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
packages/gantt/schematics/my-service/files/__name@dasherize__.service.ts.template
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,9 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { HttpClient } from '@angular/common/http'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class <%= classify(name) %>Service { | ||
constructor(private http: HttpClient) { } | ||
} |
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,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); | ||
}; | ||
} |
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,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"] | ||
} |
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,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; | ||
} |
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,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; | ||
}; | ||
} |
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,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/**/*"] | ||
} |