@yarn-tool/static-file 3.0.4 → 3.0.6
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/CHANGELOG.md +63 -0
- package/README.md +9 -4
- package/__root.d.ts +28 -0
- package/__root.js +28 -0
- package/__root.js.map +1 -1
- package/file/.gitignore +10 -0
- package/file/README.md +11 -1
- package/file/gitignore +15 -0
- package/file/jest.config.auto.js +81 -15
- package/file/jest.config.js +3 -1
- package/file/npmrc +2 -1
- package/file/nvmrc +1 -1
- package/file/pnpm-workspace.yaml +19 -0
- package/file/test/__root.ts +3 -0
- package/file/tsconfig.json +5 -0
- package/file/tsdx/tsconfig.json.tpl +7 -0
- package/file/ws-root/jest-preset.js +32 -3
- package/file/ws-root/jest.config.js +3 -2
- package/index.d.ts +25 -0
- package/index.js +25 -0
- package/index.js.map +1 -1
- package/lib/const.d.ts +57 -3
- package/lib/const.js +81 -8
- package/lib/const.js.map +1 -1
- package/lib/copyStaticFiles.d.ts +50 -0
- package/lib/copyStaticFiles.js +48 -0
- package/lib/copyStaticFiles.js.map +1 -1
- package/lib/copyStaticFilesEntry.d.ts +50 -0
- package/lib/copyStaticFilesEntry.js +48 -0
- package/lib/copyStaticFilesEntry.js.map +1 -1
- package/lib/getRowOfStaticFilesMapArray.d.ts +40 -0
- package/lib/getRowOfStaticFilesMapArray.js +32 -0
- package/lib/getRowOfStaticFilesMapArray.js.map +1 -1
- package/lib/getStaticFile.d.ts +42 -0
- package/lib/getStaticFile.js +34 -0
- package/lib/getStaticFile.js.map +1 -1
- package/lib/parseStaticMap.d.ts +39 -0
- package/lib/parseStaticMap.js +7 -0
- package/lib/parseStaticMap.js.map +1 -1
- package/lib/reMapStaticFilesMapArray.d.ts +39 -0
- package/lib/reMapStaticFilesMapArray.js +36 -0
- package/lib/reMapStaticFilesMapArray.js.map +1 -1
- package/lib/replaceTargetOfStaticFilesMapArrayEntry.d.ts +33 -0
- package/lib/replaceTargetOfStaticFilesMapArrayEntry.js +25 -0
- package/lib/replaceTargetOfStaticFilesMapArrayEntry.js.map +1 -1
- package/lib/root/getRootCopyStaticFiles.d.ts +54 -0
- package/lib/root/getRootCopyStaticFiles.js +47 -0
- package/lib/root/getRootCopyStaticFiles.js.map +1 -1
- package/lib/types.d.ts +73 -0
- package/lib/types.js.map +1 -1
- package/lib/ws/wsCopyStaticFiles.d.ts +50 -0
- package/lib/ws/wsCopyStaticFiles.js +50 -0
- package/lib/ws/wsCopyStaticFiles.js.map +1 -1
- package/package.json +4 -4
- package/file/github/workflows/linter.yml +0 -57
- package/file/node-version +0 -1
- package/file/tsdx/index.cjs +0 -5
- package/file/tsdx/index.cjs.map +0 -1
- package/file/tsdx/index.d.cts +0 -2
- package/file/ws-root/__root_ws.d.ts +0 -2
- package/file/ws-root/__root_ws.js +0 -7
- package/file/ws-root/__root_ws.js.map +0 -1
- /package/file/{browserslistrc → ws-root/browserslistrc} +0 -0
package/lib/const.d.ts
CHANGED
|
@@ -1,8 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Static file mapping constants / 靜態檔案映射常量
|
|
3
|
+
*
|
|
4
|
+
* This module defines the default static file mappings for different project scenarios.
|
|
5
|
+
* 此模組定義了不同專案情境的預設靜態檔案映射。
|
|
6
|
+
*
|
|
7
|
+
* @module const
|
|
8
|
+
*/
|
|
1
9
|
import { _Key, IStaticFilesMapArray } from './types';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Default static files for package-level copying / 套件層級複製的預設靜態檔案
|
|
12
|
+
*
|
|
13
|
+
* Contains common configuration files that should be copied to each package.
|
|
14
|
+
* 包含應複製到每個套件的常用配置檔案。
|
|
15
|
+
*
|
|
16
|
+
* Each entry follows the format: [targetFile, staticFile, detectFile?]
|
|
17
|
+
* 每個條目遵循格式:[目標檔案, 靜態檔案, 檢測檔案?]
|
|
18
|
+
*
|
|
19
|
+
* - targetFile: The destination file path / 目標檔案路徑
|
|
20
|
+
* - staticFile: The source static file path (relative to static root) / 來源靜態檔案路徑(相對於靜態根目錄)
|
|
21
|
+
* - detectFile: Optional file to check for existence before copying / 可選的檢測檔案,複製前檢查是否存在
|
|
22
|
+
*/
|
|
23
|
+
declare const _defaultCopyStaticFiles: [[".npmignore", "file/npmignore"], [".gitignore", "file/gitignore"], [".eslintignore", "file/eslintignore"], ["tsconfig.json.tpl", "file/tsconfig.json.tpl", "tsconfig.json"], ["test/tsconfig.json.tpl", "file/test/tsconfig.json.tpl", "test/tsconfig.json"], ["test/tsconfig.json", "file/test/tsconfig.json.tpl"], ["tsconfig.esm.json.tpl", "file/tsconfig.esm.json.tpl", "tsconfig.esm.json"], ["tsconfig.tsdx.json.tpl", "file/tsconfig.tsdx.json.tpl", "tsconfig.tsdx.json"], ["tsconfig.json", "file/tsconfig.json.tpl"], [".eslintrc.json.tpl", "file/eslintrc.json.tpl", ".eslintrc.json"], ["README.md", "file/README.md"], [".mocharc.yml.tpl", "file/mocharc.yml"], ["jest.config.js", "file/jest.config.auto.js"], [".nowignore", "file/nowignore"], ["now.json.tpl", "file/now.json.tpl", "now.json"], ["tsdx.config.js.tpl", "file/tsdx.config.js", "tsdx.config.js"], ["test/__root.ts", "file/test/__root.ts"], ["test/fixtures/.gitkeep", "file/test/fixtures/.gitkeep"], ...["test/temp.ts", "file/test/temp.ts"][]];
|
|
24
|
+
/**
|
|
25
|
+
* Default static files for root-level only copying / 僅根目錄層級複製的預設靜態檔案
|
|
26
|
+
*
|
|
27
|
+
* Contains configuration files that should only be copied to the workspace root.
|
|
28
|
+
* 包含僅應複製到工作區根目錄的配置檔案。
|
|
29
|
+
*
|
|
30
|
+
* These files are typically shared across all packages in a monorepo.
|
|
31
|
+
* 這些檔案通常在 monorepo 中的所有套件之間共享。
|
|
32
|
+
*/
|
|
33
|
+
declare const _defaultCopyStaticFilesRootOnly: [["lerna.json.tpl", "file/lerna.json.tpl", "lerna.json"], ["pnpm-workspace.yaml.tpl", "file/pnpm-workspace.yaml", "pnpm-workspace.yaml"], [".github/workflows/coverage.yml", "file/github/workflows/coverage.yml"], [".github/workflows/action-yarnlock-dedupe.yml", "file/github/workflows/action-yarnlock-dedupe.yml"], [".github/workflows/build.yml", "file/github/workflows/build.yml"], [".github/workflows/yarn-lock-changes.yml", "file/github/workflows/yarn-lock-changes.yml"], [".github/commit-convention.md", "file/github/commit-convention.md"], ...[".github/dependabot.yml" | ".github/workflows/codeql-analysis.yml" | ".github/workflows/cmd-rebase.yml", "file/github/dependabot.yml" | "file/github/workflows/codeql-analysis.yml" | "file/github/workflows/cmd-rebase.yml"][], [".node-version", "file/nvmrc"], [".nvmrc", "file/nvmrc"], [".eslintrc.json", "file/eslintrc.json.tpl", ".eslintrc.json"], [".yarnrc.yml.tpl", "file/root/yarnrc.yml", ".yarnrc.yml"], [".npmrc.tpl", "file/npmrc", ".npmrc"], ["jest.config.js", "file/jest.config.js"], ["jest.config.js.tpl", "file/jest.config.js"], ["jest.config.auto.js.tpl", "file/jest.config.auto.js"], [".editorconfig.tpl", "file/tpl.editorconfig"], [".editorconfig", "file/tpl.editorconfig"], ["global.tsdx.d.ts", "file/root/global.tsdx.d.ts"], [".browserslistrc", "file/ws-root/browserslistrc"], ["tsc-multi.json.tpl", "file/tsc-multi.json.tpl", "tsc-multi.json"], [".nycrc.tpl", "file/nycrc"]];
|
|
34
|
+
/**
|
|
35
|
+
* Default static files for workspace root only / 僅工作區根目錄的預設靜態檔案
|
|
36
|
+
*
|
|
37
|
+
* Contains files specific to workspace root management.
|
|
38
|
+
* 包含特定於工作區根目錄管理的檔案。
|
|
39
|
+
*/
|
|
40
|
+
declare const _defaultCopyStaticFilesWsRootOnly: [["lerna.json.tpl", "file/lerna.json.tpl"], ["pnpm-workspace.yaml", "file/pnpm-workspace.yaml"], ["tsc-multi.json.tpl", "file/tsc-multi.json.tpl", "tsc-multi.json"], ["__root_ws.ts", "file/ws-root/__root_ws.ts"], ["jest.config.js", "file/ws-root/jest.config.js"], ["jest-preset.js", "file/ws-root/jest-preset.js"], [".run/lerna_publish_yes.run.xml", "file/ws-root/.run/lerna_publish_yes.run.xml"]];
|
|
41
|
+
/**
|
|
42
|
+
* Frozen default static files for package-level / 凍結的套件層級預設靜態檔案
|
|
43
|
+
*
|
|
44
|
+
* Use this for copying static files to individual packages.
|
|
45
|
+
* 用於將靜態檔案複製到各個套件。
|
|
46
|
+
*/
|
|
5
47
|
export declare const defaultCopyStaticFiles: IStaticFilesMapArray<_Key<typeof _defaultCopyStaticFiles>>;
|
|
48
|
+
/**
|
|
49
|
+
* Frozen default static files for root-level only / 凍結的僅根目錄層級預設靜態檔案
|
|
50
|
+
*
|
|
51
|
+
* Use this for copying static files to the workspace root only.
|
|
52
|
+
* 用於將靜態檔案僅複製到工作區根目錄。
|
|
53
|
+
*/
|
|
6
54
|
export declare const defaultCopyStaticFilesRootOnly: IStaticFilesMapArray<_Key<typeof _defaultCopyStaticFilesRootOnly>>;
|
|
55
|
+
/**
|
|
56
|
+
* Frozen default static files for workspace root / 凍結的工作區根目錄預設靜態檔案
|
|
57
|
+
*
|
|
58
|
+
* Use this for workspace root specific file management.
|
|
59
|
+
* 用於工作區根目錄特定的檔案管理。
|
|
60
|
+
*/
|
|
7
61
|
export declare const defaultCopyStaticFilesWsRootOnly: IStaticFilesMapArray<_Key<typeof _defaultCopyStaticFilesWsRootOnly>>;
|
|
8
62
|
export {};
|
package/lib/const.js
CHANGED
|
@@ -1,29 +1,48 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.defaultCopyStaticFilesWsRootOnly = exports.defaultCopyStaticFilesRootOnly = exports.defaultCopyStaticFiles = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Default static files for package-level copying / 套件層級複製的預設靜態檔案
|
|
6
|
+
*
|
|
7
|
+
* Contains common configuration files that should be copied to each package.
|
|
8
|
+
* 包含應複製到每個套件的常用配置檔案。
|
|
9
|
+
*
|
|
10
|
+
* Each entry follows the format: [targetFile, staticFile, detectFile?]
|
|
11
|
+
* 每個條目遵循格式:[目標檔案, 靜態檔案, 檢測檔案?]
|
|
12
|
+
*
|
|
13
|
+
* - targetFile: The destination file path / 目標檔案路徑
|
|
14
|
+
* - staticFile: The source static file path (relative to static root) / 來源靜態檔案路徑(相對於靜態根目錄)
|
|
15
|
+
* - detectFile: Optional file to check for existence before copying / 可選的檢測檔案,複製前檢查是否存在
|
|
16
|
+
*/
|
|
4
17
|
const _defaultCopyStaticFiles = [
|
|
18
|
+
// Ignore files / 忽略檔案
|
|
5
19
|
['.npmignore', 'file/npmignore'],
|
|
6
20
|
['.gitignore', 'file/gitignore'],
|
|
7
21
|
['.eslintignore', 'file/eslintignore'],
|
|
8
|
-
|
|
9
|
-
['.browserslistrc', 'file/browserslistrc'],
|
|
22
|
+
// TypeScript configuration / TypeScript 配置
|
|
10
23
|
['tsconfig.json.tpl', 'file/tsconfig.json.tpl', 'tsconfig.json'],
|
|
11
24
|
['test/tsconfig.json.tpl', 'file/test/tsconfig.json.tpl', 'test/tsconfig.json'],
|
|
25
|
+
['test/tsconfig.json', 'file/test/tsconfig.json.tpl'],
|
|
12
26
|
['tsconfig.esm.json.tpl', 'file/tsconfig.esm.json.tpl', 'tsconfig.esm.json'],
|
|
13
27
|
['tsconfig.tsdx.json.tpl', 'file/tsconfig.tsdx.json.tpl', 'tsconfig.tsdx.json'],
|
|
28
|
+
['tsconfig.json', 'file/tsconfig.json.tpl'],
|
|
29
|
+
// ESLint configuration / ESLint 配置
|
|
14
30
|
['.eslintrc.json.tpl', 'file/eslintrc.json.tpl', '.eslintrc.json'],
|
|
31
|
+
// Documentation / 文檔
|
|
15
32
|
['README.md', 'file/README.md'],
|
|
16
|
-
|
|
33
|
+
// Test configuration / 測試配置
|
|
17
34
|
['.mocharc.yml.tpl', 'file/mocharc.yml'],
|
|
18
35
|
//['jest.config.js', 'file/jest.config.js'],
|
|
19
36
|
['jest.config.js', 'file/jest.config.auto.js'],
|
|
37
|
+
// Now/Zeit deployment / Now/Zeit 部署配置
|
|
20
38
|
['.nowignore', 'file/nowignore'],
|
|
21
39
|
['now.json.tpl', 'file/now.json.tpl', 'now.json'],
|
|
22
|
-
|
|
40
|
+
// TSDX configuration / TSDX 配置
|
|
23
41
|
['tsdx.config.js.tpl', 'file/tsdx.config.js', 'tsdx.config.js'],
|
|
24
|
-
|
|
42
|
+
// Test fixtures / 測試固定檔案
|
|
25
43
|
['test/__root.ts', 'file/test/__root.ts'],
|
|
26
44
|
['test/fixtures/.gitkeep', 'file/test/fixtures/.gitkeep'],
|
|
45
|
+
// Temporary test files / 臨時測試檔案
|
|
27
46
|
...([
|
|
28
47
|
'temp.ts',
|
|
29
48
|
].map(file => [
|
|
@@ -32,42 +51,96 @@ const _defaultCopyStaticFiles = [
|
|
|
32
51
|
])),
|
|
33
52
|
//['changelog-option.js.tpl', 'file/changelog-option.js', 'changelog-option.js'],
|
|
34
53
|
];
|
|
54
|
+
/**
|
|
55
|
+
* Default static files for root-level only copying / 僅根目錄層級複製的預設靜態檔案
|
|
56
|
+
*
|
|
57
|
+
* Contains configuration files that should only be copied to the workspace root.
|
|
58
|
+
* 包含僅應複製到工作區根目錄的配置檔案。
|
|
59
|
+
*
|
|
60
|
+
* These files are typically shared across all packages in a monorepo.
|
|
61
|
+
* 這些檔案通常在 monorepo 中的所有套件之間共享。
|
|
62
|
+
*/
|
|
35
63
|
const _defaultCopyStaticFilesRootOnly = [
|
|
64
|
+
// Monorepo configuration / Monorepo 配置
|
|
36
65
|
['lerna.json.tpl', 'file/lerna.json.tpl', 'lerna.json'],
|
|
37
66
|
['pnpm-workspace.yaml.tpl', 'file/pnpm-workspace.yaml', 'pnpm-workspace.yaml'],
|
|
67
|
+
// GitHub Actions workflows / GitHub Actions 工作流程
|
|
38
68
|
['.github/workflows/coverage.yml', 'file/github/workflows/coverage.yml'],
|
|
39
69
|
['.github/workflows/action-yarnlock-dedupe.yml', 'file/github/workflows/action-yarnlock-dedupe.yml'],
|
|
40
70
|
['.github/workflows/build.yml', 'file/github/workflows/build.yml'],
|
|
41
71
|
['.github/workflows/yarn-lock-changes.yml', 'file/github/workflows/yarn-lock-changes.yml'],
|
|
42
72
|
['.github/commit-convention.md', 'file/github/commit-convention.md'],
|
|
73
|
+
// Additional GitHub configuration / 額外的 GitHub 配置
|
|
43
74
|
...([
|
|
44
75
|
'dependabot.yml',
|
|
45
76
|
'workflows/codeql-analysis.yml',
|
|
46
77
|
'workflows/cmd-rebase.yml',
|
|
47
78
|
].map(file => [`.github/${file}`, `file/github/${file}`])),
|
|
48
|
-
|
|
49
|
-
['
|
|
79
|
+
// Node version files / Node 版本檔案
|
|
80
|
+
['.node-version', 'file/nvmrc'],
|
|
81
|
+
['.nvmrc', 'file/nvmrc'],
|
|
82
|
+
// Root TypeScript configuration / 根目錄 TypeScript 配置
|
|
50
83
|
['.eslintrc.json', 'file/eslintrc.json.tpl', '.eslintrc.json'],
|
|
51
84
|
//['changelog-option.js', 'file/changelog-option.js', 'changelog-option.js.tpl'],
|
|
85
|
+
// Package manager configuration / 套件管理器配置
|
|
52
86
|
['.yarnrc.yml.tpl', 'file/root/yarnrc.yml', '.yarnrc.yml'],
|
|
87
|
+
['.npmrc.tpl', 'file/npmrc', '.npmrc'],
|
|
88
|
+
// Jest configuration / Jest 配置
|
|
53
89
|
['jest.config.js', 'file/jest.config.js'],
|
|
54
90
|
['jest.config.js.tpl', 'file/jest.config.js'],
|
|
55
91
|
['jest.config.auto.js.tpl', 'file/jest.config.auto.js'],
|
|
92
|
+
// Editor configuration / 編輯器配置
|
|
56
93
|
['.editorconfig.tpl', 'file/tpl.editorconfig'],
|
|
57
94
|
['.editorconfig', 'file/tpl.editorconfig'],
|
|
95
|
+
// Global type declarations / 全局類型聲明
|
|
58
96
|
['global.tsdx.d.ts', 'file/root/global.tsdx.d.ts'],
|
|
97
|
+
// Browserslist configuration / Browserslist 配置
|
|
98
|
+
['.browserslistrc', 'file/ws-root/browserslistrc'],
|
|
99
|
+
// TSC multi configuration / TSC 多配置
|
|
100
|
+
['tsc-multi.json.tpl', 'file/tsc-multi.json.tpl', 'tsc-multi.json'],
|
|
101
|
+
// NYC coverage configuration / NYC 覆蓋率配置
|
|
102
|
+
['.nycrc.tpl', 'file/nycrc'],
|
|
59
103
|
];
|
|
104
|
+
/**
|
|
105
|
+
* Default static files for workspace root only / 僅工作區根目錄的預設靜態檔案
|
|
106
|
+
*
|
|
107
|
+
* Contains files specific to workspace root management.
|
|
108
|
+
* 包含特定於工作區根目錄管理的檔案。
|
|
109
|
+
*/
|
|
60
110
|
const _defaultCopyStaticFilesWsRootOnly = [
|
|
111
|
+
// Lerna configuration / Lerna 配置
|
|
61
112
|
['lerna.json.tpl', 'file/lerna.json.tpl'],
|
|
113
|
+
// pnpm workspace configuration / pnpm 工作區配置
|
|
62
114
|
['pnpm-workspace.yaml', 'file/pnpm-workspace.yaml'],
|
|
63
|
-
|
|
115
|
+
// TSC multi configuration / TSC 多配置
|
|
64
116
|
['tsc-multi.json.tpl', 'file/tsc-multi.json.tpl', 'tsc-multi.json'],
|
|
117
|
+
// Workspace root file / 工作區根目錄檔案
|
|
65
118
|
['__root_ws.ts', 'file/ws-root/__root_ws.ts'],
|
|
119
|
+
// Jest configuration / Jest 配置
|
|
66
120
|
['jest.config.js', 'file/ws-root/jest.config.js'],
|
|
67
121
|
['jest-preset.js', 'file/ws-root/jest-preset.js'],
|
|
122
|
+
// Run configurations / 執行配置
|
|
68
123
|
['.run/lerna_publish_yes.run.xml', 'file/ws-root/.run/lerna_publish_yes.run.xml'],
|
|
69
124
|
];
|
|
125
|
+
/**
|
|
126
|
+
* Frozen default static files for package-level / 凍結的套件層級預設靜態檔案
|
|
127
|
+
*
|
|
128
|
+
* Use this for copying static files to individual packages.
|
|
129
|
+
* 用於將靜態檔案複製到各個套件。
|
|
130
|
+
*/
|
|
70
131
|
exports.defaultCopyStaticFiles = Object.freeze(_defaultCopyStaticFiles);
|
|
132
|
+
/**
|
|
133
|
+
* Frozen default static files for root-level only / 凍結的僅根目錄層級預設靜態檔案
|
|
134
|
+
*
|
|
135
|
+
* Use this for copying static files to the workspace root only.
|
|
136
|
+
* 用於將靜態檔案僅複製到工作區根目錄。
|
|
137
|
+
*/
|
|
71
138
|
exports.defaultCopyStaticFilesRootOnly = Object.freeze(_defaultCopyStaticFilesRootOnly);
|
|
139
|
+
/**
|
|
140
|
+
* Frozen default static files for workspace root / 凍結的工作區根目錄預設靜態檔案
|
|
141
|
+
*
|
|
142
|
+
* Use this for workspace root specific file management.
|
|
143
|
+
* 用於工作區根目錄特定的檔案管理。
|
|
144
|
+
*/
|
|
72
145
|
exports.defaultCopyStaticFilesWsRootOnly = Object.freeze(_defaultCopyStaticFilesWsRootOnly);
|
|
73
146
|
//# sourceMappingURL=const.js.map
|
package/lib/const.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"const.js","sourceRoot":"","sources":["const.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"const.js","sourceRoot":"","sources":["const.ts"],"names":[],"mappings":"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","sourcesContent":["/**\n * Static file mapping constants / 靜態檔案映射常量\n *\n * This module defines the default static file mappings for different project scenarios.\n * 此模組定義了不同專案情境的預設靜態檔案映射。\n *\n * @module const\n */\nimport { _Key, IStaticFilesKey, IStaticFilesMapArray, IStaticFilesMapArrayEntry } from './types';\n\n/**\n * Default static files for package-level copying / 套件層級複製的預設靜態檔案\n *\n * Contains common configuration files that should be copied to each package.\n * 包含應複製到每個套件的常用配置檔案。\n *\n * Each entry follows the format: [targetFile, staticFile, detectFile?]\n * 每個條目遵循格式:[目標檔案, 靜態檔案, 檢測檔案?]\n *\n * - targetFile: The destination file path / 目標檔案路徑\n * - staticFile: The source static file path (relative to static root) / 來源靜態檔案路徑(相對於靜態根目錄)\n * - detectFile: Optional file to check for existence before copying / 可選的檢測檔案,複製前檢查是否存在\n */\nconst _defaultCopyStaticFiles = [\n\n\t// Ignore files / 忽略檔案\n\t['.npmignore', 'file/npmignore'],\n\t['.gitignore', 'file/gitignore'],\n\t['.eslintignore', 'file/eslintignore'],\n\n\t// TypeScript configuration / TypeScript 配置\n\t['tsconfig.json.tpl', 'file/tsconfig.json.tpl', 'tsconfig.json'],\n\n\t['test/tsconfig.json.tpl', 'file/test/tsconfig.json.tpl', 'test/tsconfig.json'],\n\t['test/tsconfig.json', 'file/test/tsconfig.json.tpl'],\n\n\t['tsconfig.esm.json.tpl', 'file/tsconfig.esm.json.tpl', 'tsconfig.esm.json'],\n\t['tsconfig.tsdx.json.tpl', 'file/tsconfig.tsdx.json.tpl', 'tsconfig.tsdx.json'],\n\n\t['tsconfig.json', 'file/tsconfig.json.tpl'],\n\n\t// ESLint configuration / ESLint 配置\n\t['.eslintrc.json.tpl', 'file/eslintrc.json.tpl', '.eslintrc.json'],\n\n\t// Documentation / 文檔\n\t['README.md', 'file/README.md'],\n\n\t// Test configuration / 測試配置\n\t['.mocharc.yml.tpl', 'file/mocharc.yml'],\n\t//['jest.config.js', 'file/jest.config.js'],\n\t['jest.config.js', 'file/jest.config.auto.js'],\n\n\t// Now/Zeit deployment / Now/Zeit 部署配置\n\t['.nowignore', 'file/nowignore'],\n\t['now.json.tpl', 'file/now.json.tpl', 'now.json'],\n\n\t// TSDX configuration / TSDX 配置\n\t['tsdx.config.js.tpl', 'file/tsdx.config.js', 'tsdx.config.js'],\n\n\t// Test fixtures / 測試固定檔案\n\t['test/__root.ts', 'file/test/__root.ts'],\n\t['test/fixtures/.gitkeep', 'file/test/fixtures/.gitkeep'],\n\n\t// Temporary test files / 臨時測試檔案\n\t...(([\n\t\t'temp.ts',\n\t] as const).map(file => [\n\t\t`test/${file}`,\n\t\t`file/test/${file}`\n\t] as const satisfies IStaticFilesMapArrayEntry<string>)),\n\n\t//['changelog-option.js.tpl', 'file/changelog-option.js', 'changelog-option.js'],\n\n] as const satisfies IStaticFilesMapArray<string>;\n\n/**\n * Default static files for root-level only copying / 僅根目錄層級複製的預設靜態檔案\n *\n * Contains configuration files that should only be copied to the workspace root.\n * 包含僅應複製到工作區根目錄的配置檔案。\n *\n * These files are typically shared across all packages in a monorepo.\n * 這些檔案通常在 monorepo 中的所有套件之間共享。\n */\nconst _defaultCopyStaticFilesRootOnly = [\n\n\t// Monorepo configuration / Monorepo 配置\n\t['lerna.json.tpl', 'file/lerna.json.tpl', 'lerna.json'],\n\t['pnpm-workspace.yaml.tpl', 'file/pnpm-workspace.yaml', 'pnpm-workspace.yaml'],\n\n\t// GitHub Actions workflows / GitHub Actions 工作流程\n\t['.github/workflows/coverage.yml', 'file/github/workflows/coverage.yml'],\n\t['.github/workflows/action-yarnlock-dedupe.yml', 'file/github/workflows/action-yarnlock-dedupe.yml'],\n\t['.github/workflows/build.yml', 'file/github/workflows/build.yml'],\n\t['.github/workflows/yarn-lock-changes.yml', 'file/github/workflows/yarn-lock-changes.yml'],\n\t['.github/commit-convention.md', 'file/github/commit-convention.md'],\n\n\t// Additional GitHub configuration / 額外的 GitHub 配置\n\t...(([\n\t\t'dependabot.yml',\n\t\t'workflows/codeql-analysis.yml',\n\t\t'workflows/cmd-rebase.yml',\n\t] as const).map(file => [`.github/${file}`, `file/github/${file}`] as const satisfies IStaticFilesMapArrayEntry<string>)),\n\n\t// Node version files / Node 版本檔案\n\t['.node-version', 'file/nvmrc'],\n\t['.nvmrc', 'file/nvmrc'],\n\n\t// Root TypeScript configuration / 根目錄 TypeScript 配置\n\t['.eslintrc.json', 'file/eslintrc.json.tpl', '.eslintrc.json'],\n\n\t//['changelog-option.js', 'file/changelog-option.js', 'changelog-option.js.tpl'],\n\n\t// Package manager configuration / 套件管理器配置\n\t['.yarnrc.yml.tpl', 'file/root/yarnrc.yml', '.yarnrc.yml'],\n\t['.npmrc.tpl', 'file/npmrc', '.npmrc'],\n\n\t// Jest configuration / Jest 配置\n\t['jest.config.js', 'file/jest.config.js'],\n\t['jest.config.js.tpl', 'file/jest.config.js'],\n\t['jest.config.auto.js.tpl', 'file/jest.config.auto.js'],\n\n\t// Editor configuration / 編輯器配置\n\t['.editorconfig.tpl', 'file/tpl.editorconfig'],\n\t['.editorconfig', 'file/tpl.editorconfig'],\n\n\t// Global type declarations / 全局類型聲明\n\t['global.tsdx.d.ts', 'file/root/global.tsdx.d.ts'],\n\n\t// Browserslist configuration / Browserslist 配置\n\t['.browserslistrc', 'file/ws-root/browserslistrc'],\n\n\t// TSC multi configuration / TSC 多配置\n\t['tsc-multi.json.tpl', 'file/tsc-multi.json.tpl', 'tsc-multi.json'],\n\n\t// NYC coverage configuration / NYC 覆蓋率配置\n\t['.nycrc.tpl', 'file/nycrc'],\n\n] as const satisfies IStaticFilesMapArray<string>;\n\n/**\n * Default static files for workspace root only / 僅工作區根目錄的預設靜態檔案\n *\n * Contains files specific to workspace root management.\n * 包含特定於工作區根目錄管理的檔案。\n */\nconst _defaultCopyStaticFilesWsRootOnly = [\n\n\t// Lerna configuration / Lerna 配置\n\t['lerna.json.tpl', 'file/lerna.json.tpl'],\n\n\t// pnpm workspace configuration / pnpm 工作區配置\n\t['pnpm-workspace.yaml', 'file/pnpm-workspace.yaml'],\n\n\t// TSC multi configuration / TSC 多配置\n\t['tsc-multi.json.tpl', 'file/tsc-multi.json.tpl', 'tsc-multi.json'],\n\n\t// Workspace root file / 工作區根目錄檔案\n\t['__root_ws.ts', 'file/ws-root/__root_ws.ts'],\n\n\t// Jest configuration / Jest 配置\n\t['jest.config.js', 'file/ws-root/jest.config.js'],\n\t['jest-preset.js', 'file/ws-root/jest-preset.js'],\n\n\t// Run configurations / 執行配置\n\t['.run/lerna_publish_yes.run.xml', 'file/ws-root/.run/lerna_publish_yes.run.xml'],\n\n] as const satisfies IStaticFilesMapArray<string>;\n\n/**\n * Frozen default static files for package-level / 凍結的套件層級預設靜態檔案\n *\n * Use this for copying static files to individual packages.\n * 用於將靜態檔案複製到各個套件。\n */\nexport const defaultCopyStaticFiles = Object.freeze(_defaultCopyStaticFiles) as any as IStaticFilesMapArray<_Key<typeof _defaultCopyStaticFiles>>;\n\n/**\n * Frozen default static files for root-level only / 凍結的僅根目錄層級預設靜態檔案\n *\n * Use this for copying static files to the workspace root only.\n * 用於將靜態檔案僅複製到工作區根目錄。\n */\nexport const defaultCopyStaticFilesRootOnly = Object.freeze(_defaultCopyStaticFilesRootOnly) as any as IStaticFilesMapArray<_Key<typeof _defaultCopyStaticFilesRootOnly>>;\n\n/**\n * Frozen default static files for workspace root / 凍結的工作區根目錄預設靜態檔案\n *\n * Use this for workspace root specific file management.\n * 用於工作區根目錄特定的檔案管理。\n */\nexport const defaultCopyStaticFilesWsRootOnly = Object.freeze(_defaultCopyStaticFilesWsRootOnly) as any as IStaticFilesMapArray<_Key<typeof _defaultCopyStaticFilesWsRootOnly>>;\n"]}
|
package/lib/copyStaticFiles.d.ts
CHANGED
|
@@ -1,2 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copy static files main function / 複製靜態檔案主函數
|
|
3
|
+
*
|
|
4
|
+
* This module provides the main function for copying static files to a target directory.
|
|
5
|
+
* 此模組提供將靜態檔案複製到目標目錄的主函數。
|
|
6
|
+
*
|
|
7
|
+
* @module copyStaticFiles
|
|
8
|
+
*/
|
|
1
9
|
import { ICopyStaticFilesOptions, IStaticFilesMapArrayEntry } from './types';
|
|
10
|
+
/**
|
|
11
|
+
* Copy static files to a target directory / 將靜態檔案複製到目標目錄
|
|
12
|
+
*
|
|
13
|
+
* Copies static files based on the provided file map configuration.
|
|
14
|
+
* 根據提供的檔案映射配置複製靜態檔案。
|
|
15
|
+
*
|
|
16
|
+
* @template K - The target file path type / 目標檔案路徑類型
|
|
17
|
+
*
|
|
18
|
+
* @param options - Copy options / 複製選項
|
|
19
|
+
* @param options.cwd - Current working directory (required) / 當前工作目錄(必填)
|
|
20
|
+
* @param options.staticRoot - Root directory of static files (defaults to package root) / 靜態檔案根目錄(預設為套件根目錄)
|
|
21
|
+
* @param options.overwrite - Whether to overwrite existing files / 是否覆蓋已存在的檔案
|
|
22
|
+
* @param options.file_map - Custom file mapping configuration / 自訂檔案映射配置
|
|
23
|
+
*
|
|
24
|
+
* @returns Array of entries that were successfully copied / 成功複製的條目陣列
|
|
25
|
+
*
|
|
26
|
+
* @throws {TypeError} When options.cwd is not a valid string / 當 options.cwd 不是有效的字串時
|
|
27
|
+
* @throws {TypeError} When options.cwd directory does not exist / 當 options.cwd 目錄不存在時
|
|
28
|
+
* @throws {TypeError} When file_map is invalid / 當 file_map 無效時
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* import { copyStaticFiles } from '@yarn-tool/static-file';
|
|
33
|
+
*
|
|
34
|
+
* // Copy default static files to current directory
|
|
35
|
+
* // 複製預設靜態檔案到當前目錄
|
|
36
|
+
* copyStaticFiles({
|
|
37
|
+
* cwd: process.cwd(),
|
|
38
|
+
* overwrite: true
|
|
39
|
+
* });
|
|
40
|
+
*
|
|
41
|
+
* // Copy with custom file map
|
|
42
|
+
* // 使用自訂檔案映射複製
|
|
43
|
+
* copyStaticFiles({
|
|
44
|
+
* cwd: '/path/to/project',
|
|
45
|
+
* file_map: [
|
|
46
|
+
* ['.gitignore', 'file/gitignore'],
|
|
47
|
+
* ['README.md', 'file/README.md']
|
|
48
|
+
* ]
|
|
49
|
+
* });
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
2
52
|
export declare function copyStaticFiles<K extends string>(options: ICopyStaticFilesOptions<K>): IStaticFilesMapArrayEntry<string | K>[];
|
package/lib/copyStaticFiles.js
CHANGED
|
@@ -6,20 +6,68 @@ const const_1 = require("./const");
|
|
|
6
6
|
const parseStaticMap_1 = require("./parseStaticMap");
|
|
7
7
|
const copyStaticFilesEntry_1 = require("./copyStaticFilesEntry");
|
|
8
8
|
const __root_1 = require("../__root");
|
|
9
|
+
/**
|
|
10
|
+
* Copy static files to a target directory / 將靜態檔案複製到目標目錄
|
|
11
|
+
*
|
|
12
|
+
* Copies static files based on the provided file map configuration.
|
|
13
|
+
* 根據提供的檔案映射配置複製靜態檔案。
|
|
14
|
+
*
|
|
15
|
+
* @template K - The target file path type / 目標檔案路徑類型
|
|
16
|
+
*
|
|
17
|
+
* @param options - Copy options / 複製選項
|
|
18
|
+
* @param options.cwd - Current working directory (required) / 當前工作目錄(必填)
|
|
19
|
+
* @param options.staticRoot - Root directory of static files (defaults to package root) / 靜態檔案根目錄(預設為套件根目錄)
|
|
20
|
+
* @param options.overwrite - Whether to overwrite existing files / 是否覆蓋已存在的檔案
|
|
21
|
+
* @param options.file_map - Custom file mapping configuration / 自訂檔案映射配置
|
|
22
|
+
*
|
|
23
|
+
* @returns Array of entries that were successfully copied / 成功複製的條目陣列
|
|
24
|
+
*
|
|
25
|
+
* @throws {TypeError} When options.cwd is not a valid string / 當 options.cwd 不是有效的字串時
|
|
26
|
+
* @throws {TypeError} When options.cwd directory does not exist / 當 options.cwd 目錄不存在時
|
|
27
|
+
* @throws {TypeError} When file_map is invalid / 當 file_map 無效時
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* import { copyStaticFiles } from '@yarn-tool/static-file';
|
|
32
|
+
*
|
|
33
|
+
* // Copy default static files to current directory
|
|
34
|
+
* // 複製預設靜態檔案到當前目錄
|
|
35
|
+
* copyStaticFiles({
|
|
36
|
+
* cwd: process.cwd(),
|
|
37
|
+
* overwrite: true
|
|
38
|
+
* });
|
|
39
|
+
*
|
|
40
|
+
* // Copy with custom file map
|
|
41
|
+
* // 使用自訂檔案映射複製
|
|
42
|
+
* copyStaticFiles({
|
|
43
|
+
* cwd: '/path/to/project',
|
|
44
|
+
* file_map: [
|
|
45
|
+
* ['.gitignore', 'file/gitignore'],
|
|
46
|
+
* ['README.md', 'file/README.md']
|
|
47
|
+
* ]
|
|
48
|
+
* });
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
9
51
|
function copyStaticFiles(options) {
|
|
10
52
|
var _a, _b;
|
|
53
|
+
// Validate cwd parameter / 驗證 cwd 參數
|
|
11
54
|
if (typeof options.cwd !== 'string' || !((_a = options.cwd) === null || _a === void 0 ? void 0 : _a.length) || !options.cwd) {
|
|
12
55
|
throw new TypeError(`options.cwd must is string`);
|
|
13
56
|
}
|
|
57
|
+
// Check if cwd directory exists / 檢查 cwd 目錄是否存在
|
|
14
58
|
if (!(0, fs_extra_1.pathExistsSync)(options.cwd)) {
|
|
15
59
|
throw new TypeError(`options.cwd not exists`);
|
|
16
60
|
}
|
|
61
|
+
// Parse the file map / 解析檔案映射
|
|
17
62
|
let ls = (0, parseStaticMap_1.parseStaticMap)((_b = options.file_map) !== null && _b !== void 0 ? _b : const_1.defaultCopyStaticFiles);
|
|
63
|
+
// Validate parsed file map / 驗證解析後的檔案映射
|
|
18
64
|
if (!ls.length) {
|
|
19
65
|
throw new TypeError(`Invalid file map: ${options.file_map}`);
|
|
20
66
|
}
|
|
67
|
+
// Determine static root directory / 確定靜態檔案根目錄
|
|
21
68
|
const staticRoot = options.staticRoot || __root_1.__STATIC_ROOT;
|
|
22
69
|
const { cwd, overwrite } = options;
|
|
70
|
+
// Filter and copy files / 過濾並複製檔案
|
|
23
71
|
return ls.filter((entry) => {
|
|
24
72
|
return (0, copyStaticFilesEntry_1.copyStaticFilesEntry)(entry, cwd, staticRoot, overwrite);
|
|
25
73
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"copyStaticFiles.js","sourceRoot":"","sources":["copyStaticFiles.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"copyStaticFiles.js","sourceRoot":"","sources":["copyStaticFiles.ts"],"names":[],"mappings":";;AA0DA,0CAiCC;AAlFD,uCAAgG;AAEhG,mCAAiD;AACjD,qDAAkD;AAClD,iEAA8D;AAC9D,sCAA0C;AAE1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,SAAgB,eAAe,CAAmB,OAAmC;;IAEpF,qCAAqC;IACrC,IAAI,OAAO,OAAO,CAAC,GAAG,KAAK,QAAQ,IAAI,CAAC,CAAA,MAAA,OAAO,CAAC,GAAG,0CAAE,MAAM,CAAA,IAAI,CAAC,OAAO,CAAC,GAAG,EAC3E,CAAC;QACA,MAAM,IAAI,SAAS,CAAC,4BAA4B,CAAC,CAAA;IAClD,CAAC;IAED,gDAAgD;IAChD,IAAI,CAAC,IAAA,yBAAc,EAAC,OAAO,CAAC,GAAG,CAAC,EAChC,CAAC;QACA,MAAM,IAAI,SAAS,CAAC,wBAAwB,CAAC,CAAA;IAC9C,CAAC;IAED,8BAA8B;IAC9B,IAAI,EAAE,GAAG,IAAA,+BAAc,EAAI,MAAA,OAAO,CAAC,QAAQ,mCAAI,8BAAiD,CAAC,CAAC;IAElG,wCAAwC;IACxC,IAAI,CAAC,EAAE,CAAC,MAAM,EACd,CAAC;QACA,MAAM,IAAI,SAAS,CAAC,qBAAqB,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAA;IAC7D,CAAC;IAED,8CAA8C;IAC9C,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,sBAAa,CAAC;IACvD,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;IAEnC,kCAAkC;IAClC,OAAO,EAAE,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;QAEzB,OAAO,IAAA,2CAAoB,EAAC,KAAK,EAAE,GAAG,EAAE,UAAU,EAAE,SAAS,CAAC,CAAA;IAC/D,CAAC,CAAC,CACD;AACH,CAAC","sourcesContent":["/**\n * Copy static files main function / 複製靜態檔案主函數\n *\n * This module provides the main function for copying static files to a target directory.\n * 此模組提供將靜態檔案複製到目標目錄的主函數。\n *\n * @module copyStaticFiles\n */\nimport { ICopyStaticFilesOptions, IStaticFilesMapArray, IStaticFilesMapArrayEntry } from './types';\nimport { CopyOptionsSync, copySync, ensureDirSync, existsSync, pathExistsSync } from 'fs-extra';\nimport { dirname, resolve } from 'path';\nimport { defaultCopyStaticFiles } from './const';\nimport { parseStaticMap } from './parseStaticMap';\nimport { copyStaticFilesEntry } from './copyStaticFilesEntry';\nimport { __STATIC_ROOT } from '../__root';\n\n/**\n * Copy static files to a target directory / 將靜態檔案複製到目標目錄\n *\n * Copies static files based on the provided file map configuration.\n * 根據提供的檔案映射配置複製靜態檔案。\n *\n * @template K - The target file path type / 目標檔案路徑類型\n *\n * @param options - Copy options / 複製選項\n * @param options.cwd - Current working directory (required) / 當前工作目錄(必填)\n * @param options.staticRoot - Root directory of static files (defaults to package root) / 靜態檔案根目錄(預設為套件根目錄)\n * @param options.overwrite - Whether to overwrite existing files / 是否覆蓋已存在的檔案\n * @param options.file_map - Custom file mapping configuration / 自訂檔案映射配置\n *\n * @returns Array of entries that were successfully copied / 成功複製的條目陣列\n *\n * @throws {TypeError} When options.cwd is not a valid string / 當 options.cwd 不是有效的字串時\n * @throws {TypeError} When options.cwd directory does not exist / 當 options.cwd 目錄不存在時\n * @throws {TypeError} When file_map is invalid / 當 file_map 無效時\n *\n * @example\n * ```typescript\n * import { copyStaticFiles } from '@yarn-tool/static-file';\n *\n * // Copy default static files to current directory\n * // 複製預設靜態檔案到當前目錄\n * copyStaticFiles({\n * cwd: process.cwd(),\n * overwrite: true\n * });\n *\n * // Copy with custom file map\n * // 使用自訂檔案映射複製\n * copyStaticFiles({\n * cwd: '/path/to/project',\n * file_map: [\n * ['.gitignore', 'file/gitignore'],\n * ['README.md', 'file/README.md']\n * ]\n * });\n * ```\n */\nexport function copyStaticFiles<K extends string>(options: ICopyStaticFilesOptions<K>)\n{\n\t// Validate cwd parameter / 驗證 cwd 參數\n\tif (typeof options.cwd !== 'string' || !options.cwd?.length || !options.cwd)\n\t{\n\t\tthrow new TypeError(`options.cwd must is string`)\n\t}\n\n\t// Check if cwd directory exists / 檢查 cwd 目錄是否存在\n\tif (!pathExistsSync(options.cwd))\n\t{\n\t\tthrow new TypeError(`options.cwd not exists`)\n\t}\n\n\t// Parse the file map / 解析檔案映射\n\tlet ls = parseStaticMap<K>(options.file_map ?? defaultCopyStaticFiles as IStaticFilesMapArray<K>);\n\n\t// Validate parsed file map / 驗證解析後的檔案映射\n\tif (!ls.length)\n\t{\n\t\tthrow new TypeError(`Invalid file map: ${options.file_map}`)\n\t}\n\n\t// Determine static root directory / 確定靜態檔案根目錄\n\tconst staticRoot = options.staticRoot || __STATIC_ROOT;\n\tconst { cwd, overwrite } = options;\n\n\t// Filter and copy files / 過濾並複製檔案\n\treturn ls.filter((entry) =>\n\t\t{\n\t\t\treturn copyStaticFilesEntry(entry, cwd, staticRoot, overwrite)\n\t\t})\n\t\t;\n}\n"]}
|
|
@@ -1,2 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copy single static file entry / 複製單個靜態檔案條目
|
|
3
|
+
*
|
|
4
|
+
* This module provides the function for copying a single static file entry.
|
|
5
|
+
* 此模組提供複製單個靜態檔案條目的函數。
|
|
6
|
+
*
|
|
7
|
+
* @module copyStaticFilesEntry
|
|
8
|
+
*/
|
|
1
9
|
import { IStaticFilesMapArrayEntry } from './types';
|
|
10
|
+
/**
|
|
11
|
+
* Copy a single static file entry / 複製單個靜態檔案條目
|
|
12
|
+
*
|
|
13
|
+
* Copies a single static file from the static root to the target directory.
|
|
14
|
+
* 從靜態根目錄複製單個靜態檔案到目標目錄。
|
|
15
|
+
*
|
|
16
|
+
* @param entry - The static file entry / 靜態檔案條目
|
|
17
|
+
* @param entry.0 - targetFile: Target file path / 目標檔案路徑
|
|
18
|
+
* @param entry.1 - staticFile: Source static file path / 來源靜態檔案路徑
|
|
19
|
+
* @param entry.2 - detectFile: Optional file to check for existence / 可選的檢測檔案
|
|
20
|
+
*
|
|
21
|
+
* @param cwd - Current working directory / 當前工作目錄
|
|
22
|
+
* @param staticRoot - Root directory of static files (defaults to package root) / 靜態檔案根目錄(預設為套件根目錄)
|
|
23
|
+
* @param overwrite - Whether to overwrite existing files (defaults to false) / 是否覆蓋已存在的檔案(預設為 false)
|
|
24
|
+
*
|
|
25
|
+
* @returns true if file was copied, undefined if skipped (detect file exists) / 如果檔案已複製則返回 true,如果跳過(檢測檔案存在)則返回 undefined
|
|
26
|
+
*
|
|
27
|
+
* @throws {Error} When the source static file does not exist / 當來源靜態檔案不存在時
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* import { copyStaticFilesEntry } from '@yarn-tool/static-file';
|
|
32
|
+
*
|
|
33
|
+
* // Copy a single file
|
|
34
|
+
* // 複製單個檔案
|
|
35
|
+
* const result = copyStaticFilesEntry(
|
|
36
|
+
* ['.gitignore', 'file/gitignore'],
|
|
37
|
+
* '/path/to/project',
|
|
38
|
+
* '/path/to/static/root',
|
|
39
|
+
* false
|
|
40
|
+
* );
|
|
41
|
+
*
|
|
42
|
+
* // With detect file - skips if detect file exists
|
|
43
|
+
* // 使用檢測檔案 - 如果檢測檔案存在則跳過
|
|
44
|
+
* const result = copyStaticFilesEntry(
|
|
45
|
+
* ['tsconfig.json', 'file/tsconfig.json.tpl', 'tsconfig.json'],
|
|
46
|
+
* '/path/to/project'
|
|
47
|
+
* );
|
|
48
|
+
* // Skips copy if tsconfig.json already exists in the project
|
|
49
|
+
* // 如果 tsconfig.json 已存在於專案中則跳過複製
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
2
52
|
export declare function copyStaticFilesEntry(entry: IStaticFilesMapArrayEntry<string>, cwd: string, staticRoot?: string, overwrite?: boolean): boolean;
|
|
@@ -4,20 +4,68 @@ exports.copyStaticFilesEntry = copyStaticFilesEntry;
|
|
|
4
4
|
const path_1 = require("path");
|
|
5
5
|
const fs_extra_1 = require("fs-extra");
|
|
6
6
|
const __root_1 = require("../__root");
|
|
7
|
+
/**
|
|
8
|
+
* Copy a single static file entry / 複製單個靜態檔案條目
|
|
9
|
+
*
|
|
10
|
+
* Copies a single static file from the static root to the target directory.
|
|
11
|
+
* 從靜態根目錄複製單個靜態檔案到目標目錄。
|
|
12
|
+
*
|
|
13
|
+
* @param entry - The static file entry / 靜態檔案條目
|
|
14
|
+
* @param entry.0 - targetFile: Target file path / 目標檔案路徑
|
|
15
|
+
* @param entry.1 - staticFile: Source static file path / 來源靜態檔案路徑
|
|
16
|
+
* @param entry.2 - detectFile: Optional file to check for existence / 可選的檢測檔案
|
|
17
|
+
*
|
|
18
|
+
* @param cwd - Current working directory / 當前工作目錄
|
|
19
|
+
* @param staticRoot - Root directory of static files (defaults to package root) / 靜態檔案根目錄(預設為套件根目錄)
|
|
20
|
+
* @param overwrite - Whether to overwrite existing files (defaults to false) / 是否覆蓋已存在的檔案(預設為 false)
|
|
21
|
+
*
|
|
22
|
+
* @returns true if file was copied, undefined if skipped (detect file exists) / 如果檔案已複製則返回 true,如果跳過(檢測檔案存在)則返回 undefined
|
|
23
|
+
*
|
|
24
|
+
* @throws {Error} When the source static file does not exist / 當來源靜態檔案不存在時
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* import { copyStaticFilesEntry } from '@yarn-tool/static-file';
|
|
29
|
+
*
|
|
30
|
+
* // Copy a single file
|
|
31
|
+
* // 複製單個檔案
|
|
32
|
+
* const result = copyStaticFilesEntry(
|
|
33
|
+
* ['.gitignore', 'file/gitignore'],
|
|
34
|
+
* '/path/to/project',
|
|
35
|
+
* '/path/to/static/root',
|
|
36
|
+
* false
|
|
37
|
+
* );
|
|
38
|
+
*
|
|
39
|
+
* // With detect file - skips if detect file exists
|
|
40
|
+
* // 使用檢測檔案 - 如果檢測檔案存在則跳過
|
|
41
|
+
* const result = copyStaticFilesEntry(
|
|
42
|
+
* ['tsconfig.json', 'file/tsconfig.json.tpl', 'tsconfig.json'],
|
|
43
|
+
* '/path/to/project'
|
|
44
|
+
* );
|
|
45
|
+
* // Skips copy if tsconfig.json already exists in the project
|
|
46
|
+
* // 如果 tsconfig.json 已存在於專案中則跳過複製
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
7
49
|
function copyStaticFilesEntry(entry, cwd, staticRoot = __root_1.__STATIC_ROOT, overwrite) {
|
|
8
50
|
const [targetFile, staticFile, detectFile] = entry;
|
|
51
|
+
// Check if detect file exists - skip copy if it does / 檢查檢測檔案是否存在 - 如果存在則跳過複製
|
|
9
52
|
if (detectFile === null || detectFile === void 0 ? void 0 : detectFile.length) {
|
|
10
53
|
const fc = (0, path_1.resolve)(cwd, detectFile);
|
|
11
54
|
if ((0, fs_extra_1.existsSync)(fc)) {
|
|
12
55
|
return;
|
|
13
56
|
}
|
|
14
57
|
}
|
|
58
|
+
// Resolve source file path / 解析來源檔案路徑
|
|
15
59
|
const fb = (0, path_1.resolve)(staticRoot, staticFile);
|
|
60
|
+
// Verify source file exists / 驗證來源檔案是否存在
|
|
16
61
|
if (!(0, fs_extra_1.existsSync)(fb)) {
|
|
17
62
|
throw new Error(`file not exists. ${fb}`);
|
|
18
63
|
}
|
|
64
|
+
// Resolve target file path / 解析目標檔案路徑
|
|
19
65
|
const fa = (0, path_1.resolve)(cwd, targetFile);
|
|
66
|
+
// Ensure target directory exists / 確保目標目錄存在
|
|
20
67
|
(0, fs_extra_1.ensureDirSync)((0, path_1.dirname)(fa));
|
|
68
|
+
// Copy the file / 複製檔案
|
|
21
69
|
(0, fs_extra_1.copySync)(fb, fa, {
|
|
22
70
|
overwrite: overwrite || false,
|
|
23
71
|
preserveTimestamps: true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"copyStaticFilesEntry.js","sourceRoot":"","sources":["copyStaticFilesEntry.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"copyStaticFilesEntry.js","sourceRoot":"","sources":["copyStaticFilesEntry.ts"],"names":[],"mappings":";;AAuDA,oDA0CC;AAxFD,+BAAwC;AACxC,uCAA+D;AAC/D,sCAA0C;AAE1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,SAAgB,oBAAoB,CAAC,KAAwC,EAC5E,GAAW,EACX,aAAqB,sBAAa,EAClC,SAAmB;IAGnB,MAAM,CAAC,UAAU,EAAE,UAAU,EAAE,UAAU,CAAC,GAAG,KAAK,CAAC;IAEnD,8EAA8E;IAC9E,IAAI,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,MAAM,EACtB,CAAC;QACA,MAAM,EAAE,GAAG,IAAA,cAAO,EAAC,GAAG,EAAE,UAAU,CAAC,CAAC;QAEpC,IAAI,IAAA,qBAAU,EAAC,EAAE,CAAC,EAClB,CAAC;YACA,OAAO;QACR,CAAC;IACF,CAAC;IAED,sCAAsC;IACtC,MAAM,EAAE,GAAG,IAAA,cAAO,EAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IAE3C,yCAAyC;IACzC,IAAI,CAAC,IAAA,qBAAU,EAAC,EAAE,CAAC,EACnB,CAAC;QACA,MAAM,IAAI,KAAK,CAAC,oBAAoB,EAAE,EAAE,CAAC,CAAA;IAC1C,CAAC;IAED,sCAAsC;IACtC,MAAM,EAAE,GAAG,IAAA,cAAO,EAAC,GAAG,EAAE,UAAU,CAAC,CAAC;IAEpC,4CAA4C;IAC5C,IAAA,wBAAa,EAAC,IAAA,cAAO,EAAC,EAAE,CAAC,CAAC,CAAA;IAE1B,uBAAuB;IACvB,IAAA,mBAAQ,EAAC,EAAE,EAAE,EAAE,EAAE;QAChB,SAAS,EAAE,SAAS,IAAI,KAAK;QAC7B,kBAAkB,EAAE,IAAI;QACxB,YAAY,EAAE,KAAK;KACnB,CAAC,CAAC;IAEH,OAAO,IAAI,CAAC;AACb,CAAC","sourcesContent":["/**\n * Copy single static file entry / 複製單個靜態檔案條目\n *\n * This module provides the function for copying a single static file entry.\n * 此模組提供複製單個靜態檔案條目的函數。\n *\n * @module copyStaticFilesEntry\n */\nimport { IStaticFilesMapArrayEntry } from './types';\nimport { dirname, resolve } from 'path';\nimport { copySync, ensureDirSync, existsSync } from 'fs-extra';\nimport { __STATIC_ROOT } from '../__root';\n\n/**\n * Copy a single static file entry / 複製單個靜態檔案條目\n *\n * Copies a single static file from the static root to the target directory.\n * 從靜態根目錄複製單個靜態檔案到目標目錄。\n *\n * @param entry - The static file entry / 靜態檔案條目\n * @param entry.0 - targetFile: Target file path / 目標檔案路徑\n * @param entry.1 - staticFile: Source static file path / 來源靜態檔案路徑\n * @param entry.2 - detectFile: Optional file to check for existence / 可選的檢測檔案\n *\n * @param cwd - Current working directory / 當前工作目錄\n * @param staticRoot - Root directory of static files (defaults to package root) / 靜態檔案根目錄(預設為套件根目錄)\n * @param overwrite - Whether to overwrite existing files (defaults to false) / 是否覆蓋已存在的檔案(預設為 false)\n *\n * @returns true if file was copied, undefined if skipped (detect file exists) / 如果檔案已複製則返回 true,如果跳過(檢測檔案存在)則返回 undefined\n *\n * @throws {Error} When the source static file does not exist / 當來源靜態檔案不存在時\n *\n * @example\n * ```typescript\n * import { copyStaticFilesEntry } from '@yarn-tool/static-file';\n *\n * // Copy a single file\n * // 複製單個檔案\n * const result = copyStaticFilesEntry(\n * ['.gitignore', 'file/gitignore'],\n * '/path/to/project',\n * '/path/to/static/root',\n * false\n * );\n *\n * // With detect file - skips if detect file exists\n * // 使用檢測檔案 - 如果檢測檔案存在則跳過\n * const result = copyStaticFilesEntry(\n * ['tsconfig.json', 'file/tsconfig.json.tpl', 'tsconfig.json'],\n * '/path/to/project'\n * );\n * // Skips copy if tsconfig.json already exists in the project\n * // 如果 tsconfig.json 已存在於專案中則跳過複製\n * ```\n */\nexport function copyStaticFilesEntry(entry: IStaticFilesMapArrayEntry<string>,\n\tcwd: string,\n\tstaticRoot: string = __STATIC_ROOT,\n\toverwrite?: boolean,\n)\n{\n\tconst [targetFile, staticFile, detectFile] = entry;\n\n\t// Check if detect file exists - skip copy if it does / 檢查檢測檔案是否存在 - 如果存在則跳過複製\n\tif (detectFile?.length)\n\t{\n\t\tconst fc = resolve(cwd, detectFile);\n\n\t\tif (existsSync(fc))\n\t\t{\n\t\t\treturn;\n\t\t}\n\t}\n\n\t// Resolve source file path / 解析來源檔案路徑\n\tconst fb = resolve(staticRoot, staticFile);\n\n\t// Verify source file exists / 驗證來源檔案是否存在\n\tif (!existsSync(fb))\n\t{\n\t\tthrow new Error(`file not exists. ${fb}`)\n\t}\n\n\t// Resolve target file path / 解析目標檔案路徑\n\tconst fa = resolve(cwd, targetFile);\n\n\t// Ensure target directory exists / 確保目標目錄存在\n\tensureDirSync(dirname(fa))\n\n\t// Copy the file / 複製檔案\n\tcopySync(fb, fa, {\n\t\toverwrite: overwrite || false,\n\t\tpreserveTimestamps: true,\n\t\terrorOnExist: false,\n\t});\n\n\treturn true;\n}\n"]}
|
|
@@ -1,2 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get row from static files map array / 從靜態檔案映射陣列獲取行
|
|
3
|
+
*
|
|
4
|
+
* This module provides a function to retrieve a specific entry from a static files map.
|
|
5
|
+
* 此模組提供從靜態檔案映射中檢索特定條目的函數。
|
|
6
|
+
*
|
|
7
|
+
* @module getRowOfStaticFilesMapArray
|
|
8
|
+
*/
|
|
1
9
|
import { IStaticFiles, IStaticFilesKey, IStaticFilesMapArrayEntry } from './types';
|
|
10
|
+
/**
|
|
11
|
+
* Get a specific row from static files map array / 從靜態檔案映射陣列獲取特定行
|
|
12
|
+
*
|
|
13
|
+
* Retrieves a specific entry from the static files map based on the target file key.
|
|
14
|
+
* 根據目標檔案鍵從靜態檔案映射中檢索特定條目。
|
|
15
|
+
*
|
|
16
|
+
* @template T - The static files map type / 靜態檔案映射類型
|
|
17
|
+
* @template K - The target file key type / 目標檔案鍵類型
|
|
18
|
+
*
|
|
19
|
+
* @param file_map - The static files map (array or record format) / 靜態檔案映射(陣列或記錄格式)
|
|
20
|
+
* @param key - The target file key to search for / 要搜尋的目標檔案鍵
|
|
21
|
+
*
|
|
22
|
+
* @returns The matching entry or undefined if not found / 匹配的條目,如果未找到則返回 undefined
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* import { getRowOfStaticFilesMapArray } from '@yarn-tool/static-file';
|
|
27
|
+
* import { defaultCopyStaticFiles } from '@yarn-tool/static-file/lib/const';
|
|
28
|
+
*
|
|
29
|
+
* // Get the entry for .gitignore
|
|
30
|
+
* // 獲取 .gitignore 的條目
|
|
31
|
+
* const entry = getRowOfStaticFilesMapArray(defaultCopyStaticFiles, '.gitignore');
|
|
32
|
+
* // Returns: ['.gitignore', 'file/gitignore']
|
|
33
|
+
* // 返回:['.gitignore', 'file/gitignore']
|
|
34
|
+
*
|
|
35
|
+
* // Get the entry for tsconfig.json.tpl
|
|
36
|
+
* // 獲取 tsconfig.json.tpl 的條目
|
|
37
|
+
* const tsconfigEntry = getRowOfStaticFilesMapArray(defaultCopyStaticFiles, 'tsconfig.json.tpl');
|
|
38
|
+
* // Returns: ['tsconfig.json.tpl', 'file/tsconfig.json.tpl', 'tsconfig.json']
|
|
39
|
+
* // 返回:['tsconfig.json.tpl', 'file/tsconfig.json.tpl', 'tsconfig.json']
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
2
42
|
export declare function getRowOfStaticFilesMapArray<T extends IStaticFiles<string>, K extends IStaticFilesKey<T>>(file_map: T, key: K): IStaticFilesMapArrayEntry<K>;
|