Skip to content

Commit cbb0822

Browse files
committed
chore(devextreme): create the localization gulp task alternative based on nx
1 parent f0a946c commit cbb0822

File tree

13 files changed

+1126
-166
lines changed

13 files changed

+1126
-166
lines changed

nx.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@
88
"{projectRoot}/**/*.ts",
99
"{projectRoot}/tsconfig.json",
1010
{ "externalDependencies": [ "devextreme-internal-tools", "ts-node", "typescript"] }
11+
],
12+
"devextreme-sources": [
13+
"{projectRoot}/js/**/*",
14+
"{projectRoot}/ts/**/*"
15+
],
16+
"devextreme-build-config": [
17+
"{projectRoot}/build/**/*",
18+
"{projectRoot}/webpack.config.js",
19+
"{projectRoot}/gulpfile.js"
1120
]
1221
},
1322
"targetDefaults": {

packages/devextreme/project.json

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,87 @@
77
"devextreme-scss"
88
],
99
"targets": {
10+
"clean:artifacts": {
11+
"executor": "devextreme-nx-infra-plugin:clean",
12+
"options": {
13+
"targetDirectory": "./artifacts",
14+
"excludePatterns": [
15+
"./artifacts/css",
16+
"./artifacts/npm/devextreme/package.json",
17+
"./artifacts/npm/devextreme-dist/package.json"
18+
]
19+
}
20+
},
21+
"clean:cldr-data": {
22+
"executor": "devextreme-nx-infra-plugin:clean",
23+
"options": {
24+
"targetDirectory": "./js/__internal/core/localization/cldr-data"
25+
}
26+
},
27+
"build:localization:generate": {
28+
"executor": "devextreme-nx-infra-plugin:localization",
29+
"options": {
30+
"messagesDir": "./js/localization/messages",
31+
"messageTemplate": "./build/gulp/localization-template.jst",
32+
"messageOutputDir": "./artifacts/js/localization",
33+
"generatedTemplate": "./build/gulp/generated_js.jst",
34+
"cldrDataOutputDir": "./js/__internal/core/localization/cldr-data",
35+
"defaultMessagesOutputDir": "./js/__internal/core/localization"
36+
},
37+
"inputs": [
38+
"{projectRoot}/js/localization/messages/**/*.json",
39+
"{projectRoot}/build/gulp/localization-template.jst",
40+
"{projectRoot}/build/gulp/generated_js.jst"
41+
],
42+
"outputs": [
43+
"{projectRoot}/artifacts/js/localization",
44+
"{projectRoot}/js/__internal/core/localization/default_messages.ts",
45+
"{projectRoot}/js/__internal/core/localization/cldr-data"
46+
],
47+
"cache": true
48+
},
49+
"build:localization:headers": {
50+
"executor": "devextreme-nx-infra-plugin:add-license-headers",
51+
"options": {
52+
"targetDirectory": "./artifacts/js/localization",
53+
"licenseTemplateFile": "./build/gulp/license-header.txt",
54+
"eulaUrl": "https://js.devexpress.com/Licensing/",
55+
"prependAfterLicense": "\"use strict\";\n\n",
56+
"separatorBetweenBannerAndContent": "",
57+
"includePatterns": ["**/*.js"]
58+
},
59+
"inputs": [
60+
"{projectRoot}/artifacts/js/localization/**/*.js",
61+
"{projectRoot}/build/gulp/license-header.txt"
62+
],
63+
"outputs": [
64+
"{projectRoot}/artifacts/js/localization"
65+
],
66+
"cache": true
67+
},
68+
"build:localization": {
69+
"executor": "nx:run-commands",
70+
"options": {
71+
"commands": [
72+
"pnpm nx clean:cldr-data devextreme",
73+
"pnpm nx build:localization:generate devextreme",
74+
"pnpm nx build:localization:headers devextreme"
75+
],
76+
"parallel": false
77+
},
78+
"inputs": [
79+
"{projectRoot}/js/localization/messages/**/*.json",
80+
"{projectRoot}/build/gulp/localization-template.jst",
81+
"{projectRoot}/build/gulp/generated_js.jst",
82+
"{projectRoot}/build/gulp/license-header.txt"
83+
],
84+
"outputs": [
85+
"{projectRoot}/artifacts/js/localization",
86+
"{projectRoot}/js/__internal/core/localization/default_messages.ts",
87+
"{projectRoot}/js/__internal/core/localization/cldr-data"
88+
],
89+
"cache": true
90+
},
1091
"build": {
1192
"executor": "nx:run-script",
1293
"options": {

packages/nx-infra-plugin/executors.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@
5454
"implementation": "./src/executors/karma-multi-env/executor",
5555
"schema": "./src/executors/karma-multi-env/schema.json",
5656
"description": "Run Karma tests sequentially across multiple Angular environments (client, server, hydration)"
57+
},
58+
"localization": {
59+
"implementation": "./src/executors/localization/executor",
60+
"schema": "./src/executors/localization/schema.json",
61+
"description": "Generate localization message files and TypeScript CLDR data modules"
5762
}
5863
}
5964
}

packages/nx-infra-plugin/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"dependencies": {
1515
"fs-extra": "^11.2.0",
1616
"glob": "11.1.0",
17+
"lodash": "^4.17.21",
1718
"rimraf": "3.0.2"
1819
},
1920
"peerDependencies": {
@@ -31,6 +32,7 @@
3132
"devDependencies": {
3233
"@types/fs-extra": "^11.0.4",
3334
"@types/jest": "29.5.12",
35+
"@types/lodash": "^4.17.0",
3436
"@types/node": "^18.0.0",
3537
"prettier": "catalog:tools",
3638
"ts-jest": "29.1.3",

packages/nx-infra-plugin/src/executors/add-license-headers/executor.e2e.spec.ts

Lines changed: 44 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ describe('AddLicenseHeadersExecutor E2E', () => {
6565
expect(indexContent).toContain('test-package');
6666
expect(indexContent).toContain('Version: 1.0.0');
6767
expect(indexContent).toContain('Developer Express Inc.');
68+
expect(indexContent).toContain('MIT license');
69+
const currentYear = new Date().getFullYear();
70+
expect(indexContent).toContain(`2012 - ${currentYear}`);
71+
expect(indexContent).toMatch(/Build date:/);
6872

6973
const utilsContent = await readFileText(path.join(npmDir, 'utils.js'));
7074
expect(utilsContent).toMatch(/^\/\*!/);
@@ -107,6 +111,46 @@ describe('AddLicenseHeadersExecutor E2E', () => {
107111

108112
expect(newContent).toContain(originalContent.trim());
109113
});
114+
115+
it('should support custom license template', async () => {
116+
const projectDir = path.join(tempDir, 'packages', 'test-lib');
117+
const buildDir = path.join(projectDir, 'build', 'gulp');
118+
fs.mkdirSync(buildDir, { recursive: true });
119+
120+
await writeFileText(
121+
path.join(buildDir, 'license-header.txt'),
122+
`/*!
123+
* DevExtreme (<%= file.relative %>)
124+
* Version: <%= version %>
125+
* Build date: <%= date %>
126+
*
127+
* Copyright (c) 2012 - <%= year %> Developer Express Inc. ALL RIGHTS RESERVED
128+
* Read about DevExtreme licensing here: <%= eula %>
129+
*/
130+
`,
131+
);
132+
133+
const options: AddLicenseHeadersExecutorSchema = {
134+
targetDirectory: './npm',
135+
packageJsonPath: './package.json',
136+
licenseTemplateFile: './build/gulp/license-header.txt',
137+
eulaUrl: 'https://js.devexpress.com/Licensing/',
138+
prependAfterLicense: '"use strict";\n\n',
139+
includePatterns: ['**/*.js'],
140+
};
141+
142+
const result = await executor(options, context);
143+
expect(result.success).toBe(true);
144+
145+
const npmDir = path.join(projectDir, 'npm');
146+
const content = await readFileText(path.join(npmDir, 'index.js'));
147+
148+
expect(content).toMatch(/^\/\*!/);
149+
expect(content).toContain('DevExtreme (index.js)');
150+
expect(content).toContain('https://js.devexpress.com/Licensing/');
151+
expect(content).toContain('"use strict";');
152+
expect(content).toContain("return 'Hello'");
153+
});
110154
});
111155

112156
describe('Idempotence', () => {
@@ -159,65 +203,6 @@ describe('AddLicenseHeadersExecutor E2E', () => {
159203
});
160204
});
161205

162-
describe('Header content validation', () => {
163-
it('should include package name in header', async () => {
164-
const options: AddLicenseHeadersExecutorSchema = {
165-
targetDirectory: './npm',
166-
packageJsonPath: './package.json',
167-
};
168-
169-
await executor(options, context);
170-
171-
const npmDir = path.join(tempDir, 'packages', 'test-lib', 'npm');
172-
const content = await readFileText(path.join(npmDir, 'index.js'));
173-
174-
expect(content).toContain('test-package');
175-
});
176-
177-
it('should include version in header', async () => {
178-
const options: AddLicenseHeadersExecutorSchema = {
179-
targetDirectory: './npm',
180-
packageJsonPath: './package.json',
181-
};
182-
183-
await executor(options, context);
184-
185-
const npmDir = path.join(tempDir, 'packages', 'test-lib', 'npm');
186-
const content = await readFileText(path.join(npmDir, 'index.js'));
187-
188-
expect(content).toContain('Version: 1.0.0');
189-
});
190-
191-
it('should include current year in header', async () => {
192-
const options: AddLicenseHeadersExecutorSchema = {
193-
targetDirectory: './npm',
194-
packageJsonPath: './package.json',
195-
};
196-
197-
await executor(options, context);
198-
199-
const npmDir = path.join(tempDir, 'packages', 'test-lib', 'npm');
200-
const content = await readFileText(path.join(npmDir, 'index.js'));
201-
202-
const currentYear = new Date().getFullYear();
203-
expect(content).toContain(`2012 - ${currentYear}`);
204-
});
205-
206-
it('should include build date in header', async () => {
207-
const options: AddLicenseHeadersExecutorSchema = {
208-
targetDirectory: './npm',
209-
packageJsonPath: './package.json',
210-
};
211-
212-
await executor(options, context);
213-
214-
const npmDir = path.join(tempDir, 'packages', 'test-lib', 'npm');
215-
const content = await readFileText(path.join(npmDir, 'index.js'));
216-
217-
expect(content).toMatch(/Build date:/);
218-
});
219-
});
220-
221206
describe('Error handling', () => {
222207
it('should fail gracefully with missing package.json', async () => {
223208
const options: AddLicenseHeadersExecutorSchema = {

0 commit comments

Comments
 (0)