@lsst/pik-core 0.6.6 → 0.6.7
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/README.md +8 -8
- package/dist/index.js +4 -25
- package/dist/lib/parser.d.ts +1 -5
- package/dist/lib/parser.d.ts.map +1 -1
- package/dist/lib/single-switcher.d.ts +1 -5
- package/dist/lib/single-switcher.d.ts.map +1 -1
- package/dist/lib/types/comment-style.d.ts +2 -8
- package/dist/lib/types/comment-style.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -22,11 +22,11 @@ const env = 'LOCAL'; // @pik:option LOCAL
|
|
|
22
22
|
`;
|
|
23
23
|
|
|
24
24
|
// Parse content
|
|
25
|
-
const parser = Parser.
|
|
25
|
+
const parser = Parser.forFilePath('config.ts');
|
|
26
26
|
const { selectors } = parser.parse(content);
|
|
27
27
|
|
|
28
28
|
// Switch option
|
|
29
|
-
const switcher = SingleSwitcher.
|
|
29
|
+
const switcher = SingleSwitcher.forFilePath('config.ts');
|
|
30
30
|
const newContent = switcher.switch(content, selectors[0], 'DEV');
|
|
31
31
|
```
|
|
32
32
|
|
|
@@ -84,8 +84,8 @@ export function myPlugin(config: MyPluginConfig): PikPlugin {
|
|
|
84
84
|
### Parser
|
|
85
85
|
|
|
86
86
|
```typescript
|
|
87
|
-
// Create parser for file
|
|
88
|
-
const parser = Parser.
|
|
87
|
+
// Create parser for file path
|
|
88
|
+
const parser = Parser.forFilePath('src/config.ts');
|
|
89
89
|
|
|
90
90
|
// Parse content
|
|
91
91
|
const result = parser.parse(content);
|
|
@@ -96,8 +96,8 @@ const result = parser.parse(content);
|
|
|
96
96
|
### SingleSwitcher
|
|
97
97
|
|
|
98
98
|
```typescript
|
|
99
|
-
// Create switcher for file
|
|
100
|
-
const switcher = SingleSwitcher.
|
|
99
|
+
// Create switcher for file path
|
|
100
|
+
const switcher = SingleSwitcher.forFilePath('src/config.ts');
|
|
101
101
|
|
|
102
102
|
// Switch to option (deactivates all others)
|
|
103
103
|
const newContent = switcher.switch(content, selector, 'optionName');
|
|
@@ -108,8 +108,8 @@ const newContent = switcher.switch(content, selector, 'optionName');
|
|
|
108
108
|
```typescript
|
|
109
109
|
import { CommentStyle } from '@lsst/pik-core';
|
|
110
110
|
|
|
111
|
-
// Get comment style for
|
|
112
|
-
const style = CommentStyle.
|
|
111
|
+
// Get comment style for file path
|
|
112
|
+
const style = CommentStyle.fromFilePath('script.py'); // { lineComment: '#' }
|
|
113
113
|
|
|
114
114
|
// Register custom style
|
|
115
115
|
CommentStyle.register('custom', new CommentStyle(';;'));
|
package/dist/index.js
CHANGED
|
@@ -40,18 +40,9 @@ class CommentStyle {
|
|
|
40
40
|
return !!(this.blockOpen && this.blockClose);
|
|
41
41
|
}
|
|
42
42
|
/**
|
|
43
|
-
* Get comment style for a file
|
|
44
|
-
*/
|
|
45
|
-
static fromExtension(extension) {
|
|
46
|
-
const ext = extension.replace(/^\./, "").toLowerCase();
|
|
47
|
-
return CommentStyle.styles[ext] ?? CommentStyle.defaultStyle;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Get comment style for a file path, handling dotfiles like .env correctly.
|
|
43
|
+
* Get comment style for a file path.
|
|
51
44
|
*
|
|
52
|
-
*
|
|
53
|
-
* - `.env` files (where extname returns '')
|
|
54
|
-
* - `.env.local`, `.env.development`, etc. (where extname returns '.local', '.development')
|
|
45
|
+
* Handles dotfiles like `.env`, `.env.local`, `.env.development` correctly.
|
|
55
46
|
*/
|
|
56
47
|
static fromFilePath(filePath) {
|
|
57
48
|
const basename = filePath.split(/[/\\]/).pop() ?? "";
|
|
@@ -107,13 +98,7 @@ class Parser {
|
|
|
107
98
|
static SELECT_REGEX = /@pik:select\s+(\S+)/;
|
|
108
99
|
static OPTION_REGEX = /@pik:option\s+(\S+)/;
|
|
109
100
|
/**
|
|
110
|
-
* Create a parser for a
|
|
111
|
-
*/
|
|
112
|
-
static forExtension(extension) {
|
|
113
|
-
return new Parser(CommentStyle.fromExtension(extension));
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Create a parser for a file path, correctly handling dotfiles like .env
|
|
101
|
+
* Create a parser for a file path
|
|
117
102
|
*/
|
|
118
103
|
static forFilePath(filePath) {
|
|
119
104
|
return new Parser(CommentStyle.fromFilePath(filePath));
|
|
@@ -324,13 +309,7 @@ class Switcher extends CommentManipulator {
|
|
|
324
309
|
}
|
|
325
310
|
class SingleSwitcher extends Switcher {
|
|
326
311
|
/**
|
|
327
|
-
* Create a switcher for a
|
|
328
|
-
*/
|
|
329
|
-
static forExtension(extension) {
|
|
330
|
-
return new SingleSwitcher(CommentStyle.fromExtension(extension));
|
|
331
|
-
}
|
|
332
|
-
/**
|
|
333
|
-
* Create a switcher for a file path, correctly handling dotfiles like .env
|
|
312
|
+
* Create a switcher for a file path
|
|
334
313
|
*/
|
|
335
314
|
static forFilePath(filePath) {
|
|
336
315
|
return new SingleSwitcher(CommentStyle.fromFilePath(filePath));
|
package/dist/lib/parser.d.ts
CHANGED
|
@@ -9,11 +9,7 @@ export declare class Parser {
|
|
|
9
9
|
private static readonly OPTION_REGEX;
|
|
10
10
|
constructor(commentStyle: CommentStyle);
|
|
11
11
|
/**
|
|
12
|
-
* Create a parser for a
|
|
13
|
-
*/
|
|
14
|
-
static forExtension(extension: string): Parser;
|
|
15
|
-
/**
|
|
16
|
-
* Create a parser for a file path, correctly handling dotfiles like .env
|
|
12
|
+
* Create a parser for a file path
|
|
17
13
|
*/
|
|
18
14
|
static forFilePath(filePath: string): Parser;
|
|
19
15
|
/**
|
package/dist/lib/parser.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../src/lib/parser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAU,WAAW,EAAY,MAAM,kBAAkB,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEhD;;GAEG;AACH,qBAAa,MAAM;IAIL,OAAO,CAAC,QAAQ,CAAC,YAAY;IAHzC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAyB;IAC7D,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAyB;gBAEhC,YAAY,EAAE,YAAY;IAEvD;;OAEG;IACH,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../src/lib/parser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAU,WAAW,EAAY,MAAM,kBAAkB,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEhD;;GAEG;AACH,qBAAa,MAAM;IAIL,OAAO,CAAC,QAAQ,CAAC,YAAY;IAHzC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAyB;IAC7D,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAyB;gBAEhC,YAAY,EAAE,YAAY;IAEvD;;OAEG;IACH,MAAM,CAAC,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM;IAI5C;;OAEG;IACH,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,WAAW;IAuDnC;;;OAGG;IACH,OAAO,CAAC,kBAAkB;IA6B1B;;OAEG;IACH,OAAO,CAAC,eAAe;CAkBxB"}
|
|
@@ -5,11 +5,7 @@ import { Switcher } from './switcher.js';
|
|
|
5
5
|
*/
|
|
6
6
|
export declare class SingleSwitcher extends Switcher {
|
|
7
7
|
/**
|
|
8
|
-
* Create a switcher for a
|
|
9
|
-
*/
|
|
10
|
-
static forExtension(extension: string): SingleSwitcher;
|
|
11
|
-
/**
|
|
12
|
-
* Create a switcher for a file path, correctly handling dotfiles like .env
|
|
8
|
+
* Create a switcher for a file path
|
|
13
9
|
*/
|
|
14
10
|
static forFilePath(filePath: string): SingleSwitcher;
|
|
15
11
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"single-switcher.d.ts","sourceRoot":"","sources":["../../src/lib/single-switcher.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAEjD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC;;GAEG;AACH,qBAAa,cAAe,SAAQ,QAAQ;IAC1C;;OAEG;IACH,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"single-switcher.d.ts","sourceRoot":"","sources":["../../src/lib/single-switcher.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAEjD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC;;GAEG;AACH,qBAAa,cAAe,SAAQ,QAAQ;IAC1C;;OAEG;IACH,MAAM,CAAC,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,cAAc;IAIpD;;OAEG;IACH,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM;CAyBxE"}
|
|
@@ -18,15 +18,9 @@ export declare class CommentStyle {
|
|
|
18
18
|
*/
|
|
19
19
|
get hasBlockComments(): boolean;
|
|
20
20
|
/**
|
|
21
|
-
* Get comment style for a file
|
|
22
|
-
*/
|
|
23
|
-
static fromExtension(extension: string): CommentStyle;
|
|
24
|
-
/**
|
|
25
|
-
* Get comment style for a file path, handling dotfiles like .env correctly.
|
|
21
|
+
* Get comment style for a file path.
|
|
26
22
|
*
|
|
27
|
-
*
|
|
28
|
-
* - `.env` files (where extname returns '')
|
|
29
|
-
* - `.env.local`, `.env.development`, etc. (where extname returns '.local', '.development')
|
|
23
|
+
* Handles dotfiles like `.env`, `.env.local`, `.env.development` correctly.
|
|
30
24
|
*/
|
|
31
25
|
static fromFilePath(filePath: string): CommentStyle;
|
|
32
26
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"comment-style.d.ts","sourceRoot":"","sources":["../../../src/lib/types/comment-style.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,YAAY;IAiCrB,4CAA4C;aAC5B,WAAW,EAAE,MAAM;IAjCrC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAsB5B;IAEF,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,YAAY,CAA0B;IAE9D,2CAA2C;IAC3C,SAAgB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnC,0CAA0C;IAC1C,SAAgB,UAAU,CAAC,EAAE,MAAM,CAAC;;IAGlC,4CAA4C;IAC5B,WAAW,EAAE,MAAM,EACnC,SAAS,CAAC,EAAE,MAAM,EAClB,UAAU,CAAC,EAAE,MAAM;IAMrB;;OAEG;IACH,IAAI,gBAAgB,IAAI,OAAO,CAE9B;IAED
|
|
1
|
+
{"version":3,"file":"comment-style.d.ts","sourceRoot":"","sources":["../../../src/lib/types/comment-style.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,YAAY;IAiCrB,4CAA4C;aAC5B,WAAW,EAAE,MAAM;IAjCrC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAsB5B;IAEF,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,YAAY,CAA0B;IAE9D,2CAA2C;IAC3C,SAAgB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnC,0CAA0C;IAC1C,SAAgB,UAAU,CAAC,EAAE,MAAM,CAAC;;IAGlC,4CAA4C;IAC5B,WAAW,EAAE,MAAM,EACnC,SAAS,CAAC,EAAE,MAAM,EAClB,UAAU,CAAC,EAAE,MAAM;IAMrB;;OAEG;IACH,IAAI,gBAAgB,IAAI,OAAO,CAE9B;IAED;;;;OAIG;IACH,MAAM,CAAC,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,YAAY;IAkBnD;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,GAAG,IAAI;CAI9D"}
|