@timeax/scaffold 0.0.13 → 0.1.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.cts CHANGED
@@ -178,6 +178,6 @@ declare function ensureStructureFilesFromConfig(cwd: string, options?: {
178
178
  * - If you indent under a file, an error is thrown.
179
179
  * - Folders must end with "/" in the txt; paths are normalized to POSIX.
180
180
  */
181
- declare function parseStructureText(text: string, indentStep?: number): StructureEntry[];
181
+ declare function parseStructureText(fileName: string, text: string, indentStep?: number): StructureEntry[];
182
182
 
183
183
  export { type EnsureStructuresResult, type LoadScaffoldConfigOptions, type LoadScaffoldConfigResult, type RunOptions, SCAFFOLD_ROOT_DIR, ScaffoldConfig, ScanFromConfigOptions, type ScanFromConfigResult, ScanStructureOptions, StructureEntry, ensureStructureFilesFromConfig, loadScaffoldConfig, parseStructureText, runOnce, scanDirectoryToStructureText, scanProjectFromConfig, writeScannedStructuresFromConfig };
package/dist/index.d.ts CHANGED
@@ -178,6 +178,6 @@ declare function ensureStructureFilesFromConfig(cwd: string, options?: {
178
178
  * - If you indent under a file, an error is thrown.
179
179
  * - Folders must end with "/" in the txt; paths are normalized to POSIX.
180
180
  */
181
- declare function parseStructureText(text: string, indentStep?: number): StructureEntry[];
181
+ declare function parseStructureText(fileName: string, text: string, indentStep?: number): StructureEntry[];
182
182
 
183
183
  export { type EnsureStructuresResult, type LoadScaffoldConfigOptions, type LoadScaffoldConfigResult, type RunOptions, SCAFFOLD_ROOT_DIR, ScaffoldConfig, ScanFromConfigOptions, type ScanFromConfigResult, ScanStructureOptions, StructureEntry, ensureStructureFilesFromConfig, loadScaffoldConfig, parseStructureText, runOnce, scanDirectoryToStructureText, scanProjectFromConfig, writeScannedStructuresFromConfig };
package/dist/index.mjs CHANGED
@@ -636,7 +636,7 @@ function stripInlineComment(content) {
636
636
  }
637
637
  return content.slice(0, cutIndex).trimEnd();
638
638
  }
639
- function parseLine(line, lineNo) {
639
+ function parseLine(line, lineNo, fileName) {
640
640
  const match = line.match(/^(\s*)(.*)$/);
641
641
  if (!match) return null;
642
642
  const indentSpaces = match[1].length;
@@ -654,7 +654,7 @@ function parseLine(line, lineNo) {
654
654
  const pathToken = parts[0];
655
655
  if (pathToken.includes(":")) {
656
656
  throw new Error(
657
- `structure.txt: ":" is reserved for annotations (@stub:, @include:, etc). Invalid path "${pathToken}" on line ${lineNo}.`
657
+ `${fileName}: ":" is reserved for annotations (@stub:, @include:, etc). Invalid path "${pathToken}" on line ${lineNo}.`
658
658
  );
659
659
  }
660
660
  let stub;
@@ -688,12 +688,12 @@ function parseLine(line, lineNo) {
688
688
  exclude: exclude.length ? exclude : void 0
689
689
  };
690
690
  }
691
- function parseStructureText(text, indentStep = 2) {
691
+ function parseStructureText(fileName, text, indentStep = 2) {
692
692
  const lines = text.split(/\r?\n/);
693
693
  const parsed = [];
694
694
  for (let i = 0; i < lines.length; i++) {
695
695
  const lineNo = i + 1;
696
- const p = parseLine(lines[i], lineNo);
696
+ const p = parseLine(lines[i], lineNo, fileName);
697
697
  if (p) parsed.push(p);
698
698
  }
699
699
  const rootEntries = [];
@@ -702,14 +702,14 @@ function parseStructureText(text, indentStep = 2) {
702
702
  const { indentSpaces, lineNo } = p;
703
703
  if (indentSpaces % indentStep !== 0) {
704
704
  throw new Error(
705
- `structure.txt: Invalid indent on line ${lineNo}. Indent must be multiples of ${indentStep} spaces.`
705
+ `${fileName}: Invalid indent on line ${lineNo}. Indent must be multiples of ${indentStep} spaces.`
706
706
  );
707
707
  }
708
708
  const level = indentSpaces / indentStep;
709
709
  if (level > stack.length) {
710
710
  if (level !== stack.length + 1) {
711
711
  throw new Error(
712
- `structure.txt: Invalid indentation on line ${lineNo}. You cannot jump more than one level at a time. Previous depth: ${stack.length}, this line depth: ${level}.`
712
+ `${fileName}: Invalid indentation on line ${lineNo}. You cannot jump more than one level at a time. Previous depth: ${stack.length}, this line depth: ${level}.`
713
713
  );
714
714
  }
715
715
  }
@@ -717,12 +717,12 @@ function parseStructureText(text, indentStep = 2) {
717
717
  const parent2 = stack[level - 1];
718
718
  if (!parent2) {
719
719
  throw new Error(
720
- `structure.txt: Indented entry without a parent on line ${lineNo}.`
720
+ `${fileName}: Indented entry without a parent on line ${lineNo}.`
721
721
  );
722
722
  }
723
723
  if (!parent2.isDir) {
724
724
  throw new Error(
725
- `structure.txt: Cannot indent under a file on line ${lineNo}. Files cannot have children. Parent: "${parent2.entry.path}".`
725
+ `${fileName}: Cannot indent under a file on line ${lineNo}. Files cannot have children. Parent: "${parent2.entry.path}".`
726
726
  );
727
727
  }
728
728
  }
@@ -773,7 +773,7 @@ function parseStructureText(text, indentStep = 2) {
773
773
 
774
774
  // src/core/resolve-structure.ts
775
775
  var logger2 = defaultLogger.child("[structure]");
776
- function resolveGroupStructure(scaffoldDir, group) {
776
+ function resolveGroupStructure(scaffoldDir, group, config) {
777
777
  if (group.structure && group.structure.length) {
778
778
  logger2.debug(`Using inline structure for group "${group.name}"`);
779
779
  return group.structure;
@@ -787,7 +787,7 @@ function resolveGroupStructure(scaffoldDir, group) {
787
787
  }
788
788
  logger2.debug(`Reading structure for group "${group.name}" from ${filePath}`);
789
789
  const raw = fs2.readFileSync(filePath, "utf8");
790
- return parseStructureText(raw);
790
+ return parseStructureText(fileName, raw, config.indentStep);
791
791
  }
792
792
  function resolveSingleStructure(scaffoldDir, config) {
793
793
  if (config.structure && config.structure.length) {
@@ -803,7 +803,7 @@ function resolveSingleStructure(scaffoldDir, config) {
803
803
  }
804
804
  logger2.debug(`Reading single structure from ${filePath}`);
805
805
  const raw = fs2.readFileSync(filePath, "utf8");
806
- return parseStructureText(raw);
806
+ return parseStructureText(fileName, raw, config.indentStep);
807
807
  }
808
808
  var logger3 = defaultLogger.child("[cache]");
809
809
  var DEFAULT_CACHE = {
@@ -1114,7 +1114,7 @@ async function runOnce(cwd, options = {}) {
1114
1114
  if (config.groups && config.groups.length > 0) {
1115
1115
  for (const group of config.groups) {
1116
1116
  const groupRootAbs = path2.resolve(projectRoot, group.root);
1117
- const structure = resolveGroupStructure(scaffoldDir, group);
1117
+ const structure = resolveGroupStructure(scaffoldDir, group, config);
1118
1118
  const groupLogger = logger5.child(`[group:${group.name}]`);
1119
1119
  await applyStructure({
1120
1120
  config,