Skip to content

Commit 4c3ab55

Browse files
authored
fix: allow specifying ci file in check-project (#1317)
Not all projects use js-test-and-release.yml as their main CI file so allow specifying something different.
1 parent a994888 commit 4c3ab55

5 files changed

Lines changed: 108 additions & 27 deletions

File tree

src/check-project/check-monorepo-readme.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ import {
1717
* @param {string} repoUrl
1818
* @param {string} defaultBranch
1919
* @param {string[]} projectDirs
20+
* @param {string} ciFile
2021
*/
21-
export async function checkMonorepoReadme (projectDir, repoUrl, defaultBranch, projectDirs) {
22+
export async function checkMonorepoReadme (projectDir, repoUrl, defaultBranch, projectDirs, ciFile) {
2223
const repoParts = repoUrl.split('/')
2324
const repoName = repoParts.pop()
2425
const repoOwner = repoParts.pop()
@@ -47,7 +48,7 @@ export async function checkMonorepoReadme (projectDir, repoUrl, defaultBranch, p
4748
const file = parseMarkdown(readmeContents)
4849

4950
// create basic readme with heading, CI link, etc
50-
const readme = parseMarkdown(HEADER(pkg, repoOwner, repoName, defaultBranch))
51+
const readme = parseMarkdown(HEADER(pkg, repoOwner, repoName, defaultBranch, ciFile))
5152

5253
// remove existing header, CI link, etc
5354
/** @type {import('mdast').Root} */

src/check-project/check-readme.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ import {
1616
* @param {string} projectDir
1717
* @param {string} repoUrl
1818
* @param {string} defaultBranch
19+
* @param {string} ciFile
1920
* @param {any} [rootManifest]
2021
*/
21-
export async function checkReadme (projectDir, repoUrl, defaultBranch, rootManifest) {
22+
export async function checkReadme (projectDir, repoUrl, defaultBranch, ciFile, rootManifest) {
2223
const repoParts = repoUrl.split('/')
2324
const repoName = repoParts.pop()
2425
const repoOwner = repoParts.pop()
@@ -47,7 +48,7 @@ export async function checkReadme (projectDir, repoUrl, defaultBranch, rootManif
4748
const file = parseMarkdown(readmeContents)
4849

4950
// create basic readme with heading, CI link, etc
50-
const readme = parseMarkdown(HEADER(pkg, repoOwner, repoName, defaultBranch))
51+
const readme = parseMarkdown(HEADER(pkg, repoOwner, repoName, defaultBranch, ciFile))
5152

5253
// remove existing header, CI link, etc
5354
/** @type {import('mdast').Root} */

src/check-project/index.js

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { typedCJSManifest } from './manifests/typed-cjs.js'
2222
import { typedESMManifest } from './manifests/typed-esm.js'
2323
import { typescriptManifest } from './manifests/typescript.js'
2424
import { untypedCJSManifest } from './manifests/untyped-cjs.js'
25+
import { untypedESMManifest } from './manifests/untyped-esm.js'
2526
import {
2627
sortManifest,
2728
ensureFileHasContents,
@@ -98,8 +99,9 @@ async function getConfig (projectDir) {
9899
* @param {any} manifest
99100
* @param {string} branchName
100101
* @param {string} repoUrl
102+
* @param {string} ciFile
101103
*/
102-
async function processMonorepo (projectDir, manifest, branchName, repoUrl) {
104+
async function processMonorepo (projectDir, manifest, branchName, repoUrl, ciFile) {
103105
const workspaces = manifest.workspaces
104106

105107
if (!workspaces || !Array.isArray(workspaces)) {
@@ -130,7 +132,7 @@ async function processMonorepo (projectDir, manifest, branchName, repoUrl) {
130132

131133
console.info('Found monorepo project', pkg.name)
132134

133-
await processModule(subProjectDir, pkg, branchName, repoUrl, homePage, manifest)
135+
await processModule(subProjectDir, pkg, branchName, repoUrl, homePage, ciFile, manifest)
134136

135137
projectDirs.push(subProjectDir)
136138
}
@@ -148,7 +150,7 @@ async function processMonorepo (projectDir, manifest, branchName, repoUrl) {
148150
}))
149151
await checkLicenseFiles(projectDir)
150152
await checkBuildFiles(projectDir, branchName, repoUrl)
151-
await checkMonorepoReadme(projectDir, repoUrl, branchName, projectDirs)
153+
await checkMonorepoReadme(projectDir, repoUrl, branchName, projectDirs, ciFile)
152154
await checkMonorepoFiles(projectDir)
153155
}
154156

@@ -306,9 +308,10 @@ function addReferences (deps, references, refs) {
306308
* @param {any} manifest
307309
* @param {string} branchName
308310
* @param {string} repoUrl
311+
* @param {string} ciFile
309312
*/
310-
async function processProject (projectDir, manifest, branchName, repoUrl) {
311-
await processModule(projectDir, manifest, branchName, repoUrl)
313+
async function processProject (projectDir, manifest, branchName, repoUrl, ciFile) {
314+
await processModule(projectDir, manifest, branchName, repoUrl, repoUrl, ciFile)
312315
await checkBuildFiles(projectDir, branchName, repoUrl)
313316
}
314317

@@ -326,9 +329,10 @@ function isAegirProject (manifest) {
326329
* @param {string} branchName
327330
* @param {string} repoUrl
328331
* @param {string} homePage
332+
* @param {string} ciFile
329333
* @param {any} [rootManifest]
330334
*/
331-
async function processModule (projectDir, manifest, branchName, repoUrl, homePage = repoUrl, rootManifest) {
335+
async function processModule (projectDir, manifest, branchName, repoUrl, homePage = repoUrl, ciFile, rootManifest) {
332336
if (!isAegirProject(manifest) && manifest.name !== 'aegir') {
333337
throw new Error(`"${projectDir}" is not an aegir project`)
334338
}
@@ -351,7 +355,10 @@ async function processModule (projectDir, manifest, branchName, repoUrl, homePag
351355
// 3. CJS, no types
352356
let typedCJS = cjs && hasMain && types
353357

354-
// 3. CJS, no types
358+
// 4. ESM, no types
359+
let untypedESM = esm && hasMain
360+
361+
// 5. CJS, no types
355362
let untypedCJS = cjs && hasMain
356363

357364
let proposedManifest = {}
@@ -361,10 +368,10 @@ async function processModule (projectDir, manifest, branchName, repoUrl, homePag
361368
const { projectType } = await prompt.get({
362369
properties: {
363370
projectType: {
364-
description: 'Project type: typescript | typedESM | typedCJS | untypedCJS',
371+
description: 'Project type: typescript | typedESM | typedCJS | untypedESM | untypedCJS',
365372
required: true,
366373
conform: (value) => {
367-
return ['typescript', 'typedESM', 'typedCJS', 'untypedCJS'].includes(value)
374+
return ['typescript', 'typedESM', 'typedCJS', 'untypedESM', 'untypedCJS'].includes(value)
368375
},
369376
default: 'typescript'
370377
}
@@ -377,6 +384,8 @@ async function processModule (projectDir, manifest, branchName, repoUrl, homePag
377384
typedESM = true
378385
} else if (projectType === 'typedCJS') {
379386
typedCJS = true
387+
} else if (projectType === 'untypedESM') {
388+
untypedESM = true
380389
} else if (projectType === 'untypedCJS') {
381390
untypedCJS = true
382391
} else {
@@ -393,6 +402,9 @@ async function processModule (projectDir, manifest, branchName, repoUrl, homePag
393402
} else if (typedCJS) {
394403
console.info('Typed CJS project detected')
395404
proposedManifest = await typedCJSManifest(manifest, branchName, repoUrl, homePage)
405+
} else if (untypedESM) {
406+
console.info('Untyped ESM project detected')
407+
proposedManifest = await untypedESMManifest(manifest, branchName, repoUrl, homePage)
396408
} else if (untypedCJS) {
397409
console.info('Untyped CJS project detected')
398410
proposedManifest = await untypedCJSManifest(manifest, branchName, repoUrl, homePage)
@@ -411,7 +423,7 @@ async function processModule (projectDir, manifest, branchName, repoUrl, homePag
411423
}
412424

413425
await checkLicenseFiles(projectDir)
414-
await checkReadme(projectDir, repoUrl, branchName, rootManifest)
426+
await checkReadme(projectDir, repoUrl, branchName, ciFile, rootManifest)
415427
}
416428

417429
export default new Listr([
@@ -424,11 +436,21 @@ export default new Listr([
424436
const manifest = fs.readJSONSync(path.join(projectDir, 'package.json'))
425437
const monorepo = manifest.workspaces != null
426438

439+
const ciFile = (await prompt.get({
440+
properties: {
441+
ciFile: {
442+
description: 'ciFile',
443+
required: true,
444+
default: 'js-test-and-release.yml'
445+
}
446+
}
447+
})).ciFile.toString()
448+
427449
if (monorepo) {
428450
console.info('monorepo project detected')
429-
await processMonorepo(projectDir, manifest, branchName, repoUrl)
451+
await processMonorepo(projectDir, manifest, branchName, repoUrl, ciFile)
430452
} else {
431-
await processProject(projectDir, manifest, branchName, repoUrl)
453+
await processProject(projectDir, manifest, branchName, repoUrl, ciFile)
432454
}
433455
}
434456
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import mergeOptions from 'merge-options'
2+
import { semanticReleaseConfig } from '../semantic-release-config.js'
3+
import {
4+
sortFields,
5+
constructManifest
6+
} from '../utils.js'
7+
8+
const merge = mergeOptions.bind({ ignoreUndefined: true })
9+
10+
/**
11+
* @param {any} manifest
12+
* @param {string} branchName
13+
* @param {string} repoUrl
14+
* @param {string} [homePage]
15+
*/
16+
export async function untypedESMManifest (manifest, branchName, repoUrl, homePage = repoUrl) {
17+
let proposedManifest = constructManifest(manifest, {
18+
type: 'module',
19+
files: [
20+
'src',
21+
'dist',
22+
'!dist/test',
23+
'!**/*.tsbuildinfo'
24+
],
25+
exports: {
26+
'.': {
27+
types: './dist/src/index.d.ts',
28+
import: './src/index.js'
29+
}
30+
},
31+
eslintConfig: merge({
32+
extends: 'ipfs',
33+
parserOptions: {
34+
sourceType: 'module'
35+
}
36+
}, manifest.eslintConfig),
37+
release: (manifest.scripts?.release?.includes('semantic-release') || manifest.scripts?.release?.includes('aegir release')) ? semanticReleaseConfig(branchName) : undefined
38+
}, repoUrl, homePage)
39+
40+
const rest = {
41+
...sortFields(manifest)
42+
}
43+
44+
for (const key of Object.keys(proposedManifest)) {
45+
delete rest[key]
46+
}
47+
48+
proposedManifest = {
49+
...proposedManifest,
50+
...rest,
51+
contributors: undefined,
52+
leadMaintainer: undefined
53+
}
54+
55+
return proposedManifest
56+
}

src/check-project/readme/header.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
/**
2-
* @type {Record<string, (repoOwner: string, repoName: string, defaultBranch: string) => string>}
2+
* @type {Record<string, (repoOwner: string, repoName: string, defaultBranch: string, ciFile: string) => string>}
33
*/
44
const BADGES = {
5-
libp2p: (repoOwner, repoName, defaultBranch) => `
5+
libp2p: (repoOwner, repoName, defaultBranch, ciFile) => `
66
[![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/)
77
[![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io)
88
[![codecov](https://img.shields.io/codecov/c/github/${repoOwner}/${repoName}.svg?style=flat-square)](https://codecov.io/gh/${repoOwner}/${repoName})
9-
[![CI](https://img.shields.io/github/actions/workflow/status/${repoOwner}/${repoName}/js-test-and-release.yml?branch=${defaultBranch}&style=flat-square)](https://github.com/${repoOwner}/${repoName}/actions/workflows/js-test-and-release.yml?query=branch%3A${defaultBranch})
9+
[![CI](https://img.shields.io/github/actions/workflow/status/${repoOwner}/${repoName}/${ciFile}?branch=${defaultBranch}&style=flat-square)](https://github.com/${repoOwner}/${repoName}/actions/workflows/${ciFile}?query=branch%3A${defaultBranch})
1010
`,
11-
ipfs: (repoOwner, repoName, defaultBranch) => `
11+
ipfs: (repoOwner, repoName, defaultBranch, ciFile) => `
1212
[![ipfs.tech](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](https://ipfs.tech)
1313
[![Discuss](https://img.shields.io/discourse/https/discuss.ipfs.tech/posts.svg?style=flat-square)](https://discuss.ipfs.tech)
1414
[![codecov](https://img.shields.io/codecov/c/github/${repoOwner}/${repoName}.svg?style=flat-square)](https://codecov.io/gh/${repoOwner}/${repoName})
15-
[![CI](https://img.shields.io/github/actions/workflow/status/${repoOwner}/${repoName}/js-test-and-release.yml?branch=${defaultBranch}&style=flat-square)](https://github.com/${repoOwner}/${repoName}/actions/workflows/js-test-and-release.yml?query=branch%3A${defaultBranch})
15+
[![CI](https://img.shields.io/github/actions/workflow/status/${repoOwner}/${repoName}/${ciFile}?branch=${defaultBranch}&style=flat-square)](https://github.com/${repoOwner}/${repoName}/actions/workflows/${ciFile}?query=branch%3A${defaultBranch})
1616
`,
17-
multiformats: (repoOwner, repoName, defaultBranch) => `
17+
multiformats: (repoOwner, repoName, defaultBranch, ciFile) => `
1818
[![multiformats.io](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://multiformats.io)
1919
[![codecov](https://img.shields.io/codecov/c/github/${repoOwner}/${repoName}.svg?style=flat-square)](https://codecov.io/gh/${repoOwner}/${repoName})
20-
[![CI](https://img.shields.io/github/actions/workflow/status/${repoOwner}/${repoName}/js-test-and-release.yml?branch=${defaultBranch}&style=flat-square)](https://github.com/${repoOwner}/${repoName}/actions/workflows/js-test-and-release.yml?query=branch%3A${defaultBranch})
20+
[![CI](https://img.shields.io/github/actions/workflow/status/${repoOwner}/${repoName}/${ciFile}?branch=${defaultBranch}&style=flat-square)](https://github.com/${repoOwner}/${repoName}/actions/workflows/${ciFile}?query=branch%3A${defaultBranch})
2121
`,
22-
default: (repoOwner, repoName, defaultBranch) => `
22+
default: (repoOwner, repoName, defaultBranch, ciFile) => `
2323
[![codecov](https://img.shields.io/codecov/c/github/${repoOwner}/${repoName}.svg?style=flat-square)](https://codecov.io/gh/${repoOwner}/${repoName})
24-
[![CI](https://img.shields.io/github/actions/workflow/status/${repoOwner}/${repoName}/js-test-and-release.yml?branch=${defaultBranch}&style=flat-square)](https://github.com/${repoOwner}/${repoName}/actions/workflows/js-test-and-release.yml?query=branch%3A${defaultBranch})
24+
[![CI](https://img.shields.io/github/actions/workflow/status/${repoOwner}/${repoName}/${ciFile}?branch=${defaultBranch}&style=flat-square)](https://github.com/${repoOwner}/${repoName}/actions/workflows/${ciFile}?query=branch%3A${defaultBranch})
2525
`
2626
}
2727

@@ -30,12 +30,13 @@ const BADGES = {
3030
* @param {string} repoOwner
3131
* @param {string} repoName
3232
* @param {string} defaultBranch
33+
* @param {string} ciFile
3334
*/
34-
export const HEADER = (pkg, repoOwner, repoName, defaultBranch) => {
35+
export const HEADER = (pkg, repoOwner, repoName, defaultBranch, ciFile) => {
3536
return `
3637
# ${pkg.name} <!-- omit in toc -->
3738
38-
${(BADGES[repoOwner] ?? BADGES.default)(repoOwner, repoName, defaultBranch).trim()}
39+
${(BADGES[repoOwner] ?? BADGES.default)(repoOwner, repoName, defaultBranch, ciFile).trim()}
3940
4041
> ${pkg.description}
4142

0 commit comments

Comments
 (0)