@niche-works/dev 0.4.1 → 0.4.2

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.
Files changed (214) hide show
  1. package/_virtual/_rolldown/runtime.cjs +29 -0
  2. package/addExports/addExports.cjs +61 -0
  3. package/addExports/addExports.cjs.map +1 -0
  4. package/addExports/addExports.d.cts +11 -0
  5. package/addExports/addExports.d.mts +12 -0
  6. package/addExports/addExports.mjs +59 -0
  7. package/addExports/addExports.mjs.map +1 -0
  8. package/addExports/index.cjs +3 -0
  9. package/addExports/index.d.cts +3 -0
  10. package/addExports/index.d.mts +3 -0
  11. package/addExports/index.mjs +3 -0
  12. package/addExports/types.cjs +0 -0
  13. package/{src/addExports/types.ts → addExports/types.d.cts} +33 -33
  14. package/addExports/types.d.mts +33 -0
  15. package/addExports/types.mjs +1 -0
  16. package/addJsExtensions/addJsExtensions.cjs +31 -0
  17. package/addJsExtensions/addJsExtensions.cjs.map +1 -0
  18. package/addJsExtensions/addJsExtensions.d.cts +8 -0
  19. package/addJsExtensions/addJsExtensions.d.mts +9 -0
  20. package/addJsExtensions/addJsExtensions.mjs +28 -0
  21. package/addJsExtensions/addJsExtensions.mjs.map +1 -0
  22. package/addJsExtensions/index.cjs +3 -0
  23. package/addJsExtensions/index.d.cts +2 -0
  24. package/addJsExtensions/index.d.mts +2 -0
  25. package/addJsExtensions/index.mjs +3 -0
  26. package/checkExistence/checkExistence.cjs +23 -0
  27. package/checkExistence/checkExistence.cjs.map +1 -0
  28. package/checkExistence/checkExistence.d.cts +9 -0
  29. package/checkExistence/checkExistence.d.mts +10 -0
  30. package/checkExistence/checkExistence.mjs +21 -0
  31. package/checkExistence/checkExistence.mjs.map +1 -0
  32. package/checkExistence/index.cjs +3 -0
  33. package/checkExistence/index.d.cts +2 -0
  34. package/checkExistence/index.d.mts +2 -0
  35. package/checkExistence/index.mjs +3 -0
  36. package/createExternalOptionFunction/createExternalOptionFunction.cjs +25 -0
  37. package/createExternalOptionFunction/createExternalOptionFunction.cjs.map +1 -0
  38. package/createExternalOptionFunction/createExternalOptionFunction.d.cts +10 -0
  39. package/createExternalOptionFunction/createExternalOptionFunction.d.mts +11 -0
  40. package/createExternalOptionFunction/createExternalOptionFunction.mjs +25 -0
  41. package/createExternalOptionFunction/createExternalOptionFunction.mjs.map +1 -0
  42. package/createExternalOptionFunction/index.cjs +3 -0
  43. package/createExternalOptionFunction/index.d.cts +2 -0
  44. package/createExternalOptionFunction/index.d.mts +2 -0
  45. package/createExternalOptionFunction/index.mjs +3 -0
  46. package/createExternalOptionFunction/types.cjs +0 -0
  47. package/{src/createExternalOptionFunction/types.ts → createExternalOptionFunction/types.d.cts} +31 -34
  48. package/createExternalOptionFunction/types.d.mts +31 -0
  49. package/createExternalOptionFunction/types.mjs +1 -0
  50. package/editJsonFile/editJsonFile.cjs +29 -0
  51. package/editJsonFile/editJsonFile.cjs.map +1 -0
  52. package/editJsonFile/editJsonFile.d.cts +9 -0
  53. package/editJsonFile/editJsonFile.d.mts +10 -0
  54. package/editJsonFile/editJsonFile.mjs +26 -0
  55. package/editJsonFile/editJsonFile.mjs.map +1 -0
  56. package/editJsonFile/index.cjs +3 -0
  57. package/editJsonFile/index.d.cts +2 -0
  58. package/editJsonFile/index.d.mts +2 -0
  59. package/editJsonFile/index.mjs +3 -0
  60. package/generatePublishPackageJson/generatePublishPackageJson.cjs +46 -0
  61. package/generatePublishPackageJson/generatePublishPackageJson.cjs.map +1 -0
  62. package/generatePublishPackageJson/generatePublishPackageJson.d.cts +6 -0
  63. package/generatePublishPackageJson/generatePublishPackageJson.d.mts +7 -0
  64. package/generatePublishPackageJson/generatePublishPackageJson.mjs +44 -0
  65. package/generatePublishPackageJson/generatePublishPackageJson.mjs.map +1 -0
  66. package/generatePublishPackageJson/index.cjs +3 -0
  67. package/generatePublishPackageJson/index.d.cts +3 -0
  68. package/generatePublishPackageJson/index.d.mts +3 -0
  69. package/generatePublishPackageJson/index.mjs +3 -0
  70. package/generatePublishPackageJson/types.cjs +0 -0
  71. package/{src/generatePublishPackageJson/types.ts → generatePublishPackageJson/types.d.cts} +60 -61
  72. package/generatePublishPackageJson/types.d.mts +60 -0
  73. package/generatePublishPackageJson/types.mjs +1 -0
  74. package/index.cjs +38 -0
  75. package/index.d.cts +13 -0
  76. package/index.d.mts +13 -0
  77. package/index.mjs +26 -0
  78. package/indexes/constants.cjs +123 -0
  79. package/indexes/constants.cjs.map +1 -0
  80. package/indexes/constants.d.cts +66 -0
  81. package/indexes/constants.d.mts +66 -0
  82. package/indexes/constants.mjs +106 -0
  83. package/indexes/constants.mjs.map +1 -0
  84. package/indexes/index.cjs +3 -0
  85. package/indexes/index.d.cts +3 -0
  86. package/indexes/index.d.mts +3 -0
  87. package/indexes/index.mjs +3 -0
  88. package/indexes/indexes.cjs +125 -0
  89. package/indexes/indexes.cjs.map +1 -0
  90. package/indexes/indexes.d.cts +11 -0
  91. package/indexes/indexes.d.mts +12 -0
  92. package/indexes/indexes.mjs +123 -0
  93. package/indexes/indexes.mjs.map +1 -0
  94. package/indexes/types.cjs +0 -0
  95. package/{src/indexes/types.ts → indexes/types.d.cts} +81 -87
  96. package/indexes/types.d.mts +81 -0
  97. package/indexes/types.mjs +1 -0
  98. package/installFromLocal/index.cjs +3 -0
  99. package/installFromLocal/index.d.cts +3 -0
  100. package/installFromLocal/index.d.mts +3 -0
  101. package/installFromLocal/index.mjs +3 -0
  102. package/installFromLocal/installFromLocal.cjs +46 -0
  103. package/installFromLocal/installFromLocal.cjs.map +1 -0
  104. package/installFromLocal/installFromLocal.d.cts +11 -0
  105. package/installFromLocal/installFromLocal.d.mts +12 -0
  106. package/installFromLocal/installFromLocal.mjs +43 -0
  107. package/installFromLocal/installFromLocal.mjs.map +1 -0
  108. package/installFromLocal/types.cjs +0 -0
  109. package/{src/installFromLocal/types.ts → installFromLocal/types.d.cts} +21 -19
  110. package/installFromLocal/types.d.mts +21 -0
  111. package/installFromLocal/types.mjs +1 -0
  112. package/isMatchingPath/index.cjs +3 -0
  113. package/isMatchingPath/index.d.cts +3 -0
  114. package/isMatchingPath/index.d.mts +3 -0
  115. package/isMatchingPath/index.mjs +3 -0
  116. package/isMatchingPath/isMatchingPath.cjs +52 -0
  117. package/isMatchingPath/isMatchingPath.cjs.map +1 -0
  118. package/isMatchingPath/isMatchingPath.d.cts +13 -0
  119. package/isMatchingPath/isMatchingPath.d.mts +14 -0
  120. package/isMatchingPath/isMatchingPath.mjs +50 -0
  121. package/isMatchingPath/isMatchingPath.mjs.map +1 -0
  122. package/isMatchingPath/types.cjs +0 -0
  123. package/isMatchingPath/types.d.cts +72 -0
  124. package/isMatchingPath/types.d.mts +72 -0
  125. package/isMatchingPath/types.mjs +1 -0
  126. package/isTargetPath/index.cjs +3 -0
  127. package/isTargetPath/index.d.cts +3 -0
  128. package/isTargetPath/index.d.mts +3 -0
  129. package/isTargetPath/index.mjs +3 -0
  130. package/isTargetPath/isTargetPath.cjs +21 -0
  131. package/isTargetPath/isTargetPath.cjs.map +1 -0
  132. package/isTargetPath/isTargetPath.d.cts +7 -0
  133. package/isTargetPath/isTargetPath.d.mts +8 -0
  134. package/isTargetPath/isTargetPath.mjs +19 -0
  135. package/isTargetPath/isTargetPath.mjs.map +1 -0
  136. package/isTargetPath/types.cjs +0 -0
  137. package/{src/isTargetPath/types.ts → isTargetPath/types.d.cts} +33 -38
  138. package/isTargetPath/types.d.mts +33 -0
  139. package/isTargetPath/types.mjs +1 -0
  140. package/moveFilesToSubdir/index.cjs +3 -0
  141. package/moveFilesToSubdir/index.d.cts +3 -0
  142. package/moveFilesToSubdir/index.d.mts +3 -0
  143. package/moveFilesToSubdir/index.mjs +3 -0
  144. package/moveFilesToSubdir/moveFilesToSubdir.cjs +32 -0
  145. package/moveFilesToSubdir/moveFilesToSubdir.cjs.map +1 -0
  146. package/moveFilesToSubdir/moveFilesToSubdir.d.cts +10 -0
  147. package/moveFilesToSubdir/moveFilesToSubdir.d.mts +11 -0
  148. package/moveFilesToSubdir/moveFilesToSubdir.mjs +29 -0
  149. package/moveFilesToSubdir/moveFilesToSubdir.mjs.map +1 -0
  150. package/moveFilesToSubdir/types.cjs +0 -0
  151. package/{src/moveFilesToSubdir/types.ts → moveFilesToSubdir/types.d.cts} +18 -15
  152. package/moveFilesToSubdir/types.d.mts +18 -0
  153. package/moveFilesToSubdir/types.mjs +1 -0
  154. package/package.json +20 -29
  155. package/removeFiles/index.cjs +3 -0
  156. package/removeFiles/index.d.cts +2 -0
  157. package/removeFiles/index.d.mts +2 -0
  158. package/removeFiles/index.mjs +3 -0
  159. package/removeFiles/removeFiles.cjs +15 -0
  160. package/removeFiles/removeFiles.cjs.map +1 -0
  161. package/removeFiles/removeFiles.d.cts +6 -0
  162. package/removeFiles/removeFiles.d.mts +7 -0
  163. package/removeFiles/removeFiles.mjs +12 -0
  164. package/removeFiles/removeFiles.mjs.map +1 -0
  165. package/removeFiles/types.cjs +0 -0
  166. package/removeFiles/types.d.cts +9 -0
  167. package/removeFiles/types.d.mts +9 -0
  168. package/removeFiles/types.mjs +1 -0
  169. package/ver/index.cjs +3 -0
  170. package/ver/index.d.cts +3 -0
  171. package/ver/index.d.mts +3 -0
  172. package/ver/index.mjs +3 -0
  173. package/ver/types.cjs +0 -0
  174. package/{src/ver/types.ts → ver/types.d.cts} +16 -13
  175. package/ver/types.d.mts +16 -0
  176. package/ver/types.mjs +1 -0
  177. package/ver/ver.cjs +34 -0
  178. package/ver/ver.cjs.map +1 -0
  179. package/ver/ver.d.cts +11 -0
  180. package/ver/ver.d.mts +12 -0
  181. package/ver/ver.mjs +31 -0
  182. package/ver/ver.mjs.map +1 -0
  183. package/src/addExports/addExports.ts +0 -94
  184. package/src/addExports/index.ts +0 -2
  185. package/src/addJsExtensions/addJsExtensions.ts +0 -30
  186. package/src/addJsExtensions/index.ts +0 -1
  187. package/src/checkExistence/checkExistence.ts +0 -16
  188. package/src/checkExistence/index.ts +0 -1
  189. package/src/createExternalOptionFunction/createExternalOptionFunction.ts +0 -43
  190. package/src/createExternalOptionFunction/index.ts +0 -1
  191. package/src/editJsonFile/editJsonFile.ts +0 -30
  192. package/src/editJsonFile/index.ts +0 -1
  193. package/src/generatePublishPackageJson/generatePublishPackageJson.ts +0 -55
  194. package/src/generatePublishPackageJson/index.ts +0 -2
  195. package/src/index.ts +0 -11
  196. package/src/indexes/constants.ts +0 -135
  197. package/src/indexes/index.ts +0 -2
  198. package/src/indexes/indexes.ts +0 -194
  199. package/src/installFromLocal/index.ts +0 -2
  200. package/src/installFromLocal/installFromLocal.ts +0 -63
  201. package/src/isMatchingPath/index.ts +0 -2
  202. package/src/isMatchingPath/isMatchingPath.ts +0 -94
  203. package/src/isMatchingPath/types.ts +0 -95
  204. package/src/isTargetPath/index.ts +0 -2
  205. package/src/isTargetPath/isTargetPath.ts +0 -30
  206. package/src/moveFilesToSubdir/index.ts +0 -2
  207. package/src/moveFilesToSubdir/moveFilesToSubdir.ts +0 -40
  208. package/src/removeFiles/index.ts +0 -1
  209. package/src/removeFiles/removeFiles.ts +0 -11
  210. package/src/removeFiles/types.ts +0 -5
  211. package/src/ver/index.ts +0 -2
  212. package/src/ver/ver.ts +0 -38
  213. package/tsconfig.json +0 -46
  214. package/tsdown.config.ts +0 -41
@@ -1,55 +0,0 @@
1
- import fs from 'fs-extra';
2
- import type { GeneratePublishPackageJsonOptions } from './types';
3
-
4
- async function generatePublishPackageJson(
5
- options: GeneratePublishPackageJsonOptions = {},
6
- ) {
7
- const {
8
- packageJsonPath = './package.json',
9
- outputPackageJsonPath = './dist/package.json',
10
- exports = {
11
- '.': {
12
- import: './index.js',
13
- reqire: './index.cjs',
14
- type: './index.d.ts',
15
- },
16
- './*': {
17
- import: './*/index.js',
18
- reqire: './*/index.cjs',
19
- type: './*/index.d.ts',
20
- },
21
- './constants': {
22
- import: './constants.js',
23
- reqire: './constants.cjs',
24
- type: './constants.d.ts',
25
- },
26
- './*/constants': {
27
- import: './*/constants.js',
28
- reqire: './*/constants.cjs',
29
- type: './*/constants.d.ts',
30
- },
31
- },
32
- transform = (pkgJson) => pkgJson,
33
- jsonReadOptions,
34
- jsonWriteOptions,
35
- } = options;
36
- const packageJson = await fs.readJSON(packageJsonPath, jsonReadOptions);
37
- const distPackageJson = {
38
- name: packageJson.name,
39
- version: packageJson.version,
40
- keywords: packageJson.keywords,
41
- repository: packageJson.repository,
42
- license: packageJson.license,
43
- author: packageJson.author,
44
- type: packageJson.type,
45
- exports,
46
- dependencies: packageJson.dependencies,
47
- };
48
- await fs.writeJSON(
49
- outputPackageJsonPath,
50
- transform(distPackageJson),
51
- jsonWriteOptions,
52
- );
53
- }
54
-
55
- export default generatePublishPackageJson;
@@ -1,2 +0,0 @@
1
- export { default } from './generatePublishPackageJson';
2
- export type * from './types';
package/src/index.ts DELETED
@@ -1,11 +0,0 @@
1
- export { default as addExports } from './addExports';
2
- export { default as addJsExtensions } from './addJsExtensions';
3
- export { default as checkExistence } from './checkExistence';
4
- export { default as editJsonFile } from './editJsonFile';
5
- export { default as generatePublishPackageJson } from './generatePublishPackageJson';
6
- export { default as indexes } from './indexes';
7
- export { default as installFromLocal } from './installFromLocal';
8
- export { default as isMatchingPath } from './isMatchingPath';
9
- export { default as moveFilesToSubdir } from './moveFilesToSubdir';
10
- export { default as removeFiles } from './removeFiles';
11
- export { default as ver } from './ver';
@@ -1,135 +0,0 @@
1
- import fs from 'fs-extra';
2
- import type { IsMatchingPathCondition } from '../isMatchingPath';
3
-
4
- /**
5
- * types.ts
6
- */
7
- export const TYPES: IsMatchingPathCondition = {
8
- valueType: 'base',
9
- entryType: 'file',
10
- conditions: /^types.ts$/i,
11
- };
12
-
13
- /**
14
- * constants.ts
15
- */
16
- export const CONSTANTS: IsMatchingPathCondition = {
17
- valueType: 'base',
18
- entryType: 'file',
19
- conditions: /^constants.(ts|tsx)$/i,
20
- };
21
-
22
- /**
23
- * TypeScriptとJavaScript
24
- */
25
- export const TS_JS: IsMatchingPathCondition = {
26
- valueType: 'base',
27
- entryType: 'file',
28
- conditions: /.+\.(ts|tsx|js|jsx)$/i,
29
- };
30
-
31
- /**
32
- * 配下にindexファイルのあるディレクトリ
33
- */
34
- export const HAS_INDEX_DIR: IsMatchingPathCondition = {
35
- entryType: 'dir',
36
- conditions: (values, { indexRegex }) => {
37
- const items = fs.readdirSync(values.path);
38
- for (const item of items) {
39
- if (indexRegex.test(item)) {
40
- return true;
41
- }
42
- }
43
- return false;
44
- },
45
- };
46
-
47
- /**
48
- * テストディレクトリ配下
49
- */
50
- export const TEST_DIR: IsMatchingPathCondition = {
51
- valueType: 'path',
52
- conditions: /.+\/__test__\/.+/i,
53
- };
54
-
55
- /**
56
- * ファイル名またはディレクトリ名が`_`で始まる
57
- */
58
- export const TEST_FILE: IsMatchingPathCondition = {
59
- valueType: 'base',
60
- conditions: /.*\.test\.(ts|tsx|js|jsx)$/i,
61
- };
62
-
63
- /**
64
- * ファイル名またはディレクトリ名が`_`で始まる
65
- */
66
- export const PRIVATE: IsMatchingPathCondition = {
67
- valueType: 'base',
68
- conditions: /^_/,
69
- };
70
-
71
- /**
72
- * 拡張子を除いたファイル名が親ディレクトリ名と同じ
73
- */
74
- export const MAIN_FILE: IsMatchingPathCondition = {
75
- entryType: 'file',
76
- conditions: (values) => {
77
- return values.name === values.dirbase;
78
- },
79
- };
80
-
81
- /**
82
- * ツール類の入ったディレクトリ
83
- */
84
- export const TOOLS_DIR: IsMatchingPathCondition = {
85
- entryType: 'dir',
86
- conditions: (values, { children }) => {
87
- const { base } = values;
88
- return (
89
- // 先頭が小文字
90
- base[0] === base[0].toLowerCase() &&
91
- // 子要素にディレクトリと同じ名称のファイルが無い
92
- children?.every((child: string) => child.split('.')[0] !== base)
93
- );
94
- },
95
- };
96
-
97
- /**
98
- * includeのデフォルト値
99
- */
100
- export const DEFAULT_INCLUDE = [
101
- // TypeScript,JavaScriptのファイルを対象
102
- TS_JS,
103
- // 配下にindex.tsを持つディレクトリを対象
104
- HAS_INDEX_DIR,
105
- ];
106
-
107
- /**
108
- * excludeのデフォルト値
109
- */
110
- export const DEFAULT_EXCLUDE = [
111
- // __test__フォルダ配下の全てを除外
112
- TEST_DIR,
113
- // ディレクトリ名、ファイル名が_で始まるものを除外
114
- PRIVATE,
115
- ];
116
-
117
- /**
118
- * exportTypeAllのデフォルト値
119
- */
120
- export const DEFAULT_EXPORT_TYPE_ALL = [TYPES];
121
-
122
- /**
123
- * exportAllのデフォルト値
124
- */
125
- export const DEFAULT_EXPORT_ALL = [CONSTANTS];
126
-
127
- /**
128
- * exportDefaultのデフォルト値
129
- */
130
- export const DEFAULT_EXPORT_DEFAULT = [MAIN_FILE];
131
-
132
- /**
133
- * exportAllAsのデフォルト値
134
- */
135
- export const DEFAULT_EXPORT_ALL_AS = [TOOLS_DIR];
@@ -1,2 +0,0 @@
1
- export { default } from './indexes';
2
- export type * from './types';
@@ -1,194 +0,0 @@
1
- import fs from 'fs-extra';
2
- import { posix as path } from 'path';
3
- import isMatchingPath from '../isMatchingPath';
4
- import {
5
- DEFAULT_EXCLUDE,
6
- DEFAULT_EXPORT_ALL,
7
- DEFAULT_EXPORT_ALL_AS,
8
- DEFAULT_EXPORT_DEFAULT,
9
- DEFAULT_EXPORT_TYPE_ALL,
10
- DEFAULT_INCLUDE,
11
- } from './constants';
12
- import type { IndexesOptions } from './types';
13
-
14
- const EXPORTS = {
15
- exportAll: {
16
- type: 'named',
17
- generate: (name: string) => `export * from './${name}';`,
18
- },
19
- exportAllAs: {
20
- type: 'named',
21
- generate: (name: string) => `export * as ${name} from './${name}';`,
22
- },
23
- exportDefault: {
24
- type: 'default',
25
- generate: (name: string) => `export { default } from './${name}';`,
26
- },
27
- exportDefaultAs: {
28
- type: 'named',
29
- generate: (name: string) =>
30
- `export { default as ${name} } from './${name}';`,
31
- },
32
- exportTypeAll: {
33
- type: 'type',
34
- generate: (name: string) => `export type * from './${name}';`,
35
- },
36
- } as const;
37
-
38
- /**
39
- * 対象のディレクトリ配下のindexファイルを作成する\
40
- * 対象ファイルで出力形式が特に指定されていない場合は下記の形式で出力\
41
- * `export { default as ${name} } from './${name}';`
42
- */
43
- export default function indexes(options: IndexesOptions = {}) {
44
- const {
45
- srcPath = 'src',
46
- indexFileName = 'index.ts',
47
- include = DEFAULT_INCLUDE,
48
- exclude = DEFAULT_EXCLUDE,
49
- exportAll = DEFAULT_EXPORT_ALL,
50
- exportAllAs = DEFAULT_EXPORT_ALL_AS,
51
- exportDefault = DEFAULT_EXPORT_DEFAULT,
52
- exportTypeAll = DEFAULT_EXPORT_TYPE_ALL,
53
- ...rest
54
- } = options;
55
- const indexRegex = _createRegex(indexFileName);
56
-
57
- // indexファイルの作成処理を実行
58
- _indexes(srcPath, indexRegex, {
59
- indexFileName,
60
- include,
61
- exclude,
62
- exportAll,
63
- exportAllAs,
64
- exportDefault,
65
- exportTypeAll,
66
- ...rest,
67
- });
68
- }
69
-
70
- function _indexes(
71
- targetPath: string,
72
- indexRegex: RegExp,
73
- options: IndexesOptions,
74
- ) {
75
- const {
76
- indexFileName = 'index.ts',
77
- include,
78
- exclude,
79
- includeNamedWithDefault,
80
- exportAll,
81
- exportAllAs,
82
- exportDefault,
83
- exportDefaultAs,
84
- exportTypeAll,
85
- dryRun,
86
- } = options;
87
- const exportTargets = {
88
- exportAll,
89
- exportAllAs,
90
- exportDefault,
91
- exportDefaultAs,
92
- exportTypeAll,
93
- };
94
- const stat = fs.statSync(targetPath);
95
- if (!stat.isDirectory()) {
96
- console.error(`"${targetPath}" is not directory.`);
97
- }
98
- const items = fs.readdirSync(targetPath);
99
- items.sort((a, b) => (a.toLowerCase() > b.toLowerCase() ? 1 : -1));
100
- const exportCodes = [];
101
- let hasDefaultExport = false;
102
- let hasNamedExport = false;
103
-
104
- for (const item of items) {
105
- const itemPath = path.join(targetPath, item);
106
- const { name } = path.parse(itemPath);
107
- const stat = fs.statSync(itemPath);
108
-
109
- let children;
110
- if (stat.isDirectory()) {
111
- // ディレクトリの場合は先に子要素を処理
112
- children = _indexes(itemPath, indexRegex, options);
113
- }
114
- const isMatchingPathOptions = {
115
- conditionOptions: { indexRegex, children },
116
- };
117
-
118
- if (
119
- !indexRegex.test(item) &&
120
- isMatchingPath(itemPath, include, isMatchingPathOptions) &&
121
- !isMatchingPath(itemPath, exclude, isMatchingPathOptions)
122
- ) {
123
- // indexではない場合
124
- let isExported = false;
125
- for (const type in EXPORTS) {
126
- const exportType = type as keyof typeof EXPORTS;
127
- const exportTarget = exportTargets[exportType];
128
- if (
129
- exportTarget &&
130
- isMatchingPath(itemPath, exportTarget, isMatchingPathOptions)
131
- ) {
132
- // 条件に一致した場合はexportのコードを生成
133
- const EXPORT = EXPORTS[exportType];
134
- exportCodes.push({
135
- type: EXPORT.type,
136
- code: EXPORT.generate(name),
137
- });
138
- // exportの種類に応じたフラグを立てる
139
- if (EXPORT.type === 'named') {
140
- hasNamedExport = true;
141
- } else if (EXPORT.type === 'default') {
142
- hasDefaultExport = true;
143
- }
144
- isExported = true;
145
- break;
146
- }
147
- }
148
- if (!isExported) {
149
- // 未指定の場合はexportDefaultAs
150
- exportCodes.push({
151
- type: EXPORTS.exportDefaultAs.type,
152
- code: EXPORTS.exportDefaultAs.generate(name),
153
- });
154
- hasNamedExport = true;
155
- }
156
- }
157
- }
158
-
159
- if (exportCodes.length) {
160
- let index;
161
- if (hasDefaultExport && hasNamedExport && !includeNamedWithDefault) {
162
- // デフォルトエクスポートと名前付きエクスポートの混在を許さない場合は名前付きエクスポートを除外
163
- index = exportCodes.reduce<string[]>((result, exportCode) => {
164
- if (exportCode.type !== 'named') {
165
- result.push(exportCode.code);
166
- }
167
- return result;
168
- }, []);
169
- } else {
170
- index = exportCodes.map((exportCode) => exportCode.code);
171
- }
172
-
173
- const indexPath = path.join(targetPath, indexFileName);
174
- if (!dryRun) {
175
- // indexファイルの出力
176
- fs.writeFileSync(indexPath, index.join('\r\n') + '\r\n', {
177
- encoding: 'utf8',
178
- });
179
- console.info(indexPath);
180
- } else {
181
- console.info(indexPath + '-------------------------------------');
182
- console.info(index.join('\r\n') + '\r\n');
183
- }
184
- }
185
-
186
- return items;
187
- }
188
-
189
- function _createRegex(str: string) {
190
- return new RegExp(
191
- `^${str.replace(/[.*+?^=!:${}()|\[\]\/\\]/g, '\\$&')}$`,
192
- 'i',
193
- );
194
- }
@@ -1,2 +0,0 @@
1
- export { default } from './installFromLocal';
2
- export type * from './types';
@@ -1,63 +0,0 @@
1
- import fs from 'fs-extra';
2
- import path from 'path';
3
- import { reduce } from 'remeda';
4
- import checkExistence from '../checkExistence';
5
- import type { InstallFromLocalOptions } from './types';
6
-
7
- /**
8
- * ローカルに配置されたパッケージを差し替える
9
- * @param localNodeModulesPath ローカルのnode_modulesディレクトリのパス
10
- * @param options オプション
11
- */
12
- export default function installFromLocal(
13
- localNodeModulesPath: string,
14
- options: InstallFromLocalOptions = {},
15
- ) {
16
- const {
17
- packageJsonPath = './package.json',
18
- nodeModulesPath = './node_modules',
19
- dryRun,
20
- } = options;
21
- const resolvedLocalNodeModulesPath = path.resolve(localNodeModulesPath);
22
- const resolvedPackageJsonPath = path.resolve(packageJsonPath);
23
-
24
- if (!checkExistence(resolvedLocalNodeModulesPath, resolvedPackageJsonPath)) {
25
- return;
26
- }
27
-
28
- console.info(`${localNodeModulesPath} -> ${nodeModulesPath}`);
29
-
30
- // package.jsonからローカルのnode_modulesにあるパッケージを取得
31
- const packageJson = fs.readJSONSync(resolvedPackageJsonPath);
32
- const localPackages = reduce(
33
- { ...packageJson.dependencies, ...packageJson.devDependencies },
34
- (result: Record<string, string>, value: string, key) => {
35
- if (value.startsWith(localNodeModulesPath)) {
36
- result[key] = value;
37
- } else if (value.startsWith(`file:${localNodeModulesPath}`)) {
38
- result[key] = value.substring(5);
39
- }
40
- return result;
41
- },
42
- {},
43
- );
44
-
45
- for (const packageName in localPackages) {
46
- // ローカルパッケージの確認
47
- const localPackagePath = path.resolve(localPackages[packageName]);
48
- if (fs.existsSync(localPackagePath)) {
49
- // ローカルパッケージがある場合のみ処理
50
- const installedPackagePath = path.resolve(nodeModulesPath, packageName);
51
- if (!dryRun) {
52
- // コピーを行う
53
- if (fs.existsSync(installedPackagePath)) {
54
- // 古いパッケージは削除
55
- fs.removeSync(installedPackagePath);
56
- }
57
- // パッケージをコピー
58
- fs.copySync(localPackagePath, installedPackagePath);
59
- }
60
- console.info(`${packageName} is being copied...`);
61
- }
62
- }
63
- }
@@ -1,2 +0,0 @@
1
- export { default } from './isMatchingPath';
2
- export type * from './types';
@@ -1,94 +0,0 @@
1
- import fs from 'fs-extra';
2
- import { posix as path } from 'path';
3
- import { isFunction, isString } from 'remeda';
4
- import type {
5
- ConditionFnOptions,
6
- ConditionValues,
7
- IsMatchingPathCondition,
8
- IsMatchingPathOptions,
9
- } from './types';
10
-
11
- /**
12
- * 処理対象のパスか判定する
13
- * @param targetPath 検査対象のパス
14
- * @param conditions 一致条件
15
- * @param options オプション
16
- * @returns 一致するか
17
- */
18
- export default function isMatchingPath<
19
- O extends ConditionFnOptions = ConditionFnOptions,
20
- >(
21
- targetPath: string,
22
- conditions:
23
- | IsMatchingPathCondition<O>
24
- | IsMatchingPathCondition<O>[]
25
- | null
26
- | undefined,
27
- options: IsMatchingPathOptions<O> = {},
28
- ) {
29
- if (!conditions) {
30
- return false;
31
- }
32
- const conditionList = Array.isArray(conditions) ? conditions : [conditions];
33
- // パスは'/'区切り
34
- const posixPath = path.normalize(targetPath);
35
- const parsedPath = path.parse(posixPath);
36
- const parsedDir = path.parse(parsedPath.dir);
37
- const values = {
38
- path: posixPath,
39
- ...parsedPath,
40
- dirpath: parsedPath.dir,
41
- dirbase: parsedDir.base,
42
- dirname: parsedDir.name,
43
- dirext: parsedDir.ext,
44
- };
45
- values.path = posixPath;
46
-
47
- for (const condition of conditionList) {
48
- if (_isMatching(values.path, values, condition, options)) {
49
- // conditionの内の何れかがtrueならば一致
50
- return true;
51
- }
52
- }
53
- return false;
54
- }
55
-
56
- function _isMatching<O extends ConditionFnOptions = ConditionFnOptions>(
57
- value: string,
58
- values: ConditionValues,
59
- condition: IsMatchingPathCondition<O>,
60
- options: IsMatchingPathOptions<O>,
61
- ): boolean {
62
- if (isString(condition)) {
63
- // 条件が文字列
64
- if (value.includes(condition)) {
65
- return true;
66
- }
67
- } else if (condition instanceof RegExp) {
68
- // 条件が正規表現
69
- if (condition.test(value)) {
70
- return true;
71
- }
72
- } else if (isFunction(condition)) {
73
- // 条件が関数
74
- return condition(values, (options.conditionOptions ?? {}) as O);
75
- } else {
76
- // 条件が設定
77
- const { valueType = 'path', entryType = 'both', conditions } = condition;
78
- if (entryType !== 'both') {
79
- const stat = fs.statSync(values.path);
80
- if (
81
- (stat.isDirectory() && entryType !== 'dir') ||
82
- (stat.isFile() && entryType !== 'file')
83
- ) {
84
- return false;
85
- }
86
- }
87
- const conditionList = Array.isArray(conditions) ? conditions : [conditions];
88
- // 設定配下のconditionsはand条件
89
- return conditionList.every((cond) =>
90
- _isMatching(values[valueType], values, cond, options),
91
- );
92
- }
93
- return false;
94
- }
@@ -1,95 +0,0 @@
1
- import type { ParsedPath } from 'path';
2
-
3
- /**
4
- * 一致条件
5
- *
6
- * - string: 指定された文字列がパスに含まれているものに一致する際にtrue
7
- * - RegExp: 指定された正規表現にパスが一致する際にtrue
8
- * - ConditionConfig: 条件設定に従って検査し一致したときにtrue
9
- */
10
- export type IsMatchingPathCondition<
11
- O extends ConditionFnOptions = ConditionFnOptions,
12
- > = string | RegExp | ConditionConfig<O> | ConditionFn<O>;
13
-
14
- export type IsMatchingPathOptions<
15
- O extends ConditionFnOptions = ConditionFnOptions,
16
- > = {
17
- /**
18
- * ConditionFnに渡すオプション
19
- */
20
- conditionOptions?: O;
21
- };
22
-
23
- /**
24
- * 条件設定
25
- */
26
- export type ConditionConfig<O extends ConditionFnOptions = ConditionFnOptions> =
27
- {
28
- /**
29
- * 検査対象の値
30
- *
31
- * - path: '/'で区切られたフルパス
32
- * - base: 拡張子付きのディレクトリ名 or ファイル名
33
- * - name: 拡張子を除いたディレクトリ名 or ファイル名
34
- * - ext: '.'を含む拡張子。拡張子が無い場合は空文字
35
- * - dirpath: '/'で区切られた親ディレクトリのフルパス
36
- * - base: 拡張子付きの親ディレクトリ名
37
- * - name: 拡張子を除いた親ディレクトリ名
38
- * - ext: '.'を含む親ディレクトリの拡張子。拡張子が無い場合は空文字
39
- */
40
- valueType?:
41
- | 'path'
42
- | 'base'
43
- | 'name'
44
- | 'ext'
45
- | 'dirpath'
46
- | 'dirbase'
47
- | 'dirname'
48
- | 'dirext';
49
-
50
- /**
51
- * 検査対象の種別
52
- *
53
- * - dir: ディレクトリ
54
- * - file: ファイル
55
- * - both: ディレクトリ & ファイル
56
- */
57
- entryType?: 'dir' | 'file' | 'both';
58
-
59
- /**
60
- * 一致条件
61
- * 配列で指定した場合はand条件とする
62
- *
63
- * - string: 指定された文字列を含むものに一致
64
- * - RegExp: 指定された正規表現に一致
65
- */
66
- conditions:
67
- | string
68
- | RegExp
69
- | ConditionFn<O>
70
- | (string | RegExp | ConditionFn<O>)[];
71
- };
72
-
73
- /**
74
- * カスタム条件関数
75
- */
76
- export type ConditionFn<O extends ConditionFnOptions = ConditionFnOptions> = (
77
- values: ConditionValues,
78
- options: O,
79
- ) => boolean;
80
-
81
- /**
82
- * カスタム条件関数のオプション
83
- */
84
- export type ConditionFnOptions = Record<string, any>;
85
-
86
- /**
87
- * 検証対象の値
88
- */
89
- export type ConditionValues = {
90
- path: string;
91
- dirpath: string;
92
- dirbase: string;
93
- dirname: string;
94
- dirext: string;
95
- } & ParsedPath;
@@ -1,2 +0,0 @@
1
- export { default } from './isTargetPath';
2
- export type * from './types';
@@ -1,30 +0,0 @@
1
- import fs, { Stats } from 'fs-extra';
2
- import type { ConditionFnOptions } from '../isMatchingPath';
3
- import isMatchingPath from '../isMatchingPath';
4
- import type { IsTargetPathOptions } from './types';
5
-
6
- const IS_TARGET_TYPE = {
7
- file: (stat: Stats) => stat.isFile(),
8
- dir: (stat: Stats) => stat.isDirectory(),
9
- both: (stat: Stats) => stat.isFile() || stat.isDirectory(),
10
- } as const;
11
-
12
- export default async function isTargetPath<
13
- O extends ConditionFnOptions = ConditionFnOptions,
14
- >(itemPath: string, options: IsTargetPathOptions<O> = {}) {
15
- const {
16
- itemType = 'file',
17
- defaultInclude,
18
- defaultExclude,
19
- include = defaultInclude,
20
- exclude = defaultExclude,
21
- ...rest
22
- } = options;
23
- const stat = fs.statSync(itemPath);
24
-
25
- return (
26
- IS_TARGET_TYPE[itemType](stat) &&
27
- (!include || isMatchingPath(itemPath, include, rest)) &&
28
- (!exclude || !isMatchingPath(itemPath, exclude, rest))
29
- );
30
- }