@textmode/release 0.1.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 ADDED
@@ -0,0 +1,121 @@
1
+ Creative Commons Legal Code
2
+
3
+ CC0 1.0 Universal
4
+
5
+ CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
6
+ LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
7
+ ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
8
+ INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
9
+ REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
10
+ PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
11
+ THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
12
+ HEREUNDER.
13
+
14
+ Statement of Purpose
15
+
16
+ The laws of most jurisdictions throughout the world automatically confer
17
+ exclusive Copyright and Related Rights (defined below) upon the creator
18
+ and subsequent owner(s) (each and all, an "owner") of an original work of
19
+ authorship and/or a database (each, a "Work").
20
+
21
+ Certain owners wish to permanently relinquish those rights to a Work for
22
+ the purpose of contributing to a commons of creative, cultural and
23
+ scientific works ("Commons") that the public can reliably and without fear
24
+ of later claims of infringement build upon, modify, incorporate in other
25
+ works, reuse and redistribute as freely as possible in any form whatsoever
26
+ and for any purposes, including without limitation commercial purposes.
27
+ These owners may contribute to the Commons to promote the ideal of a free
28
+ culture and the further production of creative, cultural and scientific
29
+ works, or to gain reputation or greater distribution for their Work in
30
+ part through the use and efforts of others.
31
+
32
+ For these and/or other purposes and motivations, and without any
33
+ expectation of additional consideration or compensation, the person
34
+ associating CC0 with a Work (the "Affirmer"), to the extent that he or she
35
+ is an owner of Copyright and Related Rights in the Work, voluntarily
36
+ elects to apply CC0 to the Work and publicly distribute the Work under its
37
+ terms, with knowledge of his or her Copyright and Related Rights in the
38
+ Work and the meaning and intended legal effect of CC0 on those rights.
39
+
40
+ 1. Copyright and Related Rights. A Work made available under CC0 may be
41
+ protected by copyright and related or neighboring rights ("Copyright and
42
+ Related Rights"). Copyright and Related Rights include, but are not
43
+ limited to, the following:
44
+
45
+ i. the right to reproduce, adapt, distribute, perform, display,
46
+ communicate, and translate a Work;
47
+ ii. moral rights retained by the original author(s) and/or performer(s);
48
+ iii. publicity and privacy rights pertaining to a person's image or
49
+ likeness depicted in a Work;
50
+ iv. rights protecting against unfair competition in regards to a Work,
51
+ subject to the limitations in paragraph 4(a), below;
52
+ v. rights protecting the extraction, dissemination, use and reuse of data
53
+ in a Work;
54
+ vi. database rights (such as those arising under Directive 96/9/EC of the
55
+ European Parliament and of the Council of 11 March 1996 on the legal
56
+ protection of databases, and under any national implementation
57
+ thereof, including any amended or successor version of such
58
+ directive); and
59
+ vii. other similar, equivalent or corresponding rights throughout the
60
+ world based on applicable law or treaty, and any national
61
+ implementations thereof.
62
+
63
+ 2. Waiver. To the greatest extent permitted by, but not in contravention
64
+ of, applicable law, Affirmer hereby overtly, fully, permanently,
65
+ irrevocably and unconditionally waives, abandons, and surrenders all of
66
+ Affirmer's Copyright and Related Rights and associated claims and causes
67
+ of action, whether now known or unknown (including existing as well as
68
+ future claims and causes of action), in the Work (i) in all territories
69
+ worldwide, (ii) for the maximum duration provided by applicable law or
70
+ treaty (including future time extensions), (iii) in any current or future
71
+ medium and for any number of copies, and (iv) for any purpose whatsoever,
72
+ including without limitation commercial, advertising or promotional
73
+ purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
74
+ member of the public at large and to the detriment of Affirmer's heirs and
75
+ successors, fully intending that such Waiver shall not be subject to
76
+ revocation, rescission, cancellation, termination, or any other legal or
77
+ equitable action to disrupt the quiet enjoyment of the Work by the public
78
+ as contemplated by Affirmer's express Statement of Purpose.
79
+
80
+ 3. Public License Fallback. Should any part of the Waiver for any reason
81
+ be judged legally invalid or ineffective under applicable law, then the
82
+ Waiver shall be preserved to the maximum extent permitted taking into
83
+ account Affirmer's express Statement of Purpose. In addition, to the
84
+ extent the Waiver is so judged Affirmer hereby grants to each affected
85
+ person a royalty-free, non transferable, non sublicensable, non exclusive,
86
+ irrevocable and unconditional license to exercise Affirmer's Copyright and
87
+ Related Rights in the Work (i) in all territories worldwide, (ii) for the
88
+ maximum duration provided by applicable law or treaty (including future
89
+ time extensions), (iii) in any current or future medium and for any number
90
+ of copies, and (iv) for any purpose whatsoever, including without
91
+ limitation commercial, advertising or promotional purposes (the
92
+ "License"). The License shall be deemed effective as of the date CC0 was
93
+ applied by Affirmer to the Work. Should any part of the License for any
94
+ reason be judged legally invalid or ineffective under applicable law, such
95
+ partial invalidity or ineffectiveness shall not invalidate the remainder
96
+ of the License, and in such case Affirmer hereby affirms that he or she
97
+ will not (i) exercise any of his or her remaining Copyright and Related
98
+ Rights in the Work or (ii) assert any associated claims and causes of
99
+ action with respect to the Work, in either case contrary to Affirmer's
100
+ express Statement of Purpose.
101
+
102
+ 4. Limitations and Disclaimers.
103
+
104
+ a. No trademark or patent rights held by Affirmer are waived, abandoned,
105
+ surrendered, licensed or otherwise affected by this document.
106
+ b. Affirmer offers the Work as-is and makes no representations or
107
+ warranties of any kind concerning the Work, express, implied,
108
+ statutory or otherwise, including without limitation warranties of
109
+ title, merchantability, fitness for a particular purpose, non
110
+ infringement, or the absence of latent or other defects, accuracy, or
111
+ the present or absence of errors, whether or not discoverable, all to
112
+ the greatest extent permissible under applicable law.
113
+ c. Affirmer disclaims responsibility for clearing rights of other persons
114
+ that may apply to the Work or any use thereof, including without
115
+ limitation any person's Copyright and Related Rights in the Work.
116
+ Further, Affirmer disclaims responsibility for obtaining any necessary
117
+ consents, permissions or other rights required for any use of the
118
+ Work.
119
+ d. Affirmer understands and acknowledges that Creative Commons is not a
120
+ party to this document and has no duty or obligation with respect to
121
+ this CC0 or use of the Work.
package/README.md ADDED
@@ -0,0 +1,146 @@
1
+ # @textmode/release
2
+
3
+ <div align="center">
4
+
5
+ | [![JavaScript](https://img.shields.io/badge/JavaScript-F7DF1E?logo=javascript&logoColor=black)](https://developer.mozilla.org/en-US/docs/Web/JavaScript) [![semantic-release](https://img.shields.io/badge/semantic--release-494949?logo=semanticrelease&logoColor=white)](https://semantic-release.gitbook.io/) | [![docs](https://img.shields.io/badge/docs-vitepress-646cff?logo=vitepress&logoColor=white)](https://code.textmode.art/) [![Discord](https://img.shields.io/discord/1357070706181017691?color=5865F2&label=Discord&logo=discord&logoColor=white)](https://discord.gg/sjrw8QXNks) | [![ko-fi](https://shields.io/badge/ko--fi-donate-ff5f5f?logo=ko-fi)](https://ko-fi.com/V7V8JG2FY) [![GitHub-sponsors](https://img.shields.io/badge/sponsor-30363D?logo=GitHub-Sponsors&logoColor=#EA4AAA)](https://github.com/sponsors/humanbydefinition) |
6
+ | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
7
+
8
+ </div>
9
+
10
+ `@textmode/release` owns release, hooks, and project workflow orchestration for the [`textmode.js`](https://github.com/humanbydefinition/textmode.js) ecosystem. It bundles [semantic-release](https://semantic-release.gitbook.io/), [commitlint](https://commitlint.js.org/), and [lint-staged](https://github.com/lint-staged/lint-staged) behind one `textmode-release` command, so consumers no longer install or configure the engines themselves.
11
+
12
+ Use it to release every package the same way, install the same managed Git hooks, and run the same `check`/`prepack` workflows without repeating dependencies or config files.
13
+
14
+ ## Features
15
+
16
+ - **One package, multiple engines** - semantic-release and its plugins, commitlint, and lint-staged are implementation dependencies, not peer dependencies. Consumers install only `@textmode/release`.
17
+ - **Managed Git hooks** - `textmode-release hooks` installs commitlint, lint-staged, and push-guard hooks directly into Git's hooks directory, invoking the engines from the package itself.
18
+ - **Project workflow orchestration** - `textmode-release check` and `prepack` run the domain CLIs (`textmode-lint`, `textmode-types`, `textmode-docs`, `textmode-build`) directly, so consumers do not need leaf scripts.
19
+ - **Runtime contract validation** - `check` verifies the Node 24 runtime contract before running the workflow.
20
+ - **Backward compatible behavior** - The release flow, commit rules, and hook behavior are identical to the previous `@textmode/release-config`, `@textmode/commitlint-config`, and `@textmode/tooling-scripts` packages.
21
+
22
+ ## Installation
23
+
24
+ ```bash
25
+ npm install -D @textmode/release
26
+ ```
27
+
28
+ No engine dependencies are required.
29
+
30
+ ## Usage
31
+
32
+ Conventional projects delegate their workflows to the command:
33
+
34
+ ```json
35
+ {
36
+ "scripts": {
37
+ "check": "textmode-release check",
38
+ "prepack": "textmode-release prepack",
39
+ "prepare": "textmode-release hooks",
40
+ "release": "textmode-release release"
41
+ }
42
+ }
43
+ ```
44
+
45
+ - `check` first validates the repository's Node 24 runtime contract, then runs
46
+ `format:check`, `lint`, `lint:markdown`, `typecheck`, `docs:check`, `test`,
47
+ `build`, and `types:verify` in that order using the domain CLIs directly.
48
+ - `prepack` runs `build` and `types:verify`.
49
+ - `hooks` installs the managed Git hooks.
50
+ - `release` runs semantic-release with the shared release config.
51
+
52
+ ## Commands
53
+
54
+ ```text
55
+ textmode-release release [args...]
56
+ textmode-release hooks
57
+ textmode-release check
58
+ textmode-release prepack
59
+ ```
60
+
61
+ Every argument after `release` is forwarded to semantic-release, so
62
+ `textmode-release release --dry-run` works without special handling.
63
+
64
+ Every command accepts `--cwd <directory>`, `--help`, and `--version`. Exit
65
+ status `0` means success, `1` means a workflow or engine reported a problem, and
66
+ `2` means the invocation was invalid.
67
+
68
+ ## Configuration
69
+
70
+ ### Release
71
+
72
+ `textmode-release release` runs semantic-release with the shared config, which:
73
+
74
+ - publishes stable releases on `main` and prereleases on `beta`;
75
+ - derives release types from Conventional Commits;
76
+ - updates package metadata, builds via the `build` script, then publishes;
77
+ - attaches JavaScript bundle assets derived from the package `exports` to the GitHub release.
78
+
79
+ Projects keep a `build` script that produces the publishable bundles (e.g.
80
+ `textmode-build build`).
81
+
82
+ ### Git hooks
83
+
84
+ `textmode-release hooks` installs:
85
+
86
+ | Hook | Behavior |
87
+ | --- | --- |
88
+ | `commit-msg` | Validates the message with the shared commitlint config |
89
+ | `pre-commit` | Runs the shared lint-staged config (formats staged files with `textmode-lint format`) |
90
+ | `pre-push` | Blocks direct pushes to `dev`, `beta`, and `main` |
91
+
92
+ ### commitlint
93
+
94
+ The shared rules ship at `@textmode/release/commitlint` (a `.cjs` config file)
95
+ and extend `@commitlint/config-conventional`.
96
+
97
+ ### lint-staged
98
+
99
+ The shared config ships at `@textmode/release/lint-staged` (a `.cjs` config
100
+ file) and formats staged files with `textmode-lint format`.
101
+
102
+ ## Configuration ownership
103
+
104
+ - `@textmode/release` owns the semantic-release config, commitlint rules,
105
+ lint-staged config, Git hooks, and command behavior.
106
+ - `package.json` owns only the package name, description, and the scripts that
107
+ delegate to `textmode-release`.
108
+
109
+ Consumers should not declare `semantic-release`, `@commitlint/cli`,
110
+ `lint-staged`, or the former `@textmode/release-config`,
111
+ `@textmode/commitlint-config`, and `@textmode/tooling-scripts` packages.
112
+
113
+ ## Deprecations
114
+
115
+ `@textmode/release` replaces `@textmode/release-config`,
116
+ `@textmode/commitlint-config`, and `@textmode/tooling-scripts`, which are
117
+ deprecated and removed from this workspace. Existing consumers should migrate
118
+ their scripts and Git hooks to `@textmode/release`; the older packages remain
119
+ published on npm for projects that have not migrated yet.
120
+
121
+ ## Related packages
122
+
123
+ `@textmode/release` orchestrates the following textmode-tooling packages:
124
+
125
+ | Package | Relationship |
126
+ | ------------------------------------------------------------------- | -------------------------------------------------------- |
127
+ | [`@textmode/lint`](../lint/README.md) | Powers the `format:check`, `lint`, and `lint:markdown` workflow steps and the lint-staged hook |
128
+ | [`@textmode/build`](../build/README.md) | Powers the `build` and `test` workflow steps |
129
+ | [`@textmode/docs`](../docs/README.md) | Powers the `docs:check` workflow step |
130
+ | [`@textmode/tsconfig`](../tsconfig/README.md) | Powers the `typecheck` and `types:verify` workflow steps |
131
+
132
+ ## License
133
+
134
+ The `@textmode/release` package is licensed under the [CC0 1.0 Universal](./LICENSE).
135
+
136
+ ## Acknowledgements
137
+
138
+ - **[semantic-release](https://semantic-release.gitbook.io/)**
139
+ - The release engine behind `textmode-release release`.
140
+ - License: [MIT](https://github.com/semantic-release/semantic-release/blob/master/LICENSE).
141
+ - **[commitlint](https://commitlint.js.org/)**
142
+ - The commit message linter used by the `commit-msg` hook.
143
+ - License: [MIT](https://github.com/conventional-changelog/commitlint/blob/master/LICENSE).
144
+ - **[lint-staged](https://github.com/lint-staged/lint-staged)**
145
+ - The staged-file runner used by the `pre-commit` hook.
146
+ - License: [MIT](https://github.com/lint-staged/lint-staged/blob/master/LICENSE).
@@ -0,0 +1,12 @@
1
+ module.exports = {
2
+ extends: ['@commitlint/config-conventional'],
3
+ rules: {
4
+ 'type-enum': [
5
+ 2,
6
+ 'always',
7
+ ['feat', 'fix', 'docs', 'style', 'refactor', 'perf', 'test', 'build', 'ci', 'chore', 'revert'],
8
+ ],
9
+ 'subject-case': [0],
10
+ 'header-max-length': [2, 'always', 100],
11
+ },
12
+ };
package/index.d.ts ADDED
@@ -0,0 +1,24 @@
1
+ export interface ReleaseBranch {
2
+ name: string;
3
+ prerelease?: boolean | string;
4
+ channel?: string;
5
+ range?: string;
6
+ }
7
+
8
+ export interface ReleaseConfig {
9
+ branches: (string | ReleaseBranch)[];
10
+ tagFormat: string;
11
+ plugins: unknown[];
12
+ dryRun: boolean;
13
+ ci: boolean;
14
+ }
15
+
16
+ export declare function githubAssetsFromPackageJson(packageJson: { exports?: unknown }): string[];
17
+
18
+ export declare function createReleaseConfig(options?: { githubAssets?: string[] }): ReleaseConfig;
19
+
20
+ export declare const releaseConfig: ReleaseConfig;
21
+
22
+ export declare const commitlintConfig: Record<string, unknown>;
23
+
24
+ export declare const lintStagedConfig: Record<string, unknown>;
package/index.js ADDED
@@ -0,0 +1,7 @@
1
+ export {
2
+ createReleaseConfig,
3
+ githubAssetsFromPackageJson,
4
+ default as releaseConfig,
5
+ } from './src/lib/release-config.js';
6
+ export { commitlintConfig } from './src/lib/commitlint-config.js';
7
+ export { lintStagedConfig } from './src/lib/lint-staged.js';
@@ -0,0 +1,3 @@
1
+ module.exports = {
2
+ '*': 'textmode-lint format',
3
+ };
package/package.json ADDED
@@ -0,0 +1,78 @@
1
+ {
2
+ "name": "@textmode/release",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "license": "CC0-1.0",
6
+ "description": "Shared release, hooks, and project workflow tooling for the textmode.js ecosystem (semantic-release, commitlint, lint-staged).",
7
+ "keywords": [
8
+ "textmode",
9
+ "semantic-release",
10
+ "commitlint",
11
+ "lint-staged",
12
+ "git-hooks",
13
+ "release"
14
+ ],
15
+ "author": "humanbydefinition <hello@textmode.art> (https://code.textmode.art)",
16
+ "homepage": "https://code.textmode.art",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/textmode-art/tooling.git",
20
+ "directory": "packages/release"
21
+ },
22
+ "engines": {
23
+ "node": ">=24 <25"
24
+ },
25
+ "bin": {
26
+ "textmode-release": "src/cli/textmode-release.mjs"
27
+ },
28
+ "exports": {
29
+ ".": {
30
+ "types": "./index.d.ts",
31
+ "import": "./index.js"
32
+ },
33
+ "./commitlint": "./commitlint.config.cjs",
34
+ "./lint-staged": "./lint-staged.config.cjs",
35
+ "./package.json": "./package.json"
36
+ },
37
+ "files": [
38
+ "src",
39
+ "index.js",
40
+ "index.d.ts",
41
+ "commitlint.config.cjs",
42
+ "lint-staged.config.cjs",
43
+ "README.md"
44
+ ],
45
+ "dependencies": {
46
+ "@commitlint/cli": "^21.2.1",
47
+ "@commitlint/config-conventional": "^21.2.0",
48
+ "@semantic-release/commit-analyzer": "^13.0.1",
49
+ "@semantic-release/exec": "^7.1.0",
50
+ "@semantic-release/git": "^11.0.1",
51
+ "@semantic-release/github": "^12.0.9",
52
+ "@semantic-release/npm": "^13.1.5",
53
+ "@semantic-release/release-notes-generator": "^14.1.0",
54
+ "@textmode/build": "^0.1.0",
55
+ "@textmode/docs": "^0.3.0",
56
+ "@textmode/lint": "^0.1.0",
57
+ "@textmode/tsconfig": "^0.2.0",
58
+ "lint-staged": "^17.0.8",
59
+ "semantic-release": "^25.0.5"
60
+ },
61
+ "devDependencies": {
62
+ "@types/node": "^26.1.2",
63
+ "typescript": "^6.0.3",
64
+ "vitest": "^4.1.10"
65
+ },
66
+ "scripts": {
67
+ "check": "pnpm run check:format && pnpm run lint && pnpm run check:types && pnpm run test && pnpm run check:package && pnpm run check:pack",
68
+ "check:format": "prettier --check .",
69
+ "check:package": "node scripts/check-package.mjs",
70
+ "check:pack": "node scripts/pack-smoke.mjs",
71
+ "check:types": "tsc --noEmit --strict --module NodeNext --moduleResolution NodeNext --target ES2022 test/types/consumer.ts",
72
+ "lint": "node --check src/cli/textmode-release.mjs && node --check src/internal/*.mjs && node --check src/lib/*.js",
73
+ "test": "vitest run"
74
+ },
75
+ "publishConfig": {
76
+ "access": "public"
77
+ }
78
+ }
@@ -0,0 +1,136 @@
1
+ #!/usr/bin/env node
2
+
3
+ import fs from 'node:fs';
4
+ import path from 'node:path';
5
+ import process from 'node:process';
6
+ import { fileURLToPath } from 'node:url';
7
+
8
+ import { runCheck, runPrepack } from '../internal/check.mjs';
9
+ import { runEngine } from '../internal/engines.mjs';
10
+ import { installGitHooks } from '../internal/hooks.mjs';
11
+
12
+ const PACKAGE_JSON = JSON.parse(fs.readFileSync(new URL('../../package.json', import.meta.url), 'utf8'));
13
+ const PACKAGE_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../..');
14
+
15
+ const COMMANDS = new Set(['release', 'hooks', 'check', 'prepack']);
16
+
17
+ function printGeneralHelp() {
18
+ console.log(`@textmode/release ${PACKAGE_JSON.version}`);
19
+ console.log('');
20
+ console.log('Usage: textmode-release <command> [options]');
21
+ console.log('');
22
+ console.log('Commands:');
23
+ console.log(' release [args...] Run semantic-release with the shared config');
24
+ console.log(' hooks Install managed Git hooks (commitlint, lint-staged, push guard)');
25
+ console.log(' check Run the full check workflow (format, lint, types, docs, test, build)');
26
+ console.log(' prepack Run the prepack workflow (build, types verify)');
27
+ console.log('');
28
+ console.log('Common options:');
29
+ console.log(' --cwd <directory> Directory to run in');
30
+ console.log(' --help, -h Show help');
31
+ console.log(' --version, -v Show version');
32
+ console.log('');
33
+ console.log('Every argument after the release command is forwarded to semantic-release.');
34
+ }
35
+
36
+ function printCommandHelp(command) {
37
+ const usage = {
38
+ release: 'textmode-release release [args...]',
39
+ hooks: 'textmode-release hooks',
40
+ check: 'textmode-release check',
41
+ prepack: 'textmode-release prepack',
42
+ };
43
+ console.log(`Usage: ${usage[command]}`);
44
+ }
45
+
46
+ function parseArgv(argv) {
47
+ const values = { cwd: undefined, help: false, version: false };
48
+ const rest = [];
49
+ let commandSeen = false;
50
+
51
+ for (let index = 0; index < argv.length; index += 1) {
52
+ const arg = argv[index];
53
+ if (arg === '--cwd') {
54
+ if (index + 1 >= argv.length || argv[index + 1].startsWith('-')) {
55
+ throw new Error('--cwd requires a directory value.');
56
+ }
57
+ values.cwd = argv[index + 1];
58
+ index += 1;
59
+ continue;
60
+ }
61
+ if (!commandSeen) {
62
+ if (arg === '--help' || arg === '-h') {
63
+ values.help = true;
64
+ continue;
65
+ }
66
+ if (arg === '--version' || arg === '-v') {
67
+ values.version = true;
68
+ continue;
69
+ }
70
+ if (!arg.startsWith('-')) {
71
+ commandSeen = true;
72
+ }
73
+ }
74
+ rest.push(arg);
75
+ }
76
+
77
+ const [command, ...forwarded] = rest;
78
+ if (command !== undefined && !COMMANDS.has(command)) {
79
+ throw new Error(`Unknown command "${command}".`);
80
+ }
81
+ if (command !== 'release' && forwarded.length > 0) {
82
+ throw new Error(`The ${command} command does not accept arguments.`);
83
+ }
84
+
85
+ return { command, forwarded, values };
86
+ }
87
+
88
+ function runRelease(forwarded, cwd) {
89
+ const releaseConfig = path.join(PACKAGE_ROOT, 'src', 'lib', 'release-config.js');
90
+ return runEngine('semantic-release', 'semantic-release', ['--extends', releaseConfig, ...forwarded], { cwd });
91
+ }
92
+
93
+ function main(argv) {
94
+ let parsed;
95
+ try {
96
+ parsed = parseArgv(argv);
97
+ } catch (error) {
98
+ console.error(error instanceof Error ? error.message : String(error));
99
+ return 2;
100
+ }
101
+
102
+ const { command, forwarded, values } = parsed;
103
+ const cwd = values.cwd ? path.resolve(values.cwd) : process.cwd();
104
+
105
+ if (values.version && command === undefined) {
106
+ console.log(PACKAGE_JSON.version);
107
+ return 0;
108
+ }
109
+ if (values.help && command === undefined) {
110
+ printGeneralHelp();
111
+ return 0;
112
+ }
113
+ if (command === undefined) {
114
+ console.error('Missing command. Run textmode-release --help for usage.');
115
+ return 2;
116
+ }
117
+ if (values.help) {
118
+ printCommandHelp(command);
119
+ return 0;
120
+ }
121
+
122
+ switch (command) {
123
+ case 'release':
124
+ return runRelease(forwarded, cwd);
125
+ case 'hooks':
126
+ return installGitHooks({ cwd }) === false ? 1 : 0;
127
+ case 'check':
128
+ return runCheck({ cwd });
129
+ case 'prepack':
130
+ return runPrepack({ cwd });
131
+ default:
132
+ return 2;
133
+ }
134
+ }
135
+
136
+ process.exitCode = main(process.argv.slice(2));
@@ -0,0 +1,6 @@
1
+ branch="$(git rev-parse --abbrev-ref HEAD)"
2
+
3
+ if [ "$branch" = "dev" ] || [ "$branch" = "beta" ] || [ "$branch" = "main" ]; then
4
+ echo "Direct pushes to '$branch' are not allowed. Open a pull request to dev, then promote dev -> beta -> main."
5
+ exit 1
6
+ fi
@@ -0,0 +1,85 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import process from 'node:process';
4
+
5
+ import { runEngine } from './engines.mjs';
6
+
7
+ const EXPECTED_NODE_MAJOR = '24';
8
+ const EXPECTED_NODE_RANGE = '^24.0.0';
9
+
10
+ function validateRuntimeContract(cwd) {
11
+ const nvmrcPath = path.join(cwd, '.nvmrc');
12
+ const packageJsonPath = path.join(cwd, 'package.json');
13
+ const errors = [];
14
+
15
+ if (process.versions.node.split('.')[0] !== EXPECTED_NODE_MAJOR) {
16
+ errors.push(`Node.js ${EXPECTED_NODE_MAJOR} is required; received ${process.version}.`);
17
+ }
18
+
19
+ if (!fs.existsSync(nvmrcPath) || fs.readFileSync(nvmrcPath, 'utf8').trim() !== EXPECTED_NODE_MAJOR) {
20
+ errors.push(`.nvmrc must contain ${EXPECTED_NODE_MAJOR}.`);
21
+ }
22
+
23
+ if (!fs.existsSync(packageJsonPath)) {
24
+ errors.push('package.json is required.');
25
+ } else {
26
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
27
+ const runtime = packageJson.devEngines?.runtime;
28
+ if (runtime?.name !== 'node' || runtime.version !== EXPECTED_NODE_RANGE || runtime.onFail !== 'error') {
29
+ errors.push(
30
+ `package.json devEngines.runtime must require node ${EXPECTED_NODE_RANGE} with onFail set to error.`
31
+ );
32
+ }
33
+
34
+ const nodeTypes = packageJson.devDependencies?.['@types/node'];
35
+ if (nodeTypes && !/^\^24(?:\.|$)/u.test(nodeTypes)) {
36
+ errors.push(`@types/node must target Node.js 24; received ${nodeTypes}.`);
37
+ }
38
+ }
39
+
40
+ for (const error of errors) {
41
+ console.error(`Runtime contract error: ${error}`);
42
+ }
43
+
44
+ return errors.length === 0;
45
+ }
46
+
47
+ const CHECK_STEPS = [
48
+ ['@textmode/lint', 'textmode-lint', ['format:check']],
49
+ ['@textmode/lint', 'textmode-lint', ['lint']],
50
+ ['@textmode/lint', 'textmode-lint', ['lint:markdown']],
51
+ ['@textmode/tsconfig', 'textmode-types', ['check']],
52
+ ['@textmode/docs', 'textmode-docs', ['check']],
53
+ ['@textmode/build', 'textmode-build', ['test']],
54
+ ['@textmode/build', 'textmode-build', ['build']],
55
+ ['@textmode/tsconfig', 'textmode-types', ['build']],
56
+ ['@textmode/tsconfig', 'textmode-types', ['verify']],
57
+ ];
58
+
59
+ const PREPACK_STEPS = [
60
+ ['@textmode/build', 'textmode-build', ['build']],
61
+ ['@textmode/tsconfig', 'textmode-types', ['build']],
62
+ ['@textmode/tsconfig', 'textmode-types', ['verify']],
63
+ ];
64
+
65
+ function runSteps(steps, cwd) {
66
+ for (const [packageName, binName, args] of steps) {
67
+ console.log(`\n[textmode] ${binName} ${args.join(' ')}`);
68
+ const status = runEngine(packageName, binName, args, { cwd });
69
+ if (status !== 0) {
70
+ return status;
71
+ }
72
+ }
73
+ return 0;
74
+ }
75
+
76
+ export function runCheck({ cwd = process.cwd() } = {}) {
77
+ if (!validateRuntimeContract(cwd)) {
78
+ return 1;
79
+ }
80
+ return runSteps(CHECK_STEPS, cwd);
81
+ }
82
+
83
+ export function runPrepack({ cwd = process.cwd() } = {}) {
84
+ return runSteps(PREPACK_STEPS, cwd);
85
+ }
@@ -0,0 +1,55 @@
1
+ import { spawnSync } from 'node:child_process';
2
+ import fs from 'node:fs';
3
+ import { createRequire } from 'node:module';
4
+ import path from 'node:path';
5
+ import { fileURLToPath } from 'node:url';
6
+
7
+ const require = createRequire(import.meta.url);
8
+
9
+ function resolvePackageRoot(packageName) {
10
+ let directory = path.dirname(fileURLToPath(import.meta.url));
11
+ while (true) {
12
+ const candidate = path.join(directory, 'node_modules', ...packageName.split('/'));
13
+ if (fs.existsSync(path.join(candidate, 'package.json'))) {
14
+ return candidate;
15
+ }
16
+ const parent = path.dirname(directory);
17
+ if (parent === directory) {
18
+ break;
19
+ }
20
+ directory = parent;
21
+ }
22
+ throw new Error(`Cannot resolve ${packageName}.`);
23
+ }
24
+
25
+ function resolveEngineBinary(packageName, binName) {
26
+ let manifestPath;
27
+ try {
28
+ manifestPath = require.resolve(`${packageName}/package.json`);
29
+ } catch {
30
+ manifestPath = path.join(resolvePackageRoot(packageName), 'package.json');
31
+ }
32
+ const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
33
+ const bin = typeof manifest.bin === 'string' ? manifest.bin : manifest.bin[binName];
34
+ if (typeof bin !== 'string') {
35
+ throw new Error(`Cannot resolve ${packageName} binary ${binName}.`);
36
+ }
37
+ return path.resolve(path.dirname(manifestPath), bin);
38
+ }
39
+
40
+ export function resolveEngine(packageName, binName) {
41
+ return resolveEngineBinary(packageName, binName);
42
+ }
43
+
44
+ export function runEngine(packageName, binName, args, { cwd = process.cwd() } = {}) {
45
+ const bin = resolveEngineBinary(packageName, binName);
46
+ const result = spawnSync(process.execPath, [bin, ...args], {
47
+ cwd,
48
+ stdio: 'inherit',
49
+ });
50
+ if (result.error) {
51
+ console.error(`Unable to run ${packageName}: ${result.error.message}`);
52
+ return 2;
53
+ }
54
+ return result.status ?? 1;
55
+ }
@@ -0,0 +1,94 @@
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
+ }
@@ -0,0 +1,4 @@
1
+ import config from '../../commitlint.config.cjs';
2
+
3
+ export const commitlintConfig = config;
4
+ export default config;
@@ -0,0 +1,4 @@
1
+ import config from '../../lint-staged.config.cjs';
2
+
3
+ export const lintStagedConfig = config;
4
+ export default config;
@@ -0,0 +1,109 @@
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
+ export function createReleaseConfig({ githubAssets = githubAssetsFromCurrentPackage() } = {}) {
42
+ return {
43
+ branches: [
44
+ 'main',
45
+ {
46
+ name: 'beta',
47
+ prerelease: true,
48
+ },
49
+ ],
50
+ tagFormat: 'v${version}',
51
+ plugins: [
52
+ [
53
+ '@semantic-release/commit-analyzer',
54
+ {
55
+ releaseRules: [
56
+ { type: 'feat', release: 'minor' },
57
+ { type: 'fix', release: 'patch' },
58
+ { type: 'perf', release: 'patch' },
59
+ { type: 'refactor', release: 'patch' },
60
+ { type: 'docs', release: false },
61
+ { type: 'style', release: false },
62
+ { type: 'test', release: false },
63
+ { type: 'chore', release: false },
64
+ { breaking: true, release: 'major' },
65
+ ],
66
+ },
67
+ ],
68
+ '@semantic-release/release-notes-generator',
69
+ [
70
+ '@semantic-release/npm',
71
+ {
72
+ npmPublish: false,
73
+ },
74
+ ],
75
+ [
76
+ '@semantic-release/exec',
77
+ {
78
+ prepareCmd: 'npm run build',
79
+ },
80
+ ],
81
+ [
82
+ '@semantic-release/npm',
83
+ {
84
+ npmPublish: true,
85
+ },
86
+ ],
87
+ [
88
+ '@semantic-release/git',
89
+ {
90
+ assets: ['package.json', 'package-lock.json'],
91
+ message: 'chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}',
92
+ },
93
+ ],
94
+ [
95
+ '@semantic-release/github',
96
+ {
97
+ assets: githubAssets,
98
+ successComment: false,
99
+ failComment: false,
100
+ releasedLabels: false,
101
+ },
102
+ ],
103
+ ],
104
+ dryRun: false,
105
+ ci: true,
106
+ };
107
+ }
108
+
109
+ export default createReleaseConfig();