kss-modern 0.0.41 → 0.0.42

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.
@@ -37,6 +37,12 @@ interface in2Section {
37
37
  previewFileName: string;
38
38
  fullpageFileName: string;
39
39
  }
40
+ interface in2FirstLevelSection extends in2Section {
41
+ sections: in2SecondLevelSection[];
42
+ }
43
+ interface in2SecondLevelSection extends in2Section {
44
+ sections: in2Section[];
45
+ }
40
46
 
41
47
  interface StyleguideConfiguration {
42
48
  mode: 'development' | 'production';
@@ -79,6 +85,13 @@ interface StyleguideBuildOutput {
79
85
  overwrittenSectionsIds?: string[];
80
86
  };
81
87
  }
88
+ /**
89
+ * Parse given contentDir and get structured data for further processing
90
+ */
91
+ declare function parseStyleguide(contentDir: StyleguideConfiguration['contentDir']): Promise<{
92
+ content: in2FirstLevelSection[];
93
+ overwrittenSectionsIds: string[];
94
+ }>;
82
95
  /**
83
96
  * Builds the styleguide
84
97
  * @param config - The configuration for the styleguide
@@ -92,5 +105,5 @@ declare function buildStyleguide(config: StyleguideConfiguration): Promise<Style
92
105
  */
93
106
  declare function watchStyleguide(config: StyleguideConfiguration, onChange?: () => void, onError?: (errorData: StyleguideBuildOutput['errors']) => void): Promise<void>;
94
107
 
95
- export { buildStyleguide, watchStyleguide };
108
+ export { buildStyleguide, parseStyleguide, watchStyleguide };
96
109
  export type { StyleguideConfiguration };
@@ -37,6 +37,12 @@ interface in2Section {
37
37
  previewFileName: string;
38
38
  fullpageFileName: string;
39
39
  }
40
+ interface in2FirstLevelSection extends in2Section {
41
+ sections: in2SecondLevelSection[];
42
+ }
43
+ interface in2SecondLevelSection extends in2Section {
44
+ sections: in2Section[];
45
+ }
40
46
 
41
47
  interface StyleguideConfiguration {
42
48
  mode: 'development' | 'production';
@@ -79,6 +85,13 @@ interface StyleguideBuildOutput {
79
85
  overwrittenSectionsIds?: string[];
80
86
  };
81
87
  }
88
+ /**
89
+ * Parse given contentDir and get structured data for further processing
90
+ */
91
+ declare function parseStyleguide(contentDir: StyleguideConfiguration['contentDir']): Promise<{
92
+ content: in2FirstLevelSection[];
93
+ overwrittenSectionsIds: string[];
94
+ }>;
82
95
  /**
83
96
  * Builds the styleguide
84
97
  * @param config - The configuration for the styleguide
@@ -92,5 +105,5 @@ declare function buildStyleguide(config: StyleguideConfiguration): Promise<Style
92
105
  */
93
106
  declare function watchStyleguide(config: StyleguideConfiguration, onChange?: () => void, onError?: (errorData: StyleguideBuildOutput['errors']) => void): Promise<void>;
94
107
 
95
- export { buildStyleguide, watchStyleguide };
108
+ export { buildStyleguide, parseStyleguide, watchStyleguide };
96
109
  export type { StyleguideConfiguration };
@@ -726,7 +726,7 @@ function extractMarkdownPath(input) {
726
726
  }
727
727
  return path2;
728
728
  }
729
- async function parse(input, config) {
729
+ async function parse(input, contentDir) {
730
730
  const data = kssParser(input).sections.filter((section) => Boolean(section.reference));
731
731
  const overwrittenSectionsIds = [];
732
732
  const sortedData = data.sort((a, b) => {
@@ -744,7 +744,7 @@ async function parse(input, config) {
744
744
  };
745
745
  }
746
746
  return {
747
- description: await parseMarkdown({ filePath: path.join(config.contentDir, markdownPath), rootHeadingLevel }),
747
+ description: await parseMarkdown({ filePath: path.join(contentDir, markdownPath), rootHeadingLevel }),
748
748
  hasMarkdownDescription: true
749
749
  };
750
750
  }
@@ -755,7 +755,7 @@ async function parse(input, config) {
755
755
  const isHtmlFilePath = trimmedMarkup.endsWith(".html") && !trimmedMarkup.includes("<") && !trimmedMarkup.includes("\n");
756
756
  if (isHtmlFilePath) {
757
757
  sourceMarkup = {
758
- file: path.join(config.contentDir, trimmedMarkup)
758
+ file: path.join(contentDir, trimmedMarkup)
759
759
  };
760
760
  } else if (section.markup.includes('<insert-vite-pug src="')) {
761
761
  const regexModifierLine = /<insert-vite-pug src="(.+?)".*(?:[\n\r\u2028\u2029]\s*)?(modifierClass="(.+?)")? *><\/insert-vite-pug>/g;
@@ -767,7 +767,7 @@ async function parse(input, config) {
767
767
  if (!pugSourcePath || !pugSourcePath.endsWith(".pug")) {
768
768
  throw new Error("No or invalid Pug source path found");
769
769
  }
770
- pugSourcePath = path.join(config.contentDir, pugSourcePath);
770
+ pugSourcePath = path.join(contentDir, pugSourcePath);
771
771
  sourceMarkup = {
772
772
  file: pugSourcePath
773
773
  };
@@ -2094,18 +2094,21 @@ function watchStyleguideForChanges(path, callback) {
2094
2094
  );
2095
2095
  }
2096
2096
 
2097
- async function buildStyleguide(config) {
2098
- const styleguideContentPaths = await glob(`${config.contentDir}/**/*.{css,scss}`);
2097
+ async function parseStyleguide(contentDir) {
2098
+ const styleguideContentPaths = await glob(`${contentDir}/**/*.{css,scss}`);
2099
2099
  const styleguideContent = await Promise.all(
2100
2100
  styleguideContentPaths.map(async (filePath) => ({
2101
2101
  path: filePath,
2102
2102
  contents: await fs.readFile(filePath, "utf-8")
2103
2103
  }))
2104
2104
  );
2105
- const rawParsedOutput = await parse(styleguideContent, config);
2105
+ const rawParsedOutput = await parse(styleguideContent, contentDir);
2106
2106
  if (!rawParsedOutput)
2107
2107
  throw new Error("Could not parse content");
2108
- const { content: parsedContent, overwrittenSectionsIds } = rawParsedOutput;
2108
+ return rawParsedOutput;
2109
+ }
2110
+ async function buildStyleguide(config) {
2111
+ const { content: parsedContent, overwrittenSectionsIds } = await parseStyleguide(config.contentDir);
2109
2112
  if (config.mode === "production" && await fs.exists(config.outDir)) {
2110
2113
  const files = await glob(`${config.outDir}/**/*.html`);
2111
2114
  await Promise.all(files.map((file) => fs.unlink(file)));
@@ -2321,4 +2324,4 @@ async function watchStyleguide(config, onChange, onError) {
2321
2324
  });
2322
2325
  }
2323
2326
 
2324
- export { buildStyleguide, watchStyleguide };
2327
+ export { buildStyleguide, parseStyleguide, watchStyleguide };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "kss-modern",
3
3
  "type": "module",
4
- "version": "0.0.41",
4
+ "version": "0.0.42",
5
5
  "description": "Modern KSS compatible styleguide generator",
6
6
  "repository": {
7
7
  "type": "git",