xshell 0.0.52 → 0.0.55
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/chalk.browser.d.ts +1 -1
- package/chalk.browser.js +3 -19
- package/chalk.browser.js.map +1 -1
- package/extension.cjs +55780 -0
- package/extension.cjs.map +1 -0
- package/file.d.ts +3 -1
- package/file.js +74 -97
- package/file.js.map +1 -1
- package/i18n/dict.js +1 -5
- package/i18n/dict.js.map +1 -1
- package/i18n/i18n-scan.js +9 -12
- package/i18n/i18n-scan.js.map +1 -1
- package/i18n/index.js +11 -16
- package/i18n/index.js.map +1 -1
- package/i18n/rwdict.js +3 -7
- package/i18n/rwdict.js.map +1 -1
- package/i18n/scanner/checker.js +6 -11
- package/i18n/scanner/checker.js.map +1 -1
- package/i18n/scanner/index.js +39 -44
- package/i18n/scanner/index.js.map +1 -1
- package/i18n/scanner/parser.js +15 -19
- package/i18n/scanner/parser.js.map +1 -1
- package/i18n/utils.js +3 -7
- package/i18n/utils.js.map +1 -1
- package/index.js +5 -8
- package/index.js.map +1 -1
- package/myfont.woff2 +0 -0
- package/myfontb.woff2 +0 -0
- package/net.browser.js +7 -13
- package/net.browser.js.map +1 -1
- package/net.d.ts +2 -2
- package/net.js +50 -63
- package/net.js.map +1 -1
- package/package.json +21 -21
- package/process.d.ts +3 -1
- package/process.js +18 -23
- package/process.js.map +1 -1
- package/prototype.browser.js +24 -32
- package/prototype.browser.js.map +1 -1
- package/prototype.d.ts +1 -1
- package/prototype.js +37 -46
- package/prototype.js.map +1 -1
- package/repl.js +66 -80
- package/repl.js.map +1 -1
- package/server.d.ts +3 -1
- package/server.js +32 -37
- package/server.js.map +1 -1
- package/toaster.browser.js +6 -9
- package/toaster.browser.js.map +1 -1
- package/toaster.sass +1 -1
- package/tsconfig.json +3 -3
- package/ufs.d.ts +1 -1
- package/ufs.js +5 -9
- package/ufs.js.map +1 -1
- package/utils.browser.js +4 -11
- package/utils.browser.js.map +1 -1
- package/utils.d.ts +3 -1
- package/utils.js +41 -62
- package/utils.js.map +1 -1
- package/xshell.js +2 -4
- package/xshell.js.map +1 -1
package/file.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
3
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
4
|
import { promises as fsp, default as fs } from 'fs';
|
|
3
5
|
declare type FileHandle = fsp.FileHandle & {
|
|
4
6
|
fp: string;
|
package/file.js
CHANGED
|
@@ -1,25 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const memfs_1 = tslib_1.__importDefault(require("memfs"));
|
|
12
|
-
exports.MFS = memfs_1.default;
|
|
13
|
-
const prototype_js_1 = require("./prototype.js");
|
|
14
|
-
tslib_1.__exportStar(require("./ufs.js"), exports);
|
|
1
|
+
import { promises as fsp, default as fs, } from 'fs';
|
|
2
|
+
import path from 'upath';
|
|
3
|
+
import iconv from 'iconv-lite';
|
|
4
|
+
import fse from 'fs-extra';
|
|
5
|
+
import rimraf from 'rimraf';
|
|
6
|
+
import debounce from 'lodash/debounce.js';
|
|
7
|
+
import MFS from 'memfs';
|
|
8
|
+
import { to_json } from './prototype.js';
|
|
9
|
+
export * from './ufs.js';
|
|
10
|
+
export { MFS };
|
|
15
11
|
/** Does the file/folder pointed to by fp exist? */
|
|
16
|
-
function fexists(fp, { print = true } = {}) {
|
|
17
|
-
const exists =
|
|
12
|
+
export function fexists(fp, { print = true } = {}) {
|
|
13
|
+
const exists = fs.existsSync(fp);
|
|
18
14
|
if (print)
|
|
19
15
|
console.log(exists ? 'exists:' : 'not exists:', fp);
|
|
20
16
|
return exists;
|
|
21
17
|
}
|
|
22
|
-
exports.fexists = fexists;
|
|
23
18
|
/**
|
|
24
19
|
open file, return FileHandle
|
|
25
20
|
Some characters (`< > : " / \ | ? *`) are reserved under Windows as documented
|
|
@@ -30,54 +25,49 @@ exports.fexists = fexists;
|
|
|
30
25
|
- options?:
|
|
31
26
|
- mode?: `'0o666'` Sets the file mode (permission and sticky bits) if the file is created.
|
|
32
27
|
*/
|
|
33
|
-
async function fopen(fp, flags, { mode, print } = {}) {
|
|
28
|
+
export async function fopen(fp, flags, { mode, print } = {}) {
|
|
34
29
|
if (print)
|
|
35
30
|
console.log('fopen:', fp);
|
|
36
|
-
return Object.assign(await
|
|
31
|
+
return Object.assign(await fsp.open(fp, flags, mode), {
|
|
37
32
|
fp,
|
|
38
33
|
flags,
|
|
39
34
|
mode
|
|
40
35
|
});
|
|
41
36
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
mfs.join = upath_1.default.join.bind(upath_1.default);
|
|
37
|
+
export function create_mfs() {
|
|
38
|
+
let mfs = MFS.createFsFromVolume(new MFS.Volume());
|
|
39
|
+
mfs.join = path.join.bind(path);
|
|
46
40
|
mfs.is_mfs = true;
|
|
47
41
|
return mfs;
|
|
48
42
|
}
|
|
49
|
-
|
|
50
|
-
async function fread(fp, { dir, encoding = 'utf-8', print = true } = {}) {
|
|
43
|
+
export async function fread(fp, { dir, encoding = 'utf-8', print = true } = {}) {
|
|
51
44
|
if (dir)
|
|
52
|
-
fp =
|
|
53
|
-
else if (!
|
|
45
|
+
fp = path.join(dir, fp);
|
|
46
|
+
else if (!path.isAbsolute(fp))
|
|
54
47
|
throw new Error('fp must be absolute path, or pass in \'dir\' parameter');
|
|
55
48
|
if (print)
|
|
56
49
|
console.log(`read: ${fp}`);
|
|
57
|
-
const buffer = await
|
|
50
|
+
const buffer = await fsp.readFile(fp);
|
|
58
51
|
if (encoding === 'binary')
|
|
59
52
|
return buffer;
|
|
60
53
|
if (encoding === 'utf-8')
|
|
61
54
|
return buffer.toString('utf8');
|
|
62
55
|
if (encoding === 'auto') {
|
|
63
|
-
const { detect } = await
|
|
56
|
+
const { detect } = await import('chardet');
|
|
64
57
|
encoding = detect(buffer);
|
|
65
58
|
if (print)
|
|
66
59
|
console.log(`${fp} probably has encoding: ${encoding.toLowerCase()}`);
|
|
67
60
|
}
|
|
68
|
-
return
|
|
61
|
+
return iconv.decode(buffer, encoding);
|
|
69
62
|
}
|
|
70
|
-
|
|
71
|
-
async function fread_lines(fp, options = {}) {
|
|
63
|
+
export async function fread_lines(fp, options = {}) {
|
|
72
64
|
return (await fread(fp, options))
|
|
73
65
|
.split_lines();
|
|
74
66
|
}
|
|
75
|
-
|
|
76
|
-
async function fread_json(fp, options = {}) {
|
|
67
|
+
export async function fread_json(fp, options = {}) {
|
|
77
68
|
return JSON.parse(await fread(fp, options));
|
|
78
69
|
}
|
|
79
|
-
|
|
80
|
-
async function fwrite(fp, data, { dir, encoding = 'utf-8', print = true, mkdir = false, } = {}) {
|
|
70
|
+
export async function fwrite(fp, data, { dir, encoding = 'utf-8', print = true, mkdir = false, } = {}) {
|
|
81
71
|
const is_handle = typeof fp === 'object' && fp && 'fd' in fp;
|
|
82
72
|
if (is_handle) {
|
|
83
73
|
if (print)
|
|
@@ -85,39 +75,37 @@ async function fwrite(fp, data, { dir, encoding = 'utf-8', print = true, mkdir =
|
|
|
85
75
|
}
|
|
86
76
|
else {
|
|
87
77
|
if (dir)
|
|
88
|
-
fp =
|
|
89
|
-
else if (!
|
|
78
|
+
fp = path.join(dir, fp);
|
|
79
|
+
else if (!path.isAbsolute(fp))
|
|
90
80
|
throw new Error('fp must be absolute path, or pass in "dir" parameter');
|
|
91
81
|
if (print)
|
|
92
82
|
console.log('write:', fp);
|
|
93
83
|
}
|
|
94
84
|
if (encoding === 'gb18030')
|
|
95
|
-
data =
|
|
85
|
+
data = iconv.encode(data, encoding);
|
|
96
86
|
if (!Buffer.isBuffer(data) && typeof data !== 'string')
|
|
97
|
-
data =
|
|
87
|
+
data = to_json(data);
|
|
98
88
|
try {
|
|
99
|
-
await
|
|
89
|
+
await fsp.writeFile(fp, data);
|
|
100
90
|
}
|
|
101
91
|
catch (error) {
|
|
102
92
|
if (!mkdir || error.code !== 'ENOENT' || is_handle)
|
|
103
93
|
throw error;
|
|
104
94
|
await fmkdir(fp.fdir);
|
|
105
|
-
await
|
|
95
|
+
await fsp.writeFile(fp, data);
|
|
106
96
|
}
|
|
107
97
|
}
|
|
108
|
-
|
|
109
|
-
async function fappend(fp, data, { dir, print = true } = {}) {
|
|
98
|
+
export async function fappend(fp, data, { dir, print = true } = {}) {
|
|
110
99
|
if (dir)
|
|
111
|
-
fp =
|
|
112
|
-
else if (!
|
|
100
|
+
fp = path.join(dir, fp);
|
|
101
|
+
else if (!path.isAbsolute(fp))
|
|
113
102
|
throw new Error('fp must be absolute path, or pass in "dir" parameter');
|
|
114
103
|
if (print)
|
|
115
104
|
console.log('append:', fp);
|
|
116
105
|
if (!Buffer.isBuffer(data) && typeof data !== 'string')
|
|
117
106
|
throw new Error('data is not Buffer or string');
|
|
118
|
-
await
|
|
107
|
+
await fsp.appendFile(fp, data);
|
|
119
108
|
}
|
|
120
|
-
exports.fappend = fappend;
|
|
121
109
|
/**
|
|
122
110
|
- fpd: absolute path of directory
|
|
123
111
|
- optoins?:
|
|
@@ -127,9 +115,9 @@ exports.fappend = fappend;
|
|
|
127
115
|
- filter?: `true` RegExp | (fp: string) => any, Note that when deep = true,
|
|
128
116
|
directories and files in directories that are filtered out by the filter will not be included in the results
|
|
129
117
|
*/
|
|
130
|
-
async function flist(fpd, options = {}) {
|
|
118
|
+
export async function flist(fpd, options = {}) {
|
|
131
119
|
const { filter, deep = false, absolute = false, print = true, } = options;
|
|
132
|
-
if (!
|
|
120
|
+
if (!path.isAbsolute(fpd))
|
|
133
121
|
throw new Error(`fpd (${fpd}) must be absolute path`);
|
|
134
122
|
if (!fpd.endsWith('/'))
|
|
135
123
|
throw new Error(`Argument fpd (${fpd}) must end with /`);
|
|
@@ -137,7 +125,7 @@ async function flist(fpd, options = {}) {
|
|
|
137
125
|
// 都调用了 uv_fs_scandir, 且调用参数相同,仅仅是 Node.js 侧的回调不同 AfterScanDir / AfterScanDirWithTypes
|
|
138
126
|
// 回调中通过 uv_fs_scandir_next 获取到每个条目的信息,而 uv_fs_scandir_next 中都会读取 type
|
|
139
127
|
// 速度上:都在 0.2 ms 左右就可以完成
|
|
140
|
-
const files = await
|
|
128
|
+
const files = await fsp.readdir(fpd, {
|
|
141
129
|
withFileTypes: true,
|
|
142
130
|
encoding: 'utf-8',
|
|
143
131
|
});
|
|
@@ -166,28 +154,26 @@ async function flist(fpd, options = {}) {
|
|
|
166
154
|
:
|
|
167
155
|
fps;
|
|
168
156
|
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
if (!upath_1.default.isAbsolute(fp))
|
|
157
|
+
export async function fstat(fp) {
|
|
158
|
+
if (!path.isAbsolute(fp))
|
|
172
159
|
throw new Error(`fp (${fp}) must be absolute path`);
|
|
173
|
-
return
|
|
160
|
+
return fsp.stat(fp, { bigint: true });
|
|
174
161
|
}
|
|
175
|
-
exports.fstat = fstat;
|
|
176
162
|
/** delete file or directory (use rimraf to delete directory fast)
|
|
177
163
|
- fp: path
|
|
178
164
|
- options?:
|
|
179
165
|
- print?: `true` (effective only delete single file)
|
|
180
166
|
*/
|
|
181
|
-
async function fdelete(fp, { print = true, fast = false } = {}) {
|
|
167
|
+
export async function fdelete(fp, { print = true, fast = false } = {}) {
|
|
182
168
|
if (fp.length < 6)
|
|
183
169
|
throw new Error(`${fp} too short`);
|
|
184
|
-
if (!
|
|
170
|
+
if (!path.isAbsolute(fp))
|
|
185
171
|
throw new Error('fpd must be absolute path');
|
|
186
172
|
if (fp.endsWith('/')) {
|
|
187
173
|
if (print)
|
|
188
174
|
console.log(`delete directory: ${fp}`.red);
|
|
189
175
|
await new Promise((resolve, reject) => {
|
|
190
|
-
(
|
|
176
|
+
rimraf(fp, { glob: false, disableGlob: true }, error => {
|
|
191
177
|
if (error)
|
|
192
178
|
reject(error);
|
|
193
179
|
else
|
|
@@ -198,42 +184,39 @@ async function fdelete(fp, { print = true, fast = false } = {}) {
|
|
|
198
184
|
else {
|
|
199
185
|
if (print)
|
|
200
186
|
console.log('delete:', fp);
|
|
201
|
-
await
|
|
187
|
+
await fsp.unlink(fp);
|
|
202
188
|
}
|
|
203
189
|
}
|
|
204
|
-
exports.fdelete = fdelete;
|
|
205
190
|
/** copy file or direcotry
|
|
206
191
|
- src: src file/directory absolute path
|
|
207
192
|
- dst: dst file/directory absolute path
|
|
208
193
|
@example
|
|
209
194
|
fcopy('d:/temp/camera/', 'd:/camera/')
|
|
210
195
|
*/
|
|
211
|
-
async function fcopy(fp_src, fp_dst, { print = true, overwrite = true, } = {}) {
|
|
196
|
+
export async function fcopy(fp_src, fp_dst, { print = true, overwrite = true, } = {}) {
|
|
212
197
|
if (fp_src.endsWith('/') !== fp_dst.endsWith('/'))
|
|
213
198
|
throw new Error('fp_src and fp_dst must be both file path or directory path');
|
|
214
|
-
if (!
|
|
199
|
+
if (!path.isAbsolute(fp_src) || !path.isAbsolute(fp_dst))
|
|
215
200
|
throw new Error('fp_src and fp_dst must be absolute path');
|
|
216
201
|
if (print)
|
|
217
202
|
console.log(`copy: ${fp_src} → ${fp_dst}`);
|
|
218
|
-
await
|
|
203
|
+
await fse.copy(fp_src, fp_dst, { overwrite, errorOnExist: true });
|
|
219
204
|
}
|
|
220
|
-
exports.fcopy = fcopy;
|
|
221
205
|
/** move file or direcotry
|
|
222
206
|
- src: src file/directory absolute path
|
|
223
207
|
- dst: dst file/directory absolute path
|
|
224
208
|
@example
|
|
225
209
|
fmove('d:/temp/camera/', 'd:/camera/')
|
|
226
210
|
*/
|
|
227
|
-
async function fmove(src, dst, { overwrite = false, print = true } = {}) {
|
|
211
|
+
export async function fmove(src, dst, { overwrite = false, print = true } = {}) {
|
|
228
212
|
if (src.endsWith('/') !== dst.endsWith('/'))
|
|
229
213
|
throw new Error('src and dst must be both file path or directory path');
|
|
230
|
-
if (!
|
|
214
|
+
if (!path.isAbsolute(src) || !path.isAbsolute(dst))
|
|
231
215
|
throw new Error('src and dst must be absolute path');
|
|
232
216
|
if (print)
|
|
233
217
|
console.log(`move: ${src} → ${dst}`);
|
|
234
|
-
await
|
|
218
|
+
await fse.move(src, dst, { overwrite });
|
|
235
219
|
}
|
|
236
|
-
exports.fmove = fmove;
|
|
237
220
|
/** rename file
|
|
238
221
|
- fp: current filename/path
|
|
239
222
|
- fp_: new filename/path
|
|
@@ -242,20 +225,19 @@ exports.fmove = fmove;
|
|
|
242
225
|
- print?: `true`
|
|
243
226
|
- overwrite?: `true` better performance without check
|
|
244
227
|
*/
|
|
245
|
-
async function frename(fp, fp_, { fpd, print = true, overwrite = true } = {}) {
|
|
228
|
+
export async function frename(fp, fp_, { fpd, print = true, overwrite = true } = {}) {
|
|
246
229
|
if (fpd) {
|
|
247
|
-
fp =
|
|
248
|
-
fp_ =
|
|
230
|
+
fp = path.join(fpd, fp);
|
|
231
|
+
fp_ = path.join(fpd, fp_);
|
|
249
232
|
}
|
|
250
|
-
else if (!
|
|
233
|
+
else if (!path.isAbsolute(fp) || !path.isAbsolute(fp_))
|
|
251
234
|
throw new Error('fp and fp_ must be absolute path');
|
|
252
235
|
if (print)
|
|
253
236
|
console.log('rename:', fp, '→', fp_);
|
|
254
237
|
if (!overwrite && fexists(fp_))
|
|
255
238
|
throw new Error(`file already exists:${fp_}`);
|
|
256
|
-
await
|
|
239
|
+
await fsp.rename(fp, fp_);
|
|
257
240
|
}
|
|
258
|
-
exports.frename = frename;
|
|
259
241
|
/**
|
|
260
242
|
Create folders recursively, make sure the folder pointed to by fpd exists
|
|
261
243
|
Returns the first created folder or undefined
|
|
@@ -265,13 +247,13 @@ exports.frename = frename;
|
|
|
265
247
|
- print?: `true`
|
|
266
248
|
- mode?: `'0o777'`
|
|
267
249
|
*/
|
|
268
|
-
async function fmkdir(fpd, { print = true, mode, } = {}) {
|
|
269
|
-
if (!
|
|
250
|
+
export async function fmkdir(fpd, { print = true, mode, } = {}) {
|
|
251
|
+
if (!path.isAbsolute(fpd))
|
|
270
252
|
throw new Error(`fpd must be an absolute path: ${fpd}`);
|
|
271
253
|
if (!fpd.endsWith('/'))
|
|
272
254
|
throw new Error(`fpd must end with /: ${fpd}`);
|
|
273
255
|
// CallingfsPromises.mkdir() when path is a directory that exists results in a rejection only when recursive is false.
|
|
274
|
-
const fpd_ = (await
|
|
256
|
+
const fpd_ = (await fsp.mkdir(fpd, { recursive: true, mode }))?.replaceAll('\\', '/');
|
|
275
257
|
if (fpd_) {
|
|
276
258
|
if (print)
|
|
277
259
|
console.log('folder created:', fpd);
|
|
@@ -280,13 +262,12 @@ async function fmkdir(fpd, { print = true, mode, } = {}) {
|
|
|
280
262
|
console.log('folder already exists:', fpd);
|
|
281
263
|
return fpd_;
|
|
282
264
|
}
|
|
283
|
-
exports.fmkdir = fmkdir;
|
|
284
265
|
/**
|
|
285
266
|
- fp_real: current real file/directory path
|
|
286
267
|
- fp_link: target file/directory path
|
|
287
268
|
*/
|
|
288
|
-
async function flink(fp_real, fp_link, { junction = false, print = true } = {}) {
|
|
289
|
-
if (!
|
|
269
|
+
export async function flink(fp_real, fp_link, { junction = false, print = true } = {}) {
|
|
270
|
+
if (!path.isAbsolute(fp_real) || !path.isAbsolute(fp_link))
|
|
290
271
|
throw new Error('fp must be absolute path');
|
|
291
272
|
const is_fpd_real = fp_real.endsWith('/');
|
|
292
273
|
const is_fpd_link = fp_link.endsWith('/');
|
|
@@ -297,12 +278,11 @@ async function flink(fp_real, fp_link, { junction = false, print = true } = {})
|
|
|
297
278
|
if (print)
|
|
298
279
|
console.log(`source file ${fp_real} linked to ${fp_link}`);
|
|
299
280
|
if (junction)
|
|
300
|
-
|
|
281
|
+
fsp.symlink(fp_real, fp_link, 'junction');
|
|
301
282
|
else
|
|
302
|
-
|
|
283
|
+
fsp.symlink(fp_real, fp_link, is_fpd_real ? 'dir' : 'file');
|
|
303
284
|
}
|
|
304
|
-
|
|
305
|
-
exports.fwatchers = {};
|
|
285
|
+
export let fwatchers = {};
|
|
306
286
|
/**
|
|
307
287
|
- fp: path of file or directory
|
|
308
288
|
- callback: called when modified
|
|
@@ -318,41 +298,39 @@ exports.fwatchers = {};
|
|
|
318
298
|
The listener callback is attached to the 'change' event fired by fs.FSWatcher, but it is not the same thing as the 'change' value of event.
|
|
319
299
|
|
|
320
300
|
*/
|
|
321
|
-
async function fwatch(fp, onchange, { exec = true } = {}) {
|
|
322
|
-
if (!
|
|
301
|
+
export async function fwatch(fp, onchange, { exec = true } = {}) {
|
|
302
|
+
if (!path.isAbsolute(fp))
|
|
323
303
|
throw new Error('fp must be absolute path');
|
|
324
|
-
const _watcher =
|
|
304
|
+
const _watcher = fwatchers[fp];
|
|
325
305
|
if (_watcher)
|
|
326
306
|
_watcher.close();
|
|
327
307
|
if (exec)
|
|
328
308
|
await onchange('change', fp.fname);
|
|
329
309
|
const start = new Date().getTime();
|
|
330
|
-
const debounced_onchange = (
|
|
310
|
+
const debounced_onchange = debounce((event, fname) => {
|
|
331
311
|
if (new Date().getTime() - start < 800)
|
|
332
312
|
return;
|
|
333
313
|
console.log(`file ${event}: ${fname}`);
|
|
334
|
-
onchange(event,
|
|
314
|
+
onchange(event, path.normalize(fname));
|
|
335
315
|
}, 500, { leading: false, trailing: true });
|
|
336
|
-
let watcher =
|
|
316
|
+
let watcher = fs.watch(fp, debounced_onchange);
|
|
337
317
|
watcher.on('error', error => {
|
|
338
318
|
console.error(error);
|
|
339
319
|
});
|
|
340
|
-
return
|
|
320
|
+
return fwatchers[fp] = watcher;
|
|
341
321
|
}
|
|
342
|
-
exports.fwatch = fwatch;
|
|
343
322
|
/** open a file and replace certain pattern */
|
|
344
|
-
async function freplace(fp, pattern, replacement) {
|
|
323
|
+
export async function freplace(fp, pattern, replacement) {
|
|
345
324
|
await fwrite(fp, (await fread(fp))
|
|
346
325
|
.replaceAll(pattern, replacement));
|
|
347
326
|
}
|
|
348
|
-
exports.freplace = freplace;
|
|
349
327
|
/** convert file encoding to UTF-8
|
|
350
328
|
- fp: file absolute path
|
|
351
329
|
- options?:
|
|
352
330
|
- dryrun?: `true`
|
|
353
331
|
- encoding?: `'auto'`
|
|
354
332
|
*/
|
|
355
|
-
async function f2utf8(fp, { dryrun = true, encoding = 'auto', } = {}) {
|
|
333
|
+
export async function f2utf8(fp, { dryrun = true, encoding = 'auto', } = {}) {
|
|
356
334
|
const text = await fread(fp, { encoding });
|
|
357
335
|
if (dryrun) {
|
|
358
336
|
console.log(text.slice(0, 10000));
|
|
@@ -363,5 +341,4 @@ async function f2utf8(fp, { dryrun = true, encoding = 'auto', } = {}) {
|
|
|
363
341
|
await fcopy(fp, fp_bak);
|
|
364
342
|
await fwrite(fp, text);
|
|
365
343
|
}
|
|
366
|
-
exports.f2utf8 = f2utf8;
|
|
367
344
|
//# sourceMappingURL=file.js.map
|
package/file.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file.js","sourceRoot":"","sources":["file.ts"],"names":[],"mappings":";;;;AAAA,iDAGW;AAGX,0DAAwB;AACxB,oEAA8B;AAC9B,gEAA0B;AAC1B,4DAA2B;AAE3B,6EAAyC;AAGzC,0DAAuB;AAYd,cAZF,eAAG,CAYE;AAJZ,iDAAwC;AACxC,mDAAwB;AAQxB,mDAAmD;AACnD,SAAgB,OAAO,CAAE,EAAU,EAAE,EAAE,KAAK,GAAG,IAAI,KAA0B,EAAG;IAC5E,MAAM,MAAM,GAAG,YAAE,CAAC,UAAU,CAAC,EAAE,CAAC,CAAA;IAEhC,IAAI,KAAK;QACL,OAAO,CAAC,GAAG,CACP,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,aAAa,EAClC,EAAE,CACL,CAAA;IAEL,OAAO,MAAM,CAAA;AACjB,CAAC;AAVD,0BAUC;AAGD;;;;;;;;;EASE;AACK,KAAK,UAAU,KAAK,CACvB,EAAU,EACV,KAAsB,EACtB,EACI,I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MAAM,MAIjB,EAAG;IACH,MAAM,IAAI,GAAG,MAAM,KAAK,CAAC,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAA;IAC1C,IAAI,MAAM,EAAE;QACR,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAA;QACjC,OAAM;KACT;IAED,MAAM,MAAM,GAAG,GAAG,EAAE,CAAC,IAAI,GAAG,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,kBAAkB,EAAE,UAAU,CAAC,EAAE,CAAA;IAC9E,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC;QAChB,MAAM,KAAK,CAAC,EAAE,EAAE,MAAM,CAAC,CAAA;IAE3B,MAAM,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,CAAA;AAC1B,CAAC;AAlBD,wBAkBC","sourcesContent":["import {\n promises as fsp,\n default as fs,\n} from 'fs'\ntype FileHandle = fsp.FileHandle & { fp: string }\n\nimport path from 'upath'\nimport iconv from 'iconv-lite'\nimport fse from 'fs-extra'\nimport rimraf from 'rimraf'\n\nimport debounce from 'lodash/debounce.js'\n\n\nimport MFS from 'memfs'\ndeclare module 'memfs' {\n interface IFs {\n join: typeof path.join\n is_mfs: true\n }\n}\n\nimport { to_json } from './prototype.js'\nexport * from './ufs.js'\n\n\nexport { MFS }\n\nexport type Encoding = 'utf-8' | 'gb18030' | 'shift-jis' | 'binary'\n\n\n/** Does the file/folder pointed to by fp exist? */\nexport function fexists (fp: string, { print = true }: { print?: boolean } = { }) {\n const exists = fs.existsSync(fp)\n \n if (print)\n console.log(\n exists ? 'exists:' : 'not exists:',\n fp\n )\n \n return exists\n}\n\n\n/**\n open file, return FileHandle \n Some characters (`< > : \" / \\ | ? *`) are reserved under Windows as documented\n by [Naming Files, Paths, and Namespaces](https://docs.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file). Under NTFS, if the filename contains\n a colon, Node.js will open a file system stream, as described by [this MSDN page](https://docs.microsoft.com/en-us/windows/desktop/FileIO/using-streams).\n \n - flags: `'r'`\n - options?:\n - mode?: `'0o666'` Sets the file mode (permission and sticky bits) if the file is created.\n*/\nexport async function fopen (\n fp: string,\n flags: string | number,\n {\n mode,\n print\n }: {\n mode?: fs.Mode\n print?: boolean\n } = { }\n) {\n if (print)\n console.log('fopen:', fp)\n return Object.assign(\n await fsp.open(fp, flags, mode),\n {\n fp,\n flags,\n mode\n }\n )\n}\n\n\nexport function create_mfs () {\n let mfs = MFS.createFsFromVolume(\n new MFS.Volume()\n )\n \n mfs.join = path.join.bind(path)\n mfs.is_mfs = true\n \n return mfs\n}\n\n\nexport async function fread (fp: string): Promise<string>\nexport async function fread (fp: string, { dir, encoding, print }?: { dir?: string, encoding: 'binary', print?: boolean }): Promise<Buffer>\nexport async function fread (fp: string, { dir, encoding, print }?: { dir?: string, encoding?: Encoding | 'auto', print?: boolean }): Promise<string>\nexport async function fread (fp: string, {\n dir, \n encoding = 'utf-8', \n print = true\n}: {\n dir?: string\n encoding?: Encoding | 'auto'\n print?: boolean } = { }\n) {\n if (dir)\n fp = path.join(dir, fp)\n else if (!path.isAbsolute(fp))\n throw new Error('fp must be absolute path, or pass in \\'dir\\' parameter')\n \n if (print)\n console.log(`read: ${fp}`)\n \n const buffer = await fsp.readFile(fp)\n \n if (encoding === 'binary')\n return buffer\n \n if (encoding === 'utf-8')\n return buffer.toString('utf8')\n \n if (encoding === 'auto') {\n const { detect } = await import('chardet')\n encoding = detect(buffer) as any\n if (print)\n console.log(`${fp} probably has encoding: ${encoding.toLowerCase()}`)\n }\n \n return iconv.decode(buffer, encoding)\n}\n\nexport async function fread_lines (fp: string, options: { dir?: string, encoding?: Exclude<Encoding, 'binary'> | 'auto', print?: boolean } = { }) {\n return (await fread(fp, options))\n .split_lines()\n}\n\nexport async function fread_json <T = any> (fp: string, options: { dir?: string, encoding?: Encoding, print?: boolean } = { }): Promise<T> {\n return JSON.parse(\n await fread(fp, options)\n )\n}\n\n\nexport async function fwrite (fp: string | FileHandle, data: Buffer, options?: { dir?: string, print?: boolean, mkdir?: boolean }): Promise<void>\nexport async function fwrite (fp: string | FileHandle, data: any, options?: { dir?: string, encoding?: Encoding, print?: boolean, mkdir?: boolean }): Promise<void>\nexport async function fwrite (\n fp: string | FileHandle,\n data: any,\n {\n dir,\n encoding = 'utf-8',\n print = true,\n mkdir = false,\n }: {\n dir?: string\n encoding?: Encoding\n print?: boolean\n mkdir?: boolean\n } = { }\n) {\n const is_handle = typeof fp === 'object' && fp && 'fd' in fp\n if (is_handle) {\n if (print)\n console.log('write:', (fp as FileHandle).fp)\n } else {\n if (dir)\n fp = path.join(dir, fp)\n else if (!path.isAbsolute(fp as string))\n throw new Error('fp must be absolute path, or pass in \"dir\" parameter')\n \n if (print)\n console.log('write:', fp)\n }\n \n if (encoding === 'gb18030')\n data = iconv.encode(data, encoding)\n \n if (!Buffer.isBuffer(data) && typeof data !== 'string')\n data = to_json(data)\n \n try {\n await fsp.writeFile(fp, data)\n } catch (error) {\n if (!mkdir || error.code !== 'ENOENT' || is_handle)\n throw error\n \n await fmkdir((fp as string).fdir)\n await fsp.writeFile(fp, data)\n }\n}\n\nexport async function fappend (fp: string, data: any, { dir, print = true }: { dir?: string, print?: boolean } = { }) {\n if (dir)\n fp = path.join(dir, fp)\n else if (!path.isAbsolute(fp))\n throw new Error('fp must be absolute path, or pass in \"dir\" parameter')\n \n if (print)\n console.log('append:', fp)\n \n if (!Buffer.isBuffer(data) && typeof data !== 'string')\n throw new Error('data is not Buffer or string')\n \n await fsp.appendFile(fp, data)\n}\n\n\n/**\n - fpd: absolute path of directory\n - optoins?:\n - deep?: `false` recursively\n - absolute?: `false` Return, print full path instead of relative path\n - print?: `true`\n - filter?: `true` RegExp | (fp: string) => any, Note that when deep = true, \n directories and files in directories that are filtered out by the filter will not be included in the results\n*/\nexport async function flist (\n fpd: string,\n options: {\n filter?: RegExp | ((fp: string) => any)\n deep?: boolean\n absolute?: boolean\n print?: boolean\n } = { }\n): Promise<string[]> {\n const {\n filter,\n deep = false,\n absolute = false,\n print = true,\n } = options\n \n if (!path.isAbsolute(fpd))\n throw new Error(`fpd (${fpd}) must be absolute path`)\n \n if (!fpd.endsWith('/'))\n throw new Error(`Argument fpd (${fpd}) must end with /`)\n \n // readdir withFileTypes 参数在底层有什么区别,速度上有什么差异\n // 都调用了 uv_fs_scandir, 且调用参数相同,仅仅是 Node.js 侧的回调不同 AfterScanDir / AfterScanDirWithTypes\n // 回调中通过 uv_fs_scandir_next 获取到每个条目的信息,而 uv_fs_scandir_next 中都会读取 type\n // 速度上:都在 0.2 ms 左右就可以完成\n \n const files = await fsp.readdir(fpd, {\n withFileTypes: true,\n encoding: 'utf-8',\n })\n \n const filter_regexp = filter instanceof RegExp\n const filter_fn = Boolean(filter && !filter_regexp)\n \n let fps: string[] = [ ]\n \n for (const file of files) {\n const fp = \n (absolute ? fpd : '') +\n file.name +\n (file.isDirectory() ? '/' : '')\n \n if (filter_regexp && !filter.test(fp))\n continue\n \n if (filter_fn && !(filter as Function)(fp))\n continue\n \n if (print)\n console.log(\n deep || absolute ? fpd + fp : fp\n )\n \n fps.push(fp)\n }\n \n return deep ? (\n await Promise.all(\n fps.map(async fp => \n fp.endsWith('/') ?\n [\n fp,\n ... (await flist(\n absolute ? fp : fpd + fp,\n options\n )).map(fp_ => \n absolute ? fp_ : fp + fp_)\n ]\n :\n fp)\n )\n ).flat()\n :\n fps\n}\n\n\nexport async function fstat (fp: string) {\n if (!path.isAbsolute(fp))\n throw new Error(`fp (${fp}) must be absolute path`)\n \n return fsp.stat(fp, { bigint: true })\n}\n\n\n/** delete file or directory (use rimraf to delete directory fast) \n - fp: path\n - options?:\n - print?: `true` (effective only delete single file)\n*/\nexport async function fdelete (fp: string, { print = true, fast = false }: { print?: boolean, fast?: boolean } = { }) {\n if (fp.length < 6) throw new Error(`${fp} too short`)\n if (!path.isAbsolute(fp))\n throw new Error('fpd must be absolute path')\n \n if (fp.endsWith('/')) {\n if (print)\n console.log(`delete directory: ${fp}`.red)\n await new Promise<void>((resolve, reject) => {\n rimraf(fp, { glob: false, disableGlob: true }, error => {\n if (error)\n reject(error)\n else\n resolve()\n })\n })\n } else {\n if (print)\n console.log('delete:', fp)\n await fsp.unlink(fp)\n }\n}\n\n\n/** copy file or direcotry\n - src: src file/directory absolute path\n - dst: dst file/directory absolute path\n @example\n fcopy('d:/temp/camera/', 'd:/camera/')\n*/\nexport async function fcopy (fp_src: string, fp_dst: string, {\n print = true,\n overwrite = true,\n}: {\n print?: boolean\n overwrite?: boolean\n} = { }) {\n if (fp_src.endsWith('/') !== fp_dst.endsWith('/'))\n throw new Error('fp_src and fp_dst must be both file path or directory path')\n \n if (!path.isAbsolute(fp_src) || !path.isAbsolute(fp_dst))\n throw new Error('fp_src and fp_dst must be absolute path')\n \n if (print)\n console.log(`copy: ${fp_src} → ${fp_dst}`)\n \n await fse.copy(fp_src, fp_dst, { overwrite, errorOnExist: true })\n}\n\n\n/** move file or direcotry\n - src: src file/directory absolute path\n - dst: dst file/directory absolute path\n @example\n fmove('d:/temp/camera/', 'd:/camera/')\n*/\nexport async function fmove (src: string, dst: string, {\n overwrite = false,\n print = true\n}: {\n overwrite?: boolean\n print?: boolean\n} = { }) {\n if (src.endsWith('/') !== dst.endsWith('/'))\n throw new Error('src and dst must be both file path or directory path')\n \n if (!path.isAbsolute(src) || !path.isAbsolute(dst))\n throw new Error('src and dst must be absolute path')\n \n if (print)\n console.log(`move: ${src} → ${dst}`)\n \n await fse.move(src, dst, { overwrite })\n}\n\n\n/** rename file \n - fp: current filename/path\n - fp_: new filename/path\n - options?:\n - fpd?: fp and fp_ is in same directory\n - print?: `true`\n - overwrite?: `true` better performance without check\n */\nexport async function frename (\n fp: string, \n fp_: string,\n {\n fpd,\n print = true,\n overwrite = true\n }: {\n fpd?: string\n print?: boolean\n overwrite?: boolean\n } = { }\n) {\n if (fpd) {\n fp = path.join(fpd, fp)\n fp_ = path.join(fpd, fp_)\n } else if (!path.isAbsolute(fp) || !path.isAbsolute(fp_))\n throw new Error('fp and fp_ must be absolute path')\n \n if (print)\n console.log('rename:', fp, '→', fp_)\n \n if (!overwrite && fexists(fp_))\n throw new Error(`file already exists:${fp_}`)\n \n await fsp.rename(fp, fp_)\n}\n\n\n/**\n Create folders recursively, make sure the folder pointed to by fpd exists \n Returns the first created folder or undefined\n \n - fpd: Folder full path\n - options?:\n - print?: `true`\n - mode?: `'0o777'`\n*/\nexport async function fmkdir (\n fpd: string,\n {\n print = true,\n mode,\n }: {\n print?: boolean\n \n /** `0o777` A file mode. If a string is passed, it is parsed as an octal integer. */\n mode?: string | number\n } = { }\n) {\n if (!path.isAbsolute(fpd))\n throw new Error(`fpd must be an absolute path: ${fpd}`)\n \n if (!fpd.endsWith('/'))\n throw new Error(`fpd must end with /: ${fpd}`)\n \n // CallingfsPromises.mkdir() when path is a directory that exists results in a rejection only when recursive is false.\n const fpd_ = (\n await fsp.mkdir(fpd, { recursive: true, mode })\n )?.replaceAll('\\\\', '/')\n \n if (fpd_) {\n if (print)\n console.log('folder created:', fpd)\n } else\n if (print)\n console.log('folder already exists:', fpd)\n \n return fpd_\n}\n\n\n/** \n - fp_real: current real file/directory path\n - fp_link: target file/directory path\n*/\nexport async function flink (\n fp_real: string, \n fp_link: string, \n {\n junction = false,\n print = true \n }: { \n junction?: boolean\n print?: boolean\n} = { }) {\n if (!path.isAbsolute(fp_real) || !path.isAbsolute(fp_link))\n throw new Error('fp must be absolute path')\n \n const is_fpd_real = fp_real.endsWith('/')\n const is_fpd_link = fp_link.endsWith('/')\n \n if (is_fpd_real !== is_fpd_link)\n throw new Error('fp_real and fp_link must be both file path or folder path')\n \n if (fexists(fp_link))\n throw new Error(`${ is_fpd_link ? 'folder' : 'file' } exists: ${fp_link}, could not create link`)\n \n if (print)\n console.log(`source file ${fp_real} linked to ${fp_link}`)\n \n if (junction)\n fsp.symlink(fp_real, fp_link, 'junction')\n else\n fsp.symlink(fp_real, fp_link, is_fpd_real ? 'dir' : 'file')\n}\n\n\nexport let fwatchers: Record<string, fs.FSWatcher> = { }\n\n/**\n - fp: path of file or directory\n - callback: called when modified\n - exec: call callback when watch is executed\n \n save fs.FSWatcher in watchers, subsequent call will auto close existing watcher for the same fp\n \n https://nodejs.org/dist/latest-v15.x/docs/api/fs.html#fs_fs_watch_filename_options_listener \n The listener callback gets two arguments (event, fname). \n event is either 'rename' or 'change', and filename is the name of the file which triggered the event.\n On most platforms, 'rename' is emitted whenever a filename appears or disappears in the directory.\n \n The listener callback is attached to the 'change' event fired by fs.FSWatcher, but it is not the same thing as the 'change' value of event. \n \n*/\nexport async function fwatch (\n fp: string,\n onchange: (event: string, fname: string) => any, \n { exec = true }: { exec?: boolean } = { }\n) {\n if (!path.isAbsolute(fp))\n throw new Error('fp must be absolute path')\n \n const _watcher = fwatchers[fp]\n if (_watcher)\n _watcher.close()\n \n if (exec)\n await onchange('change', fp.fname)\n \n const start = new Date().getTime()\n \n const debounced_onchange = debounce(\n (event, fname) => {\n if (new Date().getTime() - start < 800)\n return\n console.log(`file ${event}: ${fname}`)\n onchange(event, path.normalize(fname))\n },\n 500,\n { leading: false, trailing: true }\n )\n \n let watcher = fs.watch(fp, debounced_onchange)\n watcher.on('error', error => {\n console.error(error)\n })\n return fwatchers[fp] = watcher\n}\n\n\n/** open a file and replace certain pattern */\nexport async function freplace (fp: string, pattern: string | RegExp, replacement: string) {\n await fwrite(\n fp,\n (await fread(fp))\n .replaceAll(pattern, replacement)\n )\n}\n\n/** convert file encoding to UTF-8\n - fp: file absolute path\n - options?:\n - dryrun?: `true`\n - encoding?: `'auto'`\n*/\nexport async function f2utf8 (fp: string, {\n dryrun = true,\n encoding = 'auto',\n}: {\n dryrun?: boolean\n encoding?: Encoding | 'auto'\n} = { }) {\n const text = await fread(fp, { encoding })\n if (dryrun) {\n console.log(text.slice(0, 10000))\n return\n }\n \n const fp_bak = `${fp.fdir}${fp.fname.replace(/(.*?)(\\.[^.]+)?$/, '$1.bak$2')}`\n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AC,kBAAkB,EAAE,UAAU,CAAC,EAAE,CAAA;IAC9E,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC;QAChB,MAAM,KAAK,CAAC,EAAE,EAAE,MAAM,CAAC,CAAA;IAE3B,MAAM,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,CAAA;AAC1B,CAAC","sourcesContent":["import {\n promises as fsp,\n default as fs,\n} from 'fs'\ntype FileHandle = fsp.FileHandle & { fp: string }\n\nimport path from 'upath'\nimport iconv from 'iconv-lite'\nimport fse from 'fs-extra'\nimport rimraf from 'rimraf'\n\nimport debounce from 'lodash/debounce.js'\n\n\nimport MFS from 'memfs'\ndeclare module 'memfs' {\n interface IFs {\n join: typeof path.join\n is_mfs: true\n }\n}\n\nimport { to_json } from './prototype.js'\nexport * from './ufs.js'\n\n\nexport { MFS }\n\nexport type Encoding = 'utf-8' | 'gb18030' | 'shift-jis' | 'binary'\n\n\n/** Does the file/folder pointed to by fp exist? */\nexport function fexists (fp: string, { print = true }: { print?: boolean } = { }) {\n const exists = fs.existsSync(fp)\n \n if (print)\n console.log(\n exists ? 'exists:' : 'not exists:',\n fp\n )\n \n return exists\n}\n\n\n/**\n open file, return FileHandle \n Some characters (`< > : \" / \\ | ? *`) are reserved under Windows as documented\n by [Naming Files, Paths, and Namespaces](https://docs.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file). Under NTFS, if the filename contains\n a colon, Node.js will open a file system stream, as described by [this MSDN page](https://docs.microsoft.com/en-us/windows/desktop/FileIO/using-streams).\n \n - flags: `'r'`\n - options?:\n - mode?: `'0o666'` Sets the file mode (permission and sticky bits) if the file is created.\n*/\nexport async function fopen (\n fp: string,\n flags: string | number,\n {\n mode,\n print\n }: {\n mode?: fs.Mode\n print?: boolean\n } = { }\n) {\n if (print)\n console.log('fopen:', fp)\n return Object.assign(\n await fsp.open(fp, flags, mode),\n {\n fp,\n flags,\n mode\n }\n )\n}\n\n\nexport function create_mfs () {\n let mfs = MFS.createFsFromVolume(\n new MFS.Volume()\n )\n \n mfs.join = path.join.bind(path)\n mfs.is_mfs = true\n \n return mfs\n}\n\n\nexport async function fread (fp: string): Promise<string>\nexport async function fread (fp: string, { dir, encoding, print }?: { dir?: string, encoding: 'binary', print?: boolean }): Promise<Buffer>\nexport async function fread (fp: string, { dir, encoding, print }?: { dir?: string, encoding?: Encoding | 'auto', print?: boolean }): Promise<string>\nexport async function fread (fp: string, {\n dir, \n encoding = 'utf-8', \n print = true\n}: {\n dir?: string\n encoding?: Encoding | 'auto'\n print?: boolean } = { }\n) {\n if (dir)\n fp = path.join(dir, fp)\n else if (!path.isAbsolute(fp))\n throw new Error('fp must be absolute path, or pass in \\'dir\\' parameter')\n \n if (print)\n console.log(`read: ${fp}`)\n \n const buffer = await fsp.readFile(fp)\n \n if (encoding === 'binary')\n return buffer\n \n if (encoding === 'utf-8')\n return buffer.toString('utf8')\n \n if (encoding === 'auto') {\n const { detect } = await import('chardet')\n encoding = detect(buffer) as any\n if (print)\n console.log(`${fp} probably has encoding: ${encoding.toLowerCase()}`)\n }\n \n return iconv.decode(buffer, encoding)\n}\n\nexport async function fread_lines (fp: string, options: { dir?: string, encoding?: Exclude<Encoding, 'binary'> | 'auto', print?: boolean } = { }) {\n return (await fread(fp, options))\n .split_lines()\n}\n\nexport async function fread_json <T = any> (fp: string, options: { dir?: string, encoding?: Encoding, print?: boolean } = { }): Promise<T> {\n return JSON.parse(\n await fread(fp, options)\n )\n}\n\n\nexport async function fwrite (fp: string | FileHandle, data: Buffer, options?: { dir?: string, print?: boolean, mkdir?: boolean }): Promise<void>\nexport async function fwrite (fp: string | FileHandle, data: any, options?: { dir?: string, encoding?: Encoding, print?: boolean, mkdir?: boolean }): Promise<void>\nexport async function fwrite (\n fp: string | FileHandle,\n data: any,\n {\n dir,\n encoding = 'utf-8',\n print = true,\n mkdir = false,\n }: {\n dir?: string\n encoding?: Encoding\n print?: boolean\n mkdir?: boolean\n } = { }\n) {\n const is_handle = typeof fp === 'object' && fp && 'fd' in fp\n if (is_handle) {\n if (print)\n console.log('write:', (fp as FileHandle).fp)\n } else {\n if (dir)\n fp = path.join(dir, fp)\n else if (!path.isAbsolute(fp as string))\n throw new Error('fp must be absolute path, or pass in \"dir\" parameter')\n \n if (print)\n console.log('write:', fp)\n }\n \n if (encoding === 'gb18030')\n data = iconv.encode(data, encoding)\n \n if (!Buffer.isBuffer(data) && typeof data !== 'string')\n data = to_json(data)\n \n try {\n await fsp.writeFile(fp, data)\n } catch (error) {\n if (!mkdir || error.code !== 'ENOENT' || is_handle)\n throw error\n \n await fmkdir((fp as string).fdir)\n await fsp.writeFile(fp, data)\n }\n}\n\nexport async function fappend (fp: string, data: any, { dir, print = true }: { dir?: string, print?: boolean } = { }) {\n if (dir)\n fp = path.join(dir, fp)\n else if (!path.isAbsolute(fp))\n throw new Error('fp must be absolute path, or pass in \"dir\" parameter')\n \n if (print)\n console.log('append:', fp)\n \n if (!Buffer.isBuffer(data) && typeof data !== 'string')\n throw new Error('data is not Buffer or string')\n \n await fsp.appendFile(fp, data)\n}\n\n\n/**\n - fpd: absolute path of directory\n - optoins?:\n - deep?: `false` recursively\n - absolute?: `false` Return, print full path instead of relative path\n - print?: `true`\n - filter?: `true` RegExp | (fp: string) => any, Note that when deep = true, \n directories and files in directories that are filtered out by the filter will not be included in the results\n*/\nexport async function flist (\n fpd: string,\n options: {\n filter?: RegExp | ((fp: string) => any)\n deep?: boolean\n absolute?: boolean\n print?: boolean\n } = { }\n): Promise<string[]> {\n const {\n filter,\n deep = false,\n absolute = false,\n print = true,\n } = options\n \n if (!path.isAbsolute(fpd))\n throw new Error(`fpd (${fpd}) must be absolute path`)\n \n if (!fpd.endsWith('/'))\n throw new Error(`Argument fpd (${fpd}) must end with /`)\n \n // readdir withFileTypes 参数在底层有什么区别,速度上有什么差异\n // 都调用了 uv_fs_scandir, 且调用参数相同,仅仅是 Node.js 侧的回调不同 AfterScanDir / AfterScanDirWithTypes\n // 回调中通过 uv_fs_scandir_next 获取到每个条目的信息,而 uv_fs_scandir_next 中都会读取 type\n // 速度上:都在 0.2 ms 左右就可以完成\n \n const files = await fsp.readdir(fpd, {\n withFileTypes: true,\n encoding: 'utf-8',\n })\n \n const filter_regexp = filter instanceof RegExp\n const filter_fn = Boolean(filter && !filter_regexp)\n \n let fps: string[] = [ ]\n \n for (const file of files) {\n const fp = \n (absolute ? fpd : '') +\n file.name +\n (file.isDirectory() ? '/' : '')\n \n if (filter_regexp && !filter.test(fp))\n continue\n \n if (filter_fn && !(filter as Function)(fp))\n continue\n \n if (print)\n console.log(\n deep || absolute ? fpd + fp : fp\n )\n \n fps.push(fp)\n }\n \n return deep ? (\n await Promise.all(\n fps.map(async fp => \n fp.endsWith('/') ?\n [\n fp,\n ... (await flist(\n absolute ? fp : fpd + fp,\n options\n )).map(fp_ => \n absolute ? fp_ : fp + fp_)\n ]\n :\n fp)\n )\n ).flat()\n :\n fps\n}\n\n\nexport async function fstat (fp: string) {\n if (!path.isAbsolute(fp))\n throw new Error(`fp (${fp}) must be absolute path`)\n \n return fsp.stat(fp, { bigint: true })\n}\n\n\n/** delete file or directory (use rimraf to delete directory fast) \n - fp: path\n - options?:\n - print?: `true` (effective only delete single file)\n*/\nexport async function fdelete (fp: string, { print = true, fast = false }: { print?: boolean, fast?: boolean } = { }) {\n if (fp.length < 6) throw new Error(`${fp} too short`)\n if (!path.isAbsolute(fp))\n throw new Error('fpd must be absolute path')\n \n if (fp.endsWith('/')) {\n if (print)\n console.log(`delete directory: ${fp}`.red)\n await new Promise<void>((resolve, reject) => {\n rimraf(fp, { glob: false, disableGlob: true }, error => {\n if (error)\n reject(error)\n else\n resolve()\n })\n })\n } else {\n if (print)\n console.log('delete:', fp)\n await fsp.unlink(fp)\n }\n}\n\n\n/** copy file or direcotry\n - src: src file/directory absolute path\n - dst: dst file/directory absolute path\n @example\n fcopy('d:/temp/camera/', 'd:/camera/')\n*/\nexport async function fcopy (fp_src: string, fp_dst: string, {\n print = true,\n overwrite = true,\n}: {\n print?: boolean\n overwrite?: boolean\n} = { }) {\n if (fp_src.endsWith('/') !== fp_dst.endsWith('/'))\n throw new Error('fp_src and fp_dst must be both file path or directory path')\n \n if (!path.isAbsolute(fp_src) || !path.isAbsolute(fp_dst))\n throw new Error('fp_src and fp_dst must be absolute path')\n \n if (print)\n console.log(`copy: ${fp_src} → ${fp_dst}`)\n \n await fse.copy(fp_src, fp_dst, { overwrite, errorOnExist: true })\n}\n\n\n/** move file or direcotry\n - src: src file/directory absolute path\n - dst: dst file/directory absolute path\n @example\n fmove('d:/temp/camera/', 'd:/camera/')\n*/\nexport async function fmove (src: string, dst: string, {\n overwrite = false,\n print = true\n}: {\n overwrite?: boolean\n print?: boolean\n} = { }) {\n if (src.endsWith('/') !== dst.endsWith('/'))\n throw new Error('src and dst must be both file path or directory path')\n \n if (!path.isAbsolute(src) || !path.isAbsolute(dst))\n throw new Error('src and dst must be absolute path')\n \n if (print)\n console.log(`move: ${src} → ${dst}`)\n \n await fse.move(src, dst, { overwrite })\n}\n\n\n/** rename file \n - fp: current filename/path\n - fp_: new filename/path\n - options?:\n - fpd?: fp and fp_ is in same directory\n - print?: `true`\n - overwrite?: `true` better performance without check\n */\nexport async function frename (\n fp: string, \n fp_: string,\n {\n fpd,\n print = true,\n overwrite = true\n }: {\n fpd?: string\n print?: boolean\n overwrite?: boolean\n } = { }\n) {\n if (fpd) {\n fp = path.join(fpd, fp)\n fp_ = path.join(fpd, fp_)\n } else if (!path.isAbsolute(fp) || !path.isAbsolute(fp_))\n throw new Error('fp and fp_ must be absolute path')\n \n if (print)\n console.log('rename:', fp, '→', fp_)\n \n if (!overwrite && fexists(fp_))\n throw new Error(`file already exists:${fp_}`)\n \n await fsp.rename(fp, fp_)\n}\n\n\n/**\n Create folders recursively, make sure the folder pointed to by fpd exists \n Returns the first created folder or undefined\n \n - fpd: Folder full path\n - options?:\n - print?: `true`\n - mode?: `'0o777'`\n*/\nexport async function fmkdir (\n fpd: string,\n {\n print = true,\n mode,\n }: {\n print?: boolean\n \n /** `0o777` A file mode. If a string is passed, it is parsed as an octal integer. */\n mode?: string | number\n } = { }\n) {\n if (!path.isAbsolute(fpd))\n throw new Error(`fpd must be an absolute path: ${fpd}`)\n \n if (!fpd.endsWith('/'))\n throw new Error(`fpd must end with /: ${fpd}`)\n \n // CallingfsPromises.mkdir() when path is a directory that exists results in a rejection only when recursive is false.\n const fpd_ = (\n await fsp.mkdir(fpd, { recursive: true, mode })\n )?.replaceAll('\\\\', '/')\n \n if (fpd_) {\n if (print)\n console.log('folder created:', fpd)\n } else\n if (print)\n console.log('folder already exists:', fpd)\n \n return fpd_\n}\n\n\n/** \n - fp_real: current real file/directory path\n - fp_link: target file/directory path\n*/\nexport async function flink (\n fp_real: string, \n fp_link: string, \n {\n junction = false,\n print = true \n }: { \n junction?: boolean\n print?: boolean\n} = { }) {\n if (!path.isAbsolute(fp_real) || !path.isAbsolute(fp_link))\n throw new Error('fp must be absolute path')\n \n const is_fpd_real = fp_real.endsWith('/')\n const is_fpd_link = fp_link.endsWith('/')\n \n if (is_fpd_real !== is_fpd_link)\n throw new Error('fp_real and fp_link must be both file path or folder path')\n \n if (fexists(fp_link))\n throw new Error(`${ is_fpd_link ? 'folder' : 'file' } exists: ${fp_link}, could not create link`)\n \n if (print)\n console.log(`source file ${fp_real} linked to ${fp_link}`)\n \n if (junction)\n fsp.symlink(fp_real, fp_link, 'junction')\n else\n fsp.symlink(fp_real, fp_link, is_fpd_real ? 'dir' : 'file')\n}\n\n\nexport let fwatchers: Record<string, fs.FSWatcher> = { }\n\n/**\n - fp: path of file or directory\n - callback: called when modified\n - exec: call callback when watch is executed\n \n save fs.FSWatcher in watchers, subsequent call will auto close existing watcher for the same fp\n \n https://nodejs.org/dist/latest-v15.x/docs/api/fs.html#fs_fs_watch_filename_options_listener \n The listener callback gets two arguments (event, fname). \n event is either 'rename' or 'change', and filename is the name of the file which triggered the event.\n On most platforms, 'rename' is emitted whenever a filename appears or disappears in the directory.\n \n The listener callback is attached to the 'change' event fired by fs.FSWatcher, but it is not the same thing as the 'change' value of event. \n \n*/\nexport async function fwatch (\n fp: string,\n onchange: (event: string, fname: string) => any, \n { exec = true }: { exec?: boolean } = { }\n) {\n if (!path.isAbsolute(fp))\n throw new Error('fp must be absolute path')\n \n const _watcher = fwatchers[fp]\n if (_watcher)\n _watcher.close()\n \n if (exec)\n await onchange('change', fp.fname)\n \n const start = new Date().getTime()\n \n const debounced_onchange = debounce(\n (event, fname) => {\n if (new Date().getTime() - start < 800)\n return\n console.log(`file ${event}: ${fname}`)\n onchange(event, path.normalize(fname))\n },\n 500,\n { leading: false, trailing: true }\n )\n \n let watcher = fs.watch(fp, debounced_onchange)\n watcher.on('error', error => {\n console.error(error)\n })\n return fwatchers[fp] = watcher\n}\n\n\n/** open a file and replace certain pattern */\nexport async function freplace (fp: string, pattern: string | RegExp, replacement: string) {\n await fwrite(\n fp,\n (await fread(fp))\n .replaceAll(pattern, replacement)\n )\n}\n\n/** convert file encoding to UTF-8\n - fp: file absolute path\n - options?:\n - dryrun?: `true`\n - encoding?: `'auto'`\n*/\nexport async function f2utf8 (fp: string, {\n dryrun = true,\n encoding = 'auto',\n}: {\n dryrun?: boolean\n encoding?: Encoding | 'auto'\n} = { }) {\n const text = await fread(fp, { encoding })\n if (dryrun) {\n console.log(text.slice(0, 10000))\n return\n }\n \n const fp_bak = `${fp.fdir}${fp.fname.replace(/(.*?)(\\.[^.]+)?$/, '$1.bak$2')}`\n if (!fexists(fp_bak))\n await fcopy(fp, fp_bak)\n \n await fwrite(fp, text)\n}\n\n"]}
|
package/i18n/dict.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Dict = void 0;
|
|
4
|
-
class Dict {
|
|
1
|
+
export class Dict {
|
|
5
2
|
_dict;
|
|
6
3
|
constructor(_dict = {}) {
|
|
7
4
|
this._dict = _dict;
|
|
@@ -33,5 +30,4 @@ class Dict {
|
|
|
33
30
|
});
|
|
34
31
|
}
|
|
35
32
|
}
|
|
36
|
-
exports.Dict = Dict;
|
|
37
33
|
//# sourceMappingURL=dict.js.map
|
package/i18n/dict.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dict.js","sourceRoot":"","sources":["dict.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"dict.js","sourceRoot":"","sources":["dict.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,IAAI;IACb,KAAK,CAAO;IAEZ,YAAa,QAAe,EAAE;QAC1B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;IACtB,CAAC;IAID,GAAG,CAAE,GAAW,EAAE,QAAmB;QACjC,IAAI,CAAC,GAAG;YACJ,OAAO,EAAE,CAAA;QAEb,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;QAE5B,IAAI,QAAQ;YACR,OAAO,IAAI,CAAC,CAAC;gBACL,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE;gBACxB,CAAC;oBACG,EAAE,CAAA;QAEd,OAAO,IAAI,CAAA;IACf,CAAC;IAED,YAAY;QACR,OAAO,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,CAAE,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,IAAI,CAAC,EAAE,EAAE;YAC3D,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,OAAO,CAAE,CAAC,CAAE,QAAQ,EAAE,WAAW,CAAE,EAAE,EAAE;gBACxD,IAAI,CAAC,WAAW,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC;oBAAE,OAAM;gBAC1C,GAAG,CAAC,QAAQ,CAAC,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,WAAW,CAAA;YAChD,CAAC,CAAC,CAAA;YACF,OAAO,GAAG,CAAA;QACd,CAAC,EAAE;YACC,EAAE,EAAE,EAAE,WAAW,EAAE,EAAG,EAAE;YACxB,EAAE,EAAE,EAAE,WAAW,EAAE,EAAG,EAAE;YACxB,EAAE,EAAE,EAAE,WAAW,EAAE,EAAG,EAAE;YACxB,EAAE,EAAE,EAAE,WAAW,EAAE,EAAG,EAAE;SAC3B,CAAC,CAAA;IACN,CAAC;CACJ","sourcesContent":["import type { Language } from './index.js'\n\nexport class Dict {\n _dict: _Dict\n \n constructor (_dict: _Dict = {}) {\n this._dict = _dict\n }\n \n get (key: string): Item | undefined\n get (key: string, language: Language): string | ''\n get (key: string, language?: Language) {\n if (!key)\n return ''\n \n const item = this._dict[key]\n \n if (language)\n return item ?\n item[language] || ''\n :\n ''\n \n return item\n }\n \n to_resources () {\n return Object.entries(this._dict).reduce( (acc, [key, item]) => {\n Object.entries(item).forEach( ([ language, translation ]) => {\n if (!translation || !acc[language]) return\n acc[language].translation[key] = translation\n })\n return acc\n }, {\n zh: { translation: { } },\n en: { translation: { } },\n ja: { translation: { } },\n ko: { translation: { } },\n })\n }\n}\n\n\n/** 配置字段 */\nexport type Item = {\n [language in Language]?: string\n}\n\n\n/** JSON.parse(词典文件.json) 得到的对象 */\nexport interface _Dict {\n [key: string]: Item\n}\n"]}
|
package/i18n/i18n-scan.js
CHANGED
|
@@ -1,21 +1,18 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const commander_1 = require("commander");
|
|
7
|
-
const index_js_1 = require("./scanner/index.js");
|
|
8
|
-
const utils_js_1 = require("./utils.js");
|
|
2
|
+
import path from 'upath';
|
|
3
|
+
import { program } from 'commander';
|
|
4
|
+
import { scanner } from './scanner/index.js';
|
|
5
|
+
import { try_load_dict } from './utils.js';
|
|
9
6
|
(async function main() {
|
|
10
|
-
|
|
11
|
-
.option('-r, --rootdir [rootdir]', '根目录:默认为当前工作目录',
|
|
7
|
+
program.name('i18n-scan')
|
|
8
|
+
.option('-r, --rootdir [rootdir]', '根目录:默认为当前工作目录', path.normalize(process.cwd()))
|
|
12
9
|
.option('-i, --input [input]', '扫描 pattern:多个 pattern 用分号分割,采用 glob pattern 匹配,如 `src/**/*.{js,jsx,ts,tsx}`', v => v.split(';'))
|
|
13
10
|
.option('-o, --output [output]', 'i18n 目录:默认为 <rootdir>/i18n/')
|
|
14
11
|
.option('-c, --config [config]', '自定义配置文件,默认为 <rootdir>/i18n/config.js ,可参考默认配置 xshell/i18n/index.ts 以及 https://github.com/i18next/i18next-scanner', 'i18n/config.js')
|
|
15
12
|
.parse(process.argv);
|
|
16
|
-
const { rootdir, config, input, output } =
|
|
17
|
-
|
|
18
|
-
...await
|
|
13
|
+
const { rootdir, config, input, output } = program.opts();
|
|
14
|
+
scanner(rootdir, {
|
|
15
|
+
...await try_load_dict(path.resolve(rootdir, config)),
|
|
19
16
|
...input ? { input } : {},
|
|
20
17
|
...output ? { output } : {},
|
|
21
18
|
});
|
package/i18n/i18n-scan.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"i18n-scan.js","sourceRoot":"","sources":["i18n-scan.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"i18n-scan.js","sourceRoot":"","sources":["i18n-scan.ts"],"names":[],"mappings":";AAEA,OAAO,IAAI,MAAM,OAAO,CAAA;AACxB,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAEnC,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAA;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAEzC;AAAA,CAAC,KAAK,UAAU,IAAI;IACjB,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC;SACpB,MAAM,CAAC,yBAAyB,EAAK,eAAe,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;SACpF,MAAM,CAAC,qBAAqB,EAAS,6EAA6E,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;SACtI,MAAM,CAAC,uBAAuB,EAAO,6BAA6B,CAAC;SACnE,MAAM,CAAC,uBAAuB,EAAO,kHAAkH,EAAE,gBAAgB,CAAC;SAC1K,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;IAExB,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,EAAE,CAAA;IACzD,OAAO,CAAC,OAAO,EAAE;QACb,GAAI,MAAM,aAAa,CACnB,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,MAAM,CAAC,CAChC;QACD,GAAI,KAAK,CAAE,CAAC,CAAE,EAAE,KAAK,EAAE,CAAG,CAAC,CAAE,EAAG;QAChC,GAAI,MAAM,CAAC,CAAC,CAAE,EAAE,MAAM,EAAE,CAAE,CAAC,CAAE,EAAG;KACnC,CAAC,CAAA;AACN,CAAC,CAAC,EAAE,CAAA","sourcesContent":["#!/usr/bin/env node\n\nimport path from 'upath'\nimport { program } from 'commander'\n\nimport { scanner } from './scanner/index.js'\nimport { try_load_dict } from './utils.js'\n\n;(async function main () {\n program.name('i18n-scan')\n .option('-r, --rootdir [rootdir]' , '根目录:默认为当前工作目录', path.normalize(process.cwd()))\n .option('-i, --input [input]' , '扫描 pattern:多个 pattern 用分号分割,采用 glob pattern 匹配,如 `src/**/*.{js,jsx,ts,tsx}`', v => v.split(';'))\n .option('-o, --output [output]' , 'i18n 目录:默认为 <rootdir>/i18n/')\n .option('-c, --config [config]' , '自定义配置文件,默认为 <rootdir>/i18n/config.js ,可参考默认配置 xshell/i18n/index.ts 以及 https://github.com/i18next/i18next-scanner', 'i18n/config.js')\n .parse(process.argv)\n \n const { rootdir, config, input, output } = program.opts()\n scanner(rootdir, {\n ... await try_load_dict(\n path.resolve(rootdir, config)\n ),\n ... input ? { input } : { },\n ... output ? { output } : { },\n })\n})()\n"]}
|