@textmode/release 0.1.0 → 0.2.1

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/README.md CHANGED
@@ -2,22 +2,22 @@
2
2
 
3
3
  <div align="center">
4
4
 
5
+ <img alt="@textmode/release — release textmode from one command" src=".github/assets/readme-og.png" />
6
+
5
7
  | [![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
8
  | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
7
9
 
8
10
  </div>
9
11
 
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.
12
+ `@textmode/release` owns release automation and managed Git hooks 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
13
 
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.
14
+ Use it to release every package the same way and install the same managed Git hooks without repeating dependencies or config files. Consumers compose whole-project workflows such as `check`, `build`, and `prepack` explicitly in their own package scripts.
13
15
 
14
16
  ## Features
15
17
 
16
18
  - **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
19
  - **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.
20
+ - **pnpm-safe staged formatting** - The `pre-commit` hook formats staged files through an internal `format-staged` command, so it works without `textmode-lint` being exposed at the consumer root.
21
21
 
22
22
  ## Installation
23
23
 
@@ -29,41 +29,42 @@ No engine dependencies are required.
29
29
 
30
30
  ## Usage
31
31
 
32
- Conventional projects delegate their workflows to the command:
32
+ Conventional projects delegate their release and hooks to the command:
33
33
 
34
34
  ```json
35
35
  {
36
36
  "scripts": {
37
- "check": "textmode-release check",
38
- "prepack": "textmode-release prepack",
39
37
  "prepare": "textmode-release hooks",
40
38
  "release": "textmode-release release"
41
39
  }
42
40
  }
43
41
  ```
44
42
 
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
43
  - `hooks` installs the managed Git hooks.
50
44
  - `release` runs semantic-release with the shared release config.
51
45
 
46
+ Projects keep their domain scripts visible and compose them locally. A typical
47
+ library's `check` script runs formatting, linting, type checking, documentation,
48
+ tests, build, and declaration verification in the order required by that
49
+ repository. Its `prepack` script runs the local build and declaration
50
+ verification.
51
+
52
52
  ## Commands
53
53
 
54
54
  ```text
55
55
  textmode-release release [args...]
56
56
  textmode-release hooks
57
- textmode-release check
58
- textmode-release prepack
59
57
  ```
60
58
 
61
59
  Every argument after `release` is forwarded to semantic-release, so
62
60
  `textmode-release release --dry-run` works without special handling.
63
61
 
64
62
  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.
63
+ status `0` means success, `1` means an engine reported a problem, and `2` means
64
+ the invocation was invalid.
65
+
66
+ The managed pre-commit hook also invokes the internal `format-staged` command.
67
+ It is an implementation detail of the hook interface, not a project workflow.
67
68
 
68
69
  ## Configuration
69
70
 
@@ -74,11 +75,41 @@ status `0` means success, `1` means a workflow or engine reported a problem, and
74
75
  - publishes stable releases on `main` and prereleases on `beta`;
75
76
  - derives release types from Conventional Commits;
76
77
  - 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
+ - creates the GitHub release as a **private draft** by default and attaches
79
+ JavaScript bundle assets derived from the package `exports`;
80
+ - leaves publishing the drafted release to a maintainer in the GitHub UI.
78
81
 
79
82
  Projects keep a `build` script that produces the publishable bundles (e.g.
80
83
  `textmode-build build`).
81
84
 
85
+ ### GitHub release mode
86
+
87
+ The GitHub release is created as a private draft by default. A project that
88
+ wants the release published immediately opts out through a
89
+ `textmodeRelease.githubRelease` field in its own `package.json`:
90
+
91
+ ```jsonc
92
+ {
93
+ "textmodeRelease": {
94
+ "githubRelease": "draft" // default; created as a private draft
95
+ }
96
+ }
97
+ ```
98
+
99
+ ```jsonc
100
+ {
101
+ "textmodeRelease": {
102
+ "githubRelease": "direct" // published immediately
103
+ }
104
+ }
105
+ ```
106
+
107
+ The `draft` mode still uploads the bundle assets to the release, and drafts
108
+ created from the `beta` branch keep their prerelease flag when published.
109
+ Unknown values fall back to `draft` with a warning. The plugin's `addChannel`
110
+ step (promoting an already-released version to another channel) is unaffected
111
+ and publishes directly.
112
+
82
113
  ### Git hooks
83
114
 
84
115
  `textmode-release hooks` installs:
@@ -86,7 +117,7 @@ Projects keep a `build` script that produces the publishable bundles (e.g.
86
117
  | Hook | Behavior |
87
118
  | --- | --- |
88
119
  | `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`) |
120
+ | `pre-commit` | Runs the shared lint-staged config (formats staged files with `textmode-release format-staged`) |
90
121
  | `pre-push` | Blocks direct pushes to `dev`, `beta`, and `main` |
91
122
 
92
123
  ### commitlint
@@ -97,37 +128,17 @@ and extend `@commitlint/config-conventional`.
97
128
  ### lint-staged
98
129
 
99
130
  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.
131
+ file) and formats staged files through `textmode-release format-staged`, which
132
+ resolves the `textmode-lint` binary from this package's own dependency graph.
120
133
 
121
134
  ## Related packages
122
135
 
123
- `@textmode/release` orchestrates the following textmode-tooling packages:
136
+ `@textmode/lint` remains an implementation dependency because the managed
137
+ `pre-commit` hook formats staged files through it:
124
138
 
125
139
  | Package | Relationship |
126
140
  | ------------------------------------------------------------------- | -------------------------------------------------------- |
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 |
141
+ | [`@textmode/lint`](../lint/README.md) | Powers `textmode-release format-staged` for the lint-staged hook |
131
142
 
132
143
  ## License
133
144
 
package/index.d.ts CHANGED
@@ -13,9 +13,16 @@ export interface ReleaseConfig {
13
13
  ci: boolean;
14
14
  }
15
15
 
16
+ export type GitHubReleaseMode = 'draft' | 'direct';
17
+
18
+ export interface ReleaseConfigOptions {
19
+ githubAssets?: string[];
20
+ githubRelease?: GitHubReleaseMode;
21
+ }
22
+
16
23
  export declare function githubAssetsFromPackageJson(packageJson: { exports?: unknown }): string[];
17
24
 
18
- export declare function createReleaseConfig(options?: { githubAssets?: string[] }): ReleaseConfig;
25
+ export declare function createReleaseConfig(options?: ReleaseConfigOptions): ReleaseConfig;
19
26
 
20
27
  export declare const releaseConfig: ReleaseConfig;
21
28
 
@@ -1,3 +1,7 @@
1
+ 'use strict';
2
+
3
+ const path = require('node:path');
4
+
1
5
  module.exports = {
2
- '*': 'textmode-lint format',
6
+ '*': `node ${JSON.stringify(path.join(__dirname, 'src/cli/textmode-release.mjs'))} format-staged`,
3
7
  };
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@textmode/release",
3
- "version": "0.1.0",
3
+ "version": "0.2.1",
4
4
  "type": "module",
5
5
  "license": "CC0-1.0",
6
- "description": "Shared release, hooks, and project workflow tooling for the textmode.js ecosystem (semantic-release, commitlint, lint-staged).",
6
+ "description": "Shared release and Git-hook tooling for the textmode.js ecosystem (semantic-release, commitlint, lint-staged).",
7
7
  "keywords": [
8
8
  "textmode",
9
9
  "semantic-release",
@@ -51,10 +51,7 @@
51
51
  "@semantic-release/github": "^12.0.9",
52
52
  "@semantic-release/npm": "^13.1.5",
53
53
  "@semantic-release/release-notes-generator": "^14.1.0",
54
- "@textmode/build": "^0.1.0",
55
- "@textmode/docs": "^0.3.0",
56
54
  "@textmode/lint": "^0.1.0",
57
- "@textmode/tsconfig": "^0.2.0",
58
55
  "lint-staged": "^17.0.8",
59
56
  "semantic-release": "^25.0.5"
60
57
  },
@@ -5,14 +5,13 @@ import path from 'node:path';
5
5
  import process from 'node:process';
6
6
  import { fileURLToPath } from 'node:url';
7
7
 
8
- import { runCheck, runPrepack } from '../internal/check.mjs';
9
8
  import { runEngine } from '../internal/engines.mjs';
10
9
  import { installGitHooks } from '../internal/hooks.mjs';
11
10
 
12
11
  const PACKAGE_JSON = JSON.parse(fs.readFileSync(new URL('../../package.json', import.meta.url), 'utf8'));
13
12
  const PACKAGE_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../..');
14
13
 
15
- const COMMANDS = new Set(['release', 'hooks', 'check', 'prepack']);
14
+ const COMMANDS = new Set(['release', 'hooks', 'format-staged']);
16
15
 
17
16
  function printGeneralHelp() {
18
17
  console.log(`@textmode/release ${PACKAGE_JSON.version}`);
@@ -22,8 +21,7 @@ function printGeneralHelp() {
22
21
  console.log('Commands:');
23
22
  console.log(' release [args...] Run semantic-release with the shared config');
24
23
  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)');
24
+ console.log(' format-staged [files...] Format staged files with the shared Prettier config (internal)');
27
25
  console.log('');
28
26
  console.log('Common options:');
29
27
  console.log(' --cwd <directory> Directory to run in');
@@ -37,8 +35,7 @@ function printCommandHelp(command) {
37
35
  const usage = {
38
36
  release: 'textmode-release release [args...]',
39
37
  hooks: 'textmode-release hooks',
40
- check: 'textmode-release check',
41
- prepack: 'textmode-release prepack',
38
+ 'format-staged': 'textmode-release format-staged [files...]',
42
39
  };
43
40
  console.log(`Usage: ${usage[command]}`);
44
41
  }
@@ -78,7 +75,7 @@ function parseArgv(argv) {
78
75
  if (command !== undefined && !COMMANDS.has(command)) {
79
76
  throw new Error(`Unknown command "${command}".`);
80
77
  }
81
- if (command !== 'release' && forwarded.length > 0) {
78
+ if (command !== 'release' && command !== 'format-staged' && forwarded.length > 0) {
82
79
  throw new Error(`The ${command} command does not accept arguments.`);
83
80
  }
84
81
 
@@ -90,6 +87,14 @@ function runRelease(forwarded, cwd) {
90
87
  return runEngine('semantic-release', 'semantic-release', ['--extends', releaseConfig, ...forwarded], { cwd });
91
88
  }
92
89
 
90
+ function runFormatStaged(files, cwd) {
91
+ if (files.length === 0) {
92
+ console.error('format-staged requires at least one staged file.');
93
+ return 2;
94
+ }
95
+ return runEngine('@textmode/lint', 'textmode-lint', ['format', ...files], { cwd });
96
+ }
97
+
93
98
  function main(argv) {
94
99
  let parsed;
95
100
  try {
@@ -124,10 +129,8 @@ function main(argv) {
124
129
  return runRelease(forwarded, cwd);
125
130
  case 'hooks':
126
131
  return installGitHooks({ cwd }) === false ? 1 : 0;
127
- case 'check':
128
- return runCheck({ cwd });
129
- case 'prepack':
130
- return runPrepack({ cwd });
132
+ case 'format-staged':
133
+ return runFormatStaged(forwarded, cwd);
131
134
  default:
132
135
  return 2;
133
136
  }
@@ -38,7 +38,36 @@ function githubAssetsFromCurrentPackage() {
38
38
  return githubAssetsFromPackageJson(JSON.parse(fs.readFileSync(packagePath, 'utf8')));
39
39
  }
40
40
 
41
- export function createReleaseConfig({ githubAssets = githubAssetsFromCurrentPackage() } = {}) {
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
+ } = {}) {
42
71
  return {
43
72
  branches: [
44
73
  'main',
@@ -75,7 +104,7 @@ export function createReleaseConfig({ githubAssets = githubAssetsFromCurrentPack
75
104
  [
76
105
  '@semantic-release/exec',
77
106
  {
78
- prepareCmd: 'npm run build',
107
+ prepareCmd: 'npm run build --if-present',
79
108
  },
80
109
  ],
81
110
  [
@@ -95,6 +124,7 @@ export function createReleaseConfig({ githubAssets = githubAssetsFromCurrentPack
95
124
  '@semantic-release/github',
96
125
  {
97
126
  assets: githubAssets,
127
+ draftRelease: githubReleaseToDraft(githubRelease),
98
128
  successComment: false,
99
129
  failComment: false,
100
130
  releasedLabels: false,
@@ -1,85 +0,0 @@
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
- }