@ng-atomic/schematics 5.1.2 → 5.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,62 @@
1
+ {
2
+ "extends": [],
3
+ "schematics": {
4
+ "style-header": {
5
+ "aliases": ["sh"],
6
+ "description": "Add style header",
7
+ "factory": "./src/style-header/index",
8
+ "schema": "./src/style-header/schema.json"
9
+ },
10
+ "atomic-component": {
11
+ "aliases": ["ac"],
12
+ "description": "Create an atomic component",
13
+ "factory": "./src/atomic-component/index#atomicComponent",
14
+ "schema": "./src/atomic-component/schema.json"
15
+ },
16
+ "atom": {
17
+ "description": "Create an atom.",
18
+ "factory": "./src/atomic-component/index#atom",
19
+ "schema": "./src/atomic-component/schema.json"
20
+ },
21
+ "molecule": {
22
+ "description": "Create a molecule.",
23
+ "factory": "./src/atomic-component/index#molecule",
24
+ "schema": "./src/atomic-component/schema.json"
25
+ },
26
+ "organism": {
27
+ "description": "Create a organism.",
28
+ "factory": "./src/atomic-component/index#organism",
29
+ "schema": "./src/atomic-component/schema.json"
30
+ },
31
+ "template": {
32
+ "description": "Create a template.",
33
+ "factory": "./src/atomic-component/index#template",
34
+ "schema": "./src/atomic-component/schema.json"
35
+ },
36
+ "frame": {
37
+ "description": "Create a template.",
38
+ "factory": "./src/atomic-component/index#frame",
39
+ "schema": "./src/atomic-component/schema.json"
40
+ },
41
+ "page": {
42
+ "description": "Create a page",
43
+ "factory": "./src/page/index#page",
44
+ "schema": "./src/atomic-component/schema.json"
45
+ },
46
+ "pages": {
47
+ "description": "Create a pages",
48
+ "factory": "./src/pages/index#pages",
49
+ "schema": "./src/pages/schema.json"
50
+ },
51
+ "ng-add": {
52
+ "description": "Add angular-atomic-schematics",
53
+ "factory": "./src/ng-add/index",
54
+ "schema": "./src/ng-add/schema.json"
55
+ },
56
+ "setup": {
57
+ "description": "Setup angular-atomic-schematics",
58
+ "factory": "./src/setup/index#setup",
59
+ "schema": "./src/ng-add/schema.json"
60
+ }
61
+ }
62
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ng-atomic/schematics",
3
- "version": "5.1.2",
3
+ "version": "5.3.0",
4
4
  "license": "MIT",
5
5
  "schematics": "./collection.json",
6
6
  "ng-add": {
@@ -0,0 +1,6 @@
1
+ @use 'scoped-var/strict' as * with ($host: 'example');
2
+ @use 'atomic/atom' as *;
3
+
4
+ :host {
5
+ @include atom($host);
6
+ }
@@ -0,0 +1,16 @@
1
+ import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
2
+
3
+ @Component({
4
+ selector: 'atoms-example',
5
+ templateUrl: './example.atom.html',
6
+ styleUrls: ['./example.atom.scss'],
7
+ changeDetection: ChangeDetectionStrategy.OnPush
8
+ })
9
+ export class ExampleAtom implements OnInit {
10
+
11
+ constructor() { }
12
+
13
+ ngOnInit(): void {
14
+ }
15
+
16
+ }
@@ -0,0 +1,26 @@
1
+ import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
2
+ import { Meta, Story } from '@storybook/angular';
3
+ import { action } from '@storybook/addon-actions';
4
+ import { <%= classify(name) %><%= classify(type) %>, <%= classify(name) %>Module } from '.';
5
+
6
+ export default {
7
+ title: '<%= classify(type) %>s/<%= classify(name) %>',
8
+ component: <%= classify(name) %><%= classify(type) %>,
9
+ } as Meta;
10
+
11
+ const ACTIONS = {
12
+ // eventEmitterName: action('eventEmitterName'),
13
+ };
14
+
15
+
16
+ const Template: Story = (args) => ({
17
+ props: {...args, ...ACTIONS},
18
+ moduleMetadata: {
19
+ imports: [
20
+ <%= classify(name) %>Module,
21
+ ]
22
+ }
23
+ });
24
+
25
+ export const Default = Template.bind({});
26
+ Default.args = {};
@@ -0,0 +1,2 @@
1
+ export { <%= classify(name) %><%= classify(type) %> } from './<%= dasherize(name) %>.<%= dasherize(type) %>';
2
+ export { <%= classify(name) %>Module } from './<%= dasherize(name) %>.module';
@@ -0,0 +1,11 @@
1
+ {
2
+ "$schema": "../../node_modules/ng-packagr/ng-package.schema.json",
3
+ "dest": "../../dist/packages/@ng-atomic/components",
4
+ "lib": {
5
+ "entryFile": "index.ts",
6
+ "styleIncludePaths": [
7
+ "../../../../node_modules",
8
+ "../../styles"
9
+ ]
10
+ }
11
+ }
@@ -0,0 +1,187 @@
1
+ import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/testing';
2
+ import { readFileSync } from 'fs';
3
+ import path from 'path';
4
+ import { join } from 'path';
5
+ import {
6
+ buildExpectedFilePaths,
7
+ createWorkspace,
8
+ defaultWorkspaceOptions,
9
+ defaultAppOptions,
10
+ getTestProjectPath,
11
+ createNxWorkspace,
12
+ } from '../_testing';
13
+
14
+ const COLLECTION_PATH = path.join(__dirname, '../../collection.json');
15
+
16
+ describe('AtomicComponent Schematics', () => {
17
+ const runner = new SchematicTestRunner('@ng-atomic/schematics', COLLECTION_PATH);
18
+ let tree: UnitTestTree;
19
+
20
+ describe('Angular Workspace', () => {
21
+ beforeEach(async () => {
22
+ tree = await createWorkspace(runner, tree);
23
+ });
24
+
25
+ it('should create atomic component files', async () => {
26
+ const options = {project: 'app', path: '_shared/components', name: 'example'};
27
+
28
+ const { files } = await runner.runSchematicAsync('atomic-component', options, tree).toPromise();
29
+ expect(files).toContain('/projects/app/src/app/_shared/components/example/example.module.ts');
30
+ expect(files).toContain('/projects/app/src/app/_shared/components/example/example.component.html');
31
+ expect(files).toContain('/projects/app/src/app/_shared/components/example/example.component.scss');
32
+ expect(files).toContain('/projects/app/src/app/_shared/components/example/example.component.spec.ts');
33
+ expect(files).toContain('/projects/app/src/app/_shared/components/example/example.component.ts');
34
+ expect(files).toContain('/projects/app/src/app/_shared/components/example/example.stories.ts');
35
+ expect(files).toContain('/projects/app/src/app/_shared/components/example/index.ts');
36
+ });
37
+
38
+ it('should create atomic component files', async () => {
39
+ tree = await runner.runSchematicAsync('atomic-component', {project: 'app', name: '_shared/components/first'}, tree).toPromise();
40
+ tree = await runner.runSchematicAsync('atomic-component', {project: 'app', name: '_shared/components/second'}, tree).toPromise();
41
+
42
+ const { files } = tree;
43
+ expect(files).toContain('/projects/app/src/app/_shared/components/first/first.module.ts');
44
+ expect(files).toContain('/projects/app/src/app/_shared/components/first/first.component.html');
45
+ expect(files).toContain('/projects/app/src/app/_shared/components/first/first.component.scss');
46
+ expect(files).toContain('/projects/app/src/app/_shared/components/first/first.component.spec.ts');
47
+ expect(files).toContain('/projects/app/src/app/_shared/components/first/first.component.ts');
48
+ expect(files).toContain('/projects/app/src/app/_shared/components/first/first.stories.ts');
49
+ expect(files).toContain('/projects/app/src/app/_shared/components/first/index.ts');
50
+
51
+ expect(files).toContain('/projects/app/src/app/_shared/components/second/second.module.ts');
52
+ expect(files).toContain('/projects/app/src/app/_shared/components/second/second.component.html');
53
+ expect(files).toContain('/projects/app/src/app/_shared/components/second/second.component.scss');
54
+ expect(files).toContain('/projects/app/src/app/_shared/components/second/second.component.spec.ts');
55
+ expect(files).toContain('/projects/app/src/app/_shared/components/second/second.component.ts');
56
+ expect(files).toContain('/projects/app/src/app/_shared/components/second/second.stories.ts');
57
+ expect(files).toContain('/projects/app/src/app/_shared/components/second/index.ts');
58
+
59
+ // const source = tree.read('/projects/app/src/app/_shared/components/index.ts')!.toString('utf-8');
60
+ // expect(source).toEqual(`export { FirstModule } from './first';\nexport { SecondModule } from './second';`);
61
+ });
62
+
63
+ it('should create atomic components files in app2', async () => {
64
+ const options = {project: 'app2', name: '_shared/components/example'};
65
+ const projectPath = getTestProjectPath(defaultWorkspaceOptions, {...defaultAppOptions, name: 'app2'});
66
+ const expectedFilePaths = buildExpectedFilePaths(options.name, 'example', projectPath, 'component');
67
+
68
+ const { files } = await runner.runSchematicAsync('atomic-component', options, tree).toPromise();
69
+ expectedFilePaths.forEach(path => expect(files).toContain(path));
70
+ });
71
+
72
+ describe('given useTypeAsExtension is false', () => {
73
+ it('should output `example.component.ts`', async () => {
74
+ const options = {project: 'app2', name: '_shared/components/example', type: 'dialog', useTypeAsExtension: false};
75
+ const projectPath = getTestProjectPath(defaultWorkspaceOptions, {...defaultAppOptions, name: 'app2'});
76
+ const expectedFilePaths = buildExpectedFilePaths(options.name, 'example', projectPath, 'component');
77
+
78
+ tree = await runner.runSchematicAsync('atomic-component', options, tree).toPromise();
79
+ expectedFilePaths.forEach(path => expect(tree.files).toContain(path));
80
+
81
+ const inputScss = tree.read('/projects/app2/src/app/_shared/components/example/example.component.scss').toString('utf-8');
82
+ expect(inputScss.replace(/\s/g, '')).toEqual(`
83
+ @use 'scoped-var/strict' as * with ($host: 'example');
84
+ @use 'atomic/dialog' as *;
85
+
86
+ :host {
87
+ @include dialog($host);
88
+ }
89
+ `.replace(/\s/g, ''));
90
+ });
91
+ });
92
+ });
93
+
94
+ describe('Nx Workspace', () => {
95
+ beforeEach(async () => {
96
+ tree = await createNxWorkspace(runner, tree);
97
+ });
98
+
99
+ xit('', async () => {
100
+ const options = {project: 'app', name: '_shared/components/extras/example'};
101
+ // const options = {project: 'app', path: '_shared/components/extras', name: 'example'};
102
+ const { files } = await runner.runSchematicAsync('atomic-component', options, tree).toPromise();
103
+ expect(files).toContain('/apps/app/src/app/_shared/components/extras/example/example.module.ts');
104
+ });
105
+ });
106
+
107
+ });
108
+
109
+ describe('Atom Schematics', () => {
110
+ const runner = new SchematicTestRunner('@ng-atomic/schematics', COLLECTION_PATH);
111
+ let tree: UnitTestTree;
112
+
113
+ beforeEach(async () => {
114
+ tree = await createWorkspace(runner, tree);
115
+ });
116
+
117
+ it('should create atom files', async () => {
118
+ const options = {project: 'app', name: '_shared/components/example'};
119
+ const projectPath = getTestProjectPath(defaultWorkspaceOptions, {...defaultAppOptions, name: 'app'});
120
+ const expectedFilePaths = buildExpectedFilePaths(options.name, 'example', projectPath, 'atom');
121
+
122
+ const host = await runner.runSchematicAsync('atom', options, tree).toPromise();
123
+ expectedFilePaths.forEach(path => expect(host.files.includes(path)).toBeTruthy());
124
+
125
+ const inputTs = host.read('/projects/app/src/app/_shared/components/example/example.atom.ts').toString('utf-8');
126
+ const expectedTs = readFileSync(join(__dirname, '_test/example.atom.ts')).toString();
127
+ expect(inputTs.replace(/\s/g, '')).toEqual(expectedTs.replace(/\s/g, ''));
128
+
129
+ const inputScss = host.read('/projects/app/src/app/_shared/components/example/example.atom.scss').toString('utf-8');
130
+ const expectedScss = readFileSync(join(__dirname, '_test/example.atom.scss')).toString();
131
+ expect(inputScss.replace(/\s/g, '')).toEqual(expectedScss.replace(/\s/g, ''));
132
+ });
133
+ });
134
+
135
+ describe('Molecule Schematics', () => {
136
+ const runner = new SchematicTestRunner('@ng-atomic/schematics', COLLECTION_PATH);
137
+ let tree: UnitTestTree;
138
+
139
+ beforeEach(async () => {
140
+ tree = await createWorkspace(runner, tree);
141
+ });
142
+
143
+ it('should create molecule files', async () => {
144
+ const options = {project: 'app', name: '_shared/components/example'};
145
+ const projectPath = getTestProjectPath(defaultWorkspaceOptions, {...defaultAppOptions, name: 'app'});
146
+ const expectedFilePaths = buildExpectedFilePaths(options.name, 'example', projectPath, 'molecule');
147
+
148
+ const { files } = await runner.runSchematicAsync('molecule', options, tree).toPromise();
149
+ expectedFilePaths.forEach(path => expect(files.includes(path)).toBeTruthy());
150
+ });
151
+ });
152
+
153
+ describe('Organism Schematics', () => {
154
+ const runner = new SchematicTestRunner('@ng-atomic/schematics', COLLECTION_PATH);
155
+ let tree: UnitTestTree;
156
+
157
+ beforeEach(async () => {
158
+ tree = await createWorkspace(runner, tree);
159
+ });
160
+
161
+ it('should create organism files', async () => {
162
+ const options = {project: 'app', name: '_shared/components/example'};
163
+ const projectPath = getTestProjectPath(defaultWorkspaceOptions, {...defaultAppOptions, name: 'app'});
164
+ const expectedFilePaths = buildExpectedFilePaths(options.name, 'example', projectPath, 'organism');
165
+
166
+ const { files } = await runner.runSchematicAsync('organism', options, tree).toPromise();
167
+ expectedFilePaths.forEach(path => expect(files.includes(path)).toBeTruthy());
168
+ });
169
+ });
170
+
171
+ describe('Template Schematics', () => {
172
+ const runner = new SchematicTestRunner('@ng-atomic/schematics', COLLECTION_PATH);
173
+ let tree: UnitTestTree;
174
+
175
+ beforeEach(async () => {
176
+ tree = await createWorkspace(runner, tree);
177
+ });
178
+
179
+ it('should create template files', async () => {
180
+ const options = {project: 'app', name: '_shared/components/example'};
181
+ const projectPath = getTestProjectPath(defaultWorkspaceOptions, {...defaultAppOptions, name: 'app'});
182
+ const expectedFilePaths = buildExpectedFilePaths(options.name, 'example', projectPath, 'template');
183
+
184
+ const { files } = await runner.runSchematicAsync('template', options, tree).toPromise();
185
+ expectedFilePaths.forEach(path => expect(files.includes(path)).toBeTruthy());
186
+ });
187
+ });
@@ -0,0 +1,138 @@
1
+ {
2
+ "$schema": "http://json-schema.org/schema",
3
+ "$id": "SchematicsAngularComponent",
4
+ "title": "Angular Component Options Schema",
5
+ "type": "object",
6
+ "description": "Creates a new generic component definition in the given or default project.",
7
+ "properties": {
8
+ "path": {
9
+ "type": "string",
10
+ "format": "path",
11
+ "description": "The path at which to create the component file, relative to the current workspace. Default is a folder with the same name as the component in the project root.",
12
+ "visible": false
13
+ },
14
+ "project": {
15
+ "type": "string",
16
+ "description": "The name of the project.",
17
+ "$default": {
18
+ "$source": "projectName"
19
+ }
20
+ },
21
+ "name": {
22
+ "type": "string",
23
+ "description": "The name of the component.",
24
+ "$default": {
25
+ "$source": "argv",
26
+ "index": 0
27
+ },
28
+ "x-prompt": "What name would you like to use for the component?"
29
+ },
30
+ "displayBlock": {
31
+ "description": "Specifies if the style will contain `:host { display: block; }`.",
32
+ "type": "boolean",
33
+ "default": false,
34
+ "alias": "b"
35
+ },
36
+ "inlineTemplate": {
37
+ "description": "When true, includes template inline in the component.ts file. By default, an external template file is created and referenced in the component.ts file.",
38
+ "type": "boolean",
39
+ "default": false,
40
+ "alias": "t",
41
+ "x-user-analytics": 10
42
+ },
43
+ "viewEncapsulation": {
44
+ "description": "The view encapsulation strategy to use in the new component.",
45
+ "enum": ["Emulated", "Native", "None", "ShadowDom"],
46
+ "type": "string",
47
+ "alias": "v",
48
+ "x-user-analytics": 11
49
+ },
50
+ "changeDetection": {
51
+ "description": "The change detection strategy to use in the new component.",
52
+ "enum": ["Default", "OnPush"],
53
+ "type": "string",
54
+ "default": "OnPush",
55
+ "alias": "c"
56
+ },
57
+ "prefix": {
58
+ "type": "string",
59
+ "description": "The prefix to apply to the generated component selector.",
60
+ "alias": "p",
61
+ "oneOf": [
62
+ {
63
+ "maxLength": 0
64
+ },
65
+ {
66
+ "minLength": 1,
67
+ "format": "html-selector"
68
+ }
69
+ ]
70
+ },
71
+ "style": {
72
+ "description": "The file extension or preprocessor to use for style files.",
73
+ "type": "string",
74
+ "default": "scss",
75
+ "enum": [
76
+ "scss",
77
+ "sass"
78
+ ],
79
+ "x-user-analytics": 5
80
+ },
81
+ "type": {
82
+ "type": "string",
83
+ "description": "Adds a developer-defined type to the filename, in the format \"name.type.ts\"."
84
+ },
85
+ "skipTests": {
86
+ "type": "boolean",
87
+ "description": "When true, does not create \"spec.ts\" test files for the new component.",
88
+ "default": false,
89
+ "x-user-analytics": 12
90
+ },
91
+ "flat": {
92
+ "type": "boolean",
93
+ "description": "When true, creates the new files at the top level of the current project.",
94
+ "default": false
95
+ },
96
+ "skipImport": {
97
+ "type": "boolean",
98
+ "description": "When true, does not import this component into the owning NgModule.",
99
+ "default": false,
100
+ "x-user-analytics": 18
101
+ },
102
+ "selector": {
103
+ "type": "string",
104
+ "format": "html-selector",
105
+ "description": "The HTML selector to use for this component."
106
+ },
107
+ "skipSelector": {
108
+ "type": "boolean",
109
+ "default": false,
110
+ "description": "Specifies if the component should have a selector or not."
111
+ },
112
+ "module": {
113
+ "type": "string",
114
+ "description": "The declaring NgModule.",
115
+ "alias": "m"
116
+ },
117
+ "export": {
118
+ "type": "boolean",
119
+ "default": false,
120
+ "description": "When true, the declaring NgModule exports this component.",
121
+ "x-user-analytics": 19
122
+ },
123
+ "styleHeader": {
124
+ "type": "string",
125
+ "default": "@use 'scoped-var/strict' as * with ($host: '{name}');\n@use 'atomic/{type}' as *;\n:host {\n\t@include {type}($host);\n}\n",
126
+ "description": "scss header template. you can use template engine like `($host: '{name}.{type}'`. "
127
+ },
128
+ "useTypeAsExtension": {
129
+ "type": "boolean",
130
+ "default": true,
131
+ "description": "When false, atomic component extension should be `.component.ts`"
132
+ }
133
+ },
134
+ "required": [
135
+ "name"
136
+ ]
137
+ }
138
+
@@ -0,0 +1,29 @@
1
+ {
2
+ "$schema": "http://json-schema.org/schema",
3
+ "$id": "ngx-atomic-schematics-ng-add",
4
+ "title": "Angular Atomic Schematics ng-add schematic",
5
+ "type": "object",
6
+ "properties": {
7
+ "project": {
8
+ "type": "string",
9
+ "description": "Name of the project.",
10
+ "$default": {
11
+ "$source": "projectName"
12
+ }
13
+ },
14
+ "componentsDir": {
15
+ "description": "Setup components directory",
16
+ "type": "string",
17
+ "default": "_shared/components",
18
+ "x-prompt": "Where do you setup Angular Atomic Components?"
19
+ },
20
+ "stylesDir": {
21
+ "description": "Setup styles directory",
22
+ "type": "string",
23
+ "default": "src/styles",
24
+ "x-prompt": "Where do you setup Angular Atomic Styles?\nIf you use Nx workspace you should input `apps/app/src/styles`"
25
+
26
+ }
27
+ },
28
+ "required": []
29
+ }
@@ -0,0 +1,26 @@
1
+ import { NgModule } from '@angular/core';
2
+ import { CommonModule } from '@angular/common';
3
+ import { Routes, RouterModule } from '@angular/router';
4
+ import { ExamplePage } from './example.page';
5
+
6
+ const routes: Routes = [
7
+ {
8
+ path: '',
9
+ component: ExamplePage,
10
+ // loadChildren: () => import('./pages/pages.module').then(m => m.PagesModule)
11
+ }
12
+ ];
13
+
14
+ @NgModule({
15
+ declarations: [
16
+ ExamplePage
17
+ ],
18
+ imports: [
19
+ CommonModule,
20
+ RouterModule.forChild(routes)
21
+ ],
22
+ exports: [
23
+ ExamplePage
24
+ ]
25
+ })
26
+ export class ExampleModule { }
@@ -0,0 +1,6 @@
1
+ @use 'scoped-var/strict' as * with ($host:'example');
2
+ @use 'atomic/page' as *;
3
+
4
+ :host {
5
+ @include page($host);
6
+ }
@@ -0,0 +1,15 @@
1
+ import { Component, OnInit } from '@angular/core';
2
+
3
+ @Component({
4
+ selector: 'pages-example',
5
+ templateUrl: './example.page.html',
6
+ styleUrls: ['./example.page.scss']
7
+ })
8
+ export class ExamplePage implements OnInit {
9
+
10
+ constructor() { }
11
+
12
+ ngOnInit(): void {
13
+ }
14
+
15
+ }
@@ -0,0 +1,37 @@
1
+ import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/testing';
2
+ import { readFileSync } from 'fs';
3
+ import { join } from 'path';
4
+ import { COLLECTION_PATH, createWorkspace } from '../_testing';
5
+
6
+ describe('Page Schematics', () => {
7
+ const runner = new SchematicTestRunner('@ng-atomic/schematics', COLLECTION_PATH);
8
+ let tree: UnitTestTree;
9
+
10
+ beforeEach(async () => {
11
+ tree = await createWorkspace(runner, tree);
12
+ });
13
+
14
+ it('should create atomic component files', async () => {
15
+ const options = {project: 'app', name: 'example'};
16
+ const host = await runner.runSchematicAsync('page', options, tree).toPromise();
17
+ expect(host.files.includes('/projects/app/src/app/pages/pages.module.ts')).toBeTruthy();
18
+ expect(host.files.includes('/projects/app/src/app/pages/example/example.module.ts')).toBeTruthy();
19
+ expect(host.files.includes('/projects/app/src/app/pages/example/example.page.html')).toBeTruthy();
20
+ expect(host.files.includes('/projects/app/src/app/pages/example/example.page.scss')).toBeTruthy();
21
+ expect(host.files.includes('/projects/app/src/app/pages/example/example.page.spec.ts')).toBeTruthy();
22
+ expect(host.files.includes('/projects/app/src/app/pages/example/example.page.ts')).toBeTruthy();
23
+
24
+ const inputModuleTs = host.read('/projects/app/src/app/pages/example/example.module.ts').toString('utf-8');
25
+ const expectedModuleTs = readFileSync(join(__dirname, '_test/example.module.ts')).toString('utf-8');
26
+ expect(inputModuleTs.replace(/\s/g, '')).toEqual(expectedModuleTs.replace(/\s/g, ''));
27
+
28
+ const inputTs = host.read('/projects/app/src/app/pages/example/example.page.ts').toString('utf-8');
29
+ const expectedTs = readFileSync(join(__dirname, '_test/example.page.ts')).toString('utf-8');
30
+ expect(inputTs.replace(/\s/g, '')).toEqual(expectedTs.replace(/\s/g, ''));
31
+
32
+ const inputScss = host.read('/projects/app/src/app/pages/example/example.page.scss').toString('utf-8');
33
+ const expectedScss = readFileSync(join(__dirname, '_test/example.page.scss')).toString('utf-8');
34
+ expect(inputScss.replace(/\s/g, '')).toEqual(expectedScss.replace(/\s/g, ''));
35
+
36
+ });
37
+ });
@@ -0,0 +1,15 @@
1
+ import { NgModule } from '@angular/core';<% if (commonModule) { %>
2
+ import { CommonModule } from '@angular/common';<% } %>
3
+ import { Routes, RouterModule } from '@angular/router';
4
+
5
+ const routes: Routes = [
6
+ ];
7
+
8
+ @NgModule({
9
+ declarations: [],
10
+ imports: [<% if (commonModule) { %>
11
+ CommonModule,<% } %>
12
+ RouterModule.forChild(routes)
13
+ ]
14
+ })
15
+ export class <%= classify(name) %>Module { }
@@ -0,0 +1,17 @@
1
+ import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/testing';
2
+ import { COLLECTION_PATH, createWorkspace } from '../_testing';
3
+
4
+ describe('Pages Schematics', () => {
5
+ const runner = new SchematicTestRunner('@ng-atomic/schematics', COLLECTION_PATH);
6
+ let tree: UnitTestTree;
7
+
8
+ beforeEach(async () => {
9
+ tree = await createWorkspace(runner, tree);
10
+ });
11
+
12
+ it('should create component files', async () => {
13
+ const options = {project: 'app', name: 'pages'};
14
+ const { files } = await runner.runSchematicAsync('pages', options, tree).toPromise();
15
+ expect(files.includes('/projects/app/src/app/pages/pages.module.ts')).toBeTruthy();
16
+ });
17
+ });
@@ -0,0 +1,44 @@
1
+ {
2
+ "$schema": "http://json-schema.org/schema",
3
+ "$id": "SchematicsAngularModule",
4
+ "title": "Angular Module Options Schema",
5
+ "type": "object",
6
+ "description": "Creates a new generic NgModule definition in the given or default project.",
7
+ "properties": {
8
+ "name": {
9
+ "type": "string",
10
+ "description": "The name of the NgModule.",
11
+ "$default": {
12
+ "$source": "argv",
13
+ "index": 0
14
+ },
15
+ "x-prompt": "What name would you like to use for the NgModule?"
16
+ },
17
+ "path": {
18
+ "type": "string",
19
+ "format": "path",
20
+ "description": "The path at which to create the NgModule, relative to the workspace root.",
21
+ "visible": false
22
+ },
23
+ "project": {
24
+ "type": "string",
25
+ "description": "The name of the project.",
26
+ "$default": {
27
+ "$source": "projectName"
28
+ }
29
+ },
30
+ "commonModule": {
31
+ "type": "boolean",
32
+ "description": "When true, the new NgModule imports \"CommonModule\". ",
33
+ "default": true,
34
+ "visible": false
35
+ },
36
+ "lintFix": {
37
+ "type": "boolean",
38
+ "default": false,
39
+ "description": "When true, applies lint fixes after generating the module.",
40
+ "x-user-analytics": 15
41
+ }
42
+ },
43
+ "required": []
44
+ }
@@ -0,0 +1,6 @@
1
+ @use 'scoped-var' as *;
2
+ @use 'atomic/component' as *;
3
+
4
+ @mixin atom($host) {
5
+ @include component($host);
6
+ }
@@ -0,0 +1,5 @@
1
+ @use 'scoped-var' as *;
2
+
3
+ @mixin component($host) {
4
+ display: block;
5
+ }
@@ -0,0 +1,6 @@
1
+ @use 'scoped-var' as *;
2
+ @use 'atomic/component' as *;
3
+
4
+ @mixin molecule($host) {
5
+ @include component($host);
6
+ }
@@ -0,0 +1,6 @@
1
+ @use 'scoped-var' as *;
2
+ @use 'atomic/component' as *;
3
+
4
+ @mixin organism($host) {
5
+ @include component($host);
6
+ }
@@ -0,0 +1,6 @@
1
+ @use 'scoped-var' as *;
2
+ @use 'atomic/component' as *;
3
+
4
+ @mixin page($host) {
5
+ @include component($host);
6
+ }
@@ -0,0 +1,6 @@
1
+ @use 'scoped-var' as *;
2
+ @use 'atomic/component' as *;
3
+
4
+ @mixin template($host) {
5
+ @include component($host);
6
+ }
@@ -0,0 +1,37 @@
1
+ import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/testing';
2
+ import { COLLECTION_PATH, createWorkspace } from '../_testing';
3
+ import { get } from 'lodash';
4
+
5
+ describe('Setup Schematics', () => {
6
+ const runner = new SchematicTestRunner('@ng-atomic/schematics', COLLECTION_PATH);
7
+ let tree: UnitTestTree;
8
+
9
+ beforeEach(async () => {
10
+ tree = await createWorkspace(runner, tree);
11
+ });
12
+
13
+ it('should create component files', async () => {
14
+ const options = {project: 'app', name: 'pages'};
15
+ const host = await runner.runSchematicAsync('setup', options, tree).toPromise();
16
+ const angularJson = JSON.parse(host.read('/angular.json').toString('utf-8'));
17
+ expect(get(angularJson, 'cli.defaultCollection')).toEqual('@ng-atomic/schematics');
18
+ const schematicsJson = get(angularJson, 'projects.app.schematics');
19
+
20
+ for (const type of ['atom', 'molecule', 'organism', 'template']) {
21
+ expect(get(schematicsJson, `@ng-atomic/schematics:${type}`))
22
+ .toEqual({path: `_shared/components/${type}s`});
23
+ }
24
+
25
+ const architectJson = get(angularJson, 'projects.app.architect');
26
+ expect(get(architectJson, 'build.options.stylePreprocessorOptions.includePaths'))
27
+ .toContain('src/styles');
28
+
29
+ for (const type of ['component', 'atom', 'molecule', 'organism', 'template', 'page']) {
30
+ expect(host.files).toContain(`/src/styles/atomic/_${type}.scss`);
31
+ }
32
+
33
+ const tsconfigJson = JSON.parse(host.read('/tsconfig.json').toString('utf-8'));
34
+ expect(get(tsconfigJson, 'compilerOptions.paths.@components')).toContain('_shared/components');
35
+ expect(get(tsconfigJson, 'compilerOptions.paths.@components/*')).toContain('_shared/components/*');
36
+ });
37
+ });
@@ -0,0 +1,6 @@
1
+ @use 'scoped-var/strict' as * with ($host: 'example');
2
+ @use 'atomic/component' as *;
3
+
4
+ :host {
5
+ @include component($host);
6
+ }
@@ -0,0 +1,43 @@
1
+ import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/testing';
2
+ import { readFileSync } from 'fs';
3
+ import path from 'path';
4
+ import { join } from 'path';
5
+ import { createWorkspace } from '../_testing';
6
+
7
+ const COLLECTION_PATH = path.join(__dirname, '../../collection.json');
8
+
9
+ describe('StyleHeader', () => {
10
+ const runner = new SchematicTestRunner('@ng-atomic/schematics', COLLECTION_PATH);
11
+ let tree: UnitTestTree;
12
+
13
+ beforeEach(async () => {
14
+ tree = await createWorkspace(runner, tree);
15
+ const options = {project: 'app', style: 'scss', name: 'example', skipImport: true };
16
+ tree = await runner.runExternalSchematicAsync('@schematics/angular', 'component', options, tree).toPromise();
17
+ });
18
+
19
+ describe('given all options', () => {
20
+ it('should be added style header', async () => {
21
+ const PATH = '/projects/app/src/app/example/example.component.scss';
22
+ const options = {path: PATH, name: 'example', type: 'component'};
23
+
24
+ await runner.runSchematicAsync('style-header', options, tree).toPromise();
25
+ const input = tree.read(PATH).toString('utf-8');
26
+ const expected = readFileSync(join(__dirname, '_test/example.scss')).toString();
27
+ expect(input.replace(/\s/g, '')).toEqual(expected.replace(/\s/g, ''));
28
+ });
29
+ });
30
+
31
+ describe('given only options.path', () => {
32
+ it('should be added style header', async () => {
33
+ const PATH = '/projects/app/src/app/example/example.component.scss';
34
+ const options = {path: PATH};
35
+
36
+ await runner.runSchematicAsync('style-header', options, tree).toPromise();
37
+ const input = tree.read(PATH).toString('utf-8');
38
+ const expected = readFileSync(join(__dirname, '_test/example.scss')).toString();
39
+ expect(input.replace(/\s/g, '')).toEqual(expected.replace(/\s/g, ''));
40
+ });
41
+ });
42
+
43
+ });
@@ -0,0 +1,22 @@
1
+ {
2
+ "$schema": "http://json-schema.org/schema",
3
+ "$id": "SchematicsAngularComponent",
4
+ "title": "Style Header Options Schema",
5
+ "type": "object",
6
+ "description": "Creates a new generic component definition in the given or default project.",
7
+ "properties": {
8
+ "path": {
9
+ "type": "string",
10
+ "format": "path",
11
+ "description": "The path at which to create the component file, relative to the current workspace. Default is a folder with the same name as the component in the project root.",
12
+ "visible": false
13
+ },
14
+ "styleHeader": {
15
+ "type": "string",
16
+ "default": "@use 'scoped-var/strict' as * with ($host: '{name}');\n@use 'atomic/{type}' as *;\n:host {\n\t@include {type}($host);\n}\n",
17
+ "description": "scss header template. you can use template engine like `($host: '{name}.{type}'`. "
18
+ }
19
+ },
20
+ "required": ["path"]
21
+ }
22
+