@niche-works/dev 0.3.0 → 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.
- 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/createExternalOptionFunction/types.d.cts +31 -0
- package/createExternalOptionFunction/types.d.mts +31 -0
- package/createExternalOptionFunction/types.mjs +1 -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 +38 -0
- package/index.d.cts +13 -0
- package/index.d.mts +13 -0
- package/index.mjs +26 -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/isTargetPath/types.d.cts +33 -0
- 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/moveFilesToSubdir/types.d.cts +18 -0
- package/moveFilesToSubdir/types.d.mts +18 -0
- package/moveFilesToSubdir/types.mjs +1 -0
- package/package.json +20 -30
- 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 -98
- package/src/addExports/index.ts +0 -2
- package/src/addJsExtensions/addJsExtensions.ts +0 -31
- package/src/addJsExtensions/index.ts +0 -1
- package/src/checkExistence/checkExistence.ts +0 -16
- package/src/checkExistence/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 -10
- 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/_types.ts +0 -65
- package/src/isMatchingPath/index.ts +0 -2
- package/src/isMatchingPath/isMatchingPath.ts +0 -88
- package/src/isMatchingPath/types.ts +0 -21
- package/src/moveFilesToSubdir/index.ts +0 -1
- package/src/moveFilesToSubdir/moveFilesToSubdir.ts +0 -23
- package/src/ver/index.ts +0 -2
- package/src/ver/ver.ts +0 -38
- package/tsconfig.json +0 -46
- package/tsup.config.ts +0 -36
package/src/indexes/constants.ts
DELETED
|
@@ -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];
|
package/src/indexes/index.ts
DELETED
package/src/indexes/indexes.ts
DELETED
|
@@ -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,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,65 +0,0 @@
|
|
|
1
|
-
import type { ParsedPath } from 'path';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* 条件設定
|
|
5
|
-
*/
|
|
6
|
-
export type ConditionConfig = {
|
|
7
|
-
/**
|
|
8
|
-
* 検査対象の値
|
|
9
|
-
*
|
|
10
|
-
* - path: '/'で区切られたフルパス
|
|
11
|
-
* - base: 拡張子付きのディレクトリ名 or ファイル名
|
|
12
|
-
* - name: 拡張子を除いたディレクトリ名 or ファイル名
|
|
13
|
-
* - ext: '.'を含む拡張子。拡張子が無い場合は空文字
|
|
14
|
-
* - dirpath: '/'で区切られた親ディレクトリのフルパス
|
|
15
|
-
* - base: 拡張子付きの親ディレクトリ名
|
|
16
|
-
* - name: 拡張子を除いた親ディレクトリ名
|
|
17
|
-
* - ext: '.'を含む親ディレクトリの拡張子。拡張子が無い場合は空文字
|
|
18
|
-
*/
|
|
19
|
-
valueType?:
|
|
20
|
-
| 'path'
|
|
21
|
-
| 'base'
|
|
22
|
-
| 'name'
|
|
23
|
-
| 'ext'
|
|
24
|
-
| 'dirpath'
|
|
25
|
-
| 'dirbase'
|
|
26
|
-
| 'dirname'
|
|
27
|
-
| 'dirext';
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* 検査対象の種別
|
|
31
|
-
*
|
|
32
|
-
* - dir: ディレクトリ
|
|
33
|
-
* - file: ファイル
|
|
34
|
-
* - both: ディレクトリ & ファイル
|
|
35
|
-
*/
|
|
36
|
-
entryType?: 'dir' | 'file' | 'both';
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* 一致条件
|
|
40
|
-
* 配列で指定した場合はand条件とする
|
|
41
|
-
*
|
|
42
|
-
* - string: 指定された文字列を含むものに一致
|
|
43
|
-
* - RegExp: 指定された正規表現に一致
|
|
44
|
-
*/
|
|
45
|
-
conditions: string | RegExp | ConditionFn | (string | RegExp | ConditionFn)[];
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* カスタム条件関数
|
|
50
|
-
*/
|
|
51
|
-
export type ConditionFn = (
|
|
52
|
-
values: ConditionValues,
|
|
53
|
-
options: Record<string, any>,
|
|
54
|
-
) => boolean;
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* 検証対象の値
|
|
58
|
-
*/
|
|
59
|
-
export type ConditionValues = {
|
|
60
|
-
path: string;
|
|
61
|
-
dirpath: string;
|
|
62
|
-
dirbase: string;
|
|
63
|
-
dirname: string;
|
|
64
|
-
dirext: string;
|
|
65
|
-
} & ParsedPath;
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import fs from 'fs-extra';
|
|
2
|
-
import { posix as path } from 'path';
|
|
3
|
-
import { isFunction, isString } from 'remeda';
|
|
4
|
-
import type { ConditionValues } from './_types';
|
|
5
|
-
import type { IsMatchingPathCondition, IsMatchingPathOptions } from './types';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* 処理対象のパスか判定する
|
|
9
|
-
* @param targetPath 検査対象のパス
|
|
10
|
-
* @param conditions 一致条件
|
|
11
|
-
* @param options オプション
|
|
12
|
-
* @returns 一致するか
|
|
13
|
-
*/
|
|
14
|
-
export default function isMatchingPath(
|
|
15
|
-
targetPath: string,
|
|
16
|
-
conditions:
|
|
17
|
-
| IsMatchingPathCondition
|
|
18
|
-
| IsMatchingPathCondition[]
|
|
19
|
-
| null
|
|
20
|
-
| undefined,
|
|
21
|
-
options: IsMatchingPathOptions = {},
|
|
22
|
-
) {
|
|
23
|
-
if (!conditions) {
|
|
24
|
-
return false;
|
|
25
|
-
}
|
|
26
|
-
const conditionList = Array.isArray(conditions) ? conditions : [conditions];
|
|
27
|
-
// パスは'/'区切り
|
|
28
|
-
const posixPath = path.normalize(targetPath);
|
|
29
|
-
const parsedPath = path.parse(posixPath);
|
|
30
|
-
const parsedDir = path.parse(parsedPath.dir);
|
|
31
|
-
const values = {
|
|
32
|
-
path: posixPath,
|
|
33
|
-
...parsedPath,
|
|
34
|
-
dirpath: parsedPath.dir,
|
|
35
|
-
dirbase: parsedDir.base,
|
|
36
|
-
dirname: parsedDir.name,
|
|
37
|
-
dirext: parsedDir.ext,
|
|
38
|
-
};
|
|
39
|
-
values.path = posixPath;
|
|
40
|
-
|
|
41
|
-
for (const condition of conditionList) {
|
|
42
|
-
if (_isMatching(values.path, values, condition, options)) {
|
|
43
|
-
// conditionの内の何れかがtrueならば一致
|
|
44
|
-
return true;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
return false;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function _isMatching(
|
|
51
|
-
value: string,
|
|
52
|
-
values: ConditionValues,
|
|
53
|
-
condition: IsMatchingPathCondition,
|
|
54
|
-
options: IsMatchingPathOptions,
|
|
55
|
-
): boolean {
|
|
56
|
-
if (isString(condition)) {
|
|
57
|
-
// 条件が文字列
|
|
58
|
-
if (value.includes(condition)) {
|
|
59
|
-
return true;
|
|
60
|
-
}
|
|
61
|
-
} else if (condition instanceof RegExp) {
|
|
62
|
-
// 条件が正規表現
|
|
63
|
-
if (condition.test(value)) {
|
|
64
|
-
return true;
|
|
65
|
-
}
|
|
66
|
-
} else if (isFunction(condition)) {
|
|
67
|
-
// 条件が関数
|
|
68
|
-
return condition(values, options.conditionOptions ?? {});
|
|
69
|
-
} else {
|
|
70
|
-
// 条件が設定
|
|
71
|
-
const { valueType = 'path', entryType = 'both', conditions } = condition;
|
|
72
|
-
if (entryType !== 'both') {
|
|
73
|
-
const stat = fs.statSync(values.path);
|
|
74
|
-
if (
|
|
75
|
-
(stat.isDirectory() && entryType !== 'dir') ||
|
|
76
|
-
(stat.isFile() && entryType !== 'file')
|
|
77
|
-
) {
|
|
78
|
-
return false;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
const conditionList = Array.isArray(conditions) ? conditions : [conditions];
|
|
82
|
-
// 設定配下のconditionsはand条件
|
|
83
|
-
return conditionList.every((cond) =>
|
|
84
|
-
_isMatching(values[valueType], values, cond, options),
|
|
85
|
-
);
|
|
86
|
-
}
|
|
87
|
-
return false;
|
|
88
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { ConditionConfig, ConditionFn } from './_types';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* 一致条件
|
|
5
|
-
*
|
|
6
|
-
* - string: 指定された文字列がパスに含まれているものに一致する際にtrue
|
|
7
|
-
* - RegExp: 指定された正規表現にパスが一致する際にtrue
|
|
8
|
-
* - ConditionConfig: 条件設定に従って検査し一致したときにtrue
|
|
9
|
-
*/
|
|
10
|
-
export type IsMatchingPathCondition =
|
|
11
|
-
| string
|
|
12
|
-
| RegExp
|
|
13
|
-
| ConditionConfig
|
|
14
|
-
| ConditionFn;
|
|
15
|
-
|
|
16
|
-
export type IsMatchingPathOptions = {
|
|
17
|
-
/**
|
|
18
|
-
* ConditionFnに渡すオプション
|
|
19
|
-
*/
|
|
20
|
-
conditionOptions?: Record<string, any>;
|
|
21
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from './moveFilesToSubdir';
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import fs from 'fs-extra';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* 対象のディレクトリ直下のファイルを、拡張子を除いた同名のサブディレクトリ直下に移動する
|
|
6
|
-
* @param dirPath 対象のディレクトリのパス
|
|
7
|
-
*/
|
|
8
|
-
export default async function moveFilesToSubdir(dirPath: string) {
|
|
9
|
-
const items = await fs.readdir(dirPath);
|
|
10
|
-
for (const item of items) {
|
|
11
|
-
const itemPath = path.join(dirPath, item);
|
|
12
|
-
const stat = fs.statSync(itemPath);
|
|
13
|
-
if (stat.isFile()) {
|
|
14
|
-
const fileName = path.parse(item).name;
|
|
15
|
-
// 移動先のディレクトリパスを生成
|
|
16
|
-
const subdirPath = path.join(dirPath, fileName);
|
|
17
|
-
// 移動先のディレクトリが存在しなければ作成
|
|
18
|
-
fs.ensureDirSync(subdirPath);
|
|
19
|
-
// 移動先のファイルパスを生成
|
|
20
|
-
fs.moveSync(itemPath, path.join(subdirPath, item));
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
package/src/ver/index.ts
DELETED
package/src/ver/ver.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import fs from 'fs-extra';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import type { VerOptions } from './types';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* ワークスペースのパッケージにバージョンを反映する
|
|
7
|
-
* @param version バージョン
|
|
8
|
-
* @param options オプション
|
|
9
|
-
*/
|
|
10
|
-
export default async function ver(version: string, options: VerOptions = {}) {
|
|
11
|
-
const {
|
|
12
|
-
workspacePackageJsonPath = 'package.json',
|
|
13
|
-
packagesPath = 'packages',
|
|
14
|
-
} = options;
|
|
15
|
-
|
|
16
|
-
if (fs.existsSync(workspacePackageJsonPath)) {
|
|
17
|
-
// ワークスペースのpackage.jsonを更新
|
|
18
|
-
_updatePkgJson(version, workspacePackageJsonPath);
|
|
19
|
-
}
|
|
20
|
-
const pkgs = fs.readdirSync(packagesPath);
|
|
21
|
-
for (const pkg of pkgs) {
|
|
22
|
-
const packagePath = path.join(packagesPath, pkg);
|
|
23
|
-
const packageJsonPath = path.join(packagePath, 'package.json');
|
|
24
|
-
if (fs.existsSync(packageJsonPath)) {
|
|
25
|
-
// 各パッケージのpackage.jsonを更新
|
|
26
|
-
_updatePkgJson(version, packageJsonPath);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function _updatePkgJson(version: string, packageJsonPath: string) {
|
|
32
|
-
const packageJson = fs.readJsonSync(packageJsonPath, { encoding: 'utf8' });
|
|
33
|
-
packageJson.version = version;
|
|
34
|
-
fs.writeJsonSync(packageJsonPath, packageJson, {
|
|
35
|
-
encoding: 'utf8',
|
|
36
|
-
spaces: 2,
|
|
37
|
-
});
|
|
38
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2023",
|
|
4
|
-
"useDefineForClassFields": true,
|
|
5
|
-
"module": "ESNext",
|
|
6
|
-
"lib": ["ES2023", "DOM", "DOM.Iterable"],
|
|
7
|
-
"types": ["node"],
|
|
8
|
-
"skipLibCheck": true,
|
|
9
|
-
/* Bundler mode */
|
|
10
|
-
"moduleResolution": "bundler",
|
|
11
|
-
"allowImportingTsExtensions": true,
|
|
12
|
-
"verbatimModuleSyntax": true,
|
|
13
|
-
"moduleDetection": "force",
|
|
14
|
-
"noEmit": true,
|
|
15
|
-
/* Linting */
|
|
16
|
-
"strict": true,
|
|
17
|
-
"noUnusedLocals": true,
|
|
18
|
-
"noUnusedParameters": true,
|
|
19
|
-
"erasableSyntaxOnly": true,
|
|
20
|
-
"noFallthroughCasesInSwitch": true,
|
|
21
|
-
"noUncheckedSideEffectImports": true,
|
|
22
|
-
/* Source */
|
|
23
|
-
"rootDir": "src",
|
|
24
|
-
"outDir": "dist",
|
|
25
|
-
"declarationDir": "dist",
|
|
26
|
-
"typeRoots": ["./node_modules/@types"],
|
|
27
|
-
"jsx": "react-jsx",
|
|
28
|
-
"allowJs": true,
|
|
29
|
-
"checkJs": true,
|
|
30
|
-
"declaration": true,
|
|
31
|
-
"declarationMap": false,
|
|
32
|
-
"sourceMap": false,
|
|
33
|
-
"inlineSources": false,
|
|
34
|
-
"removeComments": false,
|
|
35
|
-
"importHelpers": true,
|
|
36
|
-
"noImplicitAny": false,
|
|
37
|
-
"esModuleInterop": true,
|
|
38
|
-
"forceConsistentCasingInFileNames": true,
|
|
39
|
-
"strictNullChecks": false,
|
|
40
|
-
"strictPropertyInitialization": false,
|
|
41
|
-
"preserveSymlinks": false,
|
|
42
|
-
"ignoreDeprecations": "6.0"
|
|
43
|
-
},
|
|
44
|
-
"include": ["src"],
|
|
45
|
-
"exclude": ["src/**/*.test.*"]
|
|
46
|
-
}
|