@timeax/scaffold 0.0.13 → 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/cli.mjs CHANGED
@@ -640,7 +640,7 @@ function stripInlineComment(content) {
640
640
  }
641
641
  return content.slice(0, cutIndex).trimEnd();
642
642
  }
643
- function parseLine(line, lineNo) {
643
+ function parseLine(line, lineNo, fileName) {
644
644
  const match = line.match(/^(\s*)(.*)$/);
645
645
  if (!match) return null;
646
646
  const indentSpaces = match[1].length;
@@ -658,7 +658,7 @@ function parseLine(line, lineNo) {
658
658
  const pathToken = parts[0];
659
659
  if (pathToken.includes(":")) {
660
660
  throw new Error(
661
- `structure.txt: ":" is reserved for annotations (@stub:, @include:, etc). Invalid path "${pathToken}" on line ${lineNo}.`
661
+ `${fileName}: ":" is reserved for annotations (@stub:, @include:, etc). Invalid path "${pathToken}" on line ${lineNo}.`
662
662
  );
663
663
  }
664
664
  let stub;
@@ -692,12 +692,12 @@ function parseLine(line, lineNo) {
692
692
  exclude: exclude.length ? exclude : void 0
693
693
  };
694
694
  }
695
- function parseStructureText(text, indentStep = 2) {
695
+ function parseStructureText(fileName, text, indentStep = 2) {
696
696
  const lines = text.split(/\r?\n/);
697
697
  const parsed = [];
698
698
  for (let i = 0; i < lines.length; i++) {
699
699
  const lineNo = i + 1;
700
- const p = parseLine(lines[i], lineNo);
700
+ const p = parseLine(lines[i], lineNo, fileName);
701
701
  if (p) parsed.push(p);
702
702
  }
703
703
  const rootEntries = [];
@@ -706,14 +706,14 @@ function parseStructureText(text, indentStep = 2) {
706
706
  const { indentSpaces, lineNo } = p;
707
707
  if (indentSpaces % indentStep !== 0) {
708
708
  throw new Error(
709
- `structure.txt: Invalid indent on line ${lineNo}. Indent must be multiples of ${indentStep} spaces.`
709
+ `${fileName}: Invalid indent on line ${lineNo}. Indent must be multiples of ${indentStep} spaces.`
710
710
  );
711
711
  }
712
712
  const level = indentSpaces / indentStep;
713
713
  if (level > stack.length) {
714
714
  if (level !== stack.length + 1) {
715
715
  throw new Error(
716
- `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}.`
716
+ `${fileName}: Invalid indentation on line ${lineNo}. You cannot jump more than one level at a time. Previous depth: ${stack.length}, this line depth: ${level}.`
717
717
  );
718
718
  }
719
719
  }
@@ -721,12 +721,12 @@ function parseStructureText(text, indentStep = 2) {
721
721
  const parent2 = stack[level - 1];
722
722
  if (!parent2) {
723
723
  throw new Error(
724
- `structure.txt: Indented entry without a parent on line ${lineNo}.`
724
+ `${fileName}: Indented entry without a parent on line ${lineNo}.`
725
725
  );
726
726
  }
727
727
  if (!parent2.isDir) {
728
728
  throw new Error(
729
- `structure.txt: Cannot indent under a file on line ${lineNo}. Files cannot have children. Parent: "${parent2.entry.path}".`
729
+ `${fileName}: Cannot indent under a file on line ${lineNo}. Files cannot have children. Parent: "${parent2.entry.path}".`
730
730
  );
731
731
  }
732
732
  }
@@ -777,7 +777,7 @@ function parseStructureText(text, indentStep = 2) {
777
777
 
778
778
  // src/core/resolve-structure.ts
779
779
  var logger2 = defaultLogger.child("[structure]");
780
- function resolveGroupStructure(scaffoldDir, group) {
780
+ function resolveGroupStructure(scaffoldDir, group, config) {
781
781
  if (group.structure && group.structure.length) {
782
782
  logger2.debug(`Using inline structure for group "${group.name}"`);
783
783
  return group.structure;
@@ -791,7 +791,7 @@ function resolveGroupStructure(scaffoldDir, group) {
791
791
  }
792
792
  logger2.debug(`Reading structure for group "${group.name}" from ${filePath}`);
793
793
  const raw = fs8.readFileSync(filePath, "utf8");
794
- return parseStructureText(raw);
794
+ return parseStructureText(fileName, raw, config.indentStep);
795
795
  }
796
796
  function resolveSingleStructure(scaffoldDir, config) {
797
797
  if (config.structure && config.structure.length) {
@@ -807,7 +807,7 @@ function resolveSingleStructure(scaffoldDir, config) {
807
807
  }
808
808
  logger2.debug(`Reading single structure from ${filePath}`);
809
809
  const raw = fs8.readFileSync(filePath, "utf8");
810
- return parseStructureText(raw);
810
+ return parseStructureText(fileName, raw, config.indentStep);
811
811
  }
812
812
  var logger3 = defaultLogger.child("[cache]");
813
813
  var DEFAULT_CACHE = {
@@ -1276,7 +1276,7 @@ async function runOnce(cwd, options = {}) {
1276
1276
  if (config.groups && config.groups.length > 0) {
1277
1277
  for (const group of config.groups) {
1278
1278
  const groupRootAbs = path2.resolve(projectRoot, group.root);
1279
- const structure = resolveGroupStructure(scaffoldDir, group);
1279
+ const structure = resolveGroupStructure(scaffoldDir, group, config);
1280
1280
  const groupLogger = logger6.child(`[group:${group.name}]`);
1281
1281
  await applyStructure({
1282
1282
  config,