31
loading...
This website collects cookies to deliver better user experience
$ schematics blank --name=indepth-dev-schematic
import { Rule, SchematicContext, Tree } from '@angular-devkit/schematics';
// We don't have to export the function by default. we can also have per file more than one rule factory
export function indepthDevSchematic(_options: any): Rule {
return (tree: Tree, _context: SchematicContext) => {
return tree;
};
}
import { Rule, SchematicContext, Tree } from '@angular-devkit/schematics';
// We do not have to export the function as default. You can also have per file more than one rule factory
export function indepthDevSchematic(_options: any): Rule {
return (tree: Tree, _context: SchematicContext) => {
tree.create('readme.md', '#Mentioned is the Read Me file');
return tree;
};
}
$ schematics .:indepth-dev-schematic
$ schematics.: indepth-dev-schematic --dry-run=false
import { Rule, SchematicContext, Tree } from '@angular-devkit/schematics';
import { join } from 'path';
import { capitalize } from '@angular-devkit/core/src/utils/strings';
// We do not have to export the function as default. We can also have per file more than one rule factory
export function indepthDevSchematic(_options: any): Rule {
return (tree: Tree, _context: SchematicContext) => {
const fullname: string = _options.fullname;
const content: string = _options.content;
const extension: string = _options.extension || '.md';
tree.create(join(fullname, extension), capitalize(content));
return tree;
};
}
export interface Schema {
fullname:string;
content:string;
extension?:string;
}
import { Rule, SchematicContext, Tree } from '@angular-devkit/schematics';
import { join } from 'path';
import { capitalize } from '@angular-devkit/core/src/utils/strings';
import { Schema } from './app/schema';
// We do not have to export the function as default. We can also have per file more than one rule factory
export function indepthDevSchematic(_options: Schema): Rule {
return (tree: Tree, _context: SchematicContext) => {
const fullname: string = _options.fullname;
const content: string = _options.content;
const extension: string = _options.extension || '.md';
tree.create(join(fullname, extension), capitalize(content));
return tree;
};
}
{
"$schema": "http://json-schema.org/schema",
"id": "indepth-dev-schematics",
"title": "Demo of Schematics",
"type": "object",
"properties": {
"fullname": {
"description": "File name, also same to its path",
"type": "string",
"$default": {
"$source": "argv",
"index": 0
}
},
"content": {
"description": "content of something for that file",
"type": "string",
"$default": {
"$source": "argv",
"index": 1
}
},
"extension": {
"description": "An extension for that file and markdown is to defaults",
"type": "string",
"default": ".md"
}
},
"required": [
"name", "content"
]
}
{
"$schema": "../node_modules/@angular-devkit/schematics/collection-schema.json",
"schematics": {
"indepth-dev-schematic": {
"description": "A Demo of the blank schematic.",
"factory": "./indepth-dev-schematic/index#indepthDevSchematic",
"schema": "./indepth-dev-schematic/schema.json"
}
}
}
{
"$schema": "http://json-schema.org/schema",
"id": "indepth-dev-schematics",
"title": "Demo of Schematics",
"type": "object",
"properties": {
"fullname": {
"description": "File name, also same to its path",
"type": "string",
"x-prompt": "What is your file name? (matches path)"
},
"content": {
"description": "content of something for that file",
"type": "string",
"x-prompt": "Please Enter some content for your file"
},
"extension": {
"description": "An extension for that file and markdown is to defaults",
"type": "string",
"default": ".md"
}
},
"required": [
"name", "content"
]
}
{
"$schema": "../node_modules/@angular-devkit/schematics/collection-schema.json",
"schematics": {
"indepth-dev-schematic": {
"description": "A Demo of the blank schematic.",
"factory": "./indepth-dev-schematic/index#indepthDevSchematic",
"schema": "./indepth-dev-schematic/schema.json",
"aliases": ["dive"]
}
}
}
$ schematics .:dive
$ npm link
$ npm link indepth-dev-schematic
import { Rule,SchematicsException,SchematicContext, Tree } from '@angular-devkit/schematics';
import { join } from 'path';
import { capitalize } from '@angular-devkit/core/src/utils/strings';
import { Schema } from './app/schema';
// We do not have to export the function as default. We can also have per file more than one rule factory
export function indepthDevSchematic(_options: Schema): Rule {
return (tree: Tree, _context: SchematicContext) => {
const fullname: string = _options.fullname;
const content: string = _options.content;
const extension: string = _options.extension || '.md';
const path = join(name, extension);
const angularConfig = 'angular.json';
// Let we ensure that we are in an angular workspace
if (!tree.exists(angularConfig)) {
throw new SchematicsException('It is not an Angular worksapce. Please Try again in an Angular project.');
} else {
if (!tree.exists(path)) {
tree.create(path, capitalize(content));
} else {
throw new SchematicsException('This name of file is already exists! Please try a different or new name');
}
}
return tree;
};
}
$ ng generate indepth-dev-schematic:dive