Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/schematics #18

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 89 additions & 2 deletions package-lock.json

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

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"start:prod": "node --max-old-space-size=4096 ./node_modules/.bin/ng serve --prod",
"build": "ng build --prod",
"build:core": "ng build core --prod",
"postbuild:core": "cd ./projects/core && npm run build",
"build:forms": "ng build forms --prod",
"build:core:watch": "ng build core",
"build:forms:watch": "ng build forms",
Expand Down Expand Up @@ -67,6 +68,7 @@
"ng-packagr": "^4.7.1",
"prettier": "1.16.4",
"protractor": "~5.1.2",
"schematics-utilities": "^1.1.2",
"ts-node": "~4.1.0",
"tsickle": ">=0.25.5",
"tslib": "^1.7.1",
Expand Down
8 changes: 8 additions & 0 deletions projects/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
],
"author": "thekiba <[email protected]>",
"license": "MIT",
"scripts": {
"build": "../../node_modules/.bin/tsc -p tsconfig.schematics.json",
"copy:schemas": "cp --parents schematics/*/schema.json ../../dist/core/",
"copy:files": "cp --parents -p schematics/*/files/** ../../dist/core/",
"copy:collection": "cp schematics/collection.json ../../dist/core/schematics/collection.json",
"postbuild": "npm run copy:collection"
},
"repository": {
"type": "git",
"url": "git+https://github.com/IndigoSoft/ngxd.git"
Expand All @@ -27,6 +34,7 @@
"url": "https://github.com/IndigoSoft/ngxd/issues"
},
"homepage": "https://github.com/IndigoSoft/ngxd",
"schematics": "./schematics/collection.json",
"peerDependencies": {
"@angular/common": "^6.0.0-rc.0 || ^6.0.0 || ^7.0.0 || ^8.0.0",
"@angular/core": "^6.0.0-rc.0 || ^6.0.0 || ^7.0.0 || ^8.0.0",
Expand Down
9 changes: 9 additions & 0 deletions projects/core/schematics/collection.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"$schema": "../../../node_modules/@angular-devkit/schematics/collection-schema.json",
"schematics": {
"ng-add": {
"description": "Add my library to the project.",
"factory": "./ng-add/index#ngAdd"
}
}
}
20 changes: 20 additions & 0 deletions projects/core/schematics/ng-add/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Rule, SchematicContext, Tree } from '@angular-devkit/schematics';
import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks';
import { addPackageJsonDependency, NodeDependencyType } from 'schematics-utilities';
import { readFileSync } from 'fs';
import * as path from 'path';

const packageJson = readFileSync(path.join(__dirname, '..', '..', 'package.json'), 'utf8');
const version = JSON.parse(packageJson).version;
// Just return the tree
export function ngAdd(): Rule {
return (tree: Tree, _context: SchematicContext) => {
addPackageJsonDependency(tree, {
type: NodeDependencyType.Default,
version: version,
name: '@ngxd/core',
});
_context.addTask(new NodePackageInstallTask());
return tree;
};
}
35 changes: 35 additions & 0 deletions projects/core/tsconfig.schematics.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"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/core/schematics",
"skipDefaultLibCheck": true,
"skipLibCheck": true,
"sourceMap": true,
"strictNullChecks": true,
"target": "es6",
"types": [
"jasmine",
"node"
]
},
"include": [
"schematics/**/*"
],
"exclude": [
"schematics/*/files/**/*"
]
}