Skip to content

Commit b6f0b7b

Browse files
committed
fix(nx-infra-plugin): apply license headers AFTER compress beautify to preserve banner indentation
1 parent 0d7ef32 commit b6f0b7b

6 files changed

Lines changed: 85 additions & 22 deletions

File tree

packages/devextreme/project.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -745,12 +745,7 @@
745745
"options": {
746746
"files": [
747747
{ "from": "./js/aspnet.js", "to": "./artifacts/js/dx.aspnet.mvc.js" }
748-
],
749-
"applyLicenseHeaders": {
750-
"targetSubdir": "./artifacts/js",
751-
"separator": "",
752-
"includePatterns": ["dx.aspnet.mvc.js"]
753-
}
748+
]
754749
},
755750
"inputs": ["{projectRoot}/js/aspnet.js"],
756751
"outputs": ["{projectRoot}/artifacts/js/dx.aspnet.mvc.js"]
@@ -759,7 +754,12 @@
759754
"executor": "devextreme-nx-infra-plugin:compress",
760755
"options": {
761756
"files": ["./artifacts/js/dx.aspnet.mvc.js"],
762-
"mode": { "name": "beautify" }
757+
"mode": { "name": "beautify" },
758+
"applyLicenseHeaders": {
759+
"targetSubdir": "./artifacts/js",
760+
"separator": "",
761+
"includePatterns": ["dx.aspnet.mvc.js"]
762+
}
763763
},
764764
"configurations": {
765765
"normalize": {

packages/nx-infra-plugin/src/executors/add-license-headers/schema.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,17 @@ export interface AddLicenseHeadersExecutorSchema {
1111
commentType?: '!' | '*';
1212
mode?: 'eula' | 'mit';
1313
}
14+
15+
export interface ApplyLicenseHeadersOption {
16+
licenseTemplateFile?: string;
17+
mode?: 'eula' | 'mit';
18+
eulaUrl?: string;
19+
version?: string;
20+
commentType?: '!' | '*';
21+
separator?: string;
22+
prependAfterLicense?: string;
23+
filenameMode?: 'relative' | 'basename';
24+
includePatterns?: readonly string[];
25+
excludePatterns?: readonly string[];
26+
targetSubdir?: string;
27+
}

packages/nx-infra-plugin/src/executors/compress/compress.impl.ts

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,18 @@ import { createExecutor } from '../../utils/create-executor';
66
import { expandEntries } from '../../utils/glob-discovery';
77
import {
88
ensureTrailingNewline,
9+
loadProjectPackageJson,
910
normalizeEol,
1011
readFileText,
1112
writeFileText,
1213
} from '../../utils/file-operations';
1314
import { CompressExecutorSchema, CompressMode, CompressModeName } from './schema';
14-
import { DEFAULT_EULA_URL } from '../add-license-headers/defaults';
15+
import { applyLicenseHeadersToDirectory } from '../add-license-headers/add-license-headers.impl';
16+
import { DEFAULT_EULA_URL, resolveLicenseTemplate } from '../add-license-headers/defaults';
17+
import type { ApplyLicenseHeadersOption } from '../add-license-headers/schema';
18+
19+
const ERROR_APPLY_LICENSE_HEADERS_TARGET_SUBDIR_REQUIRED =
20+
'Compress: applyLicenseHeaders.targetSubdir is required to specify the directory to apply headers to';
1521

1622
const STRIP_DEBUG_REGEX = /\/{2,}\s{0,}#DEBUG[\s\S]*?\/{2,}\s{0,}#ENDDEBUG/g;
1723

@@ -132,11 +138,41 @@ async function compressFile(filePath: string, mode: CompressMode): Promise<void>
132138
await writeFileText(filePath, await runStrategy(raw, resolved));
133139
}
134140

141+
async function applyLicenseHeadersIfRequested(
142+
applyLicenseHeaders: ApplyLicenseHeadersOption | undefined,
143+
projectRoot: string,
144+
): Promise<void> {
145+
if (!applyLicenseHeaders) {
146+
return;
147+
}
148+
if (!applyLicenseHeaders.targetSubdir) {
149+
throw new Error(ERROR_APPLY_LICENSE_HEADERS_TARGET_SUBDIR_REQUIRED);
150+
}
151+
const pkg = await loadProjectPackageJson(projectRoot);
152+
const templatePath = resolveLicenseTemplate(projectRoot, applyLicenseHeaders);
153+
const targetDir = path.join(projectRoot, applyLicenseHeaders.targetSubdir);
154+
await applyLicenseHeadersToDirectory({
155+
targetDir,
156+
pkg,
157+
templatePath,
158+
eulaUrl: applyLicenseHeaders.eulaUrl ?? DEFAULT_EULA_URL,
159+
mode: applyLicenseHeaders.mode,
160+
version: applyLicenseHeaders.version,
161+
commentType: applyLicenseHeaders.commentType,
162+
separator: applyLicenseHeaders.separator,
163+
prependAfterLicense: applyLicenseHeaders.prependAfterLicense,
164+
filenameMode: applyLicenseHeaders.filenameMode,
165+
includePatterns: applyLicenseHeaders.includePatterns,
166+
excludePatterns: applyLicenseHeaders.excludePatterns,
167+
});
168+
}
169+
135170
interface ResolvedCompress {
136171
projectRoot: string;
137172
files: string[];
138173
mode: CompressMode;
139174
modeName: string;
175+
applyLicenseHeaders?: ApplyLicenseHeadersOption;
140176
}
141177

142178
export default createExecutor<CompressExecutorSchema, ResolvedCompress>({
@@ -151,12 +187,14 @@ export default createExecutor<CompressExecutorSchema, ResolvedCompress>({
151187
files: expanded,
152188
mode: options.mode,
153189
modeName: typeof options.mode === 'string' ? options.mode : options.mode.name,
190+
applyLicenseHeaders: options.applyLicenseHeaders,
154191
};
155192
},
156-
run: async ({ projectRoot, files, mode, modeName }) => {
193+
run: async ({ projectRoot, files, mode, modeName, applyLicenseHeaders }) => {
157194
for (const filePath of files) {
158195
await compressFile(filePath, mode);
159196
logger.verbose(`Compressed ${path.relative(projectRoot, filePath)} (${modeName})`);
160197
}
198+
await applyLicenseHeadersIfRequested(applyLicenseHeaders, projectRoot);
161199
},
162200
});

packages/nx-infra-plugin/src/executors/compress/schema.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,24 @@
4141
"type": "array",
4242
"items": { "type": "string" },
4343
"description": "Glob patterns for files to exclude from compression (relative to project root)"
44+
},
45+
"applyLicenseHeaders": {
46+
"type": "object",
47+
"description": "When provided, applies DevExtreme license headers after compression. The targetSubdir field is required and resolves relative to the project root.",
48+
"properties": {
49+
"licenseTemplateFile": { "type": "string" },
50+
"mode": { "type": "string", "enum": ["eula", "mit"] },
51+
"eulaUrl": { "type": "string" },
52+
"version": { "type": "string" },
53+
"commentType": { "type": "string", "enum": ["!", "*"] },
54+
"separator": { "type": "string" },
55+
"prependAfterLicense": { "type": "string" },
56+
"filenameMode": { "type": "string", "enum": ["relative", "basename"] },
57+
"includePatterns": { "type": "array", "items": { "type": "string" } },
58+
"excludePatterns": { "type": "array", "items": { "type": "string" } },
59+
"targetSubdir": { "type": "string" }
60+
},
61+
"required": ["targetSubdir"]
4462
}
4563
},
4664
"required": ["files", "mode"]

packages/nx-infra-plugin/src/executors/compress/schema.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { ApplyLicenseHeadersOption } from '../add-license-headers/schema';
2+
13
export type CompressModeName = 'minify' | 'beautify' | 'strip-debug' | 'normalize';
24

35
export type CompressMode =
@@ -16,4 +18,5 @@ export interface CompressExecutorSchema {
1618
files: string[];
1719
mode: CompressMode;
1820
exclude?: string[];
21+
applyLicenseHeaders?: ApplyLicenseHeadersOption;
1922
}

packages/nx-infra-plugin/src/executors/copy-files/schema.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,6 @@
1-
export interface ApplyLicenseHeadersOption {
2-
licenseTemplateFile?: string;
3-
mode?: 'eula' | 'mit';
4-
eulaUrl?: string;
5-
version?: string;
6-
commentType?: '!' | '*';
7-
separator?: string;
8-
prependAfterLicense?: string;
9-
filenameMode?: 'relative' | 'basename';
10-
includePatterns?: readonly string[];
11-
excludePatterns?: readonly string[];
12-
targetSubdir?: string;
13-
}
1+
import type { ApplyLicenseHeadersOption } from '../add-license-headers/schema';
2+
3+
export type { ApplyLicenseHeadersOption };
144

155
export interface CopyFilesExecutorSchema {
166
files: Array<{

0 commit comments

Comments
 (0)