@w5s/dev 1.4.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/block.d.ts +1 -1
- package/dist/block.d.ts.map +1 -1
- package/dist/block.js +34 -11
- package/dist/block.js.map +1 -1
- package/package.json +2 -2
- package/src/block.ts +37 -12
package/dist/block.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export interface BlockOptions {
|
|
|
16
16
|
/**
|
|
17
17
|
* Insert position
|
|
18
18
|
*/
|
|
19
|
-
insertPosition?: ['before', 'BeginningOfFile'] | ['after', 'EndOfFile'];
|
|
19
|
+
insertPosition?: ['before', 'BeginningOfFile' | RegExp] | ['after', 'EndOfFile' | RegExp];
|
|
20
20
|
/**
|
|
21
21
|
* Block target state
|
|
22
22
|
*/
|
package/dist/block.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block.d.ts","sourceRoot":"","sources":["../src/block.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,YAAY;IAC3B;;;;OAIG;IACH,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,GAAG,KAAK,KAAK,MAAM,CAAC;IAC3C;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,cAAc,CAAC,EAAE,CAAC,QAAQ,EAAE,iBAAiB,CAAC,GAAG,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"block.d.ts","sourceRoot":"","sources":["../src/block.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,YAAY;IAC3B;;;;OAIG;IACH,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,GAAG,KAAK,KAAK,MAAM,CAAC;IAC3C;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,cAAc,CAAC,EAAE,CAAC,QAAQ,EAAE,iBAAiB,GAAG,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,WAAW,GAAG,MAAM,CAAC,CAAC;IAC1F;;OAEG;IACH,KAAK,CAAC,EAAE,SAAS,GAAG,QAAQ,CAAC;CAC9B;AAmGD;;;;;;;;GAQG;AACH,wBAAgB,KAAK,CAAC,OAAO,EAAE,YAAY,iBAE1C;AAED;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,YAAY,QAE9C"}
|
package/dist/block.js
CHANGED
|
@@ -4,6 +4,23 @@ exports.blockSync = exports.block = void 0;
|
|
|
4
4
|
const file_js_1 = require("./file.js");
|
|
5
5
|
const EOF = 'EndOfFile';
|
|
6
6
|
const BOF = 'BeginningOfFile';
|
|
7
|
+
const insertAt = (str, index, toInsert) => str.slice(0, index) + toInsert + str.slice(index);
|
|
8
|
+
const matchLast = (string, regexp) => {
|
|
9
|
+
const matcher = new RegExp(regexp.source, `${regexp.flags}g`);
|
|
10
|
+
let firstIndex = -1;
|
|
11
|
+
let lastIndex = -1;
|
|
12
|
+
let matches;
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
14
|
+
while (true) {
|
|
15
|
+
matches = matcher.exec(string);
|
|
16
|
+
if (matches == null) {
|
|
17
|
+
break;
|
|
18
|
+
}
|
|
19
|
+
firstIndex = matches.index;
|
|
20
|
+
lastIndex = matcher.lastIndex;
|
|
21
|
+
}
|
|
22
|
+
return { firstIndex, lastIndex };
|
|
23
|
+
};
|
|
7
24
|
function toFileOptions(options) {
|
|
8
25
|
const { marker = (mark) => `# ${mark.toUpperCase()} MANAGED BLOCK`, path, block: blockName, insertPosition = ['after', EOF], state = 'present', } = options;
|
|
9
26
|
const EOL = '\n';
|
|
@@ -33,20 +50,26 @@ function toFileOptions(options) {
|
|
|
33
50
|
return fullContent;
|
|
34
51
|
}
|
|
35
52
|
switch (positionDirection) {
|
|
36
|
-
case '
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
53
|
+
case 'before': {
|
|
54
|
+
if (positionAnchor !== BOF) {
|
|
55
|
+
const { firstIndex } = matchLast(fullContent, positionAnchor);
|
|
56
|
+
if (firstIndex >= 0) {
|
|
57
|
+
return insertAt(fullContent, firstIndex, replaceBlock + EOL);
|
|
58
|
+
}
|
|
41
59
|
}
|
|
42
|
-
|
|
60
|
+
// Beginning of file
|
|
61
|
+
return replaceBlock + EOL + fullContent;
|
|
43
62
|
}
|
|
44
|
-
case '
|
|
45
|
-
//
|
|
46
|
-
if (positionAnchor
|
|
47
|
-
|
|
63
|
+
case 'after': {
|
|
64
|
+
// insert
|
|
65
|
+
if (positionAnchor !== EOF) {
|
|
66
|
+
const { lastIndex } = matchLast(fullContent, positionAnchor);
|
|
67
|
+
if (lastIndex >= 0) {
|
|
68
|
+
return insertAt(fullContent, lastIndex, EOL + replaceBlock);
|
|
69
|
+
}
|
|
48
70
|
}
|
|
49
|
-
|
|
71
|
+
// end of file
|
|
72
|
+
return fullContent + EOL + replaceBlock;
|
|
50
73
|
}
|
|
51
74
|
default: {
|
|
52
75
|
throw new Error(`Unsupported position ${String(positionDirection)}`);
|
package/dist/block.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block.js","sourceRoot":"","sources":["../src/block.ts"],"names":[],"mappings":";;;AAAA,uCAA6D;AA2B7D,MAAM,GAAG,GAAG,WAAW,CAAC;AACxB,MAAM,GAAG,GAAG,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"block.js","sourceRoot":"","sources":["../src/block.ts"],"names":[],"mappings":";;;AAAA,uCAA6D;AA2B7D,MAAM,GAAG,GAAG,WAAW,CAAC;AACxB,MAAM,GAAG,GAAG,iBAAiB,CAAC;AAC9B,MAAM,QAAQ,GAAG,CAAC,GAAW,EAAE,KAAa,EAAE,QAAgB,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,CAA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,EAAE,SAAS,EAAE,GAAG,SAAS,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC;oBAC7D,IAAI,SAAS,IAAI,CAAC,EAAE;wBAClB,OAAO,QAAQ,CAAC,WAAW,EAAE,SAAS,EAAE,GAAG,GAAG,YAAY,CAAC,CAAC;qBAC7D;iBACF;gBAED,cAAc;gBACd,OAAO,WAAW,GAAG,GAAG,GAAG,YAAY,CAAC;aACzC;YAED,OAAO,CAAC,CAAC;gBACP,MAAM,IAAI,KAAK,CAAC,wBAAwB,MAAM,CAAC,iBAAiB,CAAC,EAAE,CAAC,CAAC;aACtE;SACF;IACH,CAAC;IAED,OAAO;QACL,IAAI;QACJ,KAAK,EAAE,SAAS;QAChB,MAAM,EAAE,CAAC,aAAa,EAAE,EAAE,CAAC,KAAK,CAAC,aAAa,EAAE,SAAS,CAAC;KAC3D,CAAC;AACJ,CAAC;AAED;;;;;;;;GAQG;AACH,SAAgB,KAAK,CAAC,OAAqB;IACzC,OAAO,IAAA,cAAI,EAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC;AACtC,CAAC;AAFD,sBAEC;AAED;;;;;;;;GAQG;AACH,SAAgB,SAAS,CAAC,OAAqB;IAC7C,OAAO,IAAA,kBAAQ,EAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC;AAC1C,CAAC;AAFD,8BAEC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@w5s/dev",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "Shared development constants and functions",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"config",
|
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
"publishConfig": {
|
|
44
44
|
"access": "public"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "824cd89a55dcf5b99977c51c8c54c00143769f24"
|
|
47
47
|
}
|
package/src/block.ts
CHANGED
|
@@ -18,7 +18,7 @@ export interface BlockOptions {
|
|
|
18
18
|
/**
|
|
19
19
|
* Insert position
|
|
20
20
|
*/
|
|
21
|
-
insertPosition?: ['before', 'BeginningOfFile'] | ['after', 'EndOfFile'];
|
|
21
|
+
insertPosition?: ['before', 'BeginningOfFile' | RegExp] | ['after', 'EndOfFile' | RegExp];
|
|
22
22
|
/**
|
|
23
23
|
* Block target state
|
|
24
24
|
*/
|
|
@@ -27,6 +27,23 @@ export interface BlockOptions {
|
|
|
27
27
|
|
|
28
28
|
const EOF = 'EndOfFile';
|
|
29
29
|
const BOF = 'BeginningOfFile';
|
|
30
|
+
const insertAt = (str: string, index: number, toInsert: string) => str.slice(0, index) + toInsert + str.slice(index);
|
|
31
|
+
const matchLast = (string: string, regexp: RegExp) => {
|
|
32
|
+
const matcher = new RegExp(regexp.source, `${regexp.flags}g`);
|
|
33
|
+
let firstIndex = -1;
|
|
34
|
+
let lastIndex = -1;
|
|
35
|
+
let matches;
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
37
|
+
while (true) {
|
|
38
|
+
matches = matcher.exec(string);
|
|
39
|
+
if (matches == null) {
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
firstIndex = matches.index;
|
|
43
|
+
lastIndex = matcher.lastIndex;
|
|
44
|
+
}
|
|
45
|
+
return { firstIndex, lastIndex };
|
|
46
|
+
};
|
|
30
47
|
|
|
31
48
|
function toFileOptions(options: BlockOptions): FileOptions {
|
|
32
49
|
const {
|
|
@@ -68,22 +85,30 @@ function toFileOptions(options: BlockOptions): FileOptions {
|
|
|
68
85
|
return fullContent;
|
|
69
86
|
}
|
|
70
87
|
switch (positionDirection) {
|
|
71
|
-
case '
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
88
|
+
case 'before': {
|
|
89
|
+
if (positionAnchor !== BOF) {
|
|
90
|
+
const { firstIndex } = matchLast(fullContent, positionAnchor);
|
|
91
|
+
if (firstIndex >= 0) {
|
|
92
|
+
return insertAt(fullContent, firstIndex, replaceBlock + EOL);
|
|
93
|
+
}
|
|
76
94
|
}
|
|
77
95
|
|
|
78
|
-
|
|
96
|
+
// Beginning of file
|
|
97
|
+
return replaceBlock + EOL + fullContent;
|
|
79
98
|
}
|
|
80
|
-
case '
|
|
81
|
-
//
|
|
82
|
-
if (positionAnchor
|
|
83
|
-
|
|
99
|
+
case 'after': {
|
|
100
|
+
// insert
|
|
101
|
+
if (positionAnchor !== EOF) {
|
|
102
|
+
const { lastIndex } = matchLast(fullContent, positionAnchor);
|
|
103
|
+
if (lastIndex >= 0) {
|
|
104
|
+
return insertAt(fullContent, lastIndex, EOL + replaceBlock);
|
|
105
|
+
}
|
|
84
106
|
}
|
|
85
|
-
|
|
107
|
+
|
|
108
|
+
// end of file
|
|
109
|
+
return fullContent + EOL + replaceBlock;
|
|
86
110
|
}
|
|
111
|
+
|
|
87
112
|
default: {
|
|
88
113
|
throw new Error(`Unsupported position ${String(positionDirection)}`);
|
|
89
114
|
}
|