-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpacktory.config.js
More file actions
117 lines (109 loc) · 3.67 KB
/
Copy pathpacktory.config.js
File metadata and controls
117 lines (109 loc) · 3.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// @ts-check
import fs from 'node:fs/promises';
import path from 'node:path';
import { execFile } from 'node:child_process';
import { promisify } from 'node:util';
const executeFile = promisify(execFile);
const projectFolder = process.cwd();
const sourcesFolder = path.join(projectFolder, 'target/build/source');
const licensePath = path.join(projectFolder, 'LICENSE');
const readmePath = path.join(projectFolder, 'README.md');
const additionalFiles = [
{ sourceFilePath: licensePath, targetFilePath: 'LICENSE' },
{ sourceFilePath: readmePath, targetFilePath: 'README.md' }
];
const packageRoots = {
main: {
js: 'index.js',
declarationFile: 'index.d.ts'
},
fireAndForgetInvoker: {
js: 'fire-and-forget-invoker.js',
declarationFile: 'fire-and-forget-invoker.d.ts'
}
};
const packageInterface = {
modules: [
{ root: 'main', export: '.' },
{ root: 'fireAndForgetInvoker', export: './fire-and-forget-invoker' }
]
};
const checks = {
typeScriptIntegrity: { enabled: true },
noDuplicatedFiles: { enabled: true },
requiredFiles: { enabled: true, files: [ 'LICENSE', 'README.md' ] },
maxBundleSize: { enabled: true, bytes: 100_000 },
noUnusedBundleDependencies: { enabled: true },
noDevDependencyImports: { enabled: true },
uniqueTargetPaths: { enabled: true }
};
/**
* @param {string} packageTags
* @param {string} initialCommit
* @returns {string | undefined}
*/
export function resolveChangelogBaseRef(packageTags, initialCommit) {
return packageTags.trim() === '' ? initialCommit.trim() : undefined;
}
/**
* @param {string} packageName
* @returns {Promise<string | undefined>}
*/
async function readChangelogBaseRef(packageName) {
const { stdout: packageTags } = await executeFile('git', [ 'tag', '--list', `${packageName}@*` ]);
const { stdout: initialCommit } = await executeFile('git', [
'rev-list',
'--max-parents=0',
'--first-parent',
'HEAD'
]);
return resolveChangelogBaseRef(packageTags, initialCommit);
}
/**
* @returns {Promise<import('@packtory/cli').PacktoryConfig>}
*/
export async function buildConfig() {
const packageJsonContent = await fs.readFile(path.join(projectFolder, 'package.json'), { encoding: 'utf8' });
const packageJson = JSON.parse(packageJsonContent);
return {
registrySettings: {
auth: {
publish: { type: 'npm-oidc', provider: 'github-actions' },
metadata: 'auto'
}
},
changelog: {
explicitBaseRef: await readChangelogBaseRef(packageJson.name),
packageTagFormat: '{packageName}@{version}',
outputs: [ { kind: 'repository-file', path: 'CHANGELOG.md' }, { kind: 'github-release' } ]
},
checks,
commonPackageSettings: {
sourcesFolder,
mainPackageJson: packageJson,
includeSourceMapFiles: true,
publishSettings: {
access: 'public',
provenance: { type: 'auto' }
},
additionalPackageJsonAttributes: {
description: packageJson.description,
author: packageJson.author,
license: packageJson.license,
repository: packageJson.repository,
bugs: packageJson.bugs,
homepage: packageJson.homepage,
engines: packageJson.engines,
keywords: packageJson.keywords
},
additionalFiles
},
packages: [
{
name: packageJson.name,
roots: packageRoots,
packageInterface
}
]
};
}