@niche-works/dev 0.4.1 → 0.5.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/_virtual/_rolldown/runtime.cjs +29 -0
- package/addExports/addExports.cjs +61 -0
- package/addExports/addExports.cjs.map +1 -0
- package/addExports/addExports.d.cts +11 -0
- package/addExports/addExports.d.mts +12 -0
- package/addExports/addExports.mjs +59 -0
- package/addExports/addExports.mjs.map +1 -0
- package/addExports/index.cjs +3 -0
- package/addExports/index.d.cts +3 -0
- package/addExports/index.d.mts +3 -0
- package/addExports/index.mjs +3 -0
- package/addExports/types.cjs +0 -0
- package/{src/addExports/types.ts → addExports/types.d.cts} +33 -33
- package/addExports/types.d.mts +33 -0
- package/addExports/types.mjs +1 -0
- package/addJsExtensions/addJsExtensions.cjs +31 -0
- package/addJsExtensions/addJsExtensions.cjs.map +1 -0
- package/addJsExtensions/addJsExtensions.d.cts +8 -0
- package/addJsExtensions/addJsExtensions.d.mts +9 -0
- package/addJsExtensions/addJsExtensions.mjs +28 -0
- package/addJsExtensions/addJsExtensions.mjs.map +1 -0
- package/addJsExtensions/index.cjs +3 -0
- package/addJsExtensions/index.d.cts +2 -0
- package/addJsExtensions/index.d.mts +2 -0
- package/addJsExtensions/index.mjs +3 -0
- package/checkExistence/checkExistence.cjs +23 -0
- package/checkExistence/checkExistence.cjs.map +1 -0
- package/checkExistence/checkExistence.d.cts +9 -0
- package/checkExistence/checkExistence.d.mts +10 -0
- package/checkExistence/checkExistence.mjs +21 -0
- package/checkExistence/checkExistence.mjs.map +1 -0
- package/checkExistence/index.cjs +3 -0
- package/checkExistence/index.d.cts +2 -0
- package/checkExistence/index.d.mts +2 -0
- package/checkExistence/index.mjs +3 -0
- package/createExternalOptionFunction/createExternalOptionFunction.cjs +25 -0
- package/createExternalOptionFunction/createExternalOptionFunction.cjs.map +1 -0
- package/createExternalOptionFunction/createExternalOptionFunction.d.cts +10 -0
- package/createExternalOptionFunction/createExternalOptionFunction.d.mts +11 -0
- package/createExternalOptionFunction/createExternalOptionFunction.mjs +25 -0
- package/createExternalOptionFunction/createExternalOptionFunction.mjs.map +1 -0
- package/createExternalOptionFunction/index.cjs +3 -0
- package/createExternalOptionFunction/index.d.cts +2 -0
- package/createExternalOptionFunction/index.d.mts +2 -0
- package/createExternalOptionFunction/index.mjs +3 -0
- package/createExternalOptionFunction/types.cjs +0 -0
- package/{src/createExternalOptionFunction/types.ts → createExternalOptionFunction/types.d.cts} +31 -34
- package/createExternalOptionFunction/types.d.mts +31 -0
- package/createExternalOptionFunction/types.mjs +1 -0
- package/createSassClassNameFunction/createSassClassNameFunction.cjs +19 -0
- package/createSassClassNameFunction/createSassClassNameFunction.cjs.map +1 -0
- package/createSassClassNameFunction/createSassClassNameFunction.d.cts +11 -0
- package/createSassClassNameFunction/createSassClassNameFunction.d.mts +12 -0
- package/createSassClassNameFunction/createSassClassNameFunction.mjs +18 -0
- package/createSassClassNameFunction/createSassClassNameFunction.mjs.map +1 -0
- package/createSassClassNameFunction/index.cjs +3 -0
- package/createSassClassNameFunction/index.d.cts +2 -0
- package/createSassClassNameFunction/index.d.mts +2 -0
- package/createSassClassNameFunction/index.mjs +3 -0
- package/editJsonFile/editJsonFile.cjs +29 -0
- package/editJsonFile/editJsonFile.cjs.map +1 -0
- package/editJsonFile/editJsonFile.d.cts +9 -0
- package/editJsonFile/editJsonFile.d.mts +10 -0
- package/editJsonFile/editJsonFile.mjs +26 -0
- package/editJsonFile/editJsonFile.mjs.map +1 -0
- package/editJsonFile/index.cjs +3 -0
- package/editJsonFile/index.d.cts +2 -0
- package/editJsonFile/index.d.mts +2 -0
- package/editJsonFile/index.mjs +3 -0
- package/generatePublishPackageJson/generatePublishPackageJson.cjs +46 -0
- package/generatePublishPackageJson/generatePublishPackageJson.cjs.map +1 -0
- package/generatePublishPackageJson/generatePublishPackageJson.d.cts +6 -0
- package/generatePublishPackageJson/generatePublishPackageJson.d.mts +7 -0
- package/generatePublishPackageJson/generatePublishPackageJson.mjs +44 -0
- package/generatePublishPackageJson/generatePublishPackageJson.mjs.map +1 -0
- package/generatePublishPackageJson/index.cjs +3 -0
- package/generatePublishPackageJson/index.d.cts +3 -0
- package/generatePublishPackageJson/index.d.mts +3 -0
- package/generatePublishPackageJson/index.mjs +3 -0
- package/generatePublishPackageJson/types.cjs +0 -0
- package/{src/generatePublishPackageJson/types.ts → generatePublishPackageJson/types.d.cts} +60 -61
- package/generatePublishPackageJson/types.d.mts +60 -0
- package/generatePublishPackageJson/types.mjs +1 -0
- package/index.cjs +41 -0
- package/index.d.cts +14 -0
- package/index.d.mts +14 -0
- package/index.mjs +28 -0
- package/indexes/constants.cjs +123 -0
- package/indexes/constants.cjs.map +1 -0
- package/indexes/constants.d.cts +66 -0
- package/indexes/constants.d.mts +66 -0
- package/indexes/constants.mjs +106 -0
- package/indexes/constants.mjs.map +1 -0
- package/indexes/index.cjs +3 -0
- package/indexes/index.d.cts +3 -0
- package/indexes/index.d.mts +3 -0
- package/indexes/index.mjs +3 -0
- package/indexes/indexes.cjs +125 -0
- package/indexes/indexes.cjs.map +1 -0
- package/indexes/indexes.d.cts +11 -0
- package/indexes/indexes.d.mts +12 -0
- package/indexes/indexes.mjs +123 -0
- package/indexes/indexes.mjs.map +1 -0
- package/indexes/types.cjs +0 -0
- package/{src/indexes/types.ts → indexes/types.d.cts} +81 -87
- package/indexes/types.d.mts +81 -0
- package/indexes/types.mjs +1 -0
- package/installFromLocal/index.cjs +3 -0
- package/installFromLocal/index.d.cts +3 -0
- package/installFromLocal/index.d.mts +3 -0
- package/installFromLocal/index.mjs +3 -0
- package/installFromLocal/installFromLocal.cjs +46 -0
- package/installFromLocal/installFromLocal.cjs.map +1 -0
- package/installFromLocal/installFromLocal.d.cts +11 -0
- package/installFromLocal/installFromLocal.d.mts +12 -0
- package/installFromLocal/installFromLocal.mjs +43 -0
- package/installFromLocal/installFromLocal.mjs.map +1 -0
- package/installFromLocal/types.cjs +0 -0
- package/{src/installFromLocal/types.ts → installFromLocal/types.d.cts} +21 -19
- package/installFromLocal/types.d.mts +21 -0
- package/installFromLocal/types.mjs +1 -0
- package/isMatchingPath/index.cjs +3 -0
- package/isMatchingPath/index.d.cts +3 -0
- package/isMatchingPath/index.d.mts +3 -0
- package/isMatchingPath/index.mjs +3 -0
- package/isMatchingPath/isMatchingPath.cjs +52 -0
- package/isMatchingPath/isMatchingPath.cjs.map +1 -0
- package/isMatchingPath/isMatchingPath.d.cts +13 -0
- package/isMatchingPath/isMatchingPath.d.mts +14 -0
- package/isMatchingPath/isMatchingPath.mjs +50 -0
- package/isMatchingPath/isMatchingPath.mjs.map +1 -0
- package/isMatchingPath/types.cjs +0 -0
- package/isMatchingPath/types.d.cts +72 -0
- package/isMatchingPath/types.d.mts +72 -0
- package/isMatchingPath/types.mjs +1 -0
- package/isTargetPath/index.cjs +3 -0
- package/isTargetPath/index.d.cts +3 -0
- package/isTargetPath/index.d.mts +3 -0
- package/isTargetPath/index.mjs +3 -0
- package/isTargetPath/isTargetPath.cjs +21 -0
- package/isTargetPath/isTargetPath.cjs.map +1 -0
- package/isTargetPath/isTargetPath.d.cts +7 -0
- package/isTargetPath/isTargetPath.d.mts +8 -0
- package/isTargetPath/isTargetPath.mjs +19 -0
- package/isTargetPath/isTargetPath.mjs.map +1 -0
- package/isTargetPath/types.cjs +0 -0
- package/{src/isTargetPath/types.ts → isTargetPath/types.d.cts} +33 -38
- package/isTargetPath/types.d.mts +33 -0
- package/isTargetPath/types.mjs +1 -0
- package/moveFilesToSubdir/index.cjs +3 -0
- package/moveFilesToSubdir/index.d.cts +3 -0
- package/moveFilesToSubdir/index.d.mts +3 -0
- package/moveFilesToSubdir/index.mjs +3 -0
- package/moveFilesToSubdir/moveFilesToSubdir.cjs +32 -0
- package/moveFilesToSubdir/moveFilesToSubdir.cjs.map +1 -0
- package/moveFilesToSubdir/moveFilesToSubdir.d.cts +10 -0
- package/moveFilesToSubdir/moveFilesToSubdir.d.mts +11 -0
- package/moveFilesToSubdir/moveFilesToSubdir.mjs +29 -0
- package/moveFilesToSubdir/moveFilesToSubdir.mjs.map +1 -0
- package/moveFilesToSubdir/types.cjs +0 -0
- package/{src/moveFilesToSubdir/types.ts → moveFilesToSubdir/types.d.cts} +18 -15
- package/moveFilesToSubdir/types.d.mts +18 -0
- package/moveFilesToSubdir/types.mjs +1 -0
- package/package.json +21 -29
- package/removeFiles/index.cjs +3 -0
- package/removeFiles/index.d.cts +2 -0
- package/removeFiles/index.d.mts +2 -0
- package/removeFiles/index.mjs +3 -0
- package/removeFiles/removeFiles.cjs +15 -0
- package/removeFiles/removeFiles.cjs.map +1 -0
- package/removeFiles/removeFiles.d.cts +6 -0
- package/removeFiles/removeFiles.d.mts +7 -0
- package/removeFiles/removeFiles.mjs +12 -0
- package/removeFiles/removeFiles.mjs.map +1 -0
- package/removeFiles/types.cjs +0 -0
- package/removeFiles/types.d.cts +9 -0
- package/removeFiles/types.d.mts +9 -0
- package/removeFiles/types.mjs +1 -0
- package/ver/index.cjs +3 -0
- package/ver/index.d.cts +3 -0
- package/ver/index.d.mts +3 -0
- package/ver/index.mjs +3 -0
- package/ver/types.cjs +0 -0
- package/{src/ver/types.ts → ver/types.d.cts} +16 -13
- package/ver/types.d.mts +16 -0
- package/ver/types.mjs +1 -0
- package/ver/ver.cjs +34 -0
- package/ver/ver.cjs.map +1 -0
- package/ver/ver.d.cts +11 -0
- package/ver/ver.d.mts +12 -0
- package/ver/ver.mjs +31 -0
- package/ver/ver.mjs.map +1 -0
- package/src/addExports/addExports.ts +0 -94
- package/src/addExports/index.ts +0 -2
- package/src/addJsExtensions/addJsExtensions.ts +0 -30
- package/src/addJsExtensions/index.ts +0 -1
- package/src/checkExistence/checkExistence.ts +0 -16
- package/src/checkExistence/index.ts +0 -1
- package/src/createExternalOptionFunction/createExternalOptionFunction.ts +0 -43
- package/src/createExternalOptionFunction/index.ts +0 -1
- package/src/editJsonFile/editJsonFile.ts +0 -30
- package/src/editJsonFile/index.ts +0 -1
- package/src/generatePublishPackageJson/generatePublishPackageJson.ts +0 -55
- package/src/generatePublishPackageJson/index.ts +0 -2
- package/src/index.ts +0 -11
- package/src/indexes/constants.ts +0 -135
- package/src/indexes/index.ts +0 -2
- package/src/indexes/indexes.ts +0 -194
- package/src/installFromLocal/index.ts +0 -2
- package/src/installFromLocal/installFromLocal.ts +0 -63
- package/src/isMatchingPath/index.ts +0 -2
- package/src/isMatchingPath/isMatchingPath.ts +0 -94
- package/src/isMatchingPath/types.ts +0 -95
- package/src/isTargetPath/index.ts +0 -2
- package/src/isTargetPath/isTargetPath.ts +0 -30
- package/src/moveFilesToSubdir/index.ts +0 -2
- package/src/moveFilesToSubdir/moveFilesToSubdir.ts +0 -40
- package/src/removeFiles/index.ts +0 -1
- package/src/removeFiles/removeFiles.ts +0 -11
- package/src/removeFiles/types.ts +0 -5
- package/src/ver/index.ts +0 -2
- package/src/ver/ver.ts +0 -38
- package/tsconfig.json +0 -46
- package/tsdown.config.ts +0 -41
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { InstallFromLocalOptions } from "./types.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/installFromLocal/installFromLocal.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* ローカルに配置されたパッケージを差し替える
|
|
6
|
+
* @param localNodeModulesPath ローカルのnode_modulesディレクトリのパス
|
|
7
|
+
* @param options オプション
|
|
8
|
+
*/
|
|
9
|
+
declare function installFromLocal(localNodeModulesPath: string, options?: InstallFromLocalOptions): void;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { installFromLocal as default };
|
|
12
|
+
//# sourceMappingURL=installFromLocal.d.mts.map
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import checkExistence from "../checkExistence/checkExistence.mjs";
|
|
2
|
+
import "../checkExistence/index.mjs";
|
|
3
|
+
import fs from "fs-extra";
|
|
4
|
+
import path from "path";
|
|
5
|
+
import { reduce } from "remeda";
|
|
6
|
+
|
|
7
|
+
//#region src/installFromLocal/installFromLocal.ts
|
|
8
|
+
/**
|
|
9
|
+
* ローカルに配置されたパッケージを差し替える
|
|
10
|
+
* @param localNodeModulesPath ローカルのnode_modulesディレクトリのパス
|
|
11
|
+
* @param options オプション
|
|
12
|
+
*/
|
|
13
|
+
function installFromLocal(localNodeModulesPath, options = {}) {
|
|
14
|
+
const { packageJsonPath = "./package.json", nodeModulesPath = "./node_modules", dryRun } = options;
|
|
15
|
+
const resolvedLocalNodeModulesPath = path.resolve(localNodeModulesPath);
|
|
16
|
+
const resolvedPackageJsonPath = path.resolve(packageJsonPath);
|
|
17
|
+
if (!checkExistence(resolvedLocalNodeModulesPath, resolvedPackageJsonPath)) return;
|
|
18
|
+
console.info(`${localNodeModulesPath} -> ${nodeModulesPath}`);
|
|
19
|
+
const packageJson = fs.readJSONSync(resolvedPackageJsonPath);
|
|
20
|
+
const localPackages = reduce({
|
|
21
|
+
...packageJson.dependencies,
|
|
22
|
+
...packageJson.devDependencies
|
|
23
|
+
}, (result, value, key) => {
|
|
24
|
+
if (value.startsWith(localNodeModulesPath)) result[key] = value;
|
|
25
|
+
else if (value.startsWith(`file:${localNodeModulesPath}`)) result[key] = value.substring(5);
|
|
26
|
+
return result;
|
|
27
|
+
}, {});
|
|
28
|
+
for (const packageName in localPackages) {
|
|
29
|
+
const localPackagePath = path.resolve(localPackages[packageName]);
|
|
30
|
+
if (fs.existsSync(localPackagePath)) {
|
|
31
|
+
const installedPackagePath = path.resolve(nodeModulesPath, packageName);
|
|
32
|
+
if (!dryRun) {
|
|
33
|
+
if (fs.existsSync(installedPackagePath)) fs.removeSync(installedPackagePath);
|
|
34
|
+
fs.copySync(localPackagePath, installedPackagePath);
|
|
35
|
+
}
|
|
36
|
+
console.info(`${packageName} is being copied...`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
//#endregion
|
|
42
|
+
export { installFromLocal as default };
|
|
43
|
+
//# sourceMappingURL=installFromLocal.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"installFromLocal.mjs","names":[],"sources":["../../src/installFromLocal/installFromLocal.ts"],"sourcesContent":["import fs from 'fs-extra';\r\nimport path from 'path';\r\nimport { reduce } from 'remeda';\r\nimport checkExistence from '../checkExistence';\r\nimport type { InstallFromLocalOptions } from './types';\r\n\r\n/**\r\n * ローカルに配置されたパッケージを差し替える\r\n * @param localNodeModulesPath ローカルのnode_modulesディレクトリのパス\r\n * @param options オプション\r\n */\r\nexport default function installFromLocal(\r\n localNodeModulesPath: string,\r\n options: InstallFromLocalOptions = {},\r\n) {\r\n const {\r\n packageJsonPath = './package.json',\r\n nodeModulesPath = './node_modules',\r\n dryRun,\r\n } = options;\r\n const resolvedLocalNodeModulesPath = path.resolve(localNodeModulesPath);\r\n const resolvedPackageJsonPath = path.resolve(packageJsonPath);\r\n\r\n if (!checkExistence(resolvedLocalNodeModulesPath, resolvedPackageJsonPath)) {\r\n return;\r\n }\r\n\r\n console.info(`${localNodeModulesPath} -> ${nodeModulesPath}`);\r\n\r\n // package.jsonからローカルのnode_modulesにあるパッケージを取得\r\n const packageJson = fs.readJSONSync(resolvedPackageJsonPath);\r\n const localPackages = reduce(\r\n { ...packageJson.dependencies, ...packageJson.devDependencies },\r\n (result: Record<string, string>, value: string, key) => {\r\n if (value.startsWith(localNodeModulesPath)) {\r\n result[key] = value;\r\n } else if (value.startsWith(`file:${localNodeModulesPath}`)) {\r\n result[key] = value.substring(5);\r\n }\r\n return result;\r\n },\r\n {},\r\n );\r\n\r\n for (const packageName in localPackages) {\r\n // ローカルパッケージの確認\r\n const localPackagePath = path.resolve(localPackages[packageName]);\r\n if (fs.existsSync(localPackagePath)) {\r\n // ローカルパッケージがある場合のみ処理\r\n const installedPackagePath = path.resolve(nodeModulesPath, packageName);\r\n if (!dryRun) {\r\n // コピーを行う\r\n if (fs.existsSync(installedPackagePath)) {\r\n // 古いパッケージは削除\r\n fs.removeSync(installedPackagePath);\r\n }\r\n // パッケージをコピー\r\n fs.copySync(localPackagePath, installedPackagePath);\r\n }\r\n console.info(`${packageName} is being copied...`);\r\n }\r\n }\r\n}\r\n"],"mappings":";;;;;;;;;;;;AAWA,SAAwB,iBACtB,sBACA,UAAmC,EAAE,EACrC;CACA,MAAM,EACJ,kBAAkB,kBAClB,kBAAkB,kBAClB,WACE;CACJ,MAAM,+BAA+B,KAAK,QAAQ,qBAAqB;CACvE,MAAM,0BAA0B,KAAK,QAAQ,gBAAgB;AAE7D,KAAI,CAAC,eAAe,8BAA8B,wBAAwB,CACxE;AAGF,SAAQ,KAAK,GAAG,qBAAqB,MAAM,kBAAkB;CAG7D,MAAM,cAAc,GAAG,aAAa,wBAAwB;CAC5D,MAAM,gBAAgB,OACpB;EAAE,GAAG,YAAY;EAAc,GAAG,YAAY;EAAiB,GAC9D,QAAgC,OAAe,QAAQ;AACtD,MAAI,MAAM,WAAW,qBAAqB,CACxC,QAAO,OAAO;WACL,MAAM,WAAW,QAAQ,uBAAuB,CACzD,QAAO,OAAO,MAAM,UAAU,EAAE;AAElC,SAAO;IAET,EAAE,CACH;AAED,MAAK,MAAM,eAAe,eAAe;EAEvC,MAAM,mBAAmB,KAAK,QAAQ,cAAc,aAAa;AACjE,MAAI,GAAG,WAAW,iBAAiB,EAAE;GAEnC,MAAM,uBAAuB,KAAK,QAAQ,iBAAiB,YAAY;AACvE,OAAI,CAAC,QAAQ;AAEX,QAAI,GAAG,WAAW,qBAAqB,CAErC,IAAG,WAAW,qBAAqB;AAGrC,OAAG,SAAS,kBAAkB,qBAAqB;;AAErD,WAAQ,KAAK,GAAG,YAAY,qBAAqB"}
|
|
File without changes
|
|
@@ -1,19 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
*
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* node_modulesのパス
|
|
10
|
-
* @default './node_modules'
|
|
11
|
-
*/
|
|
12
|
-
nodeModulesPath?: string;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
*
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
1
|
+
//#region src/installFromLocal/types.d.ts
|
|
2
|
+
type InstallFromLocalOptions = {
|
|
3
|
+
/**
|
|
4
|
+
* package.jsonのパス
|
|
5
|
+
* @default './package.json'
|
|
6
|
+
*/
|
|
7
|
+
packageJsonPath?: string;
|
|
8
|
+
/**
|
|
9
|
+
* node_modulesのパス
|
|
10
|
+
* @default './node_modules'
|
|
11
|
+
*/
|
|
12
|
+
nodeModulesPath?: string;
|
|
13
|
+
/**
|
|
14
|
+
* お試し
|
|
15
|
+
* ファイルの操作は行わない
|
|
16
|
+
*/
|
|
17
|
+
dryRun?: boolean;
|
|
18
|
+
};
|
|
19
|
+
//#endregion
|
|
20
|
+
export { InstallFromLocalOptions };
|
|
21
|
+
//# sourceMappingURL=types.d.cts.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//#region src/installFromLocal/types.d.ts
|
|
2
|
+
type InstallFromLocalOptions = {
|
|
3
|
+
/**
|
|
4
|
+
* package.jsonのパス
|
|
5
|
+
* @default './package.json'
|
|
6
|
+
*/
|
|
7
|
+
packageJsonPath?: string;
|
|
8
|
+
/**
|
|
9
|
+
* node_modulesのパス
|
|
10
|
+
* @default './node_modules'
|
|
11
|
+
*/
|
|
12
|
+
nodeModulesPath?: string;
|
|
13
|
+
/**
|
|
14
|
+
* お試し
|
|
15
|
+
* ファイルの操作は行わない
|
|
16
|
+
*/
|
|
17
|
+
dryRun?: boolean;
|
|
18
|
+
};
|
|
19
|
+
//#endregion
|
|
20
|
+
export { InstallFromLocalOptions };
|
|
21
|
+
//# sourceMappingURL=types.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { ConditionConfig, ConditionFn, ConditionFnOptions, ConditionValues, IsMatchingPathCondition, IsMatchingPathOptions } from "./types.cjs";
|
|
2
|
+
import isMatchingPath from "./isMatchingPath.cjs";
|
|
3
|
+
export { ConditionConfig, ConditionFn, ConditionFnOptions, ConditionValues, IsMatchingPathCondition, IsMatchingPathOptions, isMatchingPath as default };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { ConditionConfig, ConditionFn, ConditionFnOptions, ConditionValues, IsMatchingPathCondition, IsMatchingPathOptions } from "./types.mjs";
|
|
2
|
+
import isMatchingPath from "./isMatchingPath.mjs";
|
|
3
|
+
export { ConditionConfig, ConditionFn, ConditionFnOptions, ConditionValues, IsMatchingPathCondition, IsMatchingPathOptions, isMatchingPath as default };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
2
|
+
let fs_extra = require("fs-extra");
|
|
3
|
+
fs_extra = require_runtime.__toESM(fs_extra, 1);
|
|
4
|
+
let path = require("path");
|
|
5
|
+
let remeda = require("remeda");
|
|
6
|
+
|
|
7
|
+
//#region src/isMatchingPath/isMatchingPath.ts
|
|
8
|
+
/**
|
|
9
|
+
* 処理対象のパスか判定する
|
|
10
|
+
* @param targetPath 検査対象のパス
|
|
11
|
+
* @param conditions 一致条件
|
|
12
|
+
* @param options オプション
|
|
13
|
+
* @returns 一致するか
|
|
14
|
+
*/
|
|
15
|
+
function isMatchingPath(targetPath, conditions, options = {}) {
|
|
16
|
+
if (!conditions) return false;
|
|
17
|
+
const conditionList = Array.isArray(conditions) ? conditions : [conditions];
|
|
18
|
+
const posixPath = path.posix.normalize(targetPath);
|
|
19
|
+
const parsedPath = path.posix.parse(posixPath);
|
|
20
|
+
const parsedDir = path.posix.parse(parsedPath.dir);
|
|
21
|
+
const values = {
|
|
22
|
+
path: posixPath,
|
|
23
|
+
...parsedPath,
|
|
24
|
+
dirpath: parsedPath.dir,
|
|
25
|
+
dirbase: parsedDir.base,
|
|
26
|
+
dirname: parsedDir.name,
|
|
27
|
+
dirext: parsedDir.ext
|
|
28
|
+
};
|
|
29
|
+
values.path = posixPath;
|
|
30
|
+
for (const condition of conditionList) if (_isMatching(values.path, values, condition, options)) return true;
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
function _isMatching(value, values, condition, options) {
|
|
34
|
+
if ((0, remeda.isString)(condition)) {
|
|
35
|
+
if (value.includes(condition)) return true;
|
|
36
|
+
} else if (condition instanceof RegExp) {
|
|
37
|
+
if (condition.test(value)) return true;
|
|
38
|
+
} else if ((0, remeda.isFunction)(condition)) return condition(values, options.conditionOptions ?? {});
|
|
39
|
+
else {
|
|
40
|
+
const { valueType = "path", entryType = "both", conditions } = condition;
|
|
41
|
+
if (entryType !== "both") {
|
|
42
|
+
const stat = fs_extra.default.statSync(values.path);
|
|
43
|
+
if (stat.isDirectory() && entryType !== "dir" || stat.isFile() && entryType !== "file") return false;
|
|
44
|
+
}
|
|
45
|
+
return (Array.isArray(conditions) ? conditions : [conditions]).every((cond) => _isMatching(values[valueType], values, cond, options));
|
|
46
|
+
}
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
//#endregion
|
|
51
|
+
module.exports = isMatchingPath;
|
|
52
|
+
//# sourceMappingURL=isMatchingPath.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isMatchingPath.cjs","names":["fs"],"sources":["../../src/isMatchingPath/isMatchingPath.ts"],"sourcesContent":["import fs from 'fs-extra';\r\nimport { posix as path } from 'path';\r\nimport { isFunction, isString } from 'remeda';\r\nimport type {\r\n ConditionFnOptions,\r\n ConditionValues,\r\n IsMatchingPathCondition,\r\n IsMatchingPathOptions,\r\n} from './types';\r\n\r\n/**\r\n * 処理対象のパスか判定する\r\n * @param targetPath 検査対象のパス\r\n * @param conditions 一致条件\r\n * @param options オプション\r\n * @returns 一致するか\r\n */\r\nexport default function isMatchingPath<\r\n O extends ConditionFnOptions = ConditionFnOptions,\r\n>(\r\n targetPath: string,\r\n conditions:\r\n | IsMatchingPathCondition<O>\r\n | IsMatchingPathCondition<O>[]\r\n | null\r\n | undefined,\r\n options: IsMatchingPathOptions<O> = {},\r\n) {\r\n if (!conditions) {\r\n return false;\r\n }\r\n const conditionList = Array.isArray(conditions) ? conditions : [conditions];\r\n // パスは'/'区切り\r\n const posixPath = path.normalize(targetPath);\r\n const parsedPath = path.parse(posixPath);\r\n const parsedDir = path.parse(parsedPath.dir);\r\n const values = {\r\n path: posixPath,\r\n ...parsedPath,\r\n dirpath: parsedPath.dir,\r\n dirbase: parsedDir.base,\r\n dirname: parsedDir.name,\r\n dirext: parsedDir.ext,\r\n };\r\n values.path = posixPath;\r\n\r\n for (const condition of conditionList) {\r\n if (_isMatching(values.path, values, condition, options)) {\r\n // conditionの内の何れかがtrueならば一致\r\n return true;\r\n }\r\n }\r\n return false;\r\n}\r\n\r\nfunction _isMatching<O extends ConditionFnOptions = ConditionFnOptions>(\r\n value: string,\r\n values: ConditionValues,\r\n condition: IsMatchingPathCondition<O>,\r\n options: IsMatchingPathOptions<O>,\r\n): boolean {\r\n if (isString(condition)) {\r\n // 条件が文字列\r\n if (value.includes(condition)) {\r\n return true;\r\n }\r\n } else if (condition instanceof RegExp) {\r\n // 条件が正規表現\r\n if (condition.test(value)) {\r\n return true;\r\n }\r\n } else if (isFunction(condition)) {\r\n // 条件が関数\r\n return condition(values, (options.conditionOptions ?? {}) as O);\r\n } else {\r\n // 条件が設定\r\n const { valueType = 'path', entryType = 'both', conditions } = condition;\r\n if (entryType !== 'both') {\r\n const stat = fs.statSync(values.path);\r\n if (\r\n (stat.isDirectory() && entryType !== 'dir') ||\r\n (stat.isFile() && entryType !== 'file')\r\n ) {\r\n return false;\r\n }\r\n }\r\n const conditionList = Array.isArray(conditions) ? conditions : [conditions];\r\n // 設定配下のconditionsはand条件\r\n return conditionList.every((cond) =>\r\n _isMatching(values[valueType], values, cond, options),\r\n );\r\n }\r\n return false;\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;AAiBA,SAAwB,eAGtB,YACA,YAKA,UAAoC,EAAE,EACtC;AACA,KAAI,CAAC,WACH,QAAO;CAET,MAAM,gBAAgB,MAAM,QAAQ,WAAW,GAAG,aAAa,CAAC,WAAW;CAE3E,MAAM,YAAY,WAAK,UAAU,WAAW;CAC5C,MAAM,aAAa,WAAK,MAAM,UAAU;CACxC,MAAM,YAAY,WAAK,MAAM,WAAW,IAAI;CAC5C,MAAM,SAAS;EACb,MAAM;EACN,GAAG;EACH,SAAS,WAAW;EACpB,SAAS,UAAU;EACnB,SAAS,UAAU;EACnB,QAAQ,UAAU;EACnB;AACD,QAAO,OAAO;AAEd,MAAK,MAAM,aAAa,cACtB,KAAI,YAAY,OAAO,MAAM,QAAQ,WAAW,QAAQ,CAEtD,QAAO;AAGX,QAAO;;AAGT,SAAS,YACP,OACA,QACA,WACA,SACS;AACT,0BAAa,UAAU,EAErB;MAAI,MAAM,SAAS,UAAU,CAC3B,QAAO;YAEA,qBAAqB,QAE9B;MAAI,UAAU,KAAK,MAAM,CACvB,QAAO;mCAEW,UAAU,CAE9B,QAAO,UAAU,QAAS,QAAQ,oBAAoB,EAAE,CAAO;MAC1D;EAEL,MAAM,EAAE,YAAY,QAAQ,YAAY,QAAQ,eAAe;AAC/D,MAAI,cAAc,QAAQ;GACxB,MAAM,OAAOA,iBAAG,SAAS,OAAO,KAAK;AACrC,OACG,KAAK,aAAa,IAAI,cAAc,SACpC,KAAK,QAAQ,IAAI,cAAc,OAEhC,QAAO;;AAKX,UAFsB,MAAM,QAAQ,WAAW,GAAG,aAAa,CAAC,WAAW,EAEtD,OAAO,SAC1B,YAAY,OAAO,YAAY,QAAQ,MAAM,QAAQ,CACtD;;AAEH,QAAO"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ConditionFnOptions, IsMatchingPathCondition, IsMatchingPathOptions } from "./types.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/isMatchingPath/isMatchingPath.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* 処理対象のパスか判定する
|
|
6
|
+
* @param targetPath 検査対象のパス
|
|
7
|
+
* @param conditions 一致条件
|
|
8
|
+
* @param options オプション
|
|
9
|
+
* @returns 一致するか
|
|
10
|
+
*/
|
|
11
|
+
declare function isMatchingPath<O extends ConditionFnOptions = ConditionFnOptions>(targetPath: string, conditions: IsMatchingPathCondition<O> | IsMatchingPathCondition<O>[] | null | undefined, options?: IsMatchingPathOptions<O>): boolean;
|
|
12
|
+
export = isMatchingPath;
|
|
13
|
+
//# sourceMappingURL=isMatchingPath.d.cts.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ConditionFnOptions, IsMatchingPathCondition, IsMatchingPathOptions } from "./types.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/isMatchingPath/isMatchingPath.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* 処理対象のパスか判定する
|
|
6
|
+
* @param targetPath 検査対象のパス
|
|
7
|
+
* @param conditions 一致条件
|
|
8
|
+
* @param options オプション
|
|
9
|
+
* @returns 一致するか
|
|
10
|
+
*/
|
|
11
|
+
declare function isMatchingPath<O extends ConditionFnOptions = ConditionFnOptions>(targetPath: string, conditions: IsMatchingPathCondition<O> | IsMatchingPathCondition<O>[] | null | undefined, options?: IsMatchingPathOptions<O>): boolean;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { isMatchingPath as default };
|
|
14
|
+
//# sourceMappingURL=isMatchingPath.d.mts.map
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import fs from "fs-extra";
|
|
2
|
+
import { posix } from "path";
|
|
3
|
+
import { isFunction, isString } from "remeda";
|
|
4
|
+
|
|
5
|
+
//#region src/isMatchingPath/isMatchingPath.ts
|
|
6
|
+
/**
|
|
7
|
+
* 処理対象のパスか判定する
|
|
8
|
+
* @param targetPath 検査対象のパス
|
|
9
|
+
* @param conditions 一致条件
|
|
10
|
+
* @param options オプション
|
|
11
|
+
* @returns 一致するか
|
|
12
|
+
*/
|
|
13
|
+
function isMatchingPath(targetPath, conditions, options = {}) {
|
|
14
|
+
if (!conditions) return false;
|
|
15
|
+
const conditionList = Array.isArray(conditions) ? conditions : [conditions];
|
|
16
|
+
const posixPath = posix.normalize(targetPath);
|
|
17
|
+
const parsedPath = posix.parse(posixPath);
|
|
18
|
+
const parsedDir = posix.parse(parsedPath.dir);
|
|
19
|
+
const values = {
|
|
20
|
+
path: posixPath,
|
|
21
|
+
...parsedPath,
|
|
22
|
+
dirpath: parsedPath.dir,
|
|
23
|
+
dirbase: parsedDir.base,
|
|
24
|
+
dirname: parsedDir.name,
|
|
25
|
+
dirext: parsedDir.ext
|
|
26
|
+
};
|
|
27
|
+
values.path = posixPath;
|
|
28
|
+
for (const condition of conditionList) if (_isMatching(values.path, values, condition, options)) return true;
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
function _isMatching(value, values, condition, options) {
|
|
32
|
+
if (isString(condition)) {
|
|
33
|
+
if (value.includes(condition)) return true;
|
|
34
|
+
} else if (condition instanceof RegExp) {
|
|
35
|
+
if (condition.test(value)) return true;
|
|
36
|
+
} else if (isFunction(condition)) return condition(values, options.conditionOptions ?? {});
|
|
37
|
+
else {
|
|
38
|
+
const { valueType = "path", entryType = "both", conditions } = condition;
|
|
39
|
+
if (entryType !== "both") {
|
|
40
|
+
const stat = fs.statSync(values.path);
|
|
41
|
+
if (stat.isDirectory() && entryType !== "dir" || stat.isFile() && entryType !== "file") return false;
|
|
42
|
+
}
|
|
43
|
+
return (Array.isArray(conditions) ? conditions : [conditions]).every((cond) => _isMatching(values[valueType], values, cond, options));
|
|
44
|
+
}
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
//#endregion
|
|
49
|
+
export { isMatchingPath as default };
|
|
50
|
+
//# sourceMappingURL=isMatchingPath.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isMatchingPath.mjs","names":["path"],"sources":["../../src/isMatchingPath/isMatchingPath.ts"],"sourcesContent":["import fs from 'fs-extra';\r\nimport { posix as path } from 'path';\r\nimport { isFunction, isString } from 'remeda';\r\nimport type {\r\n ConditionFnOptions,\r\n ConditionValues,\r\n IsMatchingPathCondition,\r\n IsMatchingPathOptions,\r\n} from './types';\r\n\r\n/**\r\n * 処理対象のパスか判定する\r\n * @param targetPath 検査対象のパス\r\n * @param conditions 一致条件\r\n * @param options オプション\r\n * @returns 一致するか\r\n */\r\nexport default function isMatchingPath<\r\n O extends ConditionFnOptions = ConditionFnOptions,\r\n>(\r\n targetPath: string,\r\n conditions:\r\n | IsMatchingPathCondition<O>\r\n | IsMatchingPathCondition<O>[]\r\n | null\r\n | undefined,\r\n options: IsMatchingPathOptions<O> = {},\r\n) {\r\n if (!conditions) {\r\n return false;\r\n }\r\n const conditionList = Array.isArray(conditions) ? conditions : [conditions];\r\n // パスは'/'区切り\r\n const posixPath = path.normalize(targetPath);\r\n const parsedPath = path.parse(posixPath);\r\n const parsedDir = path.parse(parsedPath.dir);\r\n const values = {\r\n path: posixPath,\r\n ...parsedPath,\r\n dirpath: parsedPath.dir,\r\n dirbase: parsedDir.base,\r\n dirname: parsedDir.name,\r\n dirext: parsedDir.ext,\r\n };\r\n values.path = posixPath;\r\n\r\n for (const condition of conditionList) {\r\n if (_isMatching(values.path, values, condition, options)) {\r\n // conditionの内の何れかがtrueならば一致\r\n return true;\r\n }\r\n }\r\n return false;\r\n}\r\n\r\nfunction _isMatching<O extends ConditionFnOptions = ConditionFnOptions>(\r\n value: string,\r\n values: ConditionValues,\r\n condition: IsMatchingPathCondition<O>,\r\n options: IsMatchingPathOptions<O>,\r\n): boolean {\r\n if (isString(condition)) {\r\n // 条件が文字列\r\n if (value.includes(condition)) {\r\n return true;\r\n }\r\n } else if (condition instanceof RegExp) {\r\n // 条件が正規表現\r\n if (condition.test(value)) {\r\n return true;\r\n }\r\n } else if (isFunction(condition)) {\r\n // 条件が関数\r\n return condition(values, (options.conditionOptions ?? {}) as O);\r\n } else {\r\n // 条件が設定\r\n const { valueType = 'path', entryType = 'both', conditions } = condition;\r\n if (entryType !== 'both') {\r\n const stat = fs.statSync(values.path);\r\n if (\r\n (stat.isDirectory() && entryType !== 'dir') ||\r\n (stat.isFile() && entryType !== 'file')\r\n ) {\r\n return false;\r\n }\r\n }\r\n const conditionList = Array.isArray(conditions) ? conditions : [conditions];\r\n // 設定配下のconditionsはand条件\r\n return conditionList.every((cond) =>\r\n _isMatching(values[valueType], values, cond, options),\r\n );\r\n }\r\n return false;\r\n}\r\n"],"mappings":";;;;;;;;;;;;AAiBA,SAAwB,eAGtB,YACA,YAKA,UAAoC,EAAE,EACtC;AACA,KAAI,CAAC,WACH,QAAO;CAET,MAAM,gBAAgB,MAAM,QAAQ,WAAW,GAAG,aAAa,CAAC,WAAW;CAE3E,MAAM,YAAYA,MAAK,UAAU,WAAW;CAC5C,MAAM,aAAaA,MAAK,MAAM,UAAU;CACxC,MAAM,YAAYA,MAAK,MAAM,WAAW,IAAI;CAC5C,MAAM,SAAS;EACb,MAAM;EACN,GAAG;EACH,SAAS,WAAW;EACpB,SAAS,UAAU;EACnB,SAAS,UAAU;EACnB,QAAQ,UAAU;EACnB;AACD,QAAO,OAAO;AAEd,MAAK,MAAM,aAAa,cACtB,KAAI,YAAY,OAAO,MAAM,QAAQ,WAAW,QAAQ,CAEtD,QAAO;AAGX,QAAO;;AAGT,SAAS,YACP,OACA,QACA,WACA,SACS;AACT,KAAI,SAAS,UAAU,EAErB;MAAI,MAAM,SAAS,UAAU,CAC3B,QAAO;YAEA,qBAAqB,QAE9B;MAAI,UAAU,KAAK,MAAM,CACvB,QAAO;YAEA,WAAW,UAAU,CAE9B,QAAO,UAAU,QAAS,QAAQ,oBAAoB,EAAE,CAAO;MAC1D;EAEL,MAAM,EAAE,YAAY,QAAQ,YAAY,QAAQ,eAAe;AAC/D,MAAI,cAAc,QAAQ;GACxB,MAAM,OAAO,GAAG,SAAS,OAAO,KAAK;AACrC,OACG,KAAK,aAAa,IAAI,cAAc,SACpC,KAAK,QAAQ,IAAI,cAAc,OAEhC,QAAO;;AAKX,UAFsB,MAAM,QAAQ,WAAW,GAAG,aAAa,CAAC,WAAW,EAEtD,OAAO,SAC1B,YAAY,OAAO,YAAY,QAAQ,MAAM,QAAQ,CACtD;;AAEH,QAAO"}
|
|
File without changes
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { ParsedPath } from "path";
|
|
2
|
+
|
|
3
|
+
//#region src/isMatchingPath/types.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* 一致条件
|
|
6
|
+
*
|
|
7
|
+
* - string: 指定された文字列がパスに含まれているものに一致する際にtrue
|
|
8
|
+
* - RegExp: 指定された正規表現にパスが一致する際にtrue
|
|
9
|
+
* - ConditionConfig: 条件設定に従って検査し一致したときにtrue
|
|
10
|
+
*/
|
|
11
|
+
type IsMatchingPathCondition<O extends ConditionFnOptions = ConditionFnOptions> = string | RegExp | ConditionConfig<O> | ConditionFn<O>;
|
|
12
|
+
type IsMatchingPathOptions<O extends ConditionFnOptions = ConditionFnOptions> = {
|
|
13
|
+
/**
|
|
14
|
+
* ConditionFnに渡すオプション
|
|
15
|
+
*/
|
|
16
|
+
conditionOptions?: O;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* 条件設定
|
|
20
|
+
*/
|
|
21
|
+
type ConditionConfig<O extends ConditionFnOptions = ConditionFnOptions> = {
|
|
22
|
+
/**
|
|
23
|
+
* 検査対象の値
|
|
24
|
+
*
|
|
25
|
+
* - path: '/'で区切られたフルパス
|
|
26
|
+
* - base: 拡張子付きのディレクトリ名 or ファイル名
|
|
27
|
+
* - name: 拡張子を除いたディレクトリ名 or ファイル名
|
|
28
|
+
* - ext: '.'を含む拡張子。拡張子が無い場合は空文字
|
|
29
|
+
* - dirpath: '/'で区切られた親ディレクトリのフルパス
|
|
30
|
+
* - base: 拡張子付きの親ディレクトリ名
|
|
31
|
+
* - name: 拡張子を除いた親ディレクトリ名
|
|
32
|
+
* - ext: '.'を含む親ディレクトリの拡張子。拡張子が無い場合は空文字
|
|
33
|
+
*/
|
|
34
|
+
valueType?: 'path' | 'base' | 'name' | 'ext' | 'dirpath' | 'dirbase' | 'dirname' | 'dirext';
|
|
35
|
+
/**
|
|
36
|
+
* 検査対象の種別
|
|
37
|
+
*
|
|
38
|
+
* - dir: ディレクトリ
|
|
39
|
+
* - file: ファイル
|
|
40
|
+
* - both: ディレクトリ & ファイル
|
|
41
|
+
*/
|
|
42
|
+
entryType?: 'dir' | 'file' | 'both';
|
|
43
|
+
/**
|
|
44
|
+
* 一致条件
|
|
45
|
+
* 配列で指定した場合はand条件とする
|
|
46
|
+
*
|
|
47
|
+
* - string: 指定された文字列を含むものに一致
|
|
48
|
+
* - RegExp: 指定された正規表現に一致
|
|
49
|
+
*/
|
|
50
|
+
conditions: string | RegExp | ConditionFn<O> | (string | RegExp | ConditionFn<O>)[];
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* カスタム条件関数
|
|
54
|
+
*/
|
|
55
|
+
type ConditionFn<O extends ConditionFnOptions = ConditionFnOptions> = (values: ConditionValues, options: O) => boolean;
|
|
56
|
+
/**
|
|
57
|
+
* カスタム条件関数のオプション
|
|
58
|
+
*/
|
|
59
|
+
type ConditionFnOptions = Record<string, any>;
|
|
60
|
+
/**
|
|
61
|
+
* 検証対象の値
|
|
62
|
+
*/
|
|
63
|
+
type ConditionValues = {
|
|
64
|
+
path: string;
|
|
65
|
+
dirpath: string;
|
|
66
|
+
dirbase: string;
|
|
67
|
+
dirname: string;
|
|
68
|
+
dirext: string;
|
|
69
|
+
} & ParsedPath;
|
|
70
|
+
//#endregion
|
|
71
|
+
export { ConditionConfig, ConditionFn, ConditionFnOptions, ConditionValues, IsMatchingPathCondition, IsMatchingPathOptions };
|
|
72
|
+
//# sourceMappingURL=types.d.cts.map
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { ParsedPath } from "path";
|
|
2
|
+
|
|
3
|
+
//#region src/isMatchingPath/types.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* 一致条件
|
|
6
|
+
*
|
|
7
|
+
* - string: 指定された文字列がパスに含まれているものに一致する際にtrue
|
|
8
|
+
* - RegExp: 指定された正規表現にパスが一致する際にtrue
|
|
9
|
+
* - ConditionConfig: 条件設定に従って検査し一致したときにtrue
|
|
10
|
+
*/
|
|
11
|
+
type IsMatchingPathCondition<O extends ConditionFnOptions = ConditionFnOptions> = string | RegExp | ConditionConfig<O> | ConditionFn<O>;
|
|
12
|
+
type IsMatchingPathOptions<O extends ConditionFnOptions = ConditionFnOptions> = {
|
|
13
|
+
/**
|
|
14
|
+
* ConditionFnに渡すオプション
|
|
15
|
+
*/
|
|
16
|
+
conditionOptions?: O;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* 条件設定
|
|
20
|
+
*/
|
|
21
|
+
type ConditionConfig<O extends ConditionFnOptions = ConditionFnOptions> = {
|
|
22
|
+
/**
|
|
23
|
+
* 検査対象の値
|
|
24
|
+
*
|
|
25
|
+
* - path: '/'で区切られたフルパス
|
|
26
|
+
* - base: 拡張子付きのディレクトリ名 or ファイル名
|
|
27
|
+
* - name: 拡張子を除いたディレクトリ名 or ファイル名
|
|
28
|
+
* - ext: '.'を含む拡張子。拡張子が無い場合は空文字
|
|
29
|
+
* - dirpath: '/'で区切られた親ディレクトリのフルパス
|
|
30
|
+
* - base: 拡張子付きの親ディレクトリ名
|
|
31
|
+
* - name: 拡張子を除いた親ディレクトリ名
|
|
32
|
+
* - ext: '.'を含む親ディレクトリの拡張子。拡張子が無い場合は空文字
|
|
33
|
+
*/
|
|
34
|
+
valueType?: 'path' | 'base' | 'name' | 'ext' | 'dirpath' | 'dirbase' | 'dirname' | 'dirext';
|
|
35
|
+
/**
|
|
36
|
+
* 検査対象の種別
|
|
37
|
+
*
|
|
38
|
+
* - dir: ディレクトリ
|
|
39
|
+
* - file: ファイル
|
|
40
|
+
* - both: ディレクトリ & ファイル
|
|
41
|
+
*/
|
|
42
|
+
entryType?: 'dir' | 'file' | 'both';
|
|
43
|
+
/**
|
|
44
|
+
* 一致条件
|
|
45
|
+
* 配列で指定した場合はand条件とする
|
|
46
|
+
*
|
|
47
|
+
* - string: 指定された文字列を含むものに一致
|
|
48
|
+
* - RegExp: 指定された正規表現に一致
|
|
49
|
+
*/
|
|
50
|
+
conditions: string | RegExp | ConditionFn<O> | (string | RegExp | ConditionFn<O>)[];
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* カスタム条件関数
|
|
54
|
+
*/
|
|
55
|
+
type ConditionFn<O extends ConditionFnOptions = ConditionFnOptions> = (values: ConditionValues, options: O) => boolean;
|
|
56
|
+
/**
|
|
57
|
+
* カスタム条件関数のオプション
|
|
58
|
+
*/
|
|
59
|
+
type ConditionFnOptions = Record<string, any>;
|
|
60
|
+
/**
|
|
61
|
+
* 検証対象の値
|
|
62
|
+
*/
|
|
63
|
+
type ConditionValues = {
|
|
64
|
+
path: string;
|
|
65
|
+
dirpath: string;
|
|
66
|
+
dirbase: string;
|
|
67
|
+
dirname: string;
|
|
68
|
+
dirext: string;
|
|
69
|
+
} & ParsedPath;
|
|
70
|
+
//#endregion
|
|
71
|
+
export { ConditionConfig, ConditionFn, ConditionFnOptions, ConditionValues, IsMatchingPathCondition, IsMatchingPathOptions };
|
|
72
|
+
//# sourceMappingURL=types.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
2
|
+
const require_isMatchingPath_isMatchingPath = require('../isMatchingPath/isMatchingPath.cjs');
|
|
3
|
+
require('../isMatchingPath/index.cjs');
|
|
4
|
+
let fs_extra = require("fs-extra");
|
|
5
|
+
fs_extra = require_runtime.__toESM(fs_extra, 1);
|
|
6
|
+
|
|
7
|
+
//#region src/isTargetPath/isTargetPath.ts
|
|
8
|
+
const IS_TARGET_TYPE = {
|
|
9
|
+
file: (stat) => stat.isFile(),
|
|
10
|
+
dir: (stat) => stat.isDirectory(),
|
|
11
|
+
both: (stat) => stat.isFile() || stat.isDirectory()
|
|
12
|
+
};
|
|
13
|
+
async function isTargetPath(itemPath, options = {}) {
|
|
14
|
+
const { itemType = "file", defaultInclude, defaultExclude, include = defaultInclude, exclude = defaultExclude, ...rest } = options;
|
|
15
|
+
const stat = fs_extra.default.statSync(itemPath);
|
|
16
|
+
return IS_TARGET_TYPE[itemType](stat) && (!include || require_isMatchingPath_isMatchingPath(itemPath, include, rest)) && (!exclude || !require_isMatchingPath_isMatchingPath(itemPath, exclude, rest));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
//#endregion
|
|
20
|
+
module.exports = isTargetPath;
|
|
21
|
+
//# sourceMappingURL=isTargetPath.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isTargetPath.cjs","names":["fs","isMatchingPath"],"sources":["../../src/isTargetPath/isTargetPath.ts"],"sourcesContent":["import fs, { Stats } from 'fs-extra';\r\nimport type { ConditionFnOptions } from '../isMatchingPath';\r\nimport isMatchingPath from '../isMatchingPath';\r\nimport type { IsTargetPathOptions } from './types';\r\n\r\nconst IS_TARGET_TYPE = {\r\n file: (stat: Stats) => stat.isFile(),\r\n dir: (stat: Stats) => stat.isDirectory(),\r\n both: (stat: Stats) => stat.isFile() || stat.isDirectory(),\r\n} as const;\r\n\r\nexport default async function isTargetPath<\r\n O extends ConditionFnOptions = ConditionFnOptions,\r\n>(itemPath: string, options: IsTargetPathOptions<O> = {}) {\r\n const {\r\n itemType = 'file',\r\n defaultInclude,\r\n defaultExclude,\r\n include = defaultInclude,\r\n exclude = defaultExclude,\r\n ...rest\r\n } = options;\r\n const stat = fs.statSync(itemPath);\r\n\r\n return (\r\n IS_TARGET_TYPE[itemType](stat) &&\r\n (!include || isMatchingPath(itemPath, include, rest)) &&\r\n (!exclude || !isMatchingPath(itemPath, exclude, rest))\r\n );\r\n}\r\n"],"mappings":";;;;;;;AAKA,MAAM,iBAAiB;CACrB,OAAO,SAAgB,KAAK,QAAQ;CACpC,MAAM,SAAgB,KAAK,aAAa;CACxC,OAAO,SAAgB,KAAK,QAAQ,IAAI,KAAK,aAAa;CAC3D;AAED,eAA8B,aAE5B,UAAkB,UAAkC,EAAE,EAAE;CACxD,MAAM,EACJ,WAAW,QACX,gBACA,gBACA,UAAU,gBACV,UAAU,gBACV,GAAG,SACD;CACJ,MAAM,OAAOA,iBAAG,SAAS,SAAS;AAElC,QACE,eAAe,UAAU,KAAK,KAC7B,CAAC,WAAWC,sCAAe,UAAU,SAAS,KAAK,MACnD,CAAC,WAAW,CAACA,sCAAe,UAAU,SAAS,KAAK"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ConditionFnOptions } from "../isMatchingPath/types.cjs";
|
|
2
|
+
import { IsTargetPathOptions } from "./types.cjs";
|
|
3
|
+
|
|
4
|
+
//#region src/isTargetPath/isTargetPath.d.ts
|
|
5
|
+
declare function isTargetPath<O extends ConditionFnOptions = ConditionFnOptions>(itemPath: string, options?: IsTargetPathOptions<O>): Promise<boolean>;
|
|
6
|
+
export = isTargetPath;
|
|
7
|
+
//# sourceMappingURL=isTargetPath.d.cts.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ConditionFnOptions } from "../isMatchingPath/types.mjs";
|
|
2
|
+
import { IsTargetPathOptions } from "./types.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/isTargetPath/isTargetPath.d.ts
|
|
5
|
+
declare function isTargetPath<O extends ConditionFnOptions = ConditionFnOptions>(itemPath: string, options?: IsTargetPathOptions<O>): Promise<boolean>;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { isTargetPath as default };
|
|
8
|
+
//# sourceMappingURL=isTargetPath.d.mts.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import isMatchingPath from "../isMatchingPath/isMatchingPath.mjs";
|
|
2
|
+
import "../isMatchingPath/index.mjs";
|
|
3
|
+
import fs from "fs-extra";
|
|
4
|
+
|
|
5
|
+
//#region src/isTargetPath/isTargetPath.ts
|
|
6
|
+
const IS_TARGET_TYPE = {
|
|
7
|
+
file: (stat) => stat.isFile(),
|
|
8
|
+
dir: (stat) => stat.isDirectory(),
|
|
9
|
+
both: (stat) => stat.isFile() || stat.isDirectory()
|
|
10
|
+
};
|
|
11
|
+
async function isTargetPath(itemPath, options = {}) {
|
|
12
|
+
const { itemType = "file", defaultInclude, defaultExclude, include = defaultInclude, exclude = defaultExclude, ...rest } = options;
|
|
13
|
+
const stat = fs.statSync(itemPath);
|
|
14
|
+
return IS_TARGET_TYPE[itemType](stat) && (!include || isMatchingPath(itemPath, include, rest)) && (!exclude || !isMatchingPath(itemPath, exclude, rest));
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
export { isTargetPath as default };
|
|
19
|
+
//# sourceMappingURL=isTargetPath.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isTargetPath.mjs","names":[],"sources":["../../src/isTargetPath/isTargetPath.ts"],"sourcesContent":["import fs, { Stats } from 'fs-extra';\r\nimport type { ConditionFnOptions } from '../isMatchingPath';\r\nimport isMatchingPath from '../isMatchingPath';\r\nimport type { IsTargetPathOptions } from './types';\r\n\r\nconst IS_TARGET_TYPE = {\r\n file: (stat: Stats) => stat.isFile(),\r\n dir: (stat: Stats) => stat.isDirectory(),\r\n both: (stat: Stats) => stat.isFile() || stat.isDirectory(),\r\n} as const;\r\n\r\nexport default async function isTargetPath<\r\n O extends ConditionFnOptions = ConditionFnOptions,\r\n>(itemPath: string, options: IsTargetPathOptions<O> = {}) {\r\n const {\r\n itemType = 'file',\r\n defaultInclude,\r\n defaultExclude,\r\n include = defaultInclude,\r\n exclude = defaultExclude,\r\n ...rest\r\n } = options;\r\n const stat = fs.statSync(itemPath);\r\n\r\n return (\r\n IS_TARGET_TYPE[itemType](stat) &&\r\n (!include || isMatchingPath(itemPath, include, rest)) &&\r\n (!exclude || !isMatchingPath(itemPath, exclude, rest))\r\n );\r\n}\r\n"],"mappings":";;;;;AAKA,MAAM,iBAAiB;CACrB,OAAO,SAAgB,KAAK,QAAQ;CACpC,MAAM,SAAgB,KAAK,aAAa;CACxC,OAAO,SAAgB,KAAK,QAAQ,IAAI,KAAK,aAAa;CAC3D;AAED,eAA8B,aAE5B,UAAkB,UAAkC,EAAE,EAAE;CACxD,MAAM,EACJ,WAAW,QACX,gBACA,gBACA,UAAU,gBACV,UAAU,gBACV,GAAG,SACD;CACJ,MAAM,OAAO,GAAG,SAAS,SAAS;AAElC,QACE,eAAe,UAAU,KAAK,KAC7B,CAAC,WAAW,eAAe,UAAU,SAAS,KAAK,MACnD,CAAC,WAAW,CAAC,eAAe,UAAU,SAAS,KAAK"}
|
|
File without changes
|
|
@@ -1,38 +1,33 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
*
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
*
|
|
17
|
-
* 未指定の場合は`
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
*
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
* 対象から除外する条件のデフォルト
|
|
35
|
-
* 未指定の場合は除外なし
|
|
36
|
-
*/
|
|
37
|
-
defaultExclude?: IsMatchingPathCondition<O>[];
|
|
38
|
-
};
|
|
1
|
+
import { ConditionFnOptions, IsMatchingPathCondition } from "../isMatchingPath/types.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/isTargetPath/types.d.ts
|
|
4
|
+
type IsTargetPathOptions<O extends ConditionFnOptions = ConditionFnOptions> = {
|
|
5
|
+
/**
|
|
6
|
+
* 対象の種別
|
|
7
|
+
* @default 'file'
|
|
8
|
+
*/
|
|
9
|
+
itemType?: 'file' | 'dir' | 'both';
|
|
10
|
+
/**
|
|
11
|
+
* 対象とする条件
|
|
12
|
+
* 未指定の場合は`defaultInclude`が適用される
|
|
13
|
+
*/
|
|
14
|
+
include?: IsMatchingPathCondition<O>[];
|
|
15
|
+
/**
|
|
16
|
+
* 対象から除外する条件
|
|
17
|
+
* 未指定の場合は`defaultExclude`が適用される
|
|
18
|
+
*/
|
|
19
|
+
exclude?: IsMatchingPathCondition<O>[];
|
|
20
|
+
/**
|
|
21
|
+
* 対象とする条件のデフォルト
|
|
22
|
+
* 未指定の場合は条件なし
|
|
23
|
+
*/
|
|
24
|
+
defaultInclude?: IsMatchingPathCondition<O>[];
|
|
25
|
+
/**
|
|
26
|
+
* 対象から除外する条件のデフォルト
|
|
27
|
+
* 未指定の場合は除外なし
|
|
28
|
+
*/
|
|
29
|
+
defaultExclude?: IsMatchingPathCondition<O>[];
|
|
30
|
+
};
|
|
31
|
+
//#endregion
|
|
32
|
+
export { IsTargetPathOptions };
|
|
33
|
+
//# sourceMappingURL=types.d.cts.map
|