Skip to content

Commit

Permalink
Merge pull request #40 from lucienbertin/schematics
Browse files Browse the repository at this point in the history
dip - basic shematics integrated to this repo
  • Loading branch information
lucienbertin authored Feb 26, 2019
2 parents 4ed769c + 21c38c8 commit 0c31fa9
Show file tree
Hide file tree
Showing 14 changed files with 202 additions and 21 deletions.
44 changes: 24 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,25 @@
"license": "MIT",
"private": false,
"dependencies": {
"@angular/animations": "^7.0.0",
"@angular/cdk": "^7.0.0",
"@angular/common": "^7.0.0",
"@angular/compiler": "^7.0.0",
"@angular/core": "^7.0.0",
"@angular/forms": "^7.0.0",
"@angular/http": "^7.0.0",
"@angular/material": "^7.0.0",
"@angular/material-moment-adapter": "^7.0.0",
"@angular/platform-browser": "^7.0.0",
"@angular/platform-browser-dynamic": "^7.0.0",
"@angular/platform-server": "^7.0.0",
"@angular/router": "^7.0.0",
"@angular/animations": "^7.2.0",
"@angular/cdk": "^7.2.0",
"@angular/common": "^7.2.0",
"@angular/compiler": "^7.2.0",
"@angular/core": "^7.2.0",
"@angular/forms": "^7.2.0",
"@angular/http": "^7.2.0",
"@angular/material": "^7.2.0",
"@angular/material-moment-adapter": "^7.2.0",
"@angular/platform-browser": "^7.2.0",
"@angular/platform-browser-dynamic": "^7.2.0",
"@angular/platform-server": "^7.2.0",
"@angular/router": "^7.2.0",
"@lucca-front/icons": "^2.0.0",
"@lucca-front/ng": "^2.0.0",
"@lucca-front/scss": "^2.0.0",
"@ngrx/effects": "^6.1.0",
"@ngrx/store": "^6.1.0",
"@ngrx/entity": "^6.1.0",
"@ngrx/store": "^6.1.0",
"@ngrx/store-devtools": "^6.1.0",
"@nguniversal/express-engine": "^7.0.2",
"@nguniversal/module-map-ngfactory-loader": "^7.0.2",
Expand All @@ -40,13 +40,14 @@
"zone.js": "^0.8.19"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.10.0",
"@angular-devkit/build-ng-packagr": "~0.10.0",
"@angular-devkit/build-angular": "^0.12.2",
"@angular-devkit/build-ng-packagr": "^0.12.2",
"@angular-devkit/core": "7.0.4",
"@angular-devkit/schematics": "7.0.4",
"@angular-devkit/schematics-cli": "^0.12.2",
"@angular/cli": "^7.0.4",
"@angular/compiler-cli": "^7.0.0",
"@angular/language-service": "^7.0.0",
"@angular/compiler-cli": "^7.2.0",
"@angular/language-service": "^7.2.0",
"@types/jasmine": "~2.8.9",
"@types/jasminewd2": "~2.0.5",
"@types/node": "~10.12.2",
Expand All @@ -65,7 +66,7 @@
"tsickle": ">=0.29.0",
"tslib": "^1.9.0",
"tslint": "~5.11.0",
"typescript": "~3.1.1",
"typescript": "3.2.2",
"webpack-cli": "^3.1.2"
},
"scripts": {
Expand All @@ -83,6 +84,9 @@
"build:libs": "ng build models && ng build core && ng build store",
"build:apps": "ng build home && ng run home:server",
"build:server": "webpack --config webpack.server.config.js --progress --colors",
"serve": "node ./dist/server.js"
"serve": "node ./dist/server.js",
"build:schematics": "tsc --project schematics",
"link:schematics": "cd schematics && npm link",
"postlink:schematics": "npm link @meteo/schematics"
}
}
3 changes: 3 additions & 0 deletions schematics/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**/*.js
**/*.js.map
**/*.d.ts
1 change: 1 addition & 0 deletions schematics/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/*.ts
28 changes: 28 additions & 0 deletions schematics/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Getting Started With Schematics

This repository is a basic Schematic implementation that serves as a starting point to create and publish Schematics to NPM.

### Testing

To test locally, install `@angular-devkit/schematics-cli` globally and use the `schematics` command line tool. That tool acts the same as the `generate` command of the Angular CLI, but also has a debug mode.

Check the documentation with
```bash
schematics --help
```

### Unit Testing

`npm run test` will run the unit tests, using Jasmine as a runner and test framework.

### Publishing

To publish, simply do:

```bash
npm run build
npm publish
```

That's it!

10 changes: 10 additions & 0 deletions schematics/collection.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"$schema": "../node_modules/@angular-devkit/schematics/collection-schema.json",
"schematics": {
"index": {
"description": "Generate an index.ts file",
"factory": "./index",
"schema": "./index/schema.json"
},
}
}
Empty file added schematics/index/files/index.ts
Empty file.
49 changes: 49 additions & 0 deletions schematics/index/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { strings } from '@angular-devkit/core';
import {
Rule,
SchematicContext,
Tree,
apply,
url,
template,
move,
chain,
branchAndMerge,
mergeWith } from '@angular-devkit/schematics';
import { getWorkspace } from '@schematics/angular/utility/config';
import { parseName } from '@schematics/angular/utility/parse-name';
import { IIndexOptions } from './schema';

export default function example(options: IIndexOptions): Rule {
return (tree: Tree, _context: SchematicContext) => {
const workspace = getWorkspace(tree);
if (!options.project) {
options.project = Object.keys(workspace.projects)[0];
}
const project = workspace.projects[options.project];

if (options.path === undefined) {
const projectDirName = project.projectType === 'application' ? 'app' : 'lib';
options.path = `/${project.root}/src/${projectDirName}`;
}


const parsedPath = parseName(options.path, options.name);
options.name = parsedPath.name;
options.path = `${parsedPath.path}/${parsedPath.name}`;

const templateSource = apply(url('./files'), [
template({
...strings,
...options
}),
move(options.path)
]);
const rule = chain([
branchAndMerge(chain([
mergeWith(templateSource),
]))
]);
return rule(tree, _context);
};
}
28 changes: 28 additions & 0 deletions schematics/index/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"$schema": "http://json-schema.org/schema",
"id": "SchemanticsForIndex",
"title": "Index Schema",
"type": "object",
"properties": {
"name": {
"type": "string",
"$default": {
"$source": "argv",
"index": 0
}
},
"path": {
"type": "string",
"format": "path",
"description": "The path to create the index file.",
"visible": false
},
"project": {
"type": "string",
"description": "The name of the project.",
"$default": {
"$source": "projectName"
}
},
}
}
3 changes: 3 additions & 0 deletions schematics/index/schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { IOptions } from '../schema';

export interface IIndexOptions extends IOptions {}
5 changes: 5 additions & 0 deletions schematics/package-lock.json

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

11 changes: 11 additions & 0 deletions schematics/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "@meteo/schematics",
"version": "0.0.0",
"description": "schematics for meteo fiable",
"keywords": [
"schematics"
],
"author": "lucien bertin <[email protected]>",
"license": "MIT",
"schematics": "./collection.json"
}
6 changes: 6 additions & 0 deletions schematics/schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export interface IOptions {
name: string;
path?: string;
project?: string;
module?: string;
}
32 changes: 32 additions & 0 deletions schematics/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"compilerOptions": {
"baseUrl": "tsconfig",
"lib": [
"es2017",
"dom"
],
"declaration": true,
"module": "commonjs",
"moduleResolution": "node",
"noEmitOnError": true,
"noFallthroughCasesInSwitch": true,
"noImplicitAny": true,
"noImplicitThis": true,
"rootDir": "./",
"skipDefaultLibCheck": true,
"skipLibCheck": true,
"sourceMap": true,
"strictNullChecks": true,
"target": "es6",
"types": [
"jasmine",
"node"
]
},
"include": [
"**/*"
],
"exclude": [
"*/files/**/*"
]
}
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"dist/models"
],
"@meteo/store": [
"dist/store"
// "dist/store"
"libraries/store/src/index"
]
}
}
Expand Down

0 comments on commit 0c31fa9

Please sign in to comment.