@prostojs/rewrite 0.1.0 → 0.1.1
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/dist/index.cjs +9 -18
- package/dist/index.mjs +9 -18
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -23,9 +23,8 @@ const htmlTextTags = [
|
|
|
23
23
|
'style',
|
|
24
24
|
];
|
|
25
25
|
|
|
26
|
-
const errorMessage = 'Work with files supported only in NodeJS environment.';
|
|
27
26
|
async function readDir(dirPath) {
|
|
28
|
-
|
|
27
|
+
{
|
|
29
28
|
const path = await import('path');
|
|
30
29
|
const fs = await import('fs');
|
|
31
30
|
async function* getFiles(dir) {
|
|
@@ -42,10 +41,9 @@ async function readDir(dirPath) {
|
|
|
42
41
|
}
|
|
43
42
|
return getFiles(dirPath);
|
|
44
43
|
}
|
|
45
|
-
throw new Error(errorMessage);
|
|
46
44
|
}
|
|
47
45
|
async function readFile(filePath) {
|
|
48
|
-
|
|
46
|
+
{
|
|
49
47
|
const fs = await import('fs');
|
|
50
48
|
return new Promise((resolve, reject) => {
|
|
51
49
|
fs.exists(filePath, (yes) => {
|
|
@@ -62,10 +60,9 @@ async function readFile(filePath) {
|
|
|
62
60
|
});
|
|
63
61
|
});
|
|
64
62
|
}
|
|
65
|
-
throw new Error(errorMessage);
|
|
66
63
|
}
|
|
67
64
|
async function writeFile(targetPath, data) {
|
|
68
|
-
|
|
65
|
+
{
|
|
69
66
|
const path = await import('path');
|
|
70
67
|
const fs = await import('fs');
|
|
71
68
|
const dirname = path.dirname(targetPath);
|
|
@@ -73,10 +70,9 @@ async function writeFile(targetPath, data) {
|
|
|
73
70
|
await fs.promises.writeFile(targetPath, data);
|
|
74
71
|
return;
|
|
75
72
|
}
|
|
76
|
-
throw new Error(errorMessage);
|
|
77
73
|
}
|
|
78
74
|
async function copyFile(filePath, targetPath) {
|
|
79
|
-
|
|
75
|
+
{
|
|
80
76
|
if (filePath === targetPath)
|
|
81
77
|
return;
|
|
82
78
|
const path = await import('path');
|
|
@@ -86,21 +82,18 @@ async function copyFile(filePath, targetPath) {
|
|
|
86
82
|
await fs.promises.copyFile(filePath, targetPath);
|
|
87
83
|
return;
|
|
88
84
|
}
|
|
89
|
-
throw new Error(errorMessage);
|
|
90
85
|
}
|
|
91
86
|
async function pathResolve(p) {
|
|
92
|
-
|
|
87
|
+
{
|
|
93
88
|
const path = await import('path');
|
|
94
89
|
return path.resolve(p);
|
|
95
90
|
}
|
|
96
|
-
throw new Error(errorMessage);
|
|
97
91
|
}
|
|
98
92
|
async function pathJoin(...parts) {
|
|
99
|
-
|
|
93
|
+
{
|
|
100
94
|
const path = await import('path');
|
|
101
95
|
return path.join(...parts);
|
|
102
96
|
}
|
|
103
|
-
throw new Error(errorMessage);
|
|
104
97
|
}
|
|
105
98
|
|
|
106
99
|
const dim = '[2m';
|
|
@@ -3861,13 +3854,13 @@ class ProstoRewrite {
|
|
|
3861
3854
|
this.options = {
|
|
3862
3855
|
defaultMode: (options === null || options === void 0 ? void 0 : options.defaultMode) || 'auto',
|
|
3863
3856
|
debug: (options === null || options === void 0 ? void 0 : options.debug) || false,
|
|
3864
|
-
htmlPattern:
|
|
3865
|
-
textPattern:
|
|
3857
|
+
htmlPattern: ((options === null || options === void 0 ? void 0 : options.htmlPattern) || ['*.{html,xhtml,xml,svg}']).map(p => new Minimatch(p, { matchBase: true })) ,
|
|
3858
|
+
textPattern: ((options === null || options === void 0 ? void 0 : options.textPattern) || [
|
|
3866
3859
|
'*.{js,jsx,ts,tsx,txt,json,yml,yaml,md,ini}',
|
|
3867
3860
|
'Dockerfile',
|
|
3868
3861
|
'*config',
|
|
3869
3862
|
'.gitignore',
|
|
3870
|
-
]).map(p => new Minimatch(p, { matchBase: true }))
|
|
3863
|
+
]).map(p => new Minimatch(p, { matchBase: true })) ,
|
|
3871
3864
|
html: {
|
|
3872
3865
|
exprDelimeters: defaultDelimeters,
|
|
3873
3866
|
attrExpression: ':',
|
|
@@ -3927,8 +3920,6 @@ class ProstoRewrite {
|
|
|
3927
3920
|
return output;
|
|
3928
3921
|
}
|
|
3929
3922
|
async rewriteDir(opts, context) {
|
|
3930
|
-
if (__BROWSER__)
|
|
3931
|
-
return;
|
|
3932
3923
|
const files = await readDir(opts.baseDir);
|
|
3933
3924
|
const dirPath = await pathResolve(opts.baseDir);
|
|
3934
3925
|
const include = opts.include && opts.include.length ? opts.include.map(s => new Minimatch(s, { matchBase: true })) : null;
|
package/dist/index.mjs
CHANGED
|
@@ -21,9 +21,8 @@ const htmlTextTags = [
|
|
|
21
21
|
'style',
|
|
22
22
|
];
|
|
23
23
|
|
|
24
|
-
const errorMessage = 'Work with files supported only in NodeJS environment.';
|
|
25
24
|
async function readDir(dirPath) {
|
|
26
|
-
|
|
25
|
+
{
|
|
27
26
|
const path = await import('path');
|
|
28
27
|
const fs = await import('fs');
|
|
29
28
|
async function* getFiles(dir) {
|
|
@@ -40,10 +39,9 @@ async function readDir(dirPath) {
|
|
|
40
39
|
}
|
|
41
40
|
return getFiles(dirPath);
|
|
42
41
|
}
|
|
43
|
-
throw new Error(errorMessage);
|
|
44
42
|
}
|
|
45
43
|
async function readFile(filePath) {
|
|
46
|
-
|
|
44
|
+
{
|
|
47
45
|
const fs = await import('fs');
|
|
48
46
|
return new Promise((resolve, reject) => {
|
|
49
47
|
fs.exists(filePath, (yes) => {
|
|
@@ -60,10 +58,9 @@ async function readFile(filePath) {
|
|
|
60
58
|
});
|
|
61
59
|
});
|
|
62
60
|
}
|
|
63
|
-
throw new Error(errorMessage);
|
|
64
61
|
}
|
|
65
62
|
async function writeFile(targetPath, data) {
|
|
66
|
-
|
|
63
|
+
{
|
|
67
64
|
const path = await import('path');
|
|
68
65
|
const fs = await import('fs');
|
|
69
66
|
const dirname = path.dirname(targetPath);
|
|
@@ -71,10 +68,9 @@ async function writeFile(targetPath, data) {
|
|
|
71
68
|
await fs.promises.writeFile(targetPath, data);
|
|
72
69
|
return;
|
|
73
70
|
}
|
|
74
|
-
throw new Error(errorMessage);
|
|
75
71
|
}
|
|
76
72
|
async function copyFile(filePath, targetPath) {
|
|
77
|
-
|
|
73
|
+
{
|
|
78
74
|
if (filePath === targetPath)
|
|
79
75
|
return;
|
|
80
76
|
const path = await import('path');
|
|
@@ -84,21 +80,18 @@ async function copyFile(filePath, targetPath) {
|
|
|
84
80
|
await fs.promises.copyFile(filePath, targetPath);
|
|
85
81
|
return;
|
|
86
82
|
}
|
|
87
|
-
throw new Error(errorMessage);
|
|
88
83
|
}
|
|
89
84
|
async function pathResolve(p) {
|
|
90
|
-
|
|
85
|
+
{
|
|
91
86
|
const path = await import('path');
|
|
92
87
|
return path.resolve(p);
|
|
93
88
|
}
|
|
94
|
-
throw new Error(errorMessage);
|
|
95
89
|
}
|
|
96
90
|
async function pathJoin(...parts) {
|
|
97
|
-
|
|
91
|
+
{
|
|
98
92
|
const path = await import('path');
|
|
99
93
|
return path.join(...parts);
|
|
100
94
|
}
|
|
101
|
-
throw new Error(errorMessage);
|
|
102
95
|
}
|
|
103
96
|
|
|
104
97
|
const dim = '[2m';
|
|
@@ -3859,13 +3852,13 @@ class ProstoRewrite {
|
|
|
3859
3852
|
this.options = {
|
|
3860
3853
|
defaultMode: (options === null || options === void 0 ? void 0 : options.defaultMode) || 'auto',
|
|
3861
3854
|
debug: (options === null || options === void 0 ? void 0 : options.debug) || false,
|
|
3862
|
-
htmlPattern:
|
|
3863
|
-
textPattern:
|
|
3855
|
+
htmlPattern: ((options === null || options === void 0 ? void 0 : options.htmlPattern) || ['*.{html,xhtml,xml,svg}']).map(p => new Minimatch(p, { matchBase: true })) ,
|
|
3856
|
+
textPattern: ((options === null || options === void 0 ? void 0 : options.textPattern) || [
|
|
3864
3857
|
'*.{js,jsx,ts,tsx,txt,json,yml,yaml,md,ini}',
|
|
3865
3858
|
'Dockerfile',
|
|
3866
3859
|
'*config',
|
|
3867
3860
|
'.gitignore',
|
|
3868
|
-
]).map(p => new Minimatch(p, { matchBase: true }))
|
|
3861
|
+
]).map(p => new Minimatch(p, { matchBase: true })) ,
|
|
3869
3862
|
html: {
|
|
3870
3863
|
exprDelimeters: defaultDelimeters,
|
|
3871
3864
|
attrExpression: ':',
|
|
@@ -3925,8 +3918,6 @@ class ProstoRewrite {
|
|
|
3925
3918
|
return output;
|
|
3926
3919
|
}
|
|
3927
3920
|
async rewriteDir(opts, context) {
|
|
3928
|
-
if (__BROWSER__)
|
|
3929
|
-
return;
|
|
3930
3921
|
const files = await readDir(opts.baseDir);
|
|
3931
3922
|
const dirPath = await pathResolve(opts.baseDir);
|
|
3932
3923
|
const include = opts.include && opts.include.length ? opts.include.map(s => new Minimatch(s, { matchBase: true })) : null;
|