@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.
Files changed (224) 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/createSassClassNameFunction/createSassClassNameFunction.cjs +19 -0
  51. package/createSassClassNameFunction/createSassClassNameFunction.cjs.map +1 -0
  52. package/createSassClassNameFunction/createSassClassNameFunction.d.cts +11 -0
  53. package/createSassClassNameFunction/createSassClassNameFunction.d.mts +12 -0
  54. package/createSassClassNameFunction/createSassClassNameFunction.mjs +18 -0
  55. package/createSassClassNameFunction/createSassClassNameFunction.mjs.map +1 -0
  56. package/createSassClassNameFunction/index.cjs +3 -0
  57. package/createSassClassNameFunction/index.d.cts +2 -0
  58. package/createSassClassNameFunction/index.d.mts +2 -0
  59. package/createSassClassNameFunction/index.mjs +3 -0
  60. package/editJsonFile/editJsonFile.cjs +29 -0
  61. package/editJsonFile/editJsonFile.cjs.map +1 -0
  62. package/editJsonFile/editJsonFile.d.cts +9 -0
  63. package/editJsonFile/editJsonFile.d.mts +10 -0
  64. package/editJsonFile/editJsonFile.mjs +26 -0
  65. package/editJsonFile/editJsonFile.mjs.map +1 -0
  66. package/editJsonFile/index.cjs +3 -0
  67. package/editJsonFile/index.d.cts +2 -0
  68. package/editJsonFile/index.d.mts +2 -0
  69. package/editJsonFile/index.mjs +3 -0
  70. package/generatePublishPackageJson/generatePublishPackageJson.cjs +46 -0
  71. package/generatePublishPackageJson/generatePublishPackageJson.cjs.map +1 -0
  72. package/generatePublishPackageJson/generatePublishPackageJson.d.cts +6 -0
  73. package/generatePublishPackageJson/generatePublishPackageJson.d.mts +7 -0
  74. package/generatePublishPackageJson/generatePublishPackageJson.mjs +44 -0
  75. package/generatePublishPackageJson/generatePublishPackageJson.mjs.map +1 -0
  76. package/generatePublishPackageJson/index.cjs +3 -0
  77. package/generatePublishPackageJson/index.d.cts +3 -0
  78. package/generatePublishPackageJson/index.d.mts +3 -0
  79. package/generatePublishPackageJson/index.mjs +3 -0
  80. package/generatePublishPackageJson/types.cjs +0 -0
  81. package/{src/generatePublishPackageJson/types.ts → generatePublishPackageJson/types.d.cts} +60 -61
  82. package/generatePublishPackageJson/types.d.mts +60 -0
  83. package/generatePublishPackageJson/types.mjs +1 -0
  84. package/index.cjs +41 -0
  85. package/index.d.cts +14 -0
  86. package/index.d.mts +14 -0
  87. package/index.mjs +28 -0
  88. package/indexes/constants.cjs +123 -0
  89. package/indexes/constants.cjs.map +1 -0
  90. package/indexes/constants.d.cts +66 -0
  91. package/indexes/constants.d.mts +66 -0
  92. package/indexes/constants.mjs +106 -0
  93. package/indexes/constants.mjs.map +1 -0
  94. package/indexes/index.cjs +3 -0
  95. package/indexes/index.d.cts +3 -0
  96. package/indexes/index.d.mts +3 -0
  97. package/indexes/index.mjs +3 -0
  98. package/indexes/indexes.cjs +125 -0
  99. package/indexes/indexes.cjs.map +1 -0
  100. package/indexes/indexes.d.cts +11 -0
  101. package/indexes/indexes.d.mts +12 -0
  102. package/indexes/indexes.mjs +123 -0
  103. package/indexes/indexes.mjs.map +1 -0
  104. package/indexes/types.cjs +0 -0
  105. package/{src/indexes/types.ts → indexes/types.d.cts} +81 -87
  106. package/indexes/types.d.mts +81 -0
  107. package/indexes/types.mjs +1 -0
  108. package/installFromLocal/index.cjs +3 -0
  109. package/installFromLocal/index.d.cts +3 -0
  110. package/installFromLocal/index.d.mts +3 -0
  111. package/installFromLocal/index.mjs +3 -0
  112. package/installFromLocal/installFromLocal.cjs +46 -0
  113. package/installFromLocal/installFromLocal.cjs.map +1 -0
  114. package/installFromLocal/installFromLocal.d.cts +11 -0
  115. package/installFromLocal/installFromLocal.d.mts +12 -0
  116. package/installFromLocal/installFromLocal.mjs +43 -0
  117. package/installFromLocal/installFromLocal.mjs.map +1 -0
  118. package/installFromLocal/types.cjs +0 -0
  119. package/{src/installFromLocal/types.ts → installFromLocal/types.d.cts} +21 -19
  120. package/installFromLocal/types.d.mts +21 -0
  121. package/installFromLocal/types.mjs +1 -0
  122. package/isMatchingPath/index.cjs +3 -0
  123. package/isMatchingPath/index.d.cts +3 -0
  124. package/isMatchingPath/index.d.mts +3 -0
  125. package/isMatchingPath/index.mjs +3 -0
  126. package/isMatchingPath/isMatchingPath.cjs +52 -0
  127. package/isMatchingPath/isMatchingPath.cjs.map +1 -0
  128. package/isMatchingPath/isMatchingPath.d.cts +13 -0
  129. package/isMatchingPath/isMatchingPath.d.mts +14 -0
  130. package/isMatchingPath/isMatchingPath.mjs +50 -0
  131. package/isMatchingPath/isMatchingPath.mjs.map +1 -0
  132. package/isMatchingPath/types.cjs +0 -0
  133. package/isMatchingPath/types.d.cts +72 -0
  134. package/isMatchingPath/types.d.mts +72 -0
  135. package/isMatchingPath/types.mjs +1 -0
  136. package/isTargetPath/index.cjs +3 -0
  137. package/isTargetPath/index.d.cts +3 -0
  138. package/isTargetPath/index.d.mts +3 -0
  139. package/isTargetPath/index.mjs +3 -0
  140. package/isTargetPath/isTargetPath.cjs +21 -0
  141. package/isTargetPath/isTargetPath.cjs.map +1 -0
  142. package/isTargetPath/isTargetPath.d.cts +7 -0
  143. package/isTargetPath/isTargetPath.d.mts +8 -0
  144. package/isTargetPath/isTargetPath.mjs +19 -0
  145. package/isTargetPath/isTargetPath.mjs.map +1 -0
  146. package/isTargetPath/types.cjs +0 -0
  147. package/{src/isTargetPath/types.ts → isTargetPath/types.d.cts} +33 -38
  148. package/isTargetPath/types.d.mts +33 -0
  149. package/isTargetPath/types.mjs +1 -0
  150. package/moveFilesToSubdir/index.cjs +3 -0
  151. package/moveFilesToSubdir/index.d.cts +3 -0
  152. package/moveFilesToSubdir/index.d.mts +3 -0
  153. package/moveFilesToSubdir/index.mjs +3 -0
  154. package/moveFilesToSubdir/moveFilesToSubdir.cjs +32 -0
  155. package/moveFilesToSubdir/moveFilesToSubdir.cjs.map +1 -0
  156. package/moveFilesToSubdir/moveFilesToSubdir.d.cts +10 -0
  157. package/moveFilesToSubdir/moveFilesToSubdir.d.mts +11 -0
  158. package/moveFilesToSubdir/moveFilesToSubdir.mjs +29 -0
  159. package/moveFilesToSubdir/moveFilesToSubdir.mjs.map +1 -0
  160. package/moveFilesToSubdir/types.cjs +0 -0
  161. package/{src/moveFilesToSubdir/types.ts → moveFilesToSubdir/types.d.cts} +18 -15
  162. package/moveFilesToSubdir/types.d.mts +18 -0
  163. package/moveFilesToSubdir/types.mjs +1 -0
  164. package/package.json +21 -29
  165. package/removeFiles/index.cjs +3 -0
  166. package/removeFiles/index.d.cts +2 -0
  167. package/removeFiles/index.d.mts +2 -0
  168. package/removeFiles/index.mjs +3 -0
  169. package/removeFiles/removeFiles.cjs +15 -0
  170. package/removeFiles/removeFiles.cjs.map +1 -0
  171. package/removeFiles/removeFiles.d.cts +6 -0
  172. package/removeFiles/removeFiles.d.mts +7 -0
  173. package/removeFiles/removeFiles.mjs +12 -0
  174. package/removeFiles/removeFiles.mjs.map +1 -0
  175. package/removeFiles/types.cjs +0 -0
  176. package/removeFiles/types.d.cts +9 -0
  177. package/removeFiles/types.d.mts +9 -0
  178. package/removeFiles/types.mjs +1 -0
  179. package/ver/index.cjs +3 -0
  180. package/ver/index.d.cts +3 -0
  181. package/ver/index.d.mts +3 -0
  182. package/ver/index.mjs +3 -0
  183. package/ver/types.cjs +0 -0
  184. package/{src/ver/types.ts → ver/types.d.cts} +16 -13
  185. package/ver/types.d.mts +16 -0
  186. package/ver/types.mjs +1 -0
  187. package/ver/ver.cjs +34 -0
  188. package/ver/ver.cjs.map +1 -0
  189. package/ver/ver.d.cts +11 -0
  190. package/ver/ver.d.mts +12 -0
  191. package/ver/ver.mjs +31 -0
  192. package/ver/ver.mjs.map +1 -0
  193. package/src/addExports/addExports.ts +0 -94
  194. package/src/addExports/index.ts +0 -2
  195. package/src/addJsExtensions/addJsExtensions.ts +0 -30
  196. package/src/addJsExtensions/index.ts +0 -1
  197. package/src/checkExistence/checkExistence.ts +0 -16
  198. package/src/checkExistence/index.ts +0 -1
  199. package/src/createExternalOptionFunction/createExternalOptionFunction.ts +0 -43
  200. package/src/createExternalOptionFunction/index.ts +0 -1
  201. package/src/editJsonFile/editJsonFile.ts +0 -30
  202. package/src/editJsonFile/index.ts +0 -1
  203. package/src/generatePublishPackageJson/generatePublishPackageJson.ts +0 -55
  204. package/src/generatePublishPackageJson/index.ts +0 -2
  205. package/src/index.ts +0 -11
  206. package/src/indexes/constants.ts +0 -135
  207. package/src/indexes/index.ts +0 -2
  208. package/src/indexes/indexes.ts +0 -194
  209. package/src/installFromLocal/index.ts +0 -2
  210. package/src/installFromLocal/installFromLocal.ts +0 -63
  211. package/src/isMatchingPath/index.ts +0 -2
  212. package/src/isMatchingPath/isMatchingPath.ts +0 -94
  213. package/src/isMatchingPath/types.ts +0 -95
  214. package/src/isTargetPath/index.ts +0 -2
  215. package/src/isTargetPath/isTargetPath.ts +0 -30
  216. package/src/moveFilesToSubdir/index.ts +0 -2
  217. package/src/moveFilesToSubdir/moveFilesToSubdir.ts +0 -40
  218. package/src/removeFiles/index.ts +0 -1
  219. package/src/removeFiles/removeFiles.ts +0 -11
  220. package/src/removeFiles/types.ts +0 -5
  221. package/src/ver/index.ts +0 -2
  222. package/src/ver/ver.ts +0 -38
  223. package/tsconfig.json +0 -46
  224. package/tsdown.config.ts +0 -41
@@ -1,94 +0,0 @@
1
- import fs from 'fs-extra';
2
- import { posix as path } from 'path';
3
- import isTargetPath from '../isTargetPath';
4
- import type { AddExportsOptions } from './types';
5
-
6
- /**
7
- * index.tsが配置されているモジュールをpackage.jsonのexportsに追加する
8
- * @param targetPath
9
- * @param options
10
- */
11
- export default function addExports(
12
- targetPath: string = 'src',
13
- options: AddExportsOptions = {},
14
- ) {
15
- let {
16
- packageJsonPath = 'package.json',
17
- include = [],
18
- dist = 'dist',
19
- dryRun,
20
- ...rest
21
- } = options;
22
-
23
- // 処理対象を設定
24
- include = [
25
- // indexファイルを対象
26
- {
27
- valueType: 'base',
28
- entryType: 'file',
29
- conditions: /^index.(ts|tsx)$/i,
30
- },
31
- ...include,
32
- ];
33
-
34
- // exportsをpackage.jsonに追加
35
- const exportsIndex = _addExports(targetPath, {
36
- packageJsonPath,
37
- include,
38
- dist,
39
- ...rest,
40
- });
41
-
42
- const packageJson = fs.readJsonSync(packageJsonPath, { encoding: 'utf8' });
43
- packageJson.exports = {};
44
- exportsIndex.sort((a, b) => (a.key > b.key ? 1 : -1));
45
- for (const index of exportsIndex) {
46
- packageJson.exports[index.key ? './' + index.key : '.'] =
47
- './' + index.path + '.js';
48
- }
49
- if (dryRun) {
50
- console.log(packageJson);
51
- } else {
52
- fs.writeJsonSync(packageJsonPath, packageJson, {
53
- encoding: 'utf8',
54
- spaces: 2,
55
- });
56
- }
57
- }
58
-
59
- function _addExports(
60
- targetPath: string,
61
- options: AddExportsOptions,
62
- current: string = '',
63
- ) {
64
- const { include, exclude, dist = 'dist' } = options;
65
-
66
- const stat = fs.statSync(targetPath);
67
- if (!stat.isDirectory()) {
68
- console.error(`"${targetPath}" is not directory.`);
69
- }
70
- const items = fs.readdirSync(targetPath);
71
- items.sort();
72
- const exportsIndex: { key: string; path: string }[] = [];
73
-
74
- for (const item of items) {
75
- const itemPath = path.join(targetPath, item);
76
- const stat = fs.statSync(itemPath);
77
- const { name } = path.parse(itemPath);
78
-
79
- if (stat.isDirectory()) {
80
- // ディレクトリの場合は先に子要素を処理
81
- exportsIndex.push(
82
- ..._addExports(itemPath, options, path.join(current, item)),
83
- );
84
- } else if (isTargetPath(itemPath, { include, exclude })) {
85
- // exportの対象の場合
86
- exportsIndex.push({
87
- key: current,
88
- path: path.join(dist, current, name),
89
- });
90
- }
91
- }
92
-
93
- return exportsIndex;
94
- }
@@ -1,2 +0,0 @@
1
- export { default } from './addExports';
2
- export type * from './types';
@@ -1,30 +0,0 @@
1
- import fg from 'fast-glob';
2
- import fs from 'fs-extra';
3
-
4
- const PATTERNS = {
5
- '.js': /(?:from|import)\s*["'](\.\.?\/[^"']+)["']/g,
6
- '.cjs': /require\(["'](\.\.?\/[^"']+)["']\)/g,
7
- };
8
-
9
- /**
10
- * ローカルファイルのimportやrequireに拡張子を付与する
11
- * @param dir
12
- */
13
- export default async function addJsExtensions(dir: string) {
14
- const files = await fg(`${dir}/**/*.{js,cjs}`);
15
- for (const file of files) {
16
- const content = await fs.readFile(file, 'utf-8');
17
- const ext = file.endsWith('.cjs') ? '.cjs' : '.js';
18
- const fixed = content.replace(PATTERNS[ext], (match, pos1) => {
19
- if (pos1.endsWith(ext)) {
20
- // 既に拡張子あり
21
- return match;
22
- }
23
- // 拡張子を付与
24
- return match.replace(pos1, `${pos1}${ext}`);
25
- });
26
- if (content !== fixed) {
27
- await fs.writeFile(file, fixed);
28
- }
29
- }
30
- }
@@ -1 +0,0 @@
1
- export { default } from './addJsExtensions';
@@ -1,16 +0,0 @@
1
- import fs from 'fs-extra';
2
-
3
- /**
4
- * ディレクトリ、ファイルの存在チェック
5
- * @param targetPaths
6
- * @param options
7
- */
8
- export default function checkExistence(...targetPaths: string[]) {
9
- return targetPaths.every((targetPath) => {
10
- if (!fs.existsSync(targetPath)) {
11
- console.error(`${targetPath}が存在しません。`);
12
- return false;
13
- }
14
- return true;
15
- });
16
- }
@@ -1 +0,0 @@
1
- export { default } from './checkExistence';
@@ -1,43 +0,0 @@
1
- import isMatchingPath from '../isMatchingPath';
2
- import type {
3
- CreateExternalOptionFunctionOptions,
4
- ExternalOptionFunction,
5
- } from './types';
6
-
7
- /**
8
- * rolldownやrollupなどで内部モジュールのimport以外をexternalとして扱うための関数を作る関数
9
- * @param options
10
- */
11
- export default function createExternalOptionFunction(
12
- options: CreateExternalOptionFunctionOptions = {},
13
- ): ExternalOptionFunction {
14
- const { isExternal, isInternal } = options;
15
- return (
16
- source: string,
17
- _importer: string | undefined,
18
- isResolved: boolean,
19
- ) => {
20
- const isMatchingPathOptions = {
21
- conditionOptions: {
22
- source,
23
- importer: _importer,
24
- isResolved,
25
- },
26
- };
27
- if (isMatchingPath(source, isExternal, isMatchingPathOptions)) {
28
- // 外部モジュール扱い
29
- return true;
30
- } else if (isMatchingPath(source, isInternal, isMatchingPathOptions)) {
31
- // 内部モジュール扱い
32
- return;
33
- } else if (!isResolved) {
34
- // 相対パスでもなく、srcディレクトリ配下でもないものは外部モジュール扱い
35
- return (
36
- !source.startsWith('.') &&
37
- !source.startsWith('/') &&
38
- !source.startsWith('src/')
39
- );
40
- }
41
- return;
42
- };
43
- }
@@ -1 +0,0 @@
1
- export { default } from './createExternalOptionFunction';
@@ -1,30 +0,0 @@
1
- import fs from 'fs-extra';
2
- import path from 'path';
3
- import { isFunction, merge } from 'remeda';
4
- import checkExistence from '../checkExistence';
5
-
6
- /**
7
- * JSONファイルを更新する
8
- * @param jsonFilePath
9
- * @param editor
10
- */
11
- function editJsonFile(
12
- jsonFilePath: string,
13
- editor: ((obj: any) => object) | object,
14
- ) {
15
- const resolvedJsonFilePath = path.resolve(jsonFilePath);
16
- if (checkExistence(resolvedJsonFilePath)) {
17
- const obj = fs.readJSONSync(resolvedJsonFilePath);
18
- let editedJson;
19
- if (isFunction(editor)) {
20
- // 関数で編集する場合
21
- editedJson = editor(obj);
22
- } else {
23
- // 差分を反映する場合
24
- editedJson = merge(obj, editor);
25
- }
26
- fs.writeJSONSync(resolvedJsonFilePath, editedJson, { spaces: 2 });
27
- }
28
- }
29
-
30
- export default editJsonFile;
@@ -1 +0,0 @@
1
- export { default } from './editJsonFile';
@@ -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';