@tbsten/mir-core 0.0.1-alpha02 → 0.0.1-alpha04
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 +45 -0
- package/package.json +25 -3
- package/src/i18n/locales/en.ts +5 -0
- package/src/i18n/locales/ja.ts +5 -0
- package/src/i18n/types.ts +5 -0
- package/src/index.ts +0 -1
- package/src/registry.ts +3 -0
- package/src/template-engine.ts +3 -0
package/README.md
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# @tbsten/mir-core
|
|
2
|
+
|
|
3
|
+
共有コアロジックライブラリ。Handlebars テンプレートエンジン、スキーマ検証、i18n、リモート registry アクセスなどの機能を提供します。
|
|
4
|
+
|
|
5
|
+
## インストール
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @tbsten/mir-core
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## 機能
|
|
12
|
+
|
|
13
|
+
- **テンプレートエンジン**: Handlebars による変数展開
|
|
14
|
+
- **スキーマ検証**: Snippet と config の JSON Schema 検証
|
|
15
|
+
- **i18n 対応**: 日本語・英語のメッセージ管理
|
|
16
|
+
- **リモート Registry**: HTTP ベースの registry からスニペット取得
|
|
17
|
+
- **エラー処理**: カスタムエラークラスと詳細メッセージ
|
|
18
|
+
|
|
19
|
+
## 使用例
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
import { expandTemplate, loadSnippetSchema } from '@tbsten/mir-core';
|
|
23
|
+
|
|
24
|
+
// テンプレート展開
|
|
25
|
+
const result = expandTemplate('Hello {{name}}!', { name: 'World' });
|
|
26
|
+
console.log(result); // "Hello World!"
|
|
27
|
+
|
|
28
|
+
// スキーマ検証
|
|
29
|
+
const schema = await loadSnippetSchema();
|
|
30
|
+
const isValid = validateSnippetYaml(snippetData, schema);
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## API
|
|
34
|
+
|
|
35
|
+
詳細は [src/index.ts](./src/index.ts) を参照してください。
|
|
36
|
+
|
|
37
|
+
- `expandTemplate(template, variables)` - Handlebars テンプレート展開
|
|
38
|
+
- `loadSnippetSchema()` - Snippet スキーマ読み込み
|
|
39
|
+
- `loadMirconfigSchema()` - Mirconfig スキーマ読み込み
|
|
40
|
+
- `validateSnippetYaml(data, schema)` - YAML バリデーション
|
|
41
|
+
- `RemoteRegistry` - リモート registry クライアント
|
|
42
|
+
|
|
43
|
+
## ライセンス
|
|
44
|
+
|
|
45
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,10 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tbsten/mir-core",
|
|
3
|
-
"version": "0.0.1-
|
|
3
|
+
"version": "0.0.1-alpha04",
|
|
4
|
+
"description": "スニペット配布・取得ツール mir のコアロジック(テンプレート、スキーマ、i18n)",
|
|
4
5
|
"type": "module",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"snippet",
|
|
8
|
+
"template",
|
|
9
|
+
"handlebars",
|
|
10
|
+
"scaffold",
|
|
11
|
+
"generator"
|
|
12
|
+
],
|
|
13
|
+
"author": "tbsten",
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"homepage": "https://mir.tbsten.me",
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "https://github.com/tbsten/mir.git",
|
|
19
|
+
"directory": "packages/mir-core"
|
|
20
|
+
},
|
|
21
|
+
"bugs": {
|
|
22
|
+
"url": "https://github.com/tbsten/mir/issues"
|
|
23
|
+
},
|
|
5
24
|
"exports": {
|
|
6
|
-
".": "./
|
|
25
|
+
".": "./dist/index.js"
|
|
7
26
|
},
|
|
27
|
+
"main": "./dist/index.js",
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
8
29
|
"publishConfig": {
|
|
9
30
|
"registry": "https://registry.npmjs.org/",
|
|
10
31
|
"access": "public"
|
|
@@ -15,7 +36,8 @@
|
|
|
15
36
|
},
|
|
16
37
|
"scripts": {
|
|
17
38
|
"test": "vitest run",
|
|
18
|
-
"test:watch": "vitest"
|
|
39
|
+
"test:watch": "vitest",
|
|
40
|
+
"typecheck": "tsc --noEmit"
|
|
19
41
|
},
|
|
20
42
|
"devDependencies": {
|
|
21
43
|
"@types/js-yaml": "^4.0.9",
|
package/src/i18n/locales/en.ts
CHANGED
|
@@ -58,6 +58,11 @@ export const en: MessageCatalog = {
|
|
|
58
58
|
|
|
59
59
|
// error specific
|
|
60
60
|
"error.no-failed-snippets": "No failed snippet history",
|
|
61
|
+
"error.publish-token-required": "publish_token is required to publish to remote registry. Configure it in ~/.mir/mirconfig.yaml",
|
|
62
|
+
"error.publish-auth-failed": "Publish authentication failed. Please verify your publish_token",
|
|
63
|
+
"error.publish-token-invalid": "Invalid publish_token. Check your registry configuration",
|
|
64
|
+
"error.publish-failed": "Failed to publish snippet: {error}",
|
|
65
|
+
"error.publish-network-error": "Network error: {message}",
|
|
61
66
|
|
|
62
67
|
// clone
|
|
63
68
|
"clone.success": "Cloned snippet \"{name}\" to \"{alias}\"",
|
package/src/i18n/locales/ja.ts
CHANGED
|
@@ -58,6 +58,11 @@ export const ja: MessageCatalog = {
|
|
|
58
58
|
|
|
59
59
|
// error specific
|
|
60
60
|
"error.no-failed-snippets": "失敗した snippet の履歴がありません",
|
|
61
|
+
"error.publish-token-required": "リモート registry への publish には publish_token が必要です。~/.mir/mirconfig.yaml で設定してください",
|
|
62
|
+
"error.publish-auth-failed": "publish 認証に失敗しました。publish_token を確認してください",
|
|
63
|
+
"error.publish-token-invalid": "publish_token が無効です。registry の設定を確認してください",
|
|
64
|
+
"error.publish-failed": "Snippet の publish に失敗しました: {error}",
|
|
65
|
+
"error.publish-network-error": "ネットワークエラー: {message}",
|
|
61
66
|
|
|
62
67
|
// clone
|
|
63
68
|
"clone.success": "Snippet \"{name}\" を \"{alias}\" として複製しました",
|
package/src/i18n/types.ts
CHANGED
|
@@ -56,6 +56,11 @@ export interface MessageCatalog {
|
|
|
56
56
|
|
|
57
57
|
// error specific
|
|
58
58
|
"error.no-failed-snippets": string;
|
|
59
|
+
"error.publish-token-required": string;
|
|
60
|
+
"error.publish-auth-failed": string;
|
|
61
|
+
"error.publish-token-invalid": string;
|
|
62
|
+
"error.publish-failed": string;
|
|
63
|
+
"error.publish-network-error": string;
|
|
59
64
|
|
|
60
65
|
// clone
|
|
61
66
|
"clone.success": string;
|
package/src/index.ts
CHANGED
package/src/registry.ts
CHANGED
|
@@ -40,6 +40,8 @@ export function listTemplateFiles(
|
|
|
40
40
|
return listFilesRecursive(dirPath, "");
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
+
const IGNORED_FILES = new Set([".DS_Store", "Thumbs.db", "desktop.ini"]);
|
|
44
|
+
|
|
43
45
|
function listFilesRecursive(basePath: string, relativePath: string): string[] {
|
|
44
46
|
const fullPath = relativePath
|
|
45
47
|
? path.join(basePath, relativePath)
|
|
@@ -48,6 +50,7 @@ function listFilesRecursive(basePath: string, relativePath: string): string[] {
|
|
|
48
50
|
const files: string[] = [];
|
|
49
51
|
|
|
50
52
|
for (const entry of entries) {
|
|
53
|
+
if (IGNORED_FILES.has(entry.name)) continue;
|
|
51
54
|
const entryRelative = relativePath
|
|
52
55
|
? path.join(relativePath, entry.name)
|
|
53
56
|
: entry.name;
|
package/src/template-engine.ts
CHANGED
|
@@ -62,12 +62,15 @@ export function extractVariables(template: string): string[] {
|
|
|
62
62
|
return [...vars];
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
+
const IGNORED_FILES = new Set([".DS_Store", "Thumbs.db", "desktop.ini"]);
|
|
66
|
+
|
|
65
67
|
export function extractVariablesFromDirectory(dirPath: string): string[] {
|
|
66
68
|
const allVars = new Set<string>();
|
|
67
69
|
|
|
68
70
|
function walkDir(currentPath: string): void {
|
|
69
71
|
const entries = fs.readdirSync(currentPath, { withFileTypes: true });
|
|
70
72
|
for (const entry of entries) {
|
|
73
|
+
if (IGNORED_FILES.has(entry.name)) continue;
|
|
71
74
|
const fullPath = path.join(currentPath, entry.name);
|
|
72
75
|
if (entry.isDirectory()) {
|
|
73
76
|
// ディレクトリ名からも変数を抽出
|