@reelout/context 0.0.0 → 0.4.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,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Fai
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.js CHANGED
@@ -1 +1,88 @@
1
- export {};
1
+ import { GIT_TRAILER_RELEASE_AGENT, findReleaseRule, getCurrentGitBranch, getCurrentGitCommit, resolveGitRepository, resolveReleaseChannel, resolveVersionQualifier } from "@reelout/core";
2
+ import { LogLevels, createConsola } from "consola/basic";
3
+ //#region src/createContext.ts
4
+ /**
5
+ * Initialize a release context for the current execution run.
6
+ *
7
+ * Resolves the Git repository, current commit, and branch information, then
8
+ * computes target release parameters using the provided configuration rules
9
+ * and runtime options.
10
+ *
11
+ * @param options Combined release configuration and runtime options
12
+ * @returns A promise that resolves to the fully initialized release context
13
+ * @throws If the Git repository has no commits or no branch is checked out
14
+ */
15
+ async function createContext(options) {
16
+ const { cwd, stdout, stderr } = options;
17
+ let { logger } = options;
18
+ logger ??= createConsola({
19
+ level: options.debug ? LogLevels.verbose : LogLevels.info,
20
+ stdout,
21
+ stderr
22
+ });
23
+ const repository = await resolveGitRepository(cwd);
24
+ let commit;
25
+ let branch;
26
+ try {
27
+ commit = await getCurrentGitCommit(cwd, [GIT_TRAILER_RELEASE_AGENT]);
28
+ } catch (err) {
29
+ throw new Error("Initialize a Git repository with at least one commit before running this command.", { cause: err });
30
+ }
31
+ try {
32
+ branch = await getCurrentGitBranch(cwd);
33
+ } catch (err) {
34
+ throw new Error("Check out a Git branch in your repository before proceeding.", { cause: err });
35
+ }
36
+ const ref = {
37
+ type: "branch",
38
+ name: branch
39
+ };
40
+ const rule = findReleaseRule(ref, options.rules);
41
+ const now = /* @__PURE__ */ new Date();
42
+ const date = now.toISOString().slice(0, 10);
43
+ const time = now.toISOString().slice(11, 19);
44
+ const templateParams = {
45
+ date: date.replaceAll("-", ""),
46
+ time: time.replaceAll(":", "")
47
+ };
48
+ const versionQualifier = resolveVersionQualifier({
49
+ rule,
50
+ templateParams,
51
+ qualifier: options.qualifier
52
+ });
53
+ const releaseChannel = resolveReleaseChannel({
54
+ ref,
55
+ rule,
56
+ templateParams,
57
+ channel: options.channel
58
+ });
59
+ return {
60
+ cwd,
61
+ env: options.env,
62
+ today: date,
63
+ signal: options.signal,
64
+ stdout,
65
+ stderr,
66
+ logger,
67
+ repository,
68
+ ref,
69
+ commit,
70
+ author: options.author,
71
+ classifier: options.classifier,
72
+ rules: options.rules,
73
+ type: options.type ?? "auto",
74
+ versionQualifier,
75
+ releaseChannel,
76
+ allowEmpty: !!options.allowEmpty,
77
+ dryRun: !!options.dryRun,
78
+ packages: [],
79
+ plans: [],
80
+ status: null,
81
+ phase: null,
82
+ error: null
83
+ };
84
+ }
85
+ //#endregion
86
+ export { createContext };
87
+
88
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/createContext.ts"],"sourcesContent":["// SPDX-License-Identifier: MIT\n// Copyright (c) 2026 Fai\n\nimport {\n findReleaseRule,\n getCurrentGitBranch,\n getCurrentGitCommit,\n GIT_TRAILER_RELEASE_AGENT,\n resolveGitRepository,\n resolveReleaseChannel,\n resolveVersionQualifier,\n type GitCommit,\n type GitRef,\n type ReleaseContext,\n type ReleaseTypeHint,\n type ResolvedReleaseConfig,\n} from '@reelout/core'\nimport { createConsola, LogLevels } from 'consola/basic'\nimport type { ConsolaInstance } from 'consola/core'\n\nexport interface CreateContextOptions extends Omit<\n ResolvedReleaseConfig,\n 'plugins'\n> {\n cwd: string\n env: Readonly<NodeJS.ProcessEnv>\n signal?: AbortSignal | undefined\n stdout: NodeJS.WritableStream\n stderr: NodeJS.WritableStream\n logger?: ConsolaInstance | undefined\n type?: ReleaseTypeHint | undefined\n qualifier?: boolean | string | undefined\n channel?: boolean | string | undefined\n allowEmpty?: boolean | undefined\n dryRun?: boolean | undefined\n debug?: boolean | undefined\n}\n\n/**\n * Initialize a release context for the current execution run.\n *\n * Resolves the Git repository, current commit, and branch information, then\n * computes target release parameters using the provided configuration rules\n * and runtime options.\n *\n * @param options Combined release configuration and runtime options\n * @returns A promise that resolves to the fully initialized release context\n * @throws If the Git repository has no commits or no branch is checked out\n */\nexport async function createContext(\n options: CreateContextOptions\n): Promise<ReleaseContext> {\n const { cwd, stdout, stderr } = options\n let { logger } = options\n\n logger ??= createConsola({\n level: options.debug ? LogLevels.verbose : LogLevels.info,\n stdout: stdout as NodeJS.WriteStream,\n stderr: stderr as NodeJS.WriteStream,\n })\n\n const repository = await resolveGitRepository(cwd)\n let commit: GitCommit\n let branch: string\n\n try {\n commit = await getCurrentGitCommit(cwd, [GIT_TRAILER_RELEASE_AGENT])\n } catch (err) {\n throw new Error(\n 'Initialize a Git repository with at least one commit before running this command.',\n { cause: err }\n )\n }\n\n try {\n branch = await getCurrentGitBranch(cwd)\n } catch (err) {\n throw new Error(\n 'Check out a Git branch in your repository before proceeding.',\n { cause: err }\n )\n }\n\n const ref: GitRef = { type: 'branch', name: branch }\n const rule = findReleaseRule(ref, options.rules)\n\n const now = new Date()\n const date = now.toISOString().slice(0, 10) // YYYY-MM-DD\n const time = now.toISOString().slice(11, 19) // HH:mm:ss\n const templateParams = {\n date: date.replaceAll('-', ''),\n time: time.replaceAll(':', ''),\n }\n\n const versionQualifier = resolveVersionQualifier({\n rule,\n templateParams,\n qualifier: options.qualifier,\n })\n\n const releaseChannel = resolveReleaseChannel({\n ref,\n rule,\n templateParams,\n channel: options.channel,\n })\n\n return {\n cwd,\n env: options.env,\n today: date,\n signal: options.signal,\n stdout,\n stderr,\n logger,\n repository,\n ref,\n commit,\n author: options.author,\n classifier: options.classifier,\n rules: options.rules,\n type: options.type ?? 'auto',\n versionQualifier,\n releaseChannel,\n allowEmpty: !!options.allowEmpty,\n dryRun: !!options.dryRun,\n packages: [],\n plans: [],\n status: null,\n phase: null,\n error: null,\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAiDA,eAAsB,cACpB,SACyB;CACzB,MAAM,EAAE,KAAK,QAAQ,WAAW;CAChC,IAAI,EAAE,WAAW;CAEjB,WAAW,cAAc;EACvB,OAAO,QAAQ,QAAQ,UAAU,UAAU,UAAU;EAC7C;EACA;CACV,CAAC;CAED,MAAM,aAAa,MAAM,qBAAqB,GAAG;CACjD,IAAI;CACJ,IAAI;CAEJ,IAAI;EACF,SAAS,MAAM,oBAAoB,KAAK,CAAC,yBAAyB,CAAC;CACrE,SAAS,KAAK;EACZ,MAAM,IAAI,MACR,qFACA,EAAE,OAAO,IAAI,CACf;CACF;CAEA,IAAI;EACF,SAAS,MAAM,oBAAoB,GAAG;CACxC,SAAS,KAAK;EACZ,MAAM,IAAI,MACR,gEACA,EAAE,OAAO,IAAI,CACf;CACF;CAEA,MAAM,MAAc;EAAE,MAAM;EAAU,MAAM;CAAO;CACnD,MAAM,OAAO,gBAAgB,KAAK,QAAQ,KAAK;CAE/C,MAAM,sBAAM,IAAI,KAAK;CACrB,MAAM,OAAO,IAAI,YAAY,CAAC,CAAC,MAAM,GAAG,EAAE;CAC1C,MAAM,OAAO,IAAI,YAAY,CAAC,CAAC,MAAM,IAAI,EAAE;CAC3C,MAAM,iBAAiB;EACrB,MAAM,KAAK,WAAW,KAAK,EAAE;EAC7B,MAAM,KAAK,WAAW,KAAK,EAAE;CAC/B;CAEA,MAAM,mBAAmB,wBAAwB;EAC/C;EACA;EACA,WAAW,QAAQ;CACrB,CAAC;CAED,MAAM,iBAAiB,sBAAsB;EAC3C;EACA;EACA;EACA,SAAS,QAAQ;CACnB,CAAC;CAED,OAAO;EACL;EACA,KAAK,QAAQ;EACb,OAAO;EACP,QAAQ,QAAQ;EAChB;EACA;EACA;EACA;EACA;EACA;EACA,QAAQ,QAAQ;EAChB,YAAY,QAAQ;EACpB,OAAO,QAAQ;EACf,MAAM,QAAQ,QAAQ;EACtB;EACA;EACA,YAAY,CAAC,CAAC,QAAQ;EACtB,QAAQ,CAAC,CAAC,QAAQ;EAClB,UAAU,CAAC;EACX,OAAO,CAAC;EACR,QAAQ;EACR,OAAO;EACP,OAAO;CACT;AACF"}
package/package.json CHANGED
@@ -1,6 +1,12 @@
1
1
  {
2
2
  "name": "@reelout/context",
3
- "version": "0.0.0",
3
+ "version": "0.4.0",
4
+ "description": "Release context from Git and config.",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/aicest/reelout.git",
8
+ "directory": "packages/context"
9
+ },
4
10
  "license": "MIT",
5
11
  "type": "module",
6
12
  "imports": {},
@@ -25,11 +31,16 @@
25
31
  "./dist",
26
32
  "./src"
27
33
  ],
34
+ "dependencies": {
35
+ "@reelout/config": "^0.4.0",
36
+ "@reelout/core": "^0.4.0",
37
+ "consola": "^3.4.2"
38
+ },
39
+ "engines": {
40
+ "node": ">=24.15"
41
+ },
28
42
  "scripts": {
29
43
  "build": "vite build --ssr --sourcemap",
30
44
  "dev": "vite build --ssr --watch"
31
- },
32
- "engines": {
33
- "node": ">=24.11"
34
45
  }
35
- }
46
+ }
@@ -0,0 +1,16 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // Copyright (c) 2026 Fai
3
+
4
+ export class InMemoryStore {
5
+ private storage = new Map<string, object>()
6
+
7
+ get(plugin: string): object {
8
+ let state = this.storage.get(plugin)
9
+
10
+ if (state == null) {
11
+ this.storage.set(plugin, (state = {}))
12
+ }
13
+
14
+ return state
15
+ }
16
+ }
@@ -0,0 +1,133 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // Copyright (c) 2026 Fai
3
+
4
+ import {
5
+ findReleaseRule,
6
+ getCurrentGitBranch,
7
+ getCurrentGitCommit,
8
+ GIT_TRAILER_RELEASE_AGENT,
9
+ resolveGitRepository,
10
+ resolveReleaseChannel,
11
+ resolveVersionQualifier,
12
+ type GitCommit,
13
+ type GitRef,
14
+ type ReleaseContext,
15
+ type ReleaseTypeHint,
16
+ type ResolvedReleaseConfig,
17
+ } from '@reelout/core'
18
+ import { createConsola, LogLevels } from 'consola/basic'
19
+ import type { ConsolaInstance } from 'consola/core'
20
+
21
+ export interface CreateContextOptions extends Omit<
22
+ ResolvedReleaseConfig,
23
+ 'plugins'
24
+ > {
25
+ cwd: string
26
+ env: Readonly<NodeJS.ProcessEnv>
27
+ signal?: AbortSignal | undefined
28
+ stdout: NodeJS.WritableStream
29
+ stderr: NodeJS.WritableStream
30
+ logger?: ConsolaInstance | undefined
31
+ type?: ReleaseTypeHint | undefined
32
+ qualifier?: boolean | string | undefined
33
+ channel?: boolean | string | undefined
34
+ allowEmpty?: boolean | undefined
35
+ dryRun?: boolean | undefined
36
+ debug?: boolean | undefined
37
+ }
38
+
39
+ /**
40
+ * Initialize a release context for the current execution run.
41
+ *
42
+ * Resolves the Git repository, current commit, and branch information, then
43
+ * computes target release parameters using the provided configuration rules
44
+ * and runtime options.
45
+ *
46
+ * @param options Combined release configuration and runtime options
47
+ * @returns A promise that resolves to the fully initialized release context
48
+ * @throws If the Git repository has no commits or no branch is checked out
49
+ */
50
+ export async function createContext(
51
+ options: CreateContextOptions
52
+ ): Promise<ReleaseContext> {
53
+ const { cwd, stdout, stderr } = options
54
+ let { logger } = options
55
+
56
+ logger ??= createConsola({
57
+ level: options.debug ? LogLevels.verbose : LogLevels.info,
58
+ stdout: stdout as NodeJS.WriteStream,
59
+ stderr: stderr as NodeJS.WriteStream,
60
+ })
61
+
62
+ const repository = await resolveGitRepository(cwd)
63
+ let commit: GitCommit
64
+ let branch: string
65
+
66
+ try {
67
+ commit = await getCurrentGitCommit(cwd, [GIT_TRAILER_RELEASE_AGENT])
68
+ } catch (err) {
69
+ throw new Error(
70
+ 'Initialize a Git repository with at least one commit before running this command.',
71
+ { cause: err }
72
+ )
73
+ }
74
+
75
+ try {
76
+ branch = await getCurrentGitBranch(cwd)
77
+ } catch (err) {
78
+ throw new Error(
79
+ 'Check out a Git branch in your repository before proceeding.',
80
+ { cause: err }
81
+ )
82
+ }
83
+
84
+ const ref: GitRef = { type: 'branch', name: branch }
85
+ const rule = findReleaseRule(ref, options.rules)
86
+
87
+ const now = new Date()
88
+ const date = now.toISOString().slice(0, 10) // YYYY-MM-DD
89
+ const time = now.toISOString().slice(11, 19) // HH:mm:ss
90
+ const templateParams = {
91
+ date: date.replaceAll('-', ''),
92
+ time: time.replaceAll(':', ''),
93
+ }
94
+
95
+ const versionQualifier = resolveVersionQualifier({
96
+ rule,
97
+ templateParams,
98
+ qualifier: options.qualifier,
99
+ })
100
+
101
+ const releaseChannel = resolveReleaseChannel({
102
+ ref,
103
+ rule,
104
+ templateParams,
105
+ channel: options.channel,
106
+ })
107
+
108
+ return {
109
+ cwd,
110
+ env: options.env,
111
+ today: date,
112
+ signal: options.signal,
113
+ stdout,
114
+ stderr,
115
+ logger,
116
+ repository,
117
+ ref,
118
+ commit,
119
+ author: options.author,
120
+ classifier: options.classifier,
121
+ rules: options.rules,
122
+ type: options.type ?? 'auto',
123
+ versionQualifier,
124
+ releaseChannel,
125
+ allowEmpty: !!options.allowEmpty,
126
+ dryRun: !!options.dryRun,
127
+ packages: [],
128
+ plans: [],
129
+ status: null,
130
+ phase: null,
131
+ error: null,
132
+ }
133
+ }
package/src/index.ts CHANGED
@@ -1,3 +1,4 @@
1
- // Copyright (c) 2026 Fai Chen. Licensed under the MIT License.
1
+ // SPDX-License-Identifier: MIT
2
+ // Copyright (c) 2026 Fai
2
3
 
3
- export {}
4
+ export * from './createContext'