This commit is contained in:
CHEVALLIER Abel
2025-11-13 16:23:22 +01:00
parent de9c515a47
commit cb235644dc
34924 changed files with 3811102 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
<% if(displayBlock){ if(style != 'sass') { %>:host {
display: block;
}
<% } else { %>\:host
display: block;
<% }} %>

View File

@@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import <% if(!exportDefault) { %>{ <% }%><%= classify(name) %><%= classify(type) %> <% if(!exportDefault) {%>} <% }%>from './<%= dasherize(name) %><%= type ? '.' + dasherize(type): '' %>';
describe('<%= classify(name) %><%= classify(type) %>', () => {
let component: <%= classify(name) %><%= classify(type) %>;
let fixture: ComponentFixture<<%= classify(name) %><%= classify(type) %>>;
beforeEach(async () => {
await TestBed.configureTestingModule({
<%= standalone ? 'imports' : 'declarations' %>: [<%= classify(name) %><%= classify(type) %>]
})
.compileComponents();
fixture = TestBed.createComponent(<%= classify(name) %><%= classify(type) %>);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@@ -0,0 +1,22 @@
import { <% if(changeDetection !== 'Default') { %>ChangeDetectionStrategy, <% }%>Component<% if(!!viewEncapsulation) { %>, ViewEncapsulation<% }%> } from '@angular/core';
@Component({<% if(!skipSelector) {%>
selector: '<%= selector %>',<%}%><% if(standalone) {%>
imports: [],<%} else { %>
standalone: false,<% }%><% if(inlineTemplate) { %>
template: `
<p>
<%= dasherize(name) %> works!
</p>
`<% } else { %>
templateUrl: './<%= dasherize(name) %><%= type ? '.' + dasherize(type): '' %><%= ngext %>.html'<% } if(inlineStyle) { %>,
styles: `<% if(displayBlock){ %>
:host {
display: block;
}
<% } %>`<% } else if (style !== 'none') { %>,
styleUrl: './<%= dasherize(name) %><%= type ? '.' + dasherize(type): '' %>.<%= style %>'<% } %><% if(!!viewEncapsulation) { %>,
encapsulation: ViewEncapsulation.<%= viewEncapsulation %><% } if (changeDetection !== 'Default') { %>,
changeDetection: ChangeDetectionStrategy.<%= changeDetection %><% } %>
})
export <% if(exportDefault) {%>default <%}%>class <%= classify(name) %><%= classify(type) %> {}

View File

@@ -0,0 +1,15 @@
"use strict";
/**
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = default_1;
const schematics_1 = require("@angular-devkit/schematics");
const build_component_1 = require("../utils/build-component");
function default_1(options) {
return (0, schematics_1.chain)([
(0, build_component_1.buildComponent)(Object.assign({}, options))
]);
}
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../schematics/ng-component/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAOH,4BAIC;AATD,2DAAyD;AAGzD,8DAA0D;AAE1D,mBAAwB,OAAe;IACrC,OAAO,IAAA,kBAAK,EAAC;QACX,IAAA,gCAAc,oBAAM,OAAO,EAAG;KAC/B,CAAC,CAAC;AACL,CAAC"}

View File

@@ -0,0 +1,196 @@
"use strict";
/**
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
*/
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const testing_1 = require("@angular-devkit/schematics/testing");
const schema_1 = require("@schematics/angular/component/schema");
const test_app_1 = require("../testing/test-app");
const appOptions = {
name: 'ng-zorro',
inlineStyle: false,
inlineTemplate: false,
routing: false,
style: schema_1.Style.Less,
skipTests: false,
skipPackageJson: false
};
const defaultOptions = {
name: 'test',
inlineStyle: false,
inlineTemplate: false,
changeDetection: schema_1.ChangeDetection.Default,
style: schema_1.Style.Less,
type: 'Component',
skipTests: false,
module: undefined,
export: false,
project: 'ng-zorro'
};
function generateModuleContent(moduleName) {
return `
import { NgModule } from '@angular/core';
@NgModule({
imports: [],
declarations: []
})
export class ${moduleName} {}
`;
}
describe('[schematic] ng-component', () => {
let runner;
let appTree;
beforeEach(() => __awaiter(void 0, void 0, void 0, function* () {
runner = new testing_1.SchematicTestRunner('schematics', require.resolve('../collection.json'));
appTree = yield (0, test_app_1.createTestApp)(runner, Object.assign({}, appOptions));
}));
it('should create a component', () => __awaiter(void 0, void 0, void 0, function* () {
const options = Object.assign({}, defaultOptions);
const tree = yield runner.runSchematic('component', options, appTree);
const files = tree.files;
expect(files).toEqual(jasmine.arrayContaining([
'/projects/ng-zorro/src/app/test/test.component.less',
'/projects/ng-zorro/src/app/test/test.component.html',
'/projects/ng-zorro/src/app/test/test.component.spec.ts',
'/projects/ng-zorro/src/app/test/test.component.ts'
]));
}));
it('should respect the type option', () => __awaiter(void 0, void 0, void 0, function* () {
const options = Object.assign(Object.assign({}, defaultOptions), { type: 'container' });
const tree = yield runner.runSchematic('component', options, appTree);
const files = tree.files;
expect(files).toEqual(jasmine.arrayContaining([
'/projects/ng-zorro/src/app/test/test.container.less',
'/projects/ng-zorro/src/app/test/test.container.html',
'/projects/ng-zorro/src/app/test/test.container.spec.ts',
'/projects/ng-zorro/src/app/test/test.container.ts'
]));
}));
it('should allow empty string in the type option', () => __awaiter(void 0, void 0, void 0, function* () {
const options = Object.assign(Object.assign({}, defaultOptions), { type: '' });
const tree = yield runner.runSchematic('component', options, appTree);
const files = tree.files;
expect(files).toEqual(jasmine.arrayContaining([
'/projects/ng-zorro/src/app/test/test.less',
'/projects/ng-zorro/src/app/test/test.html',
'/projects/ng-zorro/src/app/test/test.spec.ts',
'/projects/ng-zorro/src/app/test/test.ts'
]));
}));
it('should not use `.ng.html` extension when ngHtml is false', () => __awaiter(void 0, void 0, void 0, function* () {
const options = Object.assign(Object.assign({}, defaultOptions), { ngHtml: false });
const tree = yield runner.runSchematic('component', options, appTree);
const content = tree.readContent('/projects/ng-zorro/src/app/test/test.component.ts');
const files = tree.files;
expect(content).toContain('test.component.html');
expect(files).toContain('/projects/ng-zorro/src/app/test/test.component.less');
expect(files).toContain('/projects/ng-zorro/src/app/test/test.component.html');
}));
it('should use `.ng.html` extension when ngHtml is true', () => __awaiter(void 0, void 0, void 0, function* () {
const options = Object.assign(Object.assign({}, defaultOptions), { ngHtml: true });
const tree = yield runner.runSchematic('component', options, appTree);
const content = tree.readContent('/projects/ng-zorro/src/app/test/test.component.ts');
const files = tree.files;
expect(content).toContain('test.component.ng.html');
expect(files).toContain('/projects/ng-zorro/src/app/test/test.component.less');
expect(files).toContain('/projects/ng-zorro/src/app/test/test.component.ng.html');
}));
describe('style', () => {
it('should create specified style', () => __awaiter(void 0, void 0, void 0, function* () {
const options = Object.assign(Object.assign({}, defaultOptions), { style: schema_1.Style.Sass });
const tree = yield runner.runSchematic('component', options, appTree);
const files = tree.files;
expect(files).toEqual(jasmine.arrayContaining([
'/projects/ng-zorro/src/app/test/test.component.sass',
'/projects/ng-zorro/src/app/test/test.component.html',
'/projects/ng-zorro/src/app/test/test.component.spec.ts',
'/projects/ng-zorro/src/app/test/test.component.ts'
]));
}));
it('should not create style file when inlineStyle is true', () => __awaiter(void 0, void 0, void 0, function* () {
const options = Object.assign(Object.assign({}, defaultOptions), { inlineStyle: true });
const tree = yield runner.runSchematic('component', options, appTree);
const files = tree.files;
expect(files).toEqual(jasmine.arrayContaining([
'/projects/ng-zorro/src/app/test/test.component.html',
'/projects/ng-zorro/src/app/test/test.component.spec.ts',
'/projects/ng-zorro/src/app/test/test.component.ts'
]));
expect(files).not.toContain('/projects/ng-zorro/src/app/test/test.component.less');
}));
it('should not create style file when style is none', () => __awaiter(void 0, void 0, void 0, function* () {
const options = Object.assign(Object.assign({}, defaultOptions), { style: schema_1.Style.None });
const tree = yield runner.runSchematic('component', options, appTree);
const files = tree.files;
expect(files).toEqual(jasmine.arrayContaining([
'/projects/ng-zorro/src/app/test/test.component.html',
'/projects/ng-zorro/src/app/test/test.component.spec.ts',
'/projects/ng-zorro/src/app/test/test.component.ts'
]));
expect(files).not.toContain('/projects/ng-zorro/src/app/test/test.component.less');
}));
});
describe('displayBlock', () => {
it('should add display block styles to the component', () => __awaiter(void 0, void 0, void 0, function* () {
const options = Object.assign(Object.assign({}, defaultOptions), { displayBlock: true });
const tree = yield runner.runSchematic('component', options, appTree);
const content = tree.readContent('/projects/ng-zorro/src/app/test/test.component.less');
expect(content).toMatch(/display: block/);
}));
it('should add display block styles to the component when inlineStyle is true', () => __awaiter(void 0, void 0, void 0, function* () {
const options = Object.assign(Object.assign({}, defaultOptions), { displayBlock: true, inlineStyle: true });
const tree = yield runner.runSchematic('component', options, appTree);
const content = tree.readContent('/projects/ng-zorro/src/app/test/test.component.ts');
expect(content).toMatch(/display: block/);
}));
});
describe('flat', () => {
it('should create a flat component', () => __awaiter(void 0, void 0, void 0, function* () {
const options = Object.assign(Object.assign({}, defaultOptions), { flat: true });
const tree = yield runner.runSchematic('component', options, appTree);
const files = tree.files;
expect(files).toEqual(jasmine.arrayContaining([
'/projects/ng-zorro/src/app/test.component.less',
'/projects/ng-zorro/src/app/test.component.html',
'/projects/ng-zorro/src/app/test.component.spec.ts',
'/projects/ng-zorro/src/app/test.component.ts'
]));
}));
});
describe('classnameWithModule', () => {
it('should find the closest module', () => __awaiter(void 0, void 0, void 0, function* () {
const options = Object.assign(Object.assign({}, defaultOptions), { standalone: false });
const closestModule = '/projects/ng-zorro/src/app/test/test-module.ts';
appTree.create(closestModule, generateModuleContent('ClosestModule'));
const tree = yield runner.runSchematic('component', options, appTree);
const fooModuleContent = tree.readContent(closestModule);
expect(fooModuleContent).toMatch(/import { TestComponent } from '.\/test.component'/);
}));
it('should set classname with the closest module', () => __awaiter(void 0, void 0, void 0, function* () {
const options = Object.assign(Object.assign({}, defaultOptions), { classnameWithModule: true, standalone: false });
const testModule = '/projects/ng-zorro/src/app/test/test-module.ts';
appTree.create(testModule, generateModuleContent('TestModule'));
const tree = yield runner.runSchematic('component', options, appTree);
const fooModuleContent = tree.readContent(testModule);
expect(fooModuleContent).toMatch(/import { TestTestComponent } from '.\/test.component'/);
}));
it('should set classname with the specified module', () => __awaiter(void 0, void 0, void 0, function* () {
const options = Object.assign(Object.assign({}, defaultOptions), { classnameWithModule: true, module: 'app-module.ts', standalone: false });
const app = yield (0, test_app_1.createTestApp)(runner, Object.assign(Object.assign({}, appOptions), { standalone: false }));
const tree = yield runner.runSchematic('component', options, app);
const appComponentContent = tree.readContent('/projects/ng-zorro/src/app/app-module.ts');
expect(appComponentContent).toMatch(/import { AppTestComponent } from '.\/test\/test.component'/);
}));
});
});
//# sourceMappingURL=index.spec.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,7 @@
"use strict";
/**
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
*/
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=schema.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../schematics/ng-component/schema.ts"],"names":[],"mappings":";AAAA;;;GAGG"}

View File

@@ -0,0 +1,155 @@
{
"$schema": "http://json-schema.org/draft-07/schema",
"$id": "PLACEHOLDER_SCHEMATICS_ID",
"title": "PLACEHOLDER_SCHEMATICS_TITLE",
"type": "object",
"properties": {
"path": {
"type": "string",
"format": "path",
"description": "The path to create the component.",
"visible": false
},
"project": {
"type": "string",
"description": "The name of the project.",
"$default": {
"$source": "projectName"
}
},
"name": {
"type": "string",
"description": "The name of the component.",
"$default": {
"$source": "argv",
"index": 0
},
"x-prompt": "What should be the name of the component?"
},
"displayBlock": {
"description": "Specifies if the style will contain `:host { display: block; }`.",
"type": "boolean",
"default": false,
"alias": "b"
},
"inlineStyle": {
"description": "When true, includes styles inline in the component.ts file. Only CSS styles can be included inline. By default, an external styles file is created and referenced in the component.ts file.",
"type": "boolean",
"default": false,
"alias": "s"
},
"inlineTemplate": {
"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.",
"type": "boolean",
"default": false,
"alias": "t"
},
"standalone": {
"description": "Whether the generated component is standalone.",
"type": "boolean",
"default": true
},
"viewEncapsulation": {
"description": "The view encapsulation strategy to use in the new component.",
"enum": ["Emulated", "Native", "None", "ShadowDom"],
"type": "string",
"alias": "v"
},
"changeDetection": {
"description": "Specifies the change detection strategy.",
"enum": ["Default", "OnPush"],
"type": "string",
"default": "Default",
"alias": "c"
},
"prefix": {
"type": "string",
"description": "The prefix to apply to the generated component selector.",
"alias": "p",
"oneOf": [
{
"maxLength": 0
},
{
"minLength": 1,
"format": "html-selector"
}
]
},
"style": {
"description": "The file extension or preprocessor to use for style files, or 'none' to skip generating the style file.",
"type": "string",
"default": "css",
"enum": [
"css",
"scss",
"sass",
"less",
"styl",
"none"
]
},
"type": {
"type": "string",
"description": "Append a custom type to the component's filename. For example, if you set the type to `container`, the file will be named `my-component.container.ts`."
},
"skipTests": {
"type": "boolean",
"description": "When true, does not create \"spec.ts\" test files for the new component.",
"default": false
},
"flat": {
"type": "boolean",
"description": "Flag to indicate if a dir is created.",
"default": false
},
"skipImport": {
"type": "boolean",
"description": "When true, does not import this component into the owning NgModule.",
"default": false
},
"selector": {
"type": "string",
"format": "html-selector",
"description": "The selector to use for the component."
},
"skipSelector": {
"type": "boolean",
"default": false,
"description": "Skip the generation of an HTML selector for the component."
},
"module": {
"type": "string",
"description": "Allows specification of the declaring module.",
"alias": "m"
},
"export": {
"type": "boolean",
"default": false,
"description": "When true, the declaring NgModule exports this component."
},
"exportDefault": {
"type": "boolean",
"default": false,
"description": "Use a default export for the component in its TypeScript file instead of a named export."
},
"ngHtml": {
"type": "boolean",
"default": false,
"description": "Generate component template files with an '.ng.html' file extension instead of '.html'."
},
"entryComponent": {
"type": "boolean",
"default": false,
"description": "When true, the new component is the entry component of the declaring NgModule."
},
"classnameWithModule": {
"type": "boolean",
"description": "When true, Use module class name as additional prefix for the component classname.",
"default": false
}
},
"required": [
"name"
]
}