Skip to content

Commit 00deb58

Browse files
committed
feat: add schematics - wip
1 parent 28c35ab commit 00deb58

File tree

7 files changed

+77
-4
lines changed

7 files changed

+77
-4
lines changed

package.json

+8-4
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@
99
"build:date-adapters": "tsc -p tsconfig-date-adapters.json",
1010
"build:styles": "node-sass projects/angular-calendar/src/angular-calendar.scss | postcss --output dist/angular-calendar/css/angular-calendar.css",
1111
"build:clean": "del-cli dist",
12-
"build:copyfiles": "copyfiles CHANGELOG.md README.md LICENSE dist/angular-calendar & cp-cli projects/angular-calendar/util/date-adapter-package.json dist/angular-calendar/date-adapters/date-fns/package.json & cp-cli projects/angular-calendar/util/date-adapter-package.json dist/angular-calendar/date-adapters/moment/package.json & copyfiles -u 3 projects/angular-calendar/src/**/*.scss dist/angular-calendar/scss",
13-
"build": "run-s build:copy-package-json build:lib build:date-adapters build:styles build:copyfiles",
12+
"build:schematics": "tsc projects/angular-calendar/schematics/ng-add/index.ts",
13+
"build:copyfiles": "copyfiles CHANGELOG.md README.md LICENSE dist/angular-calendar & cp-cli projects/angular-calendar/util/date-adapter-package.json dist/angular-calendar/date-adapters/date-fns/package.json & cp-cli projects/angular-calendar/util/date-adapter-package.json dist/angular-calendar/date-adapters/moment/package.json & copyfiles -u 3 projects/angular-calendar/src/**/*.scss dist/angular-calendar/scss & npx copyfiles -u 2 \"projects/angular-calendar/schematics/**/*.{json,js}\" dist/angular-calendar",
14+
"build": "run-s build:copy-package-json build:lib build:date-adapters build:styles build:schematics build:copyfiles",
1415
"test:single": "cross-env TZ=UTC ng test angular-calendar --watch=false --code-coverage",
1516
"test:watch": "cross-env TZ=UTC ng test angular-calendar",
16-
"test": "run-s lint test:single build build:clean",
17+
"test:schematics": "TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' mocha --require ts-node/register projects/angular-calendar/schematics/**/*.spec.ts",
18+
"test": "run-s lint test:single test:schematics build build:clean",
1719
"lint:styles": "stylelint \"{projects,src}/**/*.scss\" --fix",
1820
"lint:ts": "ng lint",
1921
"lint": "run-s lint:ts lint:styles",
@@ -34,6 +36,7 @@
3436
"gh-pages:deploy": "ngh --dir=dist/demos --no-silent",
3537
"gh-pages": "run-s build:clean gh-pages:demos gh-pages:compodoc gh-pages:deploy build:clean"
3638
},
39+
"schematics": "./schematics/collection.json",
3740
"config": {
3841
"commitizen": {
3942
"path": "@commitlint/prompt"
@@ -52,7 +55,8 @@
5255
"angular",
5356
"angular2",
5457
"angular6",
55-
"calendar"
58+
"calendar",
59+
"schematics"
5660
],
5761
"author": "Matt Lewis",
5862
"license": "MIT",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
**/*.js
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"$schema": "../../../node_modules/@angular-devkit/schematics/collection-schema.json",
3+
"schematics": {
4+
"ng-add": {
5+
"description": "Adds angular-calendar to your project",
6+
"factory": "./ng-add/index",
7+
"schema": "./ng-add/schema.json",
8+
"aliases": ["install"]
9+
}
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { Tree } from '@angular-devkit/schematics';
2+
import { SchematicTestRunner } from '@angular-devkit/schematics/testing';
3+
import * as path from 'path';
4+
import { expect } from 'chai';
5+
6+
const collectionPath = path.join(__dirname, '../collection.json');
7+
8+
describe('angular-calendar schematics', () => {
9+
it('works', async () => {
10+
const runner = new SchematicTestRunner('schematics', collectionPath);
11+
const tree = await runner
12+
.runSchematicAsync('ng-add', {}, Tree.empty())
13+
.toPromise();
14+
15+
expect(tree.files).to.deep.equal([]);
16+
});
17+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { Rule, SchematicContext, Tree } from '@angular-devkit/schematics';
2+
import { Schema } from './schema';
3+
4+
export default function(options: Schema): Rule {
5+
return (tree: Tree, _context: SchematicContext) => {
6+
return tree;
7+
};
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"$schema": "http://json-schema.org/schema",
3+
"id": "angular-calendar-schematic-ng-add",
4+
"title": "angular-calendar ng-add schematic",
5+
"type": "object",
6+
"properties": {
7+
"dateAdapter": {
8+
"description": "Which date adapter to use",
9+
"type": "string",
10+
"default": "date-fns",
11+
"x-prompt": {
12+
"message": "What date adapter would you like to use?",
13+
"type": "list",
14+
"items": [
15+
{ "value": "date-fns", "label": "date-fns [ https://date-fns.org/ ]" },
16+
{ "value": "moment", "label": "moment [ https://momentjs.com/ ]" }
17+
]
18+
}
19+
},
20+
"module": {
21+
"type": "string",
22+
"description": "Where to add the module import",
23+
"x-prompt": "Please enter a path to the NgModule that will use the calendar"
24+
}
25+
},
26+
"required": [],
27+
"additionalProperties": false
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export interface Schema {
2+
dateAdapter: 'date-fns' | 'moment';
3+
module: string;
4+
}

0 commit comments

Comments
 (0)