@lsst/pik-core 0.6.7 → 0.7.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/index.d.ts CHANGED
@@ -1,8 +1,9 @@
1
- export type { Option, Selector, ParseResult, PikPlugin } from './lib/types/index.js';
1
+ export type { Option, BlockOption, Selector, ParseResult, PikPlugin } from './lib/types/index.js';
2
2
  export { CommentStyle } from './lib/types/index.js';
3
3
  export { defineConfig, loadConfig, findLocalConfig, isValidPlugin, type PikConfig, } from './lib/config.js';
4
4
  export { Parser } from './lib/parser.js';
5
5
  export { Switcher } from './lib/switcher.js';
6
6
  export { SingleSwitcher } from './lib/single-switcher.js';
7
+ export { BlockSwitcher } from './lib/block-switcher.js';
7
8
  export { CommentManipulator } from './lib/comment-manipulator.js';
8
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACrF,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAGpD,OAAO,EACL,YAAY,EACZ,UAAU,EACV,eAAe,EACf,aAAa,EACb,KAAK,SAAS,GACf,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAGzC,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAG1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,YAAY,EAAE,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAClG,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAGpD,OAAO,EACL,YAAY,EACZ,UAAU,EACV,eAAe,EACf,aAAa,EACb,KAAK,SAAS,GACf,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAGzC,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAGxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC"}
package/dist/index.js CHANGED
@@ -97,6 +97,8 @@ class Parser {
97
97
  }
98
98
  static SELECT_REGEX = /@pik:select\s+(\S+)/;
99
99
  static OPTION_REGEX = /@pik:option\s+(\S+)/;
100
+ static BLOCK_START_REGEX = /@pik:block-start\s+(\S+)/;
101
+ static BLOCK_END_REGEX = /@pik:block-end/;
100
102
  /**
101
103
  * Create a parser for a file path
102
104
  */
@@ -110,6 +112,7 @@ class Parser {
110
112
  const lines = content.split("\n");
111
113
  const selectors = [];
112
114
  let currentSelector = null;
115
+ let currentBlock = null;
113
116
  for (let i = 0; i < lines.length; i++) {
114
117
  const line = lines[i];
115
118
  const lineNumber = i + 1;
@@ -118,11 +121,39 @@ class Parser {
118
121
  currentSelector = {
119
122
  name: selectMatch[1],
120
123
  line: lineNumber,
121
- options: []
124
+ options: [],
125
+ blockOptions: []
122
126
  };
123
127
  selectors.push(currentSelector);
124
128
  continue;
125
129
  }
130
+ const blockStartMatch = line.match(Parser.BLOCK_START_REGEX);
131
+ if (blockStartMatch && currentSelector) {
132
+ currentBlock = {
133
+ name: blockStartMatch[1],
134
+ startLine: lineNumber,
135
+ contentLines: []
136
+ };
137
+ continue;
138
+ }
139
+ const blockEndMatch = line.match(Parser.BLOCK_END_REGEX);
140
+ if (blockEndMatch && currentSelector && currentBlock) {
141
+ const isActive = currentBlock.contentLines.length > 0 ? !this.isLineCommented(lines[currentBlock.contentLines[0] - 1]) : false;
142
+ const blockOption = {
143
+ name: currentBlock.name,
144
+ startLine: currentBlock.startLine,
145
+ endLine: lineNumber,
146
+ contentLines: currentBlock.contentLines,
147
+ isActive
148
+ };
149
+ currentSelector.blockOptions.push(blockOption);
150
+ currentBlock = null;
151
+ continue;
152
+ }
153
+ if (currentBlock) {
154
+ currentBlock.contentLines.push(lineNumber);
155
+ continue;
156
+ }
126
157
  const optionMatch = line.match(Parser.OPTION_REGEX);
127
158
  if (optionMatch && currentSelector) {
128
159
  const isStandalone = this.isStandaloneMarker(line);
@@ -336,7 +367,53 @@ class SingleSwitcher extends Switcher {
336
367
  return lines.join("\n");
337
368
  }
338
369
  }
370
+ class BlockSwitcher extends CommentManipulator {
371
+ /**
372
+ * Create a switcher for a file path
373
+ */
374
+ static forFilePath(filePath) {
375
+ return new BlockSwitcher(CommentStyle.fromFilePath(filePath));
376
+ }
377
+ /**
378
+ * Switch to a specific block option, deactivating all others.
379
+ * - Selected block: all content lines uncommented
380
+ * - Other blocks: all content lines commented
381
+ */
382
+ switch(content, selector, blockName) {
383
+ this.validateBlockOption(selector, blockName);
384
+ const lines = content.split("\n");
385
+ const useBlockStyle = selector.blockOptions.some((block) => {
386
+ if (block.contentLines.length === 0) return false;
387
+ const line = lines[block.contentLines[0] - 1];
388
+ return this.isBlockCommented(line);
389
+ });
390
+ for (const block of selector.blockOptions) {
391
+ for (const lineNum of block.contentLines) {
392
+ const lineIndex = lineNum - 1;
393
+ const line = lines[lineIndex];
394
+ if (block.name === blockName) {
395
+ lines[lineIndex] = this.uncommentLine(line);
396
+ } else {
397
+ lines[lineIndex] = this.commentLine(line, useBlockStyle);
398
+ }
399
+ }
400
+ }
401
+ return lines.join("\n");
402
+ }
403
+ /**
404
+ * Validate that the block option exists in the selector
405
+ */
406
+ validateBlockOption(selector, blockName) {
407
+ const block = selector.blockOptions.find((b) => b.name === blockName);
408
+ if (!block) {
409
+ throw new Error(
410
+ `Block option "${blockName}" not found in selector "${selector.name}"`
411
+ );
412
+ }
413
+ }
414
+ }
339
415
  export {
416
+ BlockSwitcher,
340
417
  CommentManipulator,
341
418
  CommentStyle,
342
419
  Parser,
@@ -0,0 +1,22 @@
1
+ import type { Selector } from './types/index.js';
2
+ import { CommentManipulator } from './comment-manipulator.js';
3
+ /**
4
+ * Switcher that handles multi-line block options
5
+ */
6
+ export declare class BlockSwitcher extends CommentManipulator {
7
+ /**
8
+ * Create a switcher for a file path
9
+ */
10
+ static forFilePath(filePath: string): BlockSwitcher;
11
+ /**
12
+ * Switch to a specific block option, deactivating all others.
13
+ * - Selected block: all content lines uncommented
14
+ * - Other blocks: all content lines commented
15
+ */
16
+ switch(content: string, selector: Selector, blockName: string): string;
17
+ /**
18
+ * Validate that the block option exists in the selector
19
+ */
20
+ private validateBlockOption;
21
+ }
22
+ //# sourceMappingURL=block-switcher.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"block-switcher.d.ts","sourceRoot":"","sources":["../../src/lib/block-switcher.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAEjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAE9D;;GAEG;AACH,qBAAa,aAAc,SAAQ,kBAAkB;IACnD;;OAEG;IACH,MAAM,CAAC,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,aAAa;IAInD;;;;OAIG;IACH,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM;IA4BtE;;OAEG;IACH,OAAO,CAAC,mBAAmB;CAQ5B"}
@@ -7,6 +7,8 @@ export declare class Parser {
7
7
  private readonly commentStyle;
8
8
  private static readonly SELECT_REGEX;
9
9
  private static readonly OPTION_REGEX;
10
+ private static readonly BLOCK_START_REGEX;
11
+ private static readonly BLOCK_END_REGEX;
10
12
  constructor(commentStyle: CommentStyle);
11
13
  /**
12
14
  * Create a parser for a file path
@@ -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,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"}
1
+ {"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../src/lib/parser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAuB,WAAW,EAAY,MAAM,kBAAkB,CAAC;AACnF,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEhD;;GAEG;AACH,qBAAa,MAAM;IAML,OAAO,CAAC,QAAQ,CAAC,YAAY;IALzC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAyB;IAC7D,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAyB;IAC7D,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,iBAAiB,CAA8B;IACvE,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,CAAoB;gBAE9B,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;IA8FnC;;;OAGG;IACH,OAAO,CAAC,kBAAkB;IA6B1B;;OAEG;IACH,OAAO,CAAC,eAAe;CAkBxB"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Represents a multi-line block option within a selector
3
+ */
4
+ export interface BlockOption {
5
+ /** Option name (e.g., "Development", "Production") */
6
+ name: string;
7
+ /** Line number where @pik:block-start is located (1-based) */
8
+ startLine: number;
9
+ /** Line number where @pik:block-end is located (1-based) */
10
+ endLine: number;
11
+ /** Line numbers of content lines between start/end (1-based) */
12
+ contentLines: number[];
13
+ /** Whether this block is currently active (content lines are not commented out) */
14
+ isActive: boolean;
15
+ }
16
+ //# sourceMappingURL=block-option.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"block-option.d.ts","sourceRoot":"","sources":["../../../src/lib/types/block-option.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,sDAAsD;IACtD,IAAI,EAAE,MAAM,CAAC;IACb,8DAA8D;IAC9D,SAAS,EAAE,MAAM,CAAC;IAClB,4DAA4D;IAC5D,OAAO,EAAE,MAAM,CAAC;IAChB,gEAAgE;IAChE,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,mFAAmF;IACnF,QAAQ,EAAE,OAAO,CAAC;CACnB"}
@@ -1,4 +1,5 @@
1
1
  export type { Option } from './option.js';
2
+ export type { BlockOption } from './block-option.js';
2
3
  export type { Selector } from './selector.js';
3
4
  export type { ParseResult } from './parse-result.js';
4
5
  export { CommentStyle } from './comment-style.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/types/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,YAAY,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,YAAY,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,YAAY,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/types/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,YAAY,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,YAAY,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,YAAY,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,YAAY,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC"}
@@ -1,4 +1,5 @@
1
1
  import type { Option } from './option.js';
2
+ import type { BlockOption } from './block-option.js';
2
3
  /**
3
4
  * Represents a selector with its options
4
5
  */
@@ -7,7 +8,9 @@ export interface Selector {
7
8
  name: string;
8
9
  /** Line number where the selector is defined (1-based) */
9
10
  line: number;
10
- /** All options belonging to this selector */
11
+ /** All single-line options belonging to this selector */
11
12
  options: Option[];
13
+ /** All multi-line block options belonging to this selector */
14
+ blockOptions: BlockOption[];
12
15
  }
13
16
  //# sourceMappingURL=selector.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"selector.d.ts","sourceRoot":"","sources":["../../../src/lib/types/selector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1C;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,0CAA0C;IAC1C,IAAI,EAAE,MAAM,CAAC;IACb,0DAA0D;IAC1D,IAAI,EAAE,MAAM,CAAC;IACb,6CAA6C;IAC7C,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB"}
1
+ {"version":3,"file":"selector.d.ts","sourceRoot":"","sources":["../../../src/lib/types/selector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,0CAA0C;IAC1C,IAAI,EAAE,MAAM,CAAC;IACb,0DAA0D;IAC1D,IAAI,EAAE,MAAM,CAAC;IACb,yDAAyD;IACzD,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,8DAA8D;IAC9D,YAAY,EAAE,WAAW,EAAE,CAAC;CAC7B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lsst/pik-core",
3
- "version": "0.6.7",
3
+ "version": "0.7.0",
4
4
  "description": "Core library for parsing and switching @pik config markers",
5
5
  "type": "module",
6
6
  "license": "MIT",