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

65
node_modules/ng-zorro-antd/schematics/ng-add/index.js generated vendored Normal file
View File

@@ -0,0 +1,65 @@
"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 });
exports.default = default_1;
const schematics_1 = require("@angular/cdk/schematics");
const schematics_2 = require("@angular-devkit/schematics");
const tasks_1 = require("@angular-devkit/schematics/tasks");
const utility_1 = require("@schematics/angular/utility");
const dependencies_1 = require("@schematics/angular/utility/dependencies");
const latest_versions_1 = require("@schematics/angular/utility/latest-versions");
const project_style_1 = require("../utils/project-style");
// generated by scripts/schematics/set-version.ts
// @ts-ignore
const version_names_1 = require("../utils/version-names");
function default_1(options) {
return (0, schematics_2.chain)([
(host, context) => {
// The CLI inserts `ng-zorro-antd` into the `package.json` before this schematic runs.
// This means that we do not need to insert Angular Material into `package.json` files again.
// In some cases though, it could happen that this schematic runs outside of the CLI `ng add`
// command, or Material is only listed a dev dependency. If that is the case, we insert a
// version based on the current build version (substituted version placeholder).
if (!options.skipPackageJson) {
(0, dependencies_1.addPackageJsonDependency)(host, { name: 'ng-zorro-antd', version: version_names_1.zorroVersion, type: dependencies_1.NodeDependencyType.Default });
if (options.gestures) {
(0, dependencies_1.addPackageJsonDependency)(host, { name: 'hammerjs', version: version_names_1.hammerjsVersion, type: dependencies_1.NodeDependencyType.Default });
}
// Since Angular CLI v20 no longer installs `less` for the project which prefers `css` or
// `scss` as default stylesheet format, and ng-zorro-antd's custom theming requires `less`,
// we should add `less` as a dev dependency.
if (options.theme) {
(0, dependencies_1.addPackageJsonDependency)(host, { name: 'less', version: latest_versions_1.latestVersions['less'], type: dependencies_1.NodeDependencyType.Dev });
}
}
// Since the Angular Material schematics depend on the schematic utility functions from the
// CDK, we need to install the CDK before loading the schematic files that import from the CDK.
if (!options.skipInstall) {
const installTaskId = context.addTask(new tasks_1.NodePackageInstallTask());
context.addTask(new tasks_1.RunSchematicTask('ng-add-setup-project', options), [installTaskId]);
}
},
options.template ? applyTemplate(options) : (0, schematics_2.noop)()
]);
}
function applyTemplate(options) {
return (host) => __awaiter(this, void 0, void 0, function* () {
const workspace = yield (0, utility_1.readWorkspace)(host);
const project = (0, schematics_1.getProjectFromWorkspace)(workspace, options.project);
const style = (0, project_style_1.getProjectStyle)(project);
return (0, schematics_2.schematic)(options.template, Object.assign(Object.assign({}, options), { style }));
});
}
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../schematics/ng-add/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;AAgBH,4BA+BC;AA7CD,wDAAkE;AAElE,2DAAkG;AAClG,4DAA4F;AAC5F,yDAA4D;AAC5D,2EAAwG;AACxG,iFAA6E;AAG7E,0DAAyD;AACzD,iDAAiD;AACjD,aAAa;AACb,0DAAuE;AAEvE,mBAAwB,OAAe;IACrC,OAAO,IAAA,kBAAK,EAAC;QACX,CAAC,IAAU,EAAE,OAAyB,EAAE,EAAE;YACxC,sFAAsF;YACtF,6FAA6F;YAC7F,6FAA6F;YAC7F,yFAAyF;YACzF,gFAAgF;YAChF,IAAI,CAAC,OAAO,CAAC,eAAe,EAAE,CAAC;gBAC7B,IAAA,uCAAwB,EAAC,IAAI,EAAE,EAA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CAAC;QACpE,MAAM,KAAK,GAAG,IAAA,+BAAe,EAAC,OAAO,CAAC,CAAC;QAEvC,OAAO,IAAA,sBAAS,EAAC,OAAO,CAAC,QAAQ,kCAAO,OAAO,KAAE,KAAK,IAAG,CAAC;IAC5D,CAAC,CAAA,CAAC;AACJ,CAAC"}

View File

@@ -0,0 +1,154 @@
"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 schematics_1 = require("@angular/cdk/schematics");
const core_1 = require("@angular-devkit/core");
const options_1 = require("@angular-devkit/schematics/tasks/package-manager/options");
const testing_1 = require("@angular-devkit/schematics/testing");
const utility_1 = require("@schematics/angular/utility");
const dependencies_1 = require("@schematics/angular/utility/dependencies");
const path_1 = require("path");
const test_app_1 = require("../testing/test-app");
const create_custom_theme_1 = require("../utils/create-custom-theme");
const get_file_content_1 = require("../utils/get-file-content");
describe('ng-add schematic', () => {
const defaultOptions = {
project: 'ng-zorro'
};
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, { standalone: false });
}));
it('should update package.json', () => __awaiter(void 0, void 0, void 0, function* () {
const options = Object.assign({}, defaultOptions);
const tree = yield runner.runSchematic('ng-add', options, appTree);
expect((0, dependencies_1.getPackageJsonDependency)(tree, 'ng-zorro-antd')).not.toBeNull();
expect(runner.tasks.some(task => task.name === options_1.NodePackageName)).toBe(true);
}));
it('should add hammerjs to package.json', () => __awaiter(void 0, void 0, void 0, function* () {
const options = Object.assign(Object.assign({}, defaultOptions), { gestures: true });
const tree = yield runner.runSchematic('ng-add', options, appTree);
expect((0, dependencies_1.getPackageJsonDependency)(tree, 'hammerjs')).not.toBeNull();
}));
it('should skip package.json', () => __awaiter(void 0, void 0, void 0, function* () {
const options = Object.assign(Object.assign({}, defaultOptions), { skipPackageJson: true });
const tree = yield runner.runSchematic('ng-add', options, appTree);
expect((0, dependencies_1.getPackageJsonDependency)(tree, 'ng-zorro-antd')).toBeNull();
}));
it('should skip install dependency package', () => __awaiter(void 0, void 0, void 0, function* () {
const options = Object.assign(Object.assign({}, defaultOptions), { skipInstall: true });
yield runner.runSchematic('ng-add', options, appTree);
expect(runner.tasks.some(task => task.name === options_1.NodePackageName)).toBe(false);
}));
it('should add less as devDependencies when choosing custom theme in non-LESS project', () => __awaiter(void 0, void 0, void 0, function* () {
const options = Object.assign(Object.assign({}, defaultOptions), { theme: true });
const tree = yield runner.runSchematic('ng-add', options, appTree);
expect((0, dependencies_1.getPackageJsonDependency)(tree, 'less')).not.toBeNull();
}));
it('should add hammerjs import to project main file', () => __awaiter(void 0, void 0, void 0, function* () {
const options = Object.assign(Object.assign({}, defaultOptions), { gestures: true });
const tree = yield runner.runSchematic('ng-add-setup-project', options, appTree);
const workspace = yield (0, utility_1.readWorkspace)(tree);
const project = (0, schematics_1.getProjectFromWorkspace)(workspace, defaultOptions.project);
const fileContent = (0, get_file_content_1.getFileContent)(tree, (0, core_1.normalize)((0, path_1.join)(project.sourceRoot, 'main.ts')));
expect(fileContent).toContain(`import 'hammerjs';`);
}));
it('should add default theme', () => __awaiter(void 0, void 0, void 0, function* () {
const options = Object.assign({}, defaultOptions);
const tree = yield runner.runSchematic('ng-add-setup-project', options, appTree);
const workspace = yield (0, utility_1.readWorkspace)(tree);
const project = (0, schematics_1.getProjectFromWorkspace)(workspace, defaultOptions.project);
expect((0, schematics_1.getProjectTargetOptions)(project, 'build').styles).toContain('./node_modules/ng-zorro-antd/ng-zorro-antd.min.css');
}));
it('should add custom theme', () => __awaiter(void 0, void 0, void 0, function* () {
const options = Object.assign(Object.assign({}, defaultOptions), { theme: true });
appTree = yield (0, test_app_1.createTestApp)(runner, { style: 'less', standalone: false });
const tree = yield runner.runSchematic('ng-add-setup-project', options, appTree);
const workspace = yield (0, utility_1.readWorkspace)(tree);
const project = (0, schematics_1.getProjectFromWorkspace)(workspace, defaultOptions.project);
const customThemePath = (0, core_1.normalize)((0, path_1.join)(project.sourceRoot, 'styles.less'));
const buffer = tree.read(customThemePath);
const themeContent = buffer.toString();
expect(themeContent).toContain((0, create_custom_theme_1.createCustomTheme)());
expect((0, schematics_1.getProjectTargetOptions)(project, 'build').styles).toContain('projects/ng-zorro/src/styles.less');
}));
it('should add custom theme file when no LESS file in project', () => __awaiter(void 0, void 0, void 0, function* () {
const options = Object.assign(Object.assign({}, defaultOptions), { theme: true });
const tree = yield runner.runSchematic('ng-add-setup-project', options, appTree);
const workspace = yield (0, utility_1.readWorkspace)(tree);
const project = (0, schematics_1.getProjectFromWorkspace)(workspace, defaultOptions.project);
expect((0, schematics_1.getProjectTargetOptions)(project, 'build').styles).toContain('projects/ng-zorro/src/theme.less');
}));
it('should add icon assets', () => __awaiter(void 0, void 0, void 0, function* () {
const options = Object.assign(Object.assign({}, defaultOptions), { dynamicIcon: true });
const tree = yield runner.runSchematic('ng-add-setup-project', options, appTree);
const workspace = yield (0, utility_1.readWorkspace)(tree);
const project = (0, schematics_1.getProjectFromWorkspace)(workspace, defaultOptions.project);
const assets = (0, schematics_1.getProjectTargetOptions)(project, 'build').assets;
const assetsString = JSON.stringify(assets);
const iconPathSegment = '@ant-design/icons-angular';
expect(assetsString).toContain(iconPathSegment);
}));
it('should required modules and providers', () => __awaiter(void 0, void 0, void 0, function* () {
const options = Object.assign({}, defaultOptions);
const tree = yield runner.runSchematic('ng-add-setup-project', options, appTree);
const fileContent = (0, get_file_content_1.getFileContent)(tree, '/projects/ng-zorro/src/app/app-module.ts');
expect(fileContent).toContain('provideHttpClient()');
}));
it('should add provideAnimationsAsync() function call if animations is enable', () => __awaiter(void 0, void 0, void 0, function* () {
const options = Object.assign(Object.assign({}, defaultOptions), { animations: true });
const tree = yield runner.runSchematic('ng-add-setup-project', options, appTree);
const fileContent = (0, get_file_content_1.getFileContent)(tree, '/projects/ng-zorro/src/app/app-module.ts');
expect(fileContent).toContain('provideAnimationsAsync()');
}));
it(`should add provideAnimationsAsync('noop') function call if animations is disable`, () => __awaiter(void 0, void 0, void 0, function* () {
const options = Object.assign(Object.assign({}, defaultOptions), { animations: false });
const tree = yield runner.runSchematic('ng-add-setup-project', options, appTree);
const fileContent = (0, get_file_content_1.getFileContent)(tree, '/projects/ng-zorro/src/app/app-module.ts');
expect(fileContent).toContain(`provideAnimationsAsync('noop')`);
}));
it('should register default locale id', () => __awaiter(void 0, void 0, void 0, function* () {
const options = Object.assign({}, defaultOptions);
const tree = yield runner.runSchematic('ng-add-setup-project', options, appTree);
const fileContent = (0, get_file_content_1.getFileContent)(tree, '/projects/ng-zorro/src/app/app-module.ts');
expect(fileContent).not.toContain('NZ_I18N');
expect(fileContent).toContain('provideNzI18n(en_US)');
expect(fileContent).toContain('registerLocaleData(en)');
}));
it('should register specified locale id', () => __awaiter(void 0, void 0, void 0, function* () {
const options = Object.assign(Object.assign({}, defaultOptions), { locale: 'zh_CN' });
const tree = yield runner.runSchematic('ng-add-setup-project', options, appTree);
const fileContent = (0, get_file_content_1.getFileContent)(tree, '/projects/ng-zorro/src/app/app-module.ts');
expect(fileContent).not.toContain('NZ_I18N');
expect(fileContent).toContain('provideNzI18n(zh_CN)');
expect(fileContent).toContain('registerLocaleData(zh)');
}));
it('should not add locale id if locale id is set up', () => __awaiter(void 0, void 0, void 0, function* () {
const options = Object.assign(Object.assign({}, defaultOptions), { i18n: 'zh_CN' });
yield runner.runSchematic('ng-add-setup-project', Object.assign({}, defaultOptions), appTree);
spyOn(console, 'log');
const tree = yield runner.runSchematic('ng-add-setup-project', options, appTree);
const fileContent = (0, get_file_content_1.getFileContent)(tree, '/projects/ng-zorro/src/app/app-module.ts');
expect(fileContent).toContain('provideNzI18n(en_US)');
expect(fileContent).toContain('registerLocaleData(en)');
expect(fileContent).not.toContain('NZ_I18N');
expect(fileContent).not.toContain('provideNzI18n(zh_CN)');
expect(fileContent).not.toContain('registerLocaleData(zh)');
expect(console.log).toHaveBeenCalledWith(jasmine.stringMatching(/Could not add the registerLocaleData to file/));
}));
});
//# sourceMappingURL=index.spec.js.map

File diff suppressed because one or more lines are too long

15
node_modules/ng-zorro-antd/schematics/ng-add/schema.js generated vendored Normal file
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.ProjectTemplate = void 0;
var ProjectTemplate;
(function (ProjectTemplate) {
ProjectTemplate["Blank"] = "blank";
ProjectTemplate["Sidemenu"] = "sidemenu";
ProjectTemplate["Topnav"] = "topnav";
ProjectTemplate["None"] = "none";
})(ProjectTemplate || (exports.ProjectTemplate = ProjectTemplate = {}));
//# sourceMappingURL=schema.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../schematics/ng-add/schema.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAwCH,IAAY,eAKX;AALD,WAAY,eAAe;IACzB,kCAAe,CAAA;IACf,wCAAqB,CAAA;IACrB,oCAAiB,CAAA;IACjB,gCAAa,CAAA;AACf,CAAC,EALW,eAAe,+BAAf,eAAe,QAK1B"}

View File

@@ -0,0 +1,124 @@
{
"$schema": "http://json-schema.org/schema",
"$id": "nz-ng-add",
"title": "Ant Design of Angular(NG-ZORRO) ng-add schematic",
"type": "object",
"properties": {
"project": {
"type": "string",
"description": "Name of the project.",
"$default": {
"$source": "projectName"
}
},
"skipPackageJson": {
"type": "boolean",
"default": false,
"description": "Do not add ng-zorro-antd dependencies to package.json (e.g., --skipPackageJson)"
},
"skipInstall": {
"type": "boolean",
"default": false,
"description": "Do not install dependency package."
},
"dynamicIcon": {
"type": "boolean",
"default": false,
"description": "Whether icon should dynamic loading.",
"x-prompt": "Enable icon dynamic loading [ Detail: https://ng.ant.design/components/icon/en ]"
},
"theme": {
"type": "boolean",
"default": false,
"description": "Whether custom theme file should be set up.",
"x-prompt": "Set up custom theme file [ Detail: https://ng.ant.design/docs/customize-theme/en ]"
},
"locale": {
"type": "string",
"description": "Add locale code to module (e.g., --locale=en_US)",
"default": "en_US",
"x-prompt": {
"message": "Choose your locale code:",
"type": "list",
"items": [
"en_US",
"uk_UA",
"de_DE",
"fr_FR",
"zh_CN",
"zh_TW",
"ko_KR",
"ja_JP",
"ar_EG",
"cs_CZ",
"el_GR",
"et_EE",
"hu_HU",
"it_IT",
"ms_MY",
"nl_NL",
"pt_PT",
"sl_SI",
"th_TH",
"vi_VN",
"bg_BG",
"da_DK",
"en_GB",
"fa_IR",
"he_IL",
"hy_AM",
"ku_IQ",
"nb_NO",
"ro_RO",
"sr_RS",
"ca_ES",
"fi_FI",
"hi_IN",
"id_ID",
"ka_GE",
"lv_LV",
"ne_NP",
"pl_PL",
"ru_RU",
"sv_SE",
"tr_TR",
"es_ES",
"fr_BE",
"hr_HR",
"is_IS",
"kn_IN",
"mn_MN",
"nl_BE",
"pt_BR",
"sk_SK",
"ta_IN"
]
}
},
"template": {
"type": "string",
"default": "blank",
"description": "Create an Angular project with using preset template.",
"x-prompt": {
"message": "Choose template to create project:",
"type": "list",
"items": [
"blank",
"sidemenu",
"topnav"
]
}
},
"gestures": {
"type": "boolean",
"default": false,
"description": "Whether gesture support should be set up."
},
"animations": {
"type": "boolean",
"default": true,
"description": "Whether Angular browser animations should be set up."
}
},
"required": []
}

View File

@@ -0,0 +1,41 @@
"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.addIconToAssets = addIconToAssets;
const schematics_1 = require("@angular/cdk/schematics");
const utility_1 = require("@schematics/angular/utility");
const chalk_1 = require("chalk");
const iconPathSegment = '@ant-design/icons-angular';
const iconAssetObject = {
'glob': '**/*',
'input': './node_modules/@ant-design/icons-angular/src/inline-svg/',
'output': '/assets/'
};
function addIconToAssets(options) {
return (0, utility_1.updateWorkspace)(workspace => {
const project = (0, schematics_1.getProjectFromWorkspace)(workspace, options.project);
const targetOptions = (0, schematics_1.getProjectTargetOptions)(project, 'build');
if (!targetOptions.assets) {
targetOptions.assets = [Object.assign({}, iconAssetObject)];
}
else {
const assets = targetOptions.assets;
const assetsString = JSON.stringify(assets);
if (!assetsString.includes(iconPathSegment)) {
assets.push(Object.assign({}, iconAssetObject));
}
else {
console.log();
console.log((0, chalk_1.yellow)(`Could not add the icon assets to the CLI project assets ` +
`because there is already a icon assets file referenced.`));
console.log((0, chalk_1.yellow)(`Please manually add the following config to your assets:`));
console.log((0, chalk_1.cyan)(JSON.stringify(iconAssetObject, null, 2)));
return;
}
}
});
}
//# sourceMappingURL=add-icon-assets.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"add-icon-assets.js","sourceRoot":"","sources":["../../../../schematics/ng-add/setup-project/add-icon-assets.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAiBH,0CAsBC;AArCD,wDAA2F;AAG3F,yDAA8D;AAC9D,iCAAqC;AAIrC,MAAM,eAAe,GAAG,2BAA2B,CAAC;AACpD,MAAM,eAAe,GAAG;IACtB,MAAM,EAAE,MAAM;IACd,OAAO,EAAE,0DAA0D;IACnE,QAAQ,EAAE,UAAU;CACrB,CAAC;AAEF,SAAgB,eAAe,CAAC,OAAe;IAC7C,OAAO,IAAA,yBAAe,EAAC,SAAS,CAAC,EAAE;QACjC,MAAM,OAAO,GAAG,IAAA,oCAAuB,EAAC,SAAS,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;QACpE,MAAM,aAAa,GAAG,IAAA,oCAAuB,EAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAEhE,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE,CAAC;YAC1B,aAAa,CAAC,MAAM,GAAG,mBAAM,eAAe,EAAG,CAAC;QAClD,CAAC;aAAM,CAAC;YACN,MAAM,MAAM,GAAG,aAAa,CAAC,MAAgC,CAAC;YAC9D,MAAM,YAAY,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;YAC5C,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,eAAe,CAAC,EAAE,CAAC;gBAC5C,MAAM,CAAC,IAAI,mBAAM,eAAe,EAAG,CAAC;YACtC,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,GAAG,EAAE,CAAC;gBACd,OAAO,CAAC,GAAG,CAAC,IAAA,cAAM,EAAC,0DAA0D;oBAC3E,yDAAyD,CAAC,CAAC,CAAC;gBAC9D,OAAO,CAAC,GAAG,CAAC,IAAA,cAAM,EAAC,0DAA0D,CAAC,CAAC,CAAC;gBAChF,OAAO,CAAC,GAAG,CAAC,IAAA,YAAI,EAAC,IAAI,CAAC,SAAS,CAAC,eAAe,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;gBAC5D,OAAO;YACT,CAAC;QACH,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC"}

View File

@@ -0,0 +1,26 @@
"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.addRequiredProviders = addRequiredProviders;
const schematics_1 = require("@angular-devkit/schematics");
const utility_1 = require("@schematics/angular/utility");
function addRequiredProviders(options) {
return (0, schematics_1.chain)([
addAnimations(options),
addHttpClient(options)
]);
}
function addAnimations(options) {
return (0, utility_1.addRootProvider)(options.project, ({ code, external }) => {
return code `${external('provideAnimationsAsync', '@angular/platform-browser/animations/async')}(${options.animations ? '' : `'noop'`})`;
});
}
function addHttpClient(options) {
return (0, utility_1.addRootProvider)(options.project, ({ code, external }) => {
return code `${external('provideHttpClient', '@angular/common/http')}()`;
});
}
//# sourceMappingURL=add-required-providers.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"add-required-providers.js","sourceRoot":"","sources":["../../../../schematics/ng-add/setup-project/add-required-providers.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAOH,oDAKC;AAVD,2DAAyD;AACzD,yDAA8D;AAI9D,SAAgB,oBAAoB,CAAC,OAAe;IAClD,OAAO,IAAA,kBAAK,EAAC;QACX,aAAa,CAAC,OAAO,CAAC;QACtB,aAAa,CAAC,OAAO,CAAC;KACvB,CAAC,CAAC;AACL,CAAC;AAED,SAAS,aAAa,CAAC,OAAe;IACpC,OAAO,IAAA,yBAAe,EAAC,OAAO,CAAC,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE;QAC7D,OAAO,IAAI,CAAA,GAAG,QAAQ,CACpB,wBAAwB,EACxB,4CAA4C,CAC7C,IAAI,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,GAAG,CAAC;IAC7C,CAAC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,aAAa,CAAC,OAAe;IACpC,OAAO,IAAA,yBAAe,EAAC,OAAO,CAAC,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE;QAC7D,OAAO,IAAI,CAAA,GAAG,QAAQ,CACpB,mBAAmB,EACnB,sBAAsB,CACvB,IAAI,CAAC;IACR,CAAC,CAAC,CAAC;AACL,CAAC"}

View File

@@ -0,0 +1,45 @@
"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 });
exports.hammerjsImport = hammerjsImport;
const schematics_1 = require("@angular/cdk/schematics");
const utility_1 = require("@schematics/angular/utility");
const chalk_1 = require("chalk");
const hammerjsImportStatement = `import 'hammerjs';`;
/** Adds HammerJS to the main file of the specified Angular CLI project. */
function hammerjsImport(options) {
return (host) => __awaiter(this, void 0, void 0, function* () {
const workspace = yield (0, utility_1.readWorkspace)(host);
const project = (0, schematics_1.getProjectFromWorkspace)(workspace, options.project);
const mainFile = (0, schematics_1.getProjectMainFile)(project);
const recorder = host.beginUpdate(mainFile);
const buffer = host.read(mainFile);
if (!buffer) {
console.log();
console.error((0, chalk_1.red)(`Could not read the project main file (${(0, chalk_1.blue)(mainFile)}). Please manually ` +
`import HammerJS in your main TypeScript file.`));
return;
}
const fileContent = buffer.toString('utf8');
if (fileContent.includes(hammerjsImportStatement)) {
console.log();
console.log(`HammerJS is already imported in the project main file (${(0, chalk_1.blue)(mainFile)}).`);
return;
}
recorder.insertRight(0, `${hammerjsImportStatement}\n`);
host.commitUpdate(recorder);
});
}
//# sourceMappingURL=hammerjs-import.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"hammerjs-import.js","sourceRoot":"","sources":["../../../../schematics/ng-add/setup-project/hammerjs-import.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;AAaH,wCA2BC;AAtCD,wDAAsF;AAGtF,yDAA4D;AA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ICENSE 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 add_icon_assets_1 = require("./add-icon-assets");
const add_required_providers_1 = require("./add-required-providers");
const hammerjs_import_1 = require("./hammerjs-import");
const register_locale_1 = require("./register-locale");
const theming_1 = require("./theming");
function default_1(options) {
return (0, schematics_1.chain)([
(0, register_locale_1.registerLocale)(options),
(0, add_required_providers_1.addRequiredProviders)(options),
(0, theming_1.addThemeToAppStyles)(options),
options.dynamicIcon ? (0, add_icon_assets_1.addIconToAssets)(options) : (0, schematics_1.noop)(),
options.gestures ? (0, hammerjs_import_1.hammerjsImport)(options) : (0, schematics_1.noop)()
]);
}
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../schematics/ng-add/setup-project/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAWH,4BAQC;AAjBD,2DAA+D;AAG/D,uDAAoD;AACpD,qEAAgE;AAChE,uDAAmD;AACnD,uDAAmD;AACnD,uCAAgD;AAEhD,mBAAyB,OAAe;IACtC,OAAO,IAAA,kBAAK,EAAC;QACX,IAAA,gCAAc,EAAC,OAAO,CAAC;QACvB,IAAA,6CAAoB,EAAC,OAAO,CAAC;QAC7B,IAAA,6BAAmB,EAAC,OAAO,CAAC;QAC5B,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,IAAA,iCAAe,EAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAA,iBAAI,GAAE;QACvD,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAA,gCAAc,EAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAA,iBAAI,GAAE;KACpD,CAAC,CAAC;AACL,CAAC"}

View File

@@ -0,0 +1,267 @@
"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 });
exports.registerLocale = registerLocale;
const schematics_1 = require("@angular/cdk/schematics");
const schematics_2 = require("@angular-devkit/schematics");
const utility_1 = require("@schematics/angular/utility");
const change_1 = require("@schematics/angular/utility/change");
const app_config_1 = require("@schematics/angular/utility/standalone/app_config");
const util_1 = require("@schematics/angular/utility/standalone/util");
const chalk_1 = require("chalk");
const ts = require("typescript");
const apply_changes_1 = require("../../utils/apply-changes");
function registerLocale(options) {
return (host) => __awaiter(this, void 0, void 0, function* () {
const workspace = yield (0, utility_1.readWorkspace)(host);
const project = (0, schematics_1.getProjectFromWorkspace)(workspace, options.project);
const mainFile = (0, schematics_1.getProjectMainFile)(project);
if ((0, schematics_1.isStandaloneApp)(host, mainFile)) {
return registerLocaleInStandaloneApp(mainFile, options);
}
else {
return registerLocaleInAppModule(mainFile, options);
}
});
}
/**
* Safely creates an import change, returning NoopChange if the moduleSource is invalid
* or if the import already exists.
*/
function safeInsertImport(moduleSource, filePath, symbolName, fileName, isDefault = false) {
if (!moduleSource) {
console.log();
console.log((0, chalk_1.yellow)(`Could not insert import for ${symbolName} in file (${(0, chalk_1.blue)(filePath)}).`));
console.log((0, chalk_1.yellow)(`The source file is invalid.`));
return new change_1.NoopChange();
}
// Check if the import already exists
const allImports = (0, schematics_1.findNodes)(moduleSource, ts.SyntaxKind.ImportDeclaration);
if (!allImports) {
return new change_1.NoopChange();
}
const importExists = allImports.some(node => {
// Make sure it's an import declaration
if (!ts.isImportDeclaration(node)) {
return false;
}
if (!node.moduleSpecifier) {
return false;
}
// Check if this import is from the same file
if (!ts.isStringLiteral(node.moduleSpecifier)) {
return false;
}
const importPath = node.moduleSpecifier.text;
if (importPath !== fileName) {
return false;
}
// Check if the symbol is already imported
if (!node.importClause) {
return false;
}
const namedBindings = node.importClause.namedBindings;
if (!namedBindings) {
return false;
}
if (ts.isNamedImports(namedBindings)) {
return namedBindings.elements.some(element => element.name.text === symbolName);
}
return false;
});
if (importExists) {
return new change_1.NoopChange();
}
try {
return (0, schematics_1.insertImport)(moduleSource, filePath, symbolName, fileName, isDefault);
}
catch (e) {
console.log();
console.log((0, chalk_1.yellow)(`Could not insert import for ${symbolName} in file (${(0, chalk_1.blue)(filePath)}).`));
console.log((0, chalk_1.yellow)(`Error: ${e.message}`));
return new change_1.NoopChange();
}
}
function registerLocaleInAppModule(mainFile, options) {
return (host) => __awaiter(this, void 0, void 0, function* () {
const appModulePath = (0, schematics_1.getAppModulePath)(host, mainFile);
const moduleSource = (0, schematics_1.parseSourceFile)(host, appModulePath);
const locale = options.locale || 'en_US';
const localePrefix = locale.split('_')[0];
(0, apply_changes_1.applyChangesToFile)(host, appModulePath, [
safeInsertImport(moduleSource, appModulePath, 'provideNzI18n', 'ng-zorro-antd/i18n'),
safeInsertImport(moduleSource, appModulePath, locale, 'ng-zorro-antd/i18n'),
safeInsertImport(moduleSource, appModulePath, 'registerLocaleData', '@angular/common'),
safeInsertImport(moduleSource, appModulePath, localePrefix, `@angular/common/locales/${localePrefix}`, true),
registerLocaleData(moduleSource, appModulePath, localePrefix),
...insertI18nTokenProvide(moduleSource, appModulePath, locale)
]);
});
}
function registerLocaleInStandaloneApp(mainFile, options) {
const locale = options.locale || 'en_US';
return (0, schematics_2.chain)([
(host) => __awaiter(this, void 0, void 0, function* () {
try {
const bootstrapCall = (0, util_1.findBootstrapApplicationCall)(host, mainFile);
if (!bootstrapCall) {
console.log();
console.log((0, chalk_1.yellow)(`Could not find bootstrap application call in file (${(0, chalk_1.blue)(mainFile)}).`));
return void 0;
}
const appConfig = (0, app_config_1.findAppConfig)(bootstrapCall, host, mainFile);
if (!appConfig || !appConfig.filePath) {
console.log();
console.log((0, chalk_1.yellow)(`Could not find app config in file (${(0, chalk_1.blue)(mainFile)}).`));
return void 0;
}
const appConfigFile = appConfig.filePath;
const appConfigSource = (0, schematics_1.parseSourceFile)(host, appConfig.filePath);
if (!appConfigSource) {
console.log();
console.log((0, chalk_1.yellow)(`Could not parse app config file (${(0, chalk_1.blue)(appConfigFile)}).`));
return void 0;
}
const localePrefix = locale.split('_')[0];
(0, apply_changes_1.applyChangesToFile)(host, appConfigFile, [
safeInsertImport(appConfigSource, appConfigFile, locale, 'ng-zorro-antd/i18n'),
safeInsertImport(appConfigSource, appConfigFile, 'registerLocaleData', '@angular/common'),
safeInsertImport(appConfigSource, appConfigFile, localePrefix, `@angular/common/locales/${localePrefix}`, true),
registerLocaleData(appConfigSource, appConfigFile, localePrefix)
]);
}
catch (e) {
console.log((0, chalk_1.yellow)(`Error registering locale in standalone app: ${e.message}`));
}
}),
(0, utility_1.addRootProvider)(options.project, ({ code, external }) => {
return code `${external('provideNzI18n', 'ng-zorro-antd/i18n')}(${locale})`;
})
]);
}
function registerLocaleData(moduleSource, modulePath, locale) {
const allImports = (0, schematics_1.findNodes)(moduleSource, ts.SyntaxKind.ImportDeclaration);
const allFun = (0, schematics_1.findNodes)(moduleSource, ts.SyntaxKind.ExpressionStatement);
// Check if allImports is valid before proceeding
if (!allImports || allImports.length === 0) {
console.log((0, chalk_1.yellow)(`Could not add the registerLocaleData to file (${(0, chalk_1.blue)(modulePath)}).` +
`because no import declarations were found.`));
console.log((0, chalk_1.yellow)(`Please manually add the following code:`));
console.log((0, chalk_1.cyan)(`registerLocaleData(${locale});`));
return new change_1.NoopChange();
}
// Safely filter the expression statements
const registerLocaleDataFun = allFun.filter(node => {
if (!node)
return false;
const children = node.getChildren();
if (!children || children.length === 0) {
return false;
}
const firstChild = children[0];
if (!firstChild) {
return false;
}
const firstChildChildren = firstChild.getChildren();
if (!firstChildChildren || firstChildChildren.length === 0) {
return false;
}
const firstChildFirstChild = firstChildChildren[0];
if (!firstChildFirstChild) {
return false;
}
return firstChildFirstChild.getText() === 'registerLocaleData';
});
if (registerLocaleDataFun.length === 0) {
return (0, schematics_1.insertAfterLastOccurrence)(allImports, `\n\nregisterLocaleData(${locale});`, modulePath, 0);
}
else {
console.log((0, chalk_1.yellow)(`Could not add the registerLocaleData to file (${(0, chalk_1.blue)(modulePath)}).` +
`because there is already a registerLocaleData function.`));
console.log((0, chalk_1.yellow)(`Please manually add the following code:`));
console.log((0, chalk_1.cyan)(`registerLocaleData(${locale});`));
return new change_1.NoopChange();
}
}
function insertI18nTokenProvide(moduleSource, modulePath, locale) {
const metadataField = 'providers';
const nodes = (0, schematics_1.getDecoratorMetadata)(moduleSource, 'NgModule', '@angular/core');
// Check if nodes are valid
if (!nodes || nodes.length === 0) {
console.log((0, chalk_1.yellow)(`Could not find NgModule decorator in file (${(0, chalk_1.blue)(modulePath)}).`));
console.log((0, chalk_1.yellow)(`Please manually add the following code to your providers:`));
console.log((0, chalk_1.cyan)(`provideNzI18n(${locale})`));
return [];
}
const addProvide = (0, schematics_1.addSymbolToNgModuleMetadata)(moduleSource, modulePath, 'providers', `provideNzI18n(${locale})`, null);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const node = nodes[0];
if (!node) {
return [];
}
// Check if a node has properties
if (!node.properties) {
console.log((0, chalk_1.yellow)(`Could not find properties in NgModule decorator in file (${(0, chalk_1.blue)(modulePath)}).`));
console.log((0, chalk_1.yellow)(`Please manually add the following code to your providers:`));
console.log((0, chalk_1.cyan)(`provideNzI18n(${locale})`));
return [];
}
const matchingProperties = node.properties
.filter(prop => prop && prop.kind === ts.SyntaxKind.PropertyAssignment)
.filter((prop) => {
if (!prop || !prop.name)
return false;
const name = prop.name;
switch (name.kind) {
case ts.SyntaxKind.Identifier:
return name.getText(moduleSource) === metadataField;
case ts.SyntaxKind.StringLiteral:
return name.text === metadataField;
}
return false;
});
if (!matchingProperties) {
return [];
}
if (matchingProperties.length) {
const assignment = matchingProperties[0];
if (!assignment || !assignment.initializer || assignment.initializer.kind !== ts.SyntaxKind.ArrayLiteralExpression) {
return [];
}
const arrLiteral = assignment.initializer;
if (!arrLiteral.elements || arrLiteral.elements.length === 0) {
return addProvide;
}
else {
// Safely check for getText method before calling it
const provideWithToken = arrLiteral.elements.some(e => e && typeof e.getText === 'function' && e.getText().includes('NZ_I18N'));
const provideWithFunc = arrLiteral.elements.some(e => e && typeof e.getText === 'function' && e.getText().includes('provideNzI18n'));
if (!provideWithFunc && !provideWithToken) {
return addProvide;
}
console.log();
console.log((0, chalk_1.yellow)(`Could not provide the locale token to file (${(0, chalk_1.blue)(modulePath)}), because there is already a locale token in providers.`));
if (provideWithToken) {
console.log((0, chalk_1.yellow)(`Please manually add the following code to your providers:`));
console.log((0, chalk_1.cyan)(`provideNzI18n(${locale})`));
}
return [];
}
}
else {
return addProvide;
}
}
//# sourceMappingURL=register-locale.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,141 @@
"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 });
exports.addThemeToAppStyles = addThemeToAppStyles;
const schematics_1 = require("@angular/cdk/schematics");
const core_1 = require("@angular-devkit/core");
const schematics_2 = require("@angular-devkit/schematics");
const utility_1 = require("@schematics/angular/utility");
const change_1 = require("@schematics/angular/utility/change");
const path_1 = require("path");
const create_custom_theme_1 = require("../../utils/create-custom-theme");
const compiledThemePathSegment = 'ng-zorro-antd';
const compiledThemePath = './node_modules/ng-zorro-antd/ng-zorro-antd.min.css';
const defaultCustomThemeFilename = 'theme.less';
/** Object that maps a CLI target to its default builder name. */
const defaultTargetBuilders = {
build: ['@angular/build:application'],
test: ['@angular/build:karma']
};
/** Add pre-built styles to the main project style file. */
function addThemeToAppStyles(options) {
return (host, context) => __awaiter(this, void 0, void 0, function* () {
if (options.theme) {
return insertCustomTheme(options.project, host, context.logger);
}
else {
return insertCompiledTheme(options.project, context.logger);
}
});
}
/**
* Insert a custom theme to a project style file. If no valid style file could be found, a new
* Scss file for the custom theme will be created.
*/
function insertCustomTheme(projectName, host, logger) {
return __awaiter(this, void 0, void 0, function* () {
const workspace = yield (0, utility_1.readWorkspace)(host);
const project = (0, schematics_1.getProjectFromWorkspace)(workspace, projectName);
const stylesPath = (0, schematics_1.getProjectStyleFile)(project, 'less');
const themeContent = (0, create_custom_theme_1.createCustomTheme)();
if (!stylesPath) {
if (!project.sourceRoot) {
throw new schematics_2.SchematicsException(`Could not find source root for project: "${projectName}". ` +
`Please make sure that the "sourceRoot" property is set in the workspace config.`);
}
// Normalize the path through the devkit utilities because we want to avoid having
// unnecessary path segments and window backslash delimiters.
const customThemePath = (0, core_1.normalize)((0, path_1.join)(project.sourceRoot, defaultCustomThemeFilename));
if (host.exists(customThemePath)) {
logger.warn(`Cannot create a custom NG-ZORRO theme because
${customThemePath} already exists. Skipping custom theme generation.`);
return (0, schematics_2.noop)();
}
host.create(customThemePath, themeContent);
return addThemeStyleToTarget(projectName, 'build', customThemePath, logger);
}
const insertion = new change_1.InsertChange(stylesPath, 0, themeContent);
const recorder = host.beginUpdate(stylesPath);
recorder.insertLeft(insertion.pos, insertion.toAdd);
host.commitUpdate(recorder);
});
}
/** Insert a pre-built theme into the angular.json file. */
function insertCompiledTheme(project, logger) {
return (0, schematics_2.chain)([
addThemeStyleToTarget(project, 'build', compiledThemePath, logger),
addThemeStyleToTarget(project, 'test', compiledThemePath, logger)
]);
}
/** Adds a theming style entry to the given project target options. */
function addThemeStyleToTarget(projectName, targetName, assetPath, logger) {
return (0, utility_1.updateWorkspace)(workspace => {
const project = (0, schematics_1.getProjectFromWorkspace)(workspace, projectName);
// Do not update the builder options in case the target does not use the default CLI builder.
if (!validateDefaultTargetBuilder(project, targetName, logger)) {
return;
}
const targetOptions = (0, schematics_1.getProjectTargetOptions)(project, targetName);
const styles = targetOptions.styles;
if (!styles) {
targetOptions.styles = [assetPath];
}
else {
const existingStyles = styles.map(s => (typeof s === 'string' ? s : s.input));
for (const [index, stylePath] of existingStyles.entries()) {
// If the given asset is already specified in the styles, we don't need to do anything.
if (stylePath === assetPath) {
return;
}
// In case a prebuilt theme is already set up, we can safely replace the theme with the new
// theme file. If a custom theme is set up, we are not able to safely replace the custom
// theme because these files can contain custom styles, while prebuilt themes are
// always packaged and considered replaceable.
if (stylePath.includes(defaultCustomThemeFilename)) {
logger.error(`Could not style file to the CLI project configuration ` +
`because there is already a custom theme file referenced.`);
logger.info(`Please manually add the following style file to your configuration:`);
logger.info(`${assetPath}`);
return;
}
else if (stylePath.includes(compiledThemePathSegment)) {
styles.splice(index, 1);
}
}
}
styles.unshift(assetPath);
});
}
/**
* Validates that the specified project target is configured with the default builders which are
* provided by the Angular CLI. If the configured builder does not match the default builder,
* this function can either throw or just show a warning.
*/
function validateDefaultTargetBuilder(project, targetName, logger) {
const defaultBuilder = defaultTargetBuilders[targetName];
const targetConfig = project.targets && project.targets.get(targetName);
const isDefaultBuilder = targetConfig && defaultBuilder.includes(targetConfig.builder);
if (!isDefaultBuilder && targetName === 'build') {
throw new schematics_2.SchematicsException(`Your project is not using the default builders for ` +
`"${targetName}". The NG-ZORRO schematics cannot add a theme to the workspace ` +
`configuration if the builder has been changed.`);
}
else if (!isDefaultBuilder) {
logger.warn(`Your project is not using the default builders for "${targetName}". This ` +
`means that we cannot add the configured theme to the "${targetName}" target.`);
}
return isDefaultBuilder;
}
//# sourceMappingURL=theming.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"theming.js","sourceRoot":"","sources":["../../../../schematics/ng-add/setup-project/theming.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;AAyBH,kDAQC;AA/BD,wDAAgH;AAEhH,+CAA0D;AAC1D,2DAA4G;AAC5G,yDAAgG;AAChG,+DAAkE;AAElE,+BAA4B;AAE5B,yEAAoE;AAGpE,MAAM,wBAAwB,GAAG,eAAe,CAAC;AACjD,MAAM,iBAAiB,GAAG,oDAAoD,CAAC;AAC/E,MAAM,0BAA0B,GAAG,YAAY,CAAC;AAEhD,iEAAiE;AACjE,MAAM,qBAAqB,GAAG;IAC5B,KAAK,EAAE,CAAC,4BAA4B,CAAC;IACrC,IAAI,EAAE,CAAC,sBAAsB,CAAC;CAC/B,CAAC;AAEF,2DAA2D;AAC3D,SAAgB,mBAAmB,CAAC,OAAe;IACjD,OAAO,CAAO,IAAU,EAAE,OAAyB,EAAE,EAAE;QACrD,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;YAClB,OAAO,iBAAiB,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;QAClE,CAAC;aAAM,CAAC;YACN,OAAO,mBAAmB,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;QAC9D,CAAC;IACH,CAAC,CAAA,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,SAAe,iBAAiB,CAAC,WAAmB,EAAE,IAAU,EAAE,MAAyB;;QACzF,MAAM,SAAS,GAAG,MAAM,IAAA,uBAAa,EAAC,IAAI,CAAC,CAAC;QAC5C,MAAM,OAAO,GAAG,IAAA,oCAAuB,EAAC,SAAS,EAAE,WAAW,CAAC,CAAC;QAChE,MAAM,UAAU,GAAG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C,IAAI,CAAC,qEAAqE,CAAC,CAAC;oBACnF,MAAM,CAAC,IAAI,CAAC,GAAG,SAAS,EAAE,CAAC,CAAC;oBAC5B,OAAO;gBACT,CAAC;qBAAM,IAAI,SAAS,CAAC,QAAQ,CAAC,wBAAwB,CAAC,EAAE,CAAC;oBACxD,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;gBAC1B,CAAC;YACH,CAAC;QACH,CAAC;QACD,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAC5B,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;;GAIG;AACH,SAAS,4BAA4B,CACnC,OAA0B,EAC1B,UAA4B,EAC5B,MAAyB;IAEzB,MAAM,cAAc,GAAG,qBAAqB,CAAC,UAAU,CAAC,CAAC;IACzD,MAAM,YAAY,GAAG,OAAO,CAAC,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IACxE,MAAM,gBAAgB,GAAG,YAAY,IAAI,cAAc,CAAC,QAAQ,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;IAEvF,IAAI,CAAC,gBAAgB,IAAI,UAAU,KAAK,OAAO,EAAE,CAAC;QAChD,MAAM,IAAI,gCAAmB,CAC3B,qDAAqD;YACrD,IAAI,UAAU,iEAAiE;YAC/E,gDAAgD,CACjD,CAAC;IACJ,CAAC;SAAM,IAAI,CAAC,gBAAgB,EAAE,CAAC;QAC7B,MAAM,CAAC,IAAI,CACT,uDAAuD,UAAU,UAAU;YAC3E,yDAAyD,UAAU,WAAW,CAC/E,CAAC;IACJ,CAAC;IAED,OAAO,gBAAgB,CAAC;AAC1B,CAAC"}

View File

@@ -0,0 +1,151 @@
"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 schematics_1 = require("@angular/cdk/schematics");
const core_1 = require("@angular-devkit/core");
const options_1 = require("@angular-devkit/schematics/tasks/package-manager/options");
const testing_1 = require("@angular-devkit/schematics/testing");
const utility_1 = require("@schematics/angular/utility");
const path_1 = require("path");
const test_app_1 = require("../testing/test-app");
const create_custom_theme_1 = require("../utils/create-custom-theme");
const get_file_content_1 = require("../utils/get-file-content");
describe('[standalone] ng-add schematic', () => {
const defaultOptions = {
project: 'ng-zorro'
};
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);
}));
it('should update package.json', () => __awaiter(void 0, void 0, void 0, function* () {
const options = Object.assign({}, defaultOptions);
const tree = yield runner.runSchematic('ng-add', options, appTree);
const packageJson = JSON.parse((0, get_file_content_1.getFileContent)(tree, '/package.json'));
const dependencies = packageJson.dependencies;
expect(dependencies['ng-zorro-antd']).toBeDefined();
expect(runner.tasks.some(task => task.name === options_1.NodePackageName)).toBe(true);
}));
it('should add hammerjs to package.json', () => __awaiter(void 0, void 0, void 0, function* () {
const options = Object.assign(Object.assign({}, defaultOptions), { gestures: true });
const tree = yield runner.runSchematic('ng-add', options, appTree);
const packageJson = JSON.parse((0, get_file_content_1.getFileContent)(tree, '/package.json'));
const dependencies = packageJson.dependencies;
expect(dependencies.hammerjs).toBeDefined();
}));
it('should skip package.json', () => __awaiter(void 0, void 0, void 0, function* () {
const options = Object.assign(Object.assign({}, defaultOptions), { skipPackageJson: true });
const tree = yield runner.runSchematic('ng-add', options, appTree);
const packageJson = JSON.parse((0, get_file_content_1.getFileContent)(tree, '/package.json'));
const dependencies = packageJson.dependencies;
expect(dependencies['ng-zorro-antd']).toBeUndefined();
}));
it('should skip install dependency package', () => __awaiter(void 0, void 0, void 0, function* () {
const options = Object.assign(Object.assign({}, defaultOptions), { skipInstall: true });
yield runner.runSchematic('ng-add', options, appTree);
expect(runner.tasks.some(task => task.name === options_1.NodePackageName)).toBe(false);
}));
it('should add hammerjs import to project main file', () => __awaiter(void 0, void 0, void 0, function* () {
const options = Object.assign(Object.assign({}, defaultOptions), { gestures: true });
const tree = yield runner.runSchematic('ng-add-setup-project', options, appTree);
const workspace = yield (0, utility_1.readWorkspace)(tree);
const project = (0, schematics_1.getProjectFromWorkspace)(workspace, defaultOptions.project);
const fileContent = (0, get_file_content_1.getFileContent)(tree, (0, core_1.normalize)((0, path_1.join)(project.sourceRoot, 'main.ts')));
expect(fileContent).toContain(`import 'hammerjs';`);
}));
it('should add default theme', () => __awaiter(void 0, void 0, void 0, function* () {
const options = Object.assign({}, defaultOptions);
const tree = yield runner.runSchematic('ng-add-setup-project', options, appTree);
const workspace = yield (0, utility_1.readWorkspace)(tree);
const project = (0, schematics_1.getProjectFromWorkspace)(workspace, defaultOptions.project);
expect((0, schematics_1.getProjectTargetOptions)(project, 'build').styles).toContain('./node_modules/ng-zorro-antd/ng-zorro-antd.min.css');
}));
it('should add custom theme', () => __awaiter(void 0, void 0, void 0, function* () {
const options = Object.assign(Object.assign({}, defaultOptions), { theme: true });
appTree = yield (0, test_app_1.createTestApp)(runner, { style: 'less' });
const tree = yield runner.runSchematic('ng-add-setup-project', options, appTree);
const workspace = yield (0, utility_1.readWorkspace)(tree);
const project = (0, schematics_1.getProjectFromWorkspace)(workspace, defaultOptions.project);
const customThemePath = (0, core_1.normalize)((0, path_1.join)(project.sourceRoot, 'styles.less'));
const buffer = tree.read(customThemePath);
const themeContent = buffer.toString();
expect(themeContent).toContain((0, create_custom_theme_1.createCustomTheme)());
expect((0, schematics_1.getProjectTargetOptions)(project, 'build').styles).toContain('projects/ng-zorro/src/styles.less');
}));
it('should add custom theme file when no LESS file in project', () => __awaiter(void 0, void 0, void 0, function* () {
const options = Object.assign(Object.assign({}, defaultOptions), { theme: true });
const tree = yield runner.runSchematic('ng-add-setup-project', options, appTree);
const workspace = yield (0, utility_1.readWorkspace)(tree);
const project = (0, schematics_1.getProjectFromWorkspace)(workspace, defaultOptions.project);
expect((0, schematics_1.getProjectTargetOptions)(project, 'build').styles).toContain('projects/ng-zorro/src/theme.less');
}));
it('should add icon assets', () => __awaiter(void 0, void 0, void 0, function* () {
const options = Object.assign(Object.assign({}, defaultOptions), { dynamicIcon: true });
const tree = yield runner.runSchematic('ng-add-setup-project', options, appTree);
const workspace = yield (0, utility_1.readWorkspace)(tree);
const project = (0, schematics_1.getProjectFromWorkspace)(workspace, defaultOptions.project);
const assets = (0, schematics_1.getProjectTargetOptions)(project, 'build').assets;
const assetsString = JSON.stringify(assets);
const iconPathSegment = '@ant-design/icons-angular';
expect(assetsString).toContain(iconPathSegment);
}));
it('should required modules and providers', () => __awaiter(void 0, void 0, void 0, function* () {
const options = Object.assign({}, defaultOptions);
const tree = yield runner.runSchematic('ng-add-setup-project', options, appTree);
const fileContent = (0, get_file_content_1.getFileContent)(tree, '/projects/ng-zorro/src/app/app.config.ts');
expect(fileContent).toContain('provideHttpClient()');
}));
it('should add provideAnimationsAsync() call function if animations is enable', () => __awaiter(void 0, void 0, void 0, function* () {
const options = Object.assign(Object.assign({}, defaultOptions), { animations: true });
const tree = yield runner.runSchematic('ng-add-setup-project', options, appTree);
const fileContent = (0, get_file_content_1.getFileContent)(tree, '/projects/ng-zorro/src/app/app.config.ts');
expect(fileContent).toContain('provideAnimationsAsync()');
}));
it(`should add provideAnimationsAsync('noop') function call if animations is disable`, () => __awaiter(void 0, void 0, void 0, function* () {
const options = Object.assign(Object.assign({}, defaultOptions), { animations: false });
const tree = yield runner.runSchematic('ng-add-setup-project', options, appTree);
const fileContent = (0, get_file_content_1.getFileContent)(tree, '/projects/ng-zorro/src/app/app.config.ts');
expect(fileContent).toContain(`provideAnimationsAsync('noop')`);
}));
it('should register default locale id', () => __awaiter(void 0, void 0, void 0, function* () {
const options = Object.assign({}, defaultOptions);
const tree = yield runner.runSchematic('ng-add-setup-project', options, appTree);
const fileContent = (0, get_file_content_1.getFileContent)(tree, '/projects/ng-zorro/src/app/app.config.ts');
expect(fileContent).toContain('provideNzI18n(en_US)');
expect(fileContent).toContain('registerLocaleData(en)');
}));
it('should register specified locale id', () => __awaiter(void 0, void 0, void 0, function* () {
const options = Object.assign(Object.assign({}, defaultOptions), { locale: 'zh_CN' });
const tree = yield runner.runSchematic('ng-add-setup-project', options, appTree);
const fileContent = (0, get_file_content_1.getFileContent)(tree, '/projects/ng-zorro/src/app/app.config.ts');
expect(fileContent).toContain('provideNzI18n(zh_CN)');
expect(fileContent).toContain('registerLocaleData(zh)');
}));
it('should not add locale id if locale id is set up', () => __awaiter(void 0, void 0, void 0, function* () {
const options = Object.assign(Object.assign({}, defaultOptions), { i18n: 'zh_CN' });
yield runner.runSchematic('ng-add-setup-project', Object.assign({}, defaultOptions), appTree);
spyOn(console, 'log');
const tree = yield runner.runSchematic('ng-add-setup-project', options, appTree);
const fileContent = (0, get_file_content_1.getFileContent)(tree, '/projects/ng-zorro/src/app/app.config.ts');
expect(fileContent).toContain('provideNzI18n(en_US)');
expect(fileContent).toContain('registerLocaleData(en)');
expect(fileContent).not.toContain('provideNzI18n(zh_CN)');
expect(fileContent).not.toContain('registerLocaleData(zh)');
expect(console.log).toHaveBeenCalledWith(jasmine.stringMatching(/Could not add the registerLocaleData to file/));
}));
});
//# sourceMappingURL=standalone.spec.js.map

File diff suppressed because one or more lines are too long