@atls/code-schematics 2.0.20 → 2.0.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +26 -0
- package/dist/generated/schematic-factory-export.d.ts +1 -1
- package/dist/generated/schematic-factory-export.js +1 -1
- package/dist/schematic/project/project.factory.js +39 -5
- package/dist/schematic/utils/index.d.ts +1 -0
- package/dist/schematic/utils/index.js +1 -0
- package/dist/schematic/utils/merge-gitignore-content.utils.d.ts +6 -0
- package/dist/schematic/utils/merge-gitignore-content.utils.js +40 -0
- package/package.json +7 -6
|
@@ -4,8 +4,42 @@ import { mergeWith } from '@angular-devkit/schematics';
|
|
|
4
4
|
import { updateTsConfigRule } from '../rules/index.js';
|
|
5
5
|
import { generateCommonSource } from '../sources/index.js';
|
|
6
6
|
import { generateProjectSpecificSource } from '../sources/index.js';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
import { mergeGitIgnoreContent } from '../utils/index.js';
|
|
8
|
+
const GITIGNORE_PATH = '.gitignore';
|
|
9
|
+
const captureGitIgnoreContentRule = (state) => (host) => {
|
|
10
|
+
const gitIgnoreBuffer = host.read(GITIGNORE_PATH);
|
|
11
|
+
if (!gitIgnoreBuffer) {
|
|
12
|
+
return host;
|
|
13
|
+
}
|
|
14
|
+
state.content = gitIgnoreBuffer.toString('utf-8');
|
|
15
|
+
return host;
|
|
16
|
+
};
|
|
17
|
+
const mergeGitIgnoreContentRule = (state) => (host, context) => {
|
|
18
|
+
if (state.content === undefined) {
|
|
19
|
+
return host;
|
|
20
|
+
}
|
|
21
|
+
const gitIgnoreBuffer = host.read(GITIGNORE_PATH);
|
|
22
|
+
if (!gitIgnoreBuffer) {
|
|
23
|
+
return host;
|
|
24
|
+
}
|
|
25
|
+
const templateContent = gitIgnoreBuffer.toString('utf-8');
|
|
26
|
+
const mergedContent = mergeGitIgnoreContent({
|
|
27
|
+
existingContent: state.content,
|
|
28
|
+
templateContent,
|
|
29
|
+
});
|
|
30
|
+
if (mergedContent !== templateContent) {
|
|
31
|
+
context.logger.info('Merging template .gitignore with project-specific entries');
|
|
32
|
+
host.overwrite(GITIGNORE_PATH, mergedContent);
|
|
33
|
+
}
|
|
34
|
+
return host;
|
|
35
|
+
};
|
|
36
|
+
export const main = (options) => {
|
|
37
|
+
const state = {};
|
|
38
|
+
return chain([
|
|
39
|
+
captureGitIgnoreContentRule(state),
|
|
40
|
+
updateTsConfigRule,
|
|
41
|
+
mergeWith(generateCommonSource(options), MergeStrategy.Overwrite),
|
|
42
|
+
mergeWith(generateProjectSpecificSource(options), MergeStrategy.Overwrite),
|
|
43
|
+
mergeGitIgnoreContentRule(state),
|
|
44
|
+
]);
|
|
45
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
const PROJECT_SPECIFIC_START_MARKER = '# raijin:begin project-specific gitignore';
|
|
2
|
+
const PROJECT_SPECIFIC_END_MARKER = '# raijin:end project-specific gitignore';
|
|
3
|
+
const normalizeContent = (content) => content.replace(/\r\n/g, '\n');
|
|
4
|
+
const getNormalizedLines = (content) => normalizeContent(content).split('\n');
|
|
5
|
+
const trimTrailingEmptyLines = (lines) => {
|
|
6
|
+
const normalizedLines = [...lines];
|
|
7
|
+
while (normalizedLines.length > 0 && normalizedLines[normalizedLines.length - 1] === '') {
|
|
8
|
+
normalizedLines.pop();
|
|
9
|
+
}
|
|
10
|
+
return normalizedLines;
|
|
11
|
+
};
|
|
12
|
+
const isProjectSpecificLine = (line, templateLineSet) => line !== '' &&
|
|
13
|
+
!templateLineSet.has(line) &&
|
|
14
|
+
line !== PROJECT_SPECIFIC_START_MARKER &&
|
|
15
|
+
line !== PROJECT_SPECIFIC_END_MARKER;
|
|
16
|
+
const getProjectSpecificLines = (existingLines, templateLineSet) => {
|
|
17
|
+
const startIndex = existingLines.indexOf(PROJECT_SPECIFIC_START_MARKER);
|
|
18
|
+
const endIndex = existingLines.indexOf(PROJECT_SPECIFIC_END_MARKER);
|
|
19
|
+
if (startIndex !== -1 && endIndex > startIndex) {
|
|
20
|
+
return Array.from(new Set(existingLines.filter((line) => isProjectSpecificLine(line, templateLineSet))));
|
|
21
|
+
}
|
|
22
|
+
return existingLines.filter((line) => isProjectSpecificLine(line, templateLineSet));
|
|
23
|
+
};
|
|
24
|
+
export const mergeGitIgnoreContent = ({ existingContent, templateContent, }) => {
|
|
25
|
+
const templateLines = getNormalizedLines(templateContent);
|
|
26
|
+
const templateLineSet = new Set(templateLines);
|
|
27
|
+
const existingLines = getNormalizedLines(existingContent);
|
|
28
|
+
const projectSpecificLines = getProjectSpecificLines(existingLines, templateLineSet);
|
|
29
|
+
if (projectSpecificLines.length === 0) {
|
|
30
|
+
return trimTrailingEmptyLines(templateLines).join('\n');
|
|
31
|
+
}
|
|
32
|
+
const mergedLines = trimTrailingEmptyLines(templateLines);
|
|
33
|
+
if (mergedLines.length > 0) {
|
|
34
|
+
mergedLines.push('');
|
|
35
|
+
}
|
|
36
|
+
mergedLines.push(PROJECT_SPECIFIC_START_MARKER);
|
|
37
|
+
mergedLines.push(...projectSpecificLines);
|
|
38
|
+
mergedLines.push(PROJECT_SPECIFIC_END_MARKER);
|
|
39
|
+
return mergedLines.join('\n');
|
|
40
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atls/code-schematics",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.22",
|
|
4
4
|
"license": "BSD-3-Clause",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -24,15 +24,16 @@
|
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@angular-devkit/core": "19.1.5",
|
|
26
26
|
"@angular-devkit/schematics": "19.1.5",
|
|
27
|
+
"js-yaml": "4.1.0",
|
|
27
28
|
"strip-json-comments": "3.1.1"
|
|
28
29
|
},
|
|
29
30
|
"devDependencies": {
|
|
30
|
-
"@atls/code-runtime": "2.1.
|
|
31
|
-
"@types/node": "
|
|
32
|
-
"@yarnpkg/cli": "4.
|
|
33
|
-
"@yarnpkg/core": "4.
|
|
31
|
+
"@atls/code-runtime": "2.1.27",
|
|
32
|
+
"@types/node": "24.12.2",
|
|
33
|
+
"@yarnpkg/cli": "4.14.1",
|
|
34
|
+
"@yarnpkg/core": "4.7.0",
|
|
34
35
|
"@yarnpkg/esbuild-plugin-pnp": "3.0.0-rc.15",
|
|
35
|
-
"@yarnpkg/fslib": "3.1.
|
|
36
|
+
"@yarnpkg/fslib": "3.1.5",
|
|
36
37
|
"esbuild": "0.24.2",
|
|
37
38
|
"rxjs": "7.8.1"
|
|
38
39
|
},
|