create-promptex-js 1.0.0 → 1.0.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 +5 -7
- package/dist/index.js +27 -42
- package/dist/messages.generated.js +12 -24
- package/package.json +2 -1
- package/templates/adapter-starter/README.md +45 -0
- package/templates/adapter-starter/_gitignore +6 -0
- package/templates/adapter-starter/example/promptex.config.ts +12 -0
- package/templates/adapter-starter/example/prompts/nodes.ts +18 -0
- package/templates/adapter-starter/package.json +28 -0
- package/templates/adapter-starter/promptex.config.schema.json +12 -0
- package/templates/adapter-starter/src/index.ts +93 -0
- package/templates/adapter-starter/tsconfig.json +14 -0
- package/templates/plugin-starter/README.md +40 -0
- package/templates/plugin-starter/_gitignore +5 -0
- package/templates/plugin-starter/example/promptex.config.ts +12 -0
- package/templates/plugin-starter/example/prompts/nodes.ts +16 -0
- package/templates/plugin-starter/package.json +28 -0
- package/templates/plugin-starter/promptex.config.schema.json +12 -0
- package/templates/plugin-starter/src/index.ts +63 -0
- package/templates/plugin-starter/tsconfig.json +14 -0
- package/templates/project-starter/README.md +30 -0
- package/templates/project-starter/_gitignore +11 -0
- package/templates/project-starter/package.json +13 -0
- package/templates/project-starter/promptex.config.ts +8 -0
- package/templates/project-starter/prompts/example-skill.ts +14 -0
- package/templates/project-starter/prompts/example.ts +14 -0
- package/dist/default-ref.d.ts +0 -6
- package/dist/default-ref.js +0 -14
package/README.md
CHANGED
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Scaffold a [promptex](https://github.com/promptex-ai/promptex) TypeScript
|
|
4
4
|
project, plugin or adapter from the
|
|
5
|
-
|
|
6
|
-
starters.
|
|
5
|
+
starter templates bundled with this package.
|
|
7
6
|
|
|
8
7
|
```console
|
|
9
8
|
npm create promptex-js
|
|
@@ -19,8 +18,7 @@ npm create promptex-js my-prompts -- --template project --name my-prompts --no-g
|
|
|
19
18
|
| :--- | :--- |
|
|
20
19
|
| `--template <t>` | `project`(消費專案)、`plugin`、`adapter` |
|
|
21
20
|
| `--name <n>` | kebab-case 名稱;預設取目標目錄名正規化 |
|
|
22
|
-
| `--
|
|
23
|
-
| `--source <p>` | 改用本地 promptex-templates checkout(離線與開發用) |
|
|
21
|
+
| `--source <p>` | 改讀本地模板目錄(含各 `*-starter` 的那一層),開發模板時用 |
|
|
24
22
|
| `--git` / `--no-git` | 是否 `git init`;互動預設是 |
|
|
25
23
|
| `--install` | 鷹架後直接 `npm install`;預設只印下一步 |
|
|
26
24
|
| `--yes` | 跳過互動,全部取預設或旗標值 |
|
|
@@ -32,9 +30,9 @@ npm create promptex-js my-prompts -- --template project --name my-prompts --no-g
|
|
|
32
30
|
用哪個語系寫([ADR-030](https://github.com/promptex-ai/ssot)):那份內容從產出
|
|
33
31
|
當下起就歸你,框架不再改寫它。plugin 與 adapter 骨架裡教你怎麼填的註解維持英文。
|
|
34
32
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
目標目錄非空時列出既有項目、零寫入退出。模板隨本套件一起發布,
|
|
34
|
+
鷹架時不需要網路,每個版本具現化的都是它發布時的模板。`{{promptexVersion}}`
|
|
35
|
+
於鷹架當下以本套件版本填入,三套件與 SDK 同版發布。
|
|
38
36
|
|
|
39
37
|
`promptex init` 與本工具的分工:init 在既有專案就地補上 promptex(非互動、
|
|
40
38
|
極簡骨架);本工具從零開一個 repo(互動、三種模板、git init)。
|
package/dist/index.js
CHANGED
|
@@ -1,27 +1,26 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// 鷹架 CLI
|
|
3
|
-
//
|
|
4
|
-
//
|
|
2
|
+
// 鷹架 CLI:開出 TypeScript 的 project/plugin/adapter 專案。六階段:環境檢查 →
|
|
3
|
+
// 互動收集 → 模板取得 → 具現化 → 後處理 → 稽核輸出;非互動時(--yes 或無 TTY)
|
|
4
|
+
// 全部取預設或旗標值。
|
|
5
5
|
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
6
|
+
// Templates ship inside this package (templates/), so every version scaffolds the
|
|
7
|
+
// templates it was released with, offline. --source points at a local templates
|
|
8
|
+
// directory (the one holding the *-starter folders) for template development.
|
|
9
9
|
//
|
|
10
10
|
// 用法:
|
|
11
11
|
// npm create promptex-js [目標目錄] [-- --template project|plugin|adapter \
|
|
12
|
-
// --name <kebab 名> --
|
|
12
|
+
// --name <kebab 名> --source <模板目錄> \
|
|
13
13
|
// --git|--no-git --install --yes --locale <語系>]
|
|
14
|
-
import {
|
|
15
|
-
import { existsSync, mkdirSync,
|
|
16
|
-
import { tmpdir } from 'node:os';
|
|
14
|
+
import { spawnSync } from 'node:child_process';
|
|
15
|
+
import { existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from 'node:fs';
|
|
17
16
|
import { basename, dirname, join, resolve } from 'node:path';
|
|
18
17
|
import { fileURLToPath } from 'node:url';
|
|
19
18
|
import * as p from '@clack/prompts';
|
|
20
19
|
import mri from 'mri';
|
|
21
|
-
import { resolveRef } from './default-ref.js';
|
|
22
20
|
import { resolveLocale, t } from './messages.generated.js';
|
|
23
21
|
const here = fileURLToPath(new URL('.', import.meta.url));
|
|
24
22
|
const ownVersion = JSON.parse(readFileSync(join(here, '..', 'package.json'), 'utf8')).version;
|
|
23
|
+
const BUNDLED_TEMPLATES = join(here, '..', 'templates');
|
|
25
24
|
const TEMPLATES = ['project', 'plugin', 'adapter'];
|
|
26
25
|
// 與 promptex init 的單元名正規化同一套規則(crates/promptex-core/src/init.rs)。
|
|
27
26
|
const RESERVED_UNIT_NAMES = ['cache', 'preview', 'content', 'content-index', 'graph', 'main'];
|
|
@@ -40,13 +39,21 @@ function bail(message) {
|
|
|
40
39
|
console.error(message);
|
|
41
40
|
process.exit(1);
|
|
42
41
|
}
|
|
43
|
-
const
|
|
42
|
+
const BOOLEAN_FLAGS = ['install', 'yes', 'git', 'help'];
|
|
43
|
+
const STRING_FLAGS = ['template', 'name', 'source', 'locale'];
|
|
44
44
|
const args = mri(process.argv.slice(2), {
|
|
45
|
-
boolean:
|
|
46
|
-
string:
|
|
45
|
+
boolean: BOOLEAN_FLAGS,
|
|
46
|
+
string: STRING_FLAGS,
|
|
47
47
|
alias: { h: 'help' },
|
|
48
48
|
});
|
|
49
49
|
const locale = resolveLocale(args.locale);
|
|
50
|
+
// mri accepts any flag, so reject the ones this tool does not declare (a removed
|
|
51
|
+
// --ref must fail loudly instead of being ignored). `--no-git` arrives as `git`.
|
|
52
|
+
const knownFlags = new Set(['_', 'h', ...BOOLEAN_FLAGS, ...STRING_FLAGS]);
|
|
53
|
+
for (const key of Object.keys(args)) {
|
|
54
|
+
if (!knownFlags.has(key))
|
|
55
|
+
bail(t('scaffold.error.unknown_argument', locale, { arg: `--${key}` }));
|
|
56
|
+
}
|
|
50
57
|
const separator = t('common.list_separator', locale);
|
|
51
58
|
if (args.help) {
|
|
52
59
|
console.log(t('scaffold.usage.js', locale));
|
|
@@ -116,32 +123,12 @@ if (existsSync(targetDir)) {
|
|
|
116
123
|
}
|
|
117
124
|
}
|
|
118
125
|
const gitAvailable = spawnSync('git', ['--version'], { stdio: 'ignore' }).status === 0;
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
if (args.source) {
|
|
126
|
-
sourceRoot = join(resolve(args.source), 'typescript');
|
|
127
|
-
sourceLabel = t('scaffold.source.local', locale, { path: resolve(args.source) });
|
|
128
|
-
}
|
|
129
|
-
else {
|
|
130
|
-
const { ref, showCloneHint } = resolveRef(args.ref, ownVersion);
|
|
131
|
-
cloneDir = mkdtempSync(join(tmpdir(), 'promptex-templates-'));
|
|
132
|
-
try {
|
|
133
|
-
execFileSync('git', ['clone', '--depth', '1', '--branch', ref, TEMPLATES_REPO, cloneDir], {
|
|
134
|
-
stdio: ['ignore', 'ignore', 'inherit'],
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
catch {
|
|
138
|
-
const hint = showCloneHint ? t('scaffold.error.clone_hint', locale) : '';
|
|
139
|
-
bail(t('scaffold.error.clone_failed', locale, { ref, hint }));
|
|
140
|
-
}
|
|
141
|
-
sourceRoot = join(cloneDir, 'typescript');
|
|
142
|
-
sourceLabel = `promptex-templates@${ref}`;
|
|
143
|
-
}
|
|
144
|
-
const starterDir = join(sourceRoot, `${template}-starter`);
|
|
126
|
+
// ── 模板取得:預設用內附模板;--source 讀本地模板目錄。 ──
|
|
127
|
+
const templatesRoot = args.source ? resolve(args.source) : BUNDLED_TEMPLATES;
|
|
128
|
+
const sourceLabel = args.source
|
|
129
|
+
? t('scaffold.source.local', locale, { path: templatesRoot })
|
|
130
|
+
: t('scaffold.source.bundled', locale, { version: ownVersion });
|
|
131
|
+
const starterDir = join(templatesRoot, `${template}-starter`);
|
|
145
132
|
if (!existsSync(starterDir))
|
|
146
133
|
bail(t('scaffold.error.starter_missing', locale, { template, path: starterDir }));
|
|
147
134
|
// ── 具現化:複製、佔位替換、_gitignore 改名。 ──
|
|
@@ -209,8 +196,6 @@ for (const rel of walk(starterDir)) {
|
|
|
209
196
|
writeFileSync(destPath, substitute(readFileSync(join(starterDir, rel), 'utf8')));
|
|
210
197
|
written.push(destRel);
|
|
211
198
|
}
|
|
212
|
-
if (cloneDir)
|
|
213
|
-
rmSync(cloneDir, { recursive: true, force: true });
|
|
214
199
|
// ── 後處理:git init(可選)、--install 裝依賴。 ──
|
|
215
200
|
if (wantGit && gitAvailable)
|
|
216
201
|
spawnSync('git', ['init', '--quiet'], { cwd: targetDir, stdio: 'inherit' });
|
|
@@ -19,14 +19,6 @@ export const MESSAGES = {
|
|
|
19
19
|
"en": "Wrote %{count} files → %{path} (template source: %{source})",
|
|
20
20
|
"zh-Hant": "已寫入 %{count} 個檔案 → %{path}(模板來源:%{source})",
|
|
21
21
|
},
|
|
22
|
-
"scaffold.error.clone_failed": {
|
|
23
|
-
"en": "git clone promptex-templates@%{ref} failed. %{hint}",
|
|
24
|
-
"zh-Hant": "git clone promptex-templates@%{ref} 失敗。%{hint}",
|
|
25
|
-
},
|
|
26
|
-
"scaffold.error.clone_hint": {
|
|
27
|
-
"en": "The tag for this version may not have been created yet: use --ref main to get the latest, or --source <local-path> to take it offline.",
|
|
28
|
-
"zh-Hant": "此版本的 tag 可能尚未建立:用 --ref main 抓最新、或 --source <本地路徑> 離線取用。",
|
|
29
|
-
},
|
|
30
22
|
"scaffold.error.dir_create": {
|
|
31
23
|
"en": "Creating %{path} failed: %{reason}",
|
|
32
24
|
"zh-Hant": "建立 %{path} 失敗:%{reason}",
|
|
@@ -47,10 +39,6 @@ export const MESSAGES = {
|
|
|
47
39
|
"en": "%{flag} is missing its value",
|
|
48
40
|
"zh-Hant": "%{flag} 缺值",
|
|
49
41
|
},
|
|
50
|
-
"scaffold.error.git_required": {
|
|
51
|
-
"en": "Getting the template needs git (or give a local promptex-templates path with --source).",
|
|
52
|
-
"zh-Hant": "取得模板需要 git(或用 --source 指定本地 promptex-templates 路徑)。",
|
|
53
|
-
},
|
|
54
42
|
"scaffold.error.install_failed.js": {
|
|
55
43
|
"en": "npm install failed; the scaffold files were written, the dependencies were not installed.",
|
|
56
44
|
"zh-Hant": "npm install 失敗,鷹架檔案已寫入、依賴未裝。",
|
|
@@ -95,13 +83,9 @@ export const MESSAGES = {
|
|
|
95
83
|
"en": "kebab-case name, defaults to the normalized target directory name",
|
|
96
84
|
"zh-Hant": "kebab-case 名稱,預設取目標目錄名正規化",
|
|
97
85
|
},
|
|
98
|
-
"scaffold.help.ref": {
|
|
99
|
-
"en": "take the given branch/tag of promptex-templates (defaults to v<this package's version>; pre-release versions default to main)",
|
|
100
|
-
"zh-Hant": "抓 promptex-templates 的指定 branch/tag(預設 v<本套件版本>;預發布版預設 main)",
|
|
101
|
-
},
|
|
102
86
|
"scaffold.help.source": {
|
|
103
|
-
"en": "use a local
|
|
104
|
-
"zh-Hant": "
|
|
87
|
+
"en": "use a local templates directory (the one holding the *-starter folders) instead of the bundled templates, for template development",
|
|
88
|
+
"zh-Hant": "改用本地模板目錄(含各 *-starter 的那一層)取代內附模板,開發模板時用",
|
|
105
89
|
},
|
|
106
90
|
"scaffold.help.target_dir": {
|
|
107
91
|
"en": "target directory",
|
|
@@ -139,6 +123,10 @@ export const MESSAGES = {
|
|
|
139
123
|
"en": "Template (%{choices})",
|
|
140
124
|
"zh-Hant": "模板(%{choices})",
|
|
141
125
|
},
|
|
126
|
+
"scaffold.source.bundled": {
|
|
127
|
+
"en": "bundled templates (v%{version})",
|
|
128
|
+
"zh-Hant": "內附模板(v%{version})",
|
|
129
|
+
},
|
|
142
130
|
"scaffold.source.local": {
|
|
143
131
|
"en": "local template (%{path})",
|
|
144
132
|
"zh-Hant": "本地模板(%{path})",
|
|
@@ -156,16 +144,16 @@ export const MESSAGES = {
|
|
|
156
144
|
"zh-Hant": "project:提示詞源碼樹(消費專案)",
|
|
157
145
|
},
|
|
158
146
|
"scaffold.usage.js": {
|
|
159
|
-
"en": "create-promptex-js [target-dir] --template project|plugin|adapter --name <kebab-name> [--
|
|
160
|
-
"zh-Hant": "create-promptex-js [目標目錄] --template project|plugin|adapter --name <kebab 名> [--
|
|
147
|
+
"en": "create-promptex-js [target-dir] --template project|plugin|adapter --name <kebab-name> [--source <templates-dir>] [--git|--no-git] [--install] [--yes] [--locale <locale>]",
|
|
148
|
+
"zh-Hant": "create-promptex-js [目標目錄] --template project|plugin|adapter --name <kebab 名> [--source <模板目錄>] [--git|--no-git] [--install] [--yes] [--locale <語系>]",
|
|
161
149
|
},
|
|
162
150
|
"scaffold.usage.py": {
|
|
163
|
-
"en": "uvx create-promptex-py [target-dir] [--template project|plugin|adapter] [--name <kebab-name>] [--
|
|
164
|
-
"zh-Hant": "uvx create-promptex-py [目標目錄] [--template project|plugin|adapter] [--name <kebab 名>] [--
|
|
151
|
+
"en": "uvx create-promptex-py [target-dir] [--template project|plugin|adapter] [--name <kebab-name>] [--source <templates-dir>] [--git|--no-git] [--install] [--yes] [--locale <locale>]",
|
|
152
|
+
"zh-Hant": "uvx create-promptex-py [目標目錄] [--template project|plugin|adapter] [--name <kebab 名>] [--source <模板目錄>] [--git|--no-git] [--install] [--yes] [--locale <語系>]",
|
|
165
153
|
},
|
|
166
154
|
"scaffold.usage.rs": {
|
|
167
|
-
"en": "cargo create-promptex-rs [target-dir] --template project|plugin|adapter --name <kebab-name> [--
|
|
168
|
-
"zh-Hant": "cargo create-promptex-rs [目標目錄] --template project|plugin|adapter --name <kebab 名> [--
|
|
155
|
+
"en": "cargo create-promptex-rs [target-dir] --template project|plugin|adapter --name <kebab-name> [--source <templates-dir>] [--git|--no-git] [--install] [--yes] [--locale <locale>]",
|
|
156
|
+
"zh-Hant": "cargo create-promptex-rs [目標目錄] --template project|plugin|adapter --name <kebab 名> [--source <模板目錄>] [--git|--no-git] [--install] [--yes] [--locale <語系>]",
|
|
169
157
|
},
|
|
170
158
|
"template.adapter_demo.rule_content": {
|
|
171
159
|
"en": "On the custom platform this rule degrades to always-on, with its scope noted in the body.",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-promptex-js",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Scaffold a promptex TypeScript project, plugin or adapter.",
|
|
5
5
|
"license": "MIT OR Apache-2.0",
|
|
6
6
|
"homepage": "https://github.com/promptex-ai/promptex/tree/main/packages/create-promptex-js#readme",
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
"files": [
|
|
32
32
|
"bin",
|
|
33
33
|
"dist",
|
|
34
|
+
"templates",
|
|
34
35
|
"LICENSE-MIT",
|
|
35
36
|
"LICENSE-APACHE"
|
|
36
37
|
],
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# promptex-adapter-{{name}}
|
|
2
|
+
|
|
3
|
+
A publishable third-party [promptex](https://github.com/promptex-ai/promptex)
|
|
4
|
+
platform adapter, written in TypeScript.
|
|
5
|
+
|
|
6
|
+
**Adapters are language-bound**: this package serves TypeScript prompt projects
|
|
7
|
+
only. To support the same platform from Python or Rust projects, implement the
|
|
8
|
+
same `emit` chain against that language's SDK.
|
|
9
|
+
|
|
10
|
+
The factory returns the same shape as the built-in `claude()` / `codex()`
|
|
11
|
+
targets, so consumers list it right alongside them. Its `emit` function walks a
|
|
12
|
+
fixed responsibility chain:
|
|
13
|
+
|
|
14
|
+
1. Compute the layout table first — rendering needs it to resolve references.
|
|
15
|
+
2. Report every unsupported kind via `ctx.unsupported` — never drop silently.
|
|
16
|
+
3. Render supported entries via `ctx.render(entry, selfPath, layout)`; where
|
|
17
|
+
the platform lacks a feature (e.g. scoped loading), record it with
|
|
18
|
+
`ctx.degrade` and degrade in the output. Read platform-native keys via
|
|
19
|
+
`ctx.overrides`, never from the entry config directly.
|
|
20
|
+
4. Emit referenced resources.
|
|
21
|
+
|
|
22
|
+
## Try it
|
|
23
|
+
|
|
24
|
+
```console
|
|
25
|
+
npm install
|
|
26
|
+
cd example
|
|
27
|
+
npx promptex build --install .
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
The example project lists `targets: [claude(), target()]`; after install you
|
|
31
|
+
get both `.claude/` and `.{{name}}/` artifacts, and the install report shows
|
|
32
|
+
the `scopedLoading` degradation for the example rule. `npx promptex build --install --dry-run .`
|
|
33
|
+
previews without writing.
|
|
34
|
+
|
|
35
|
+
## Publishing
|
|
36
|
+
|
|
37
|
+
- `npm run build` compiles `src/` to `dist/`; the package ships `dist/` plus
|
|
38
|
+
`promptex.config.schema.json`.
|
|
39
|
+
- Keep `promptex.config.schema.json` at the package root: `promptex config
|
|
40
|
+
declare promptex-adapter-{{name}}` reads it from there, and `src/index.ts`
|
|
41
|
+
reads that same root copy at load time (a runtime read, not a compile-time
|
|
42
|
+
JSON import, so the emitted tree keeps a single copy and `dist/` stays flat)
|
|
43
|
+
and passes it to `defineTarget`, so it also travels with the intermediate
|
|
44
|
+
representation.
|
|
45
|
+
- Keep the `promptex-adapter-` name prefix so consumers can find the package.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// 最小消費專案:自訂 target 與內建 claude() 並列,裝完依賴即可在本目錄執行
|
|
2
|
+
// npx promptex build --install . 驗證兩個平台的產物。真實消費端改為從發布後的套件名
|
|
3
|
+
// import。
|
|
4
|
+
import { claude, defineConfig } from 'promptex-js'
|
|
5
|
+
import target from '../src/index.ts'
|
|
6
|
+
|
|
7
|
+
export default defineConfig({
|
|
8
|
+
name: 'adapter-example',
|
|
9
|
+
srcDir: './prompts',
|
|
10
|
+
outDir: '.',
|
|
11
|
+
targets: [claude(), target()],
|
|
12
|
+
})
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { defineRule, defineSkill } from 'promptex-js'
|
|
2
|
+
|
|
3
|
+
export const exampleSkill = defineSkill({
|
|
4
|
+
id: 'adapter-demo-skill',
|
|
5
|
+
name: '{{demoSkillName}}',
|
|
6
|
+
description: '{{adapterDemoSkillDescription}}',
|
|
7
|
+
config: { whenToUse: '{{adapterDemoSkillWhenToUse}}' },
|
|
8
|
+
content: '{{adapterDemoSkillContent}}',
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
// A rule carrying appliesTo: the custom platform has no scoped-loading mechanism,
|
|
12
|
+
// so the install report shows a scopedLoading degrade entry.
|
|
13
|
+
export const exampleRule = defineRule({
|
|
14
|
+
id: 'adapter-demo-rule',
|
|
15
|
+
name: '{{demoRuleName}}',
|
|
16
|
+
config: { appliesTo: ['prompts/**'] },
|
|
17
|
+
content: '{{adapterDemoRuleContent}}',
|
|
18
|
+
})
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "promptex-adapter-{{name}}",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A third-party promptex platform adapter.",
|
|
5
|
+
"license": "MIT OR Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist",
|
|
9
|
+
"promptex.config.schema.json"
|
|
10
|
+
],
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"default": "./dist/index.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "tsc"
|
|
19
|
+
},
|
|
20
|
+
"peerDependencies": {
|
|
21
|
+
"promptex-js": "^{{promptexVersion}}"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@types/node": "^22.10.0",
|
|
25
|
+
"promptex-js": "^{{promptexVersion}}",
|
|
26
|
+
"typescript": "^7.0.2"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"title": "promptex-adapter-{{name}} options",
|
|
4
|
+
"type": "object",
|
|
5
|
+
"properties": {
|
|
6
|
+
"root": {
|
|
7
|
+
"type": "string",
|
|
8
|
+
"description": "Root directory for emitted artifacts, relative to the install root. Defaults to \".{{name}}\"."
|
|
9
|
+
}
|
|
10
|
+
},
|
|
11
|
+
"additionalProperties": false
|
|
12
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
// 第三方 adapter:以 SDK 層實作,只用 AdapterContext 的公開介面。emit 的
|
|
2
|
+
// 責任鏈固定四步:① 算落點表 → ② 回報不支援的 kind → ③ 渲染並產出節點
|
|
3
|
+
// (平台缺某機制時記 degrade 降級)→ ④ 產出被引用的資源。發布前把落點
|
|
4
|
+
// 規則與能力集合換成你的平台實況。
|
|
5
|
+
//
|
|
6
|
+
// adapter 綁語言:本套件服務 TypeScript 專案;Python/Rust 專案要用同一個
|
|
7
|
+
// 平台時,各自以該語言的 SDK 實作一份。
|
|
8
|
+
import { readFileSync } from 'node:fs'
|
|
9
|
+
|
|
10
|
+
import { defineTarget, type AdapterContext, type AdapterTarget, type PluginEntry } from 'promptex-js'
|
|
11
|
+
|
|
12
|
+
// 參數宣告(標準 JSON Schema)住套件根,由本檔在載入時讀進來。用執行期讀檔而非
|
|
13
|
+
// 編譯期 import:JSON 在 include 的 src 之外,靜態 import 會把編譯器的共同來源根
|
|
14
|
+
// 抬到套件根,產物因此多一層 src/,包裡還會留下第二份 schema。改讀檔之後
|
|
15
|
+
// src/index.ts 與 dist/index.js 對套件根的相對位置相同,兩種形態都指向同一份。
|
|
16
|
+
const configSchema = JSON.parse(readFileSync(new URL('../promptex.config.schema.json', import.meta.url), 'utf8'))
|
|
17
|
+
|
|
18
|
+
/** 建構參數:與 promptex.config.schema.json 的宣告一一對應。 */
|
|
19
|
+
export interface Options {
|
|
20
|
+
/** 產物落點的根目錄;預設 `.{{name}}`。 */
|
|
21
|
+
readonly root?: string
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** 平台能力:本範例只有提示詞單檔與參考資料,無代理、無事件機制。 */
|
|
25
|
+
const SUPPORTED = ['skill', 'rule', 'instruction'] as const
|
|
26
|
+
const UNSUPPORTED = ['agent', 'hook', 'mcp', 'permission'] as const
|
|
27
|
+
|
|
28
|
+
export default function target(options: Options = {}): AdapterTarget {
|
|
29
|
+
const root = options.root ?? '.{{name}}'
|
|
30
|
+
// 落點規則:提示詞一律單檔平鋪,資源集中於 refs/。
|
|
31
|
+
const nodePath = (e: PluginEntry) => `${root}/prompts/${e.id}.md`
|
|
32
|
+
const resourcePath = (e: PluginEntry) => `${root}/refs/${e.id}.md`
|
|
33
|
+
|
|
34
|
+
const emit = (ctx: AdapterContext): Map<string, string> => {
|
|
35
|
+
const files = new Map<string, string>()
|
|
36
|
+
|
|
37
|
+
// ① 先算落點表:渲染需要它解析引用,故必須在渲染之前完成。
|
|
38
|
+
const layout = new Map<string, string>()
|
|
39
|
+
for (const kind of SUPPORTED) {
|
|
40
|
+
for (const e of ctx.entries(kind)) layout.set(`${kind}:${e.id}`, nodePath(e))
|
|
41
|
+
}
|
|
42
|
+
for (const kind of ['resource', 'asset', 'dir'] as const) {
|
|
43
|
+
for (const e of ctx.entries(kind)) layout.set(`${kind}:${e.id}`, resourcePath(e))
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// ② 不支援的 kind 逐一列報告,不靜默丟棄。
|
|
47
|
+
for (const kind of UNSUPPORTED) {
|
|
48
|
+
for (const e of ctx.entries(kind)) {
|
|
49
|
+
ctx.unsupported({ kind, nodeId: e.id, feature: kind, note: `{{name}} 無 ${kind} 對應機制,該節點未產出` })
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// ③ 產出提示詞單檔;rule 的載入範圍在本平台無對應機制,降級為內文標註。
|
|
54
|
+
for (const kind of SUPPORTED) {
|
|
55
|
+
for (const e of ctx.entries(kind)) {
|
|
56
|
+
const path = nodePath(e)
|
|
57
|
+
const cfg = e.def.config as { appliesTo?: readonly string[] } | undefined
|
|
58
|
+
let note = ''
|
|
59
|
+
if (kind === 'rule' && cfg?.appliesTo?.length) {
|
|
60
|
+
note = `適用範圍:${cfg.appliesTo.join('、')}\n\n`
|
|
61
|
+
ctx.degrade({
|
|
62
|
+
kind,
|
|
63
|
+
nodeId: e.id,
|
|
64
|
+
feature: 'scopedLoading',
|
|
65
|
+
note: '{{name}} 無範圍載入機制,改為常駐並於內文標註適用範圍',
|
|
66
|
+
})
|
|
67
|
+
}
|
|
68
|
+
files.set(path, `${frontmatter(ctx, e)}# ${e.name}\n\n${note}${ctx.render(e, path, layout)}\n`)
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// ④ 被引用的資源。
|
|
73
|
+
for (const e of ctx.entries('resource')) {
|
|
74
|
+
const path = resourcePath(e)
|
|
75
|
+
files.set(path, `# ${e.name}\n\n${ctx.render(e, path, layout)}\n`)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return files
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// 參數宣告隨中介表示交給讀取端;
|
|
82
|
+
// `promptex config declare` 讀的是套件根的同一份檔案。
|
|
83
|
+
return defineTarget('{{name}}', emit, { configSchema })
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// 平台原生鍵的覆寫:一律經 ctx.overrides 讀取,不自己走
|
|
87
|
+
// entry.def.config.platforms:「空物件視同未宣告」的判定與框架保留鍵
|
|
88
|
+
// (promptex: 前綴)的過濾都由核心同一份實作承載,自己讀會各自重造而漂移。
|
|
89
|
+
const frontmatter = (ctx: AdapterContext, e: PluginEntry): string => {
|
|
90
|
+
const overrides = ctx.overrides(e)
|
|
91
|
+
if (!overrides) return ''
|
|
92
|
+
return `---\n${Object.entries(overrides).map(([k, v]) => `${k}: ${String(v)}`).join('\n')}\n---\n\n`
|
|
93
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"module": "nodenext",
|
|
4
|
+
"moduleResolution": "nodenext",
|
|
5
|
+
"target": "es2022",
|
|
6
|
+
"strict": true,
|
|
7
|
+
"declaration": true,
|
|
8
|
+
"outDir": "dist",
|
|
9
|
+
"rootDir": "src",
|
|
10
|
+
"skipLibCheck": true,
|
|
11
|
+
"types": ["node"]
|
|
12
|
+
},
|
|
13
|
+
"include": ["src"]
|
|
14
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# promptex-plugin-{{name}}
|
|
2
|
+
|
|
3
|
+
A publishable [promptex](https://github.com/promptex-ai/promptex) plugin,
|
|
4
|
+
written in TypeScript for TypeScript prompt projects.
|
|
5
|
+
|
|
6
|
+
A plugin hooks into the evaluation pipeline in a fixed order:
|
|
7
|
+
|
|
8
|
+
1. `prepare` — the only async stage, runs before source collection. Fetch
|
|
9
|
+
external data here (cache it under `ctx.cacheDir`, record pins with
|
|
10
|
+
`ctx.writeLock`) and pass it to later stages through the plugin's closure.
|
|
11
|
+
2. `transform` — rewrite existing entries through the context operations
|
|
12
|
+
(`appendContent` / `patchConfig`) or add new nodes with `define*`.
|
|
13
|
+
3. `validate` — structural checks over the registry; return diagnostics
|
|
14
|
+
(an empty array passes). Core checks run first.
|
|
15
|
+
|
|
16
|
+
Plugins produce **nodes**, not files: anything you want on disk becomes a
|
|
17
|
+
resource node that the core lays out.
|
|
18
|
+
|
|
19
|
+
## Try it
|
|
20
|
+
|
|
21
|
+
```console
|
|
22
|
+
npm install
|
|
23
|
+
cd example
|
|
24
|
+
npx promptex build --install .
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
The example project wires the plugin in via `plugins: [createPlugin(...)]` and
|
|
28
|
+
shows the banner appended to both entries. `npx promptex build --install --dry-run .` previews
|
|
29
|
+
without writing.
|
|
30
|
+
|
|
31
|
+
## Publishing
|
|
32
|
+
|
|
33
|
+
- `npm run build` compiles `src/` to `dist/`; the package ships `dist/` plus
|
|
34
|
+
`promptex.config.schema.json`.
|
|
35
|
+
- Keep `promptex.config.schema.json` at the package root: `promptex config
|
|
36
|
+
declare promptex-plugin-{{name}}` reads it from there, and `src/index.ts`
|
|
37
|
+
reads that same root copy at load time (a runtime read, not a compile-time
|
|
38
|
+
JSON import, so the emitted tree keeps a single copy and `dist/` stays flat),
|
|
39
|
+
so the schema also travels with the intermediate representation.
|
|
40
|
+
- Keep the `promptex-plugin-` name prefix so consumers can find the package.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// 最小消費專案:直接以相對路徑掛上本套件的 plugin,裝完依賴即可在本目錄
|
|
2
|
+
// 執行 npx promptex build --install . 驗證產物。真實消費端改為從發布後的套件名 import。
|
|
3
|
+
import { claude, defineConfig } from 'promptex-js'
|
|
4
|
+
import { createPlugin } from '../src/index.ts'
|
|
5
|
+
|
|
6
|
+
export default defineConfig({
|
|
7
|
+
name: 'plugin-example',
|
|
8
|
+
srcDir: './prompts',
|
|
9
|
+
outDir: '.',
|
|
10
|
+
targets: [claude()],
|
|
11
|
+
plugins: [createPlugin({ banner: '(由 {{name}} plugin 追加)' })],
|
|
12
|
+
})
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { defineRule, defineSkill } from 'promptex-js'
|
|
2
|
+
|
|
3
|
+
export const exampleSkill = defineSkill({
|
|
4
|
+
id: 'plugin-demo-skill',
|
|
5
|
+
name: '{{demoSkillName}}',
|
|
6
|
+
description: '{{pluginDemoSkillDescription}}',
|
|
7
|
+
config: { whenToUse: '{{pluginDemoSkillWhenToUse}}' },
|
|
8
|
+
content: '{{pluginDemoSkillContent}}',
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
export const exampleRule = defineRule({
|
|
12
|
+
id: 'plugin-demo-rule',
|
|
13
|
+
name: '{{demoRuleName}}',
|
|
14
|
+
config: { appliesTo: ['prompts/**'] },
|
|
15
|
+
content: '{{pluginDemoRuleContent}}',
|
|
16
|
+
})
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "promptex-plugin-{{name}}",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A promptex plugin.",
|
|
5
|
+
"license": "MIT OR Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist",
|
|
9
|
+
"promptex.config.schema.json"
|
|
10
|
+
],
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"default": "./dist/index.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "tsc"
|
|
19
|
+
},
|
|
20
|
+
"peerDependencies": {
|
|
21
|
+
"promptex-js": "^{{promptexVersion}}"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@types/node": "^22.10.0",
|
|
25
|
+
"promptex-js": "^{{promptexVersion}}",
|
|
26
|
+
"typescript": "^7.0.2"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"title": "promptex-plugin-{{name}} options",
|
|
4
|
+
"type": "object",
|
|
5
|
+
"properties": {
|
|
6
|
+
"banner": {
|
|
7
|
+
"type": "string",
|
|
8
|
+
"description": "Appended to every skill and rule at the transform stage. Defaults to a built-in notice."
|
|
9
|
+
}
|
|
10
|
+
},
|
|
11
|
+
"additionalProperties": false
|
|
12
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// 最小可發布 plugin:三個生命週期各示範一件事,發布前把內容換成你的邏輯。
|
|
2
|
+
// 生命週期固定順序:prepare(唯一 async 的階段,收集遍之前)→ 源碼求值 →
|
|
3
|
+
// transform(改寫遍)→ validate(解析遍,核心檢查在先)。
|
|
4
|
+
import { readFileSync } from 'node:fs'
|
|
5
|
+
|
|
6
|
+
import type { Diagnostic, Plugin } from 'promptex-js'
|
|
7
|
+
|
|
8
|
+
// 參數宣告(標準 JSON Schema)住套件根,由本檔在載入時讀進來。用執行期讀檔而非
|
|
9
|
+
// 編譯期 import:JSON 在 include 的 src 之外,靜態 import 會把編譯器的共同來源根
|
|
10
|
+
// 抬到套件根,產物因此多一層 src/,包裡還會留下第二份 schema。改讀檔之後
|
|
11
|
+
// src/index.ts 與 dist/index.js 對套件根的相對位置相同,兩種形態都指向同一份。
|
|
12
|
+
const configSchema = JSON.parse(readFileSync(new URL('../promptex.config.schema.json', import.meta.url), 'utf8'))
|
|
13
|
+
|
|
14
|
+
/** 建構參數:與 promptex.config.schema.json 的宣告一一對應。 */
|
|
15
|
+
export interface Options {
|
|
16
|
+
/** transform 階段追加到每個 skill 與 rule 的內容;省略時用預設文字。 */
|
|
17
|
+
readonly banner?: string
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const DEFAULT_BANNER = '(本節點由 {{name}} plugin 追加此行)'
|
|
21
|
+
|
|
22
|
+
export function createPlugin(options: Options = {}): Plugin {
|
|
23
|
+
// prepare 取得的資料存進閉包,transform 只讀閉包、不知道資料從何而來。
|
|
24
|
+
let banner = ''
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
name: '{{name}}',
|
|
28
|
+
// 宣告本擴充作用在哪幾種節點類型(供文件與讀取端),不隱含過濾。
|
|
29
|
+
kinds: ['skill', 'rule'],
|
|
30
|
+
// 相容的框架版本範圍:安裝的 promptex-js 落在範圍外時於編譯開始前報錯。
|
|
31
|
+
version: '^{{promptexVersion}}',
|
|
32
|
+
// 參數宣告隨中介表示交給讀取端;
|
|
33
|
+
// `promptex config declare` 讀的是套件根的同一份檔案。
|
|
34
|
+
configSchema,
|
|
35
|
+
|
|
36
|
+
// 準備:唯一 async 的生命週期。真實 plugin 在這裡請求外部資源,或以
|
|
37
|
+
// ctx.cacheDir 快取、ctx.writeLock 記錄鎖定;本範例只把參數收斂成
|
|
38
|
+
// transform 要用的值。
|
|
39
|
+
async prepare() {
|
|
40
|
+
banner = options.banner ?? DEFAULT_BANNER
|
|
41
|
+
},
|
|
42
|
+
|
|
43
|
+
// 改寫:改寫既有節點一律經 ctx 操作函式(appendContent/patchConfig),
|
|
44
|
+
// 型別安全、變更可追蹤、衝突可偵測;也可在此以 define* 新增節點。
|
|
45
|
+
transform(ctx) {
|
|
46
|
+
for (const entry of ctx.entries) {
|
|
47
|
+
if (entry.kind === 'skill' || entry.kind === 'rule') ctx.appendContent(entry, banner)
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
|
|
51
|
+
// 驗證:對註冊表做結構驗證,回傳診斷(空陣列即通過)。
|
|
52
|
+
validate(ctx): Diagnostic[] {
|
|
53
|
+
return ctx.entries
|
|
54
|
+
.filter((e) => e.id.startsWith('promptex-'))
|
|
55
|
+
.map((e) => ({
|
|
56
|
+
code: '{{name}}-reserved-id',
|
|
57
|
+
message: `節點 ${e.id} 以保留前綴 promptex- 命名,請改用其他 id`,
|
|
58
|
+
at: [e.at],
|
|
59
|
+
severity: 'error',
|
|
60
|
+
}))
|
|
61
|
+
},
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"module": "nodenext",
|
|
4
|
+
"moduleResolution": "nodenext",
|
|
5
|
+
"target": "es2022",
|
|
6
|
+
"strict": true,
|
|
7
|
+
"declaration": true,
|
|
8
|
+
"outDir": "dist",
|
|
9
|
+
"rootDir": "src",
|
|
10
|
+
"skipLibCheck": true,
|
|
11
|
+
"types": ["node"]
|
|
12
|
+
},
|
|
13
|
+
"include": ["src"]
|
|
14
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# {{name}}
|
|
2
|
+
|
|
3
|
+
A [promptex](https://github.com/promptex-ai/promptex) prompt-source tree:
|
|
4
|
+
resources are declared in TypeScript under `prompts/` and projected onto your
|
|
5
|
+
AI coding tool by the `promptex` CLI.
|
|
6
|
+
|
|
7
|
+
## Getting started
|
|
8
|
+
|
|
9
|
+
```console
|
|
10
|
+
npm install
|
|
11
|
+
npm run install:prompts
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
`npm run install:prompts` compiles the declarations and writes the platform
|
|
15
|
+
artifacts (e.g. `.claude/`) into this directory. `npm run build` only refreshes
|
|
16
|
+
the framework metadata under `.promptex/` without touching platform artifacts;
|
|
17
|
+
`npx promptex build --install --dry-run .` previews the diff without writing anything.
|
|
18
|
+
|
|
19
|
+
## Layout
|
|
20
|
+
|
|
21
|
+
| Path | Role |
|
|
22
|
+
| :--- | :--- |
|
|
23
|
+
| `promptex.config.ts` | Unit configuration: source dir, output dir, targets |
|
|
24
|
+
| `prompts/example.ts` | Example rule (scope-loaded via `appliesTo`) |
|
|
25
|
+
| `prompts/example-skill.ts` | Example skill (invoked via `whenToUse`) |
|
|
26
|
+
|
|
27
|
+
Add more resources as ordinary `.ts` files under `prompts/`; every file in the
|
|
28
|
+
source dir is evaluated. See the
|
|
29
|
+
[promptex-js README](https://github.com/promptex-ai/promptex/tree/main/packages/promptex-js)
|
|
30
|
+
for the full API.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# === promptex init 產生的忽略規則(重跑以本行判定,勿改寫)===
|
|
2
|
+
# 框架的建置快取。整個 .promptex/ 不忽略:查詢進入點的覆寫檔 .promptex/query
|
|
3
|
+
# 是作者手寫的內容,要入版控;匯出的 .promptex/preview/ 入不入版控由你決定。
|
|
4
|
+
.promptex/cache/
|
|
5
|
+
# 框架每次建置重寫的中繼(結構與內容本體),可重建、不入版控。逐檔明列而非
|
|
6
|
+
# 用 .promptex/*/ 這類萬用:同一層還住著所有權登記 {平台}.json,那是要入版控的。
|
|
7
|
+
.promptex/*/graph.json
|
|
8
|
+
.promptex/*/content.json
|
|
9
|
+
.promptex/*/content-index.json
|
|
10
|
+
# npm 安裝依賴的落點。
|
|
11
|
+
node_modules/
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { defineSkill } from 'promptex-js'
|
|
2
|
+
|
|
3
|
+
export const exampleSkill = defineSkill({
|
|
4
|
+
id: 'example-skill',
|
|
5
|
+
name: '{{exampleSkillName}}',
|
|
6
|
+
description: '{{exampleSkillDescription}}',
|
|
7
|
+
config: {
|
|
8
|
+
whenToUse: '{{exampleSkillWhenToUse}}',
|
|
9
|
+
},
|
|
10
|
+
content: [
|
|
11
|
+
'{{exampleSkillIntro}}',
|
|
12
|
+
'{{exampleSkillInvoked}}',
|
|
13
|
+
],
|
|
14
|
+
})
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { defineRule } from 'promptex-js'
|
|
2
|
+
|
|
3
|
+
export const exampleRule = defineRule({
|
|
4
|
+
id: 'example-rule',
|
|
5
|
+
name: '{{exampleRuleName}}',
|
|
6
|
+
config: {
|
|
7
|
+
appliesTo: ['prompts/**'],
|
|
8
|
+
},
|
|
9
|
+
content: [
|
|
10
|
+
'{{exampleRuleIntro}}',
|
|
11
|
+
'{{exampleRuleScoped}}',
|
|
12
|
+
'{{exampleRuleOtherStates}}',
|
|
13
|
+
],
|
|
14
|
+
})
|
package/dist/default-ref.d.ts
DELETED
package/dist/default-ref.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
// 預設 templates ref 的判定(決策 d006)。三個 create-* 鷹架規則一致:
|
|
2
|
-
// GA 版號(X.Y.Z)抓對應 tag `v<版本>`;帶預發布後綴(-alpha.N、-beta.N、-rc.N 等)
|
|
3
|
-
// 的版本,tag 不一定存在,預設抓 `main`;使用者給 --ref 一律照用。
|
|
4
|
-
const GA_VERSION = /^\d+\.\d+\.\d+$/;
|
|
5
|
-
export function defaultRef(version) {
|
|
6
|
-
return GA_VERSION.test(version) ? `v${version}` : 'main';
|
|
7
|
-
}
|
|
8
|
-
/** `showCloneHint`:clone 失敗時是否附上「tag 可能尚未建立」提示,只在 GA 預設 ref 時為真。 */
|
|
9
|
-
export function resolveRef(explicit, version) {
|
|
10
|
-
if (explicit)
|
|
11
|
-
return { ref: explicit, showCloneHint: false };
|
|
12
|
-
const ref = defaultRef(version);
|
|
13
|
-
return { ref, showCloneHint: ref !== 'main' };
|
|
14
|
-
}
|