enablement-build-template-generate 1.7.0 → 1.8.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "enablement-build-template-generate",
3
- "version": "1.7.0",
3
+ "version": "1.8.2",
4
4
  "description": "Generates build yaml for mono repos",
5
5
  "type": "module",
6
6
  "module": "./src/index.mjs",
@@ -9,7 +9,7 @@
9
9
  "dependencies": {
10
10
  "globby": "^16.2.0",
11
11
  "user": "^0.0.0",
12
- "enablement-build-manifest": "1.8.0"
12
+ "enablement-build-manifest": "1.8.7"
13
13
  },
14
14
  "devDependencies": {
15
15
  "jest": "^30.4.2"
package/src/index.mjs CHANGED
@@ -17,6 +17,7 @@ import {
17
17
  wrapWithBanner,
18
18
  resolveWorkspaceChildren,
19
19
  excludeChildren,
20
+ resolvePackageFolder,
20
21
  buildPackageJsonGlob,
21
22
  detectCicdType,
22
23
  isAdvancedTemplatedFormat,
@@ -174,10 +175,8 @@ async function convertLegacyTemplatedJson(rawConfig, templatePath, options) {
174
175
  }
175
176
 
176
177
  // ---------------------------------------------------------------------------
177
- // Discover packages not yet assigned to any template and add them, using
178
- // detected package type + the existing convention (same packageFolder, else
179
- // same output type, else the default "PACKAGES" placeholder). Mutates
180
- // `templated`/`cicd` in place; returns true if anything was added.
178
+ // Discover package metadata and assign packages not yet mapped to a template.
179
+ // Mutates `templated`/`cicd` in place; returns true if either config changed.
181
180
  // ---------------------------------------------------------------------------
182
181
  async function detectAndAssignNewPackages(templated, cicd, options, templatePath) {
183
182
  const assigned = collectAssignedPackages(templated);
@@ -194,15 +193,24 @@ async function detectAndAssignNewPackages(templated, cicd, options, templatePath
194
193
  pkgPaths.forEach(pkgPath => {
195
194
  let pkg;
196
195
  try { pkg = JSON.parse(readFileSync(pkgPath, 'utf8')); } catch { return; }
197
- if (!pkg.name || !pkg.version || assigned.has(pkg.name)) return;
196
+ if (!pkg.name || !pkg.version) return;
198
197
 
199
198
  const folderName = path.basename(path.dirname(pkgPath));
200
199
  if (options.exclude.includes(folderName)) return;
201
200
 
202
- const packageFolder = path.relative(
203
- process.cwd(),
204
- path.dirname(path.dirname(pkgPath)),
205
- );
201
+ const packageFolder = resolvePackageFolder(pkgPath);
202
+ const existingCicd = cicd[pkg.name] || {};
203
+ if (!existingCicd.folderName || !existingCicd.packageFolder) {
204
+ cicd[pkg.name] = {
205
+ ...existingCicd,
206
+ folderName: existingCicd.folderName || folderName,
207
+ packageFolder: existingCicd.packageFolder || packageFolder,
208
+ };
209
+ added = true;
210
+ }
211
+
212
+ if (assigned.has(pkg.name)) return;
213
+
206
214
  const detected = detectCicdType(pkg.name, pkg, pkgPath);
207
215
  const { pipelineFile, placeholder, template } = chooseAssignmentForNewPackage({
208
216
  packageFolder,
@@ -309,7 +317,10 @@ async function main(options) {
309
317
  writeFileSync(manifestPath, JSON.stringify(manifestToPersist, null, 2), 'utf8');
310
318
  }
311
319
  if (templatedJsonDirty) {
312
- writeFileSync(templatedJsonPath, JSON.stringify({ version: TEMPLATED_JSON_ADVANCED_VERSION, templated, cicd }, null, 2), 'utf8');
320
+ const sortedCicd = Object.fromEntries(
321
+ Object.entries(cicd).sort(([nameA], [nameB]) => nameA.localeCompare(nameB)),
322
+ );
323
+ writeFileSync(templatedJsonPath, JSON.stringify({ version: TEMPLATED_JSON_ADVANCED_VERSION, templated, cicd: sortedCicd }, null, 2), 'utf8');
313
324
  }
314
325
 
315
326
  // ── Generate.
package/src/lib.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import path from 'path';
2
2
  import { readdirSync } from 'fs';
3
3
  import { detectCicdType } from 'enablement-build-manifest/src/detect.mjs';
4
- import { resolveWorkspaceChildren, buildPackageJsonGlob, excludeChildren } from 'enablement-build-manifest/src/workspace.mjs';
4
+ import { resolveWorkspaceChildren, buildPackageJsonGlob, excludeChildren, resolvePackageFolder } from 'enablement-build-manifest/src/workspace.mjs';
5
5
 
6
6
  // Re-exposes the manifest package's pure package-type detector (output/language/
7
7
  // tier/packageType from package.json shape or csproj/pyproject.toml/Dockerfile)
@@ -12,7 +12,7 @@ export { detectCicdType };
12
12
  // (pnpm-workspace.yaml or package.json#workspaces), the exclude filter for it,
13
13
  // and the glob it implies, so template-generate can find package roots
14
14
  // without needing manifest.json.
15
- export { resolveWorkspaceChildren, buildPackageJsonGlob, excludeChildren };
15
+ export { resolveWorkspaceChildren, buildPackageJsonGlob, excludeChildren, resolvePackageFolder };
16
16
 
17
17
  // Re-exposes the manifest package's dependency-order sort, so a package's
18
18
  // local dependencies (per manifest.json's "dependencies") are generated
@@ -311,7 +311,7 @@ describe('templated.json migration', () => {
311
311
  }
312
312
  });
313
313
 
314
- it('detects a new package, assigns it a template by type, and leaves existing packages untouched', () => {
314
+ it('detects new packages and fills missing cicd metadata for existing assignments', () => {
315
315
  const root = mkdtempSync(path.join(os.tmpdir(), 'template-generate-'));
316
316
  try {
317
317
  mkdirSync(path.join(root, '.cicd', 'templates'), { recursive: true });
@@ -346,21 +346,20 @@ describe('templated.json migration', () => {
346
346
  PACKAGES: { 'existing-lib': 'job.yml' },
347
347
  },
348
348
  },
349
- cicd: {
350
- 'existing-lib': { folderName: 'existing-lib', packageFolder: 'packages' },
351
- },
349
+ cicd: {},
352
350
  });
353
351
 
354
352
  const firstOut = runGenerator(root);
355
353
  const templatedAfterFirst = JSON.parse(readFileSync(path.join(root, '.cicd', 'templates', 'templated.json'), 'utf8'));
356
354
 
357
- // Existing package untouched.
355
+ // Existing assignment remains, and missing cicd metadata is detected from its path.
358
356
  expect(templatedAfterFirst.templated['build.yml'].PACKAGES['existing-lib']).toBe('job.yml');
359
357
  expect(templatedAfterFirst.cicd['existing-lib']).toEqual({ folderName: 'existing-lib', packageFolder: 'packages' });
360
358
 
361
359
  // New package detected, classified as a node package, and assigned the node build template.
362
360
  expect(templatedAfterFirst.templated['build.yml'].PACKAGES['new-svc']).toBe('_build_node_package.yml');
363
361
  expect(templatedAfterFirst.cicd['new-svc']).toEqual({ folderName: 'new-svc', packageFolder: 'apps' });
362
+ expect(Object.keys(templatedAfterFirst.cicd)).toEqual(['existing-lib', 'new-svc']);
364
363
 
365
364
  expect(firstOut).toContain('NAME=existing-lib');
366
365
  expect(firstOut).toContain('NAME=new-svc');