@textmode/release 0.2.1 → 0.3.0
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/LICENSE +21 -121
- package/README.md +13 -12
- package/dist/cli/textmode-release.d.ts +3 -0
- package/dist/cli/textmode-release.d.ts.map +1 -0
- package/dist/cli/textmode-release.js +150 -0
- package/dist/cli/textmode-release.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/engines.d.ts +5 -0
- package/dist/internal/engines.d.ts.map +1 -0
- package/dist/internal/engines.js +22 -0
- package/dist/internal/engines.js.map +1 -0
- package/dist/internal/hooks.d.ts +11 -0
- package/dist/internal/hooks.d.ts.map +1 -0
- package/dist/internal/hooks.js +78 -0
- package/dist/internal/hooks.js.map +1 -0
- package/dist/lib/commitlint-config.d.ts +10 -0
- package/dist/lib/commitlint-config.d.ts.map +1 -0
- package/dist/lib/commitlint-config.js +8 -0
- package/dist/lib/commitlint-config.js.map +1 -0
- package/dist/lib/lint-staged.d.ts +10 -0
- package/dist/lib/lint-staged.d.ts.map +1 -0
- package/dist/lib/lint-staged.js +8 -0
- package/dist/lib/lint-staged.js.map +1 -0
- package/dist/lib/release-config-cli.d.ts +3 -0
- package/dist/lib/release-config-cli.d.ts.map +1 -0
- package/dist/lib/release-config-cli.js +3 -0
- package/dist/lib/release-config-cli.js.map +1 -0
- package/dist/lib/release-config.d.ts +82 -0
- package/dist/lib/release-config.d.ts.map +1 -0
- package/dist/lib/release-config.js +153 -0
- package/dist/lib/release-config.js.map +1 -0
- package/lint-staged.config.cjs +1 -1
- package/package.json +67 -74
- package/index.d.ts +0 -31
- package/index.js +0 -7
- package/src/cli/textmode-release.mjs +0 -139
- package/src/husky/pre-push +0 -6
- package/src/internal/engines.mjs +0 -55
- package/src/internal/hooks.mjs +0 -94
- package/src/lib/commitlint-config.js +0 -4
- package/src/lib/lint-staged.js +0 -4
- package/src/lib/release-config.js +0 -139
package/src/internal/hooks.mjs
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import process from 'node:process';
|
|
4
|
-
import { spawnSync } from 'node:child_process';
|
|
5
|
-
import { fileURLToPath } from 'node:url';
|
|
6
|
-
|
|
7
|
-
import { resolveEngine } from './engines.mjs';
|
|
8
|
-
|
|
9
|
-
const MANAGED_MARKER = '# textmode-tooling managed hook';
|
|
10
|
-
const packageRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../..');
|
|
11
|
-
|
|
12
|
-
function runGit(args, cwd) {
|
|
13
|
-
return spawnSync('git', args, {
|
|
14
|
-
cwd,
|
|
15
|
-
encoding: 'utf8',
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function removeLegacyHuskyHookPath(cwd) {
|
|
20
|
-
const configuredHookPath = runGit(['config', '--local', '--get', 'core.hooksPath'], cwd);
|
|
21
|
-
if (configuredHookPath.status !== 0) {
|
|
22
|
-
return true;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const hookPath = configuredHookPath.stdout.trim().replace(/\\/g, '/');
|
|
26
|
-
if (!hookPath.endsWith('/.husky/_') && hookPath !== '.husky/_') {
|
|
27
|
-
console.warn(`Skipping Git hook installation because core.hooksPath is managed externally: ${hookPath}`);
|
|
28
|
-
return false;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const unsetResult = runGit(['config', '--local', '--unset-all', 'core.hooksPath'], cwd);
|
|
32
|
-
if (unsetResult.status !== 0) {
|
|
33
|
-
throw new Error('Unable to remove the legacy Husky core.hooksPath setting.');
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
console.log('Removed legacy Husky core.hooksPath setting.');
|
|
37
|
-
return true;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function gitHooksDir(cwd) {
|
|
41
|
-
const result = runGit(['rev-parse', '--git-common-dir'], cwd);
|
|
42
|
-
|
|
43
|
-
if (result.status !== 0) {
|
|
44
|
-
return undefined;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return path.resolve(cwd, result.stdout.trim(), 'hooks');
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function writeHook(hooksDir, hookName, source) {
|
|
51
|
-
const targetPath = path.join(hooksDir, hookName);
|
|
52
|
-
if (fs.existsSync(targetPath) && !fs.readFileSync(targetPath, 'utf8').includes(MANAGED_MARKER)) {
|
|
53
|
-
console.warn(`Skipping existing unmanaged Git hook: ${targetPath}`);
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
fs.writeFileSync(targetPath, `#!/bin/sh\n${MANAGED_MARKER}\n${source}`);
|
|
58
|
-
fs.chmodSync(targetPath, 0o755);
|
|
59
|
-
console.log(`Installed Git hook: ${hookName}`);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export function installGitHooks({ cwd = process.cwd() } = {}) {
|
|
63
|
-
if (!removeLegacyHuskyHookPath(cwd)) {
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const hooksDir = gitHooksDir(cwd);
|
|
68
|
-
if (!hooksDir) {
|
|
69
|
-
console.log('Skipping Git hook installation outside a Git worktree.');
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
fs.mkdirSync(hooksDir, { recursive: true });
|
|
74
|
-
|
|
75
|
-
const nodeBinDir = path.dirname(process.execPath);
|
|
76
|
-
const hookPrologue = `PATH="${nodeBinDir}:./node_modules/.bin:$PATH"\nexport PATH`;
|
|
77
|
-
|
|
78
|
-
const commitlintBin = resolveEngine('@commitlint/cli', 'commitlint');
|
|
79
|
-
const lintStagedBin = resolveEngine('lint-staged', 'lint-staged');
|
|
80
|
-
const commitlintConfig = path.join(packageRoot, 'commitlint.config.cjs');
|
|
81
|
-
const lintStagedConfig = path.join(packageRoot, 'lint-staged.config.cjs');
|
|
82
|
-
|
|
83
|
-
writeHook(
|
|
84
|
-
hooksDir,
|
|
85
|
-
'commit-msg',
|
|
86
|
-
`${hookPrologue}\nnode "${commitlintBin}" --config "${commitlintConfig}" --edit "$1"`
|
|
87
|
-
);
|
|
88
|
-
writeHook(hooksDir, 'pre-commit', `${hookPrologue}\nnode "${lintStagedBin}" --config "${lintStagedConfig}"`);
|
|
89
|
-
writeHook(
|
|
90
|
-
hooksDir,
|
|
91
|
-
'pre-push',
|
|
92
|
-
`${hookPrologue}\n${fs.readFileSync(path.join(packageRoot, 'src/husky/pre-push'), 'utf8')}`
|
|
93
|
-
);
|
|
94
|
-
}
|
package/src/lib/lint-staged.js
DELETED
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
|
|
4
|
-
function collectBundleAssets(value, assets) {
|
|
5
|
-
if (typeof value === 'string') {
|
|
6
|
-
if (value.startsWith('./dist/') && /\.(?:[cm]?js)$/.test(value)) {
|
|
7
|
-
assets.add(value.slice(2));
|
|
8
|
-
}
|
|
9
|
-
return;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
if (Array.isArray(value)) {
|
|
13
|
-
for (const item of value) {
|
|
14
|
-
collectBundleAssets(item, assets);
|
|
15
|
-
}
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
if (value && typeof value === 'object') {
|
|
20
|
-
for (const item of Object.values(value)) {
|
|
21
|
-
collectBundleAssets(item, assets);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export function githubAssetsFromPackageJson(packageJson) {
|
|
27
|
-
const assets = new Set();
|
|
28
|
-
collectBundleAssets(packageJson.exports, assets);
|
|
29
|
-
return [...assets].sort();
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function githubAssetsFromCurrentPackage() {
|
|
33
|
-
const packagePath = path.resolve(process.cwd(), 'package.json');
|
|
34
|
-
if (!fs.existsSync(packagePath)) {
|
|
35
|
-
return [];
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return githubAssetsFromPackageJson(JSON.parse(fs.readFileSync(packagePath, 'utf8')));
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function githubReleaseFromCurrentPackage() {
|
|
42
|
-
const packagePath = path.resolve(process.cwd(), 'package.json');
|
|
43
|
-
if (!fs.existsSync(packagePath)) {
|
|
44
|
-
return undefined;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return JSON.parse(fs.readFileSync(packagePath, 'utf8'))?.textmodeRelease?.githubRelease;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Resolve the GitHub release mode to the `@semantic-release/github`
|
|
52
|
-
* `draftRelease` boolean. Drafts are the default; `direct` publishes the
|
|
53
|
-
* release immediately. Unknown values warn and fall back to the default.
|
|
54
|
-
*/
|
|
55
|
-
function githubReleaseToDraft(githubRelease) {
|
|
56
|
-
if (githubRelease === 'direct') {
|
|
57
|
-
return false;
|
|
58
|
-
}
|
|
59
|
-
if (githubRelease !== undefined && githubRelease !== 'draft') {
|
|
60
|
-
console.error(
|
|
61
|
-
`@textmode/release: unknown textmodeRelease.githubRelease value ${JSON.stringify(githubRelease)}; using "draft".`
|
|
62
|
-
);
|
|
63
|
-
}
|
|
64
|
-
return true;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export function createReleaseConfig({
|
|
68
|
-
githubAssets = githubAssetsFromCurrentPackage(),
|
|
69
|
-
githubRelease = githubReleaseFromCurrentPackage(),
|
|
70
|
-
} = {}) {
|
|
71
|
-
return {
|
|
72
|
-
branches: [
|
|
73
|
-
'main',
|
|
74
|
-
{
|
|
75
|
-
name: 'beta',
|
|
76
|
-
prerelease: true,
|
|
77
|
-
},
|
|
78
|
-
],
|
|
79
|
-
tagFormat: 'v${version}',
|
|
80
|
-
plugins: [
|
|
81
|
-
[
|
|
82
|
-
'@semantic-release/commit-analyzer',
|
|
83
|
-
{
|
|
84
|
-
releaseRules: [
|
|
85
|
-
{ type: 'feat', release: 'minor' },
|
|
86
|
-
{ type: 'fix', release: 'patch' },
|
|
87
|
-
{ type: 'perf', release: 'patch' },
|
|
88
|
-
{ type: 'refactor', release: 'patch' },
|
|
89
|
-
{ type: 'docs', release: false },
|
|
90
|
-
{ type: 'style', release: false },
|
|
91
|
-
{ type: 'test', release: false },
|
|
92
|
-
{ type: 'chore', release: false },
|
|
93
|
-
{ breaking: true, release: 'major' },
|
|
94
|
-
],
|
|
95
|
-
},
|
|
96
|
-
],
|
|
97
|
-
'@semantic-release/release-notes-generator',
|
|
98
|
-
[
|
|
99
|
-
'@semantic-release/npm',
|
|
100
|
-
{
|
|
101
|
-
npmPublish: false,
|
|
102
|
-
},
|
|
103
|
-
],
|
|
104
|
-
[
|
|
105
|
-
'@semantic-release/exec',
|
|
106
|
-
{
|
|
107
|
-
prepareCmd: 'npm run build --if-present',
|
|
108
|
-
},
|
|
109
|
-
],
|
|
110
|
-
[
|
|
111
|
-
'@semantic-release/npm',
|
|
112
|
-
{
|
|
113
|
-
npmPublish: true,
|
|
114
|
-
},
|
|
115
|
-
],
|
|
116
|
-
[
|
|
117
|
-
'@semantic-release/git',
|
|
118
|
-
{
|
|
119
|
-
assets: ['package.json', 'package-lock.json'],
|
|
120
|
-
message: 'chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}',
|
|
121
|
-
},
|
|
122
|
-
],
|
|
123
|
-
[
|
|
124
|
-
'@semantic-release/github',
|
|
125
|
-
{
|
|
126
|
-
assets: githubAssets,
|
|
127
|
-
draftRelease: githubReleaseToDraft(githubRelease),
|
|
128
|
-
successComment: false,
|
|
129
|
-
failComment: false,
|
|
130
|
-
releasedLabels: false,
|
|
131
|
-
},
|
|
132
|
-
],
|
|
133
|
-
],
|
|
134
|
-
dryRun: false,
|
|
135
|
-
ci: true,
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
export default createReleaseConfig();
|