@kenjura/ursa 0.52.0 → 0.54.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/CHANGELOG.md +16 -0
- package/meta/menu.js +44 -13
- package/package.json +2 -1
- package/src/helper/automenu.js +23 -12
- package/src/helper/build/autoIndex.js +197 -0
- package/src/helper/build/batch.js +19 -0
- package/src/helper/build/cacheBust.js +62 -0
- package/src/helper/build/excludeFilter.js +67 -0
- package/src/helper/build/footer.js +113 -0
- package/src/helper/build/index.js +13 -0
- package/src/helper/build/menu.js +19 -0
- package/src/helper/build/metadata.js +30 -0
- package/src/helper/build/pathUtils.js +13 -0
- package/src/helper/build/progress.js +35 -0
- package/src/helper/build/templates.js +30 -0
- package/src/helper/build/titleCase.js +7 -0
- package/src/helper/build/watchCache.js +26 -0
- package/src/jobs/generate.js +82 -573
- package/src/serve.js +10 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Barrel file for build helpers
|
|
2
|
+
export * from './cacheBust.js';
|
|
3
|
+
export * from './batch.js';
|
|
4
|
+
export * from './progress.js';
|
|
5
|
+
export * from './watchCache.js';
|
|
6
|
+
export * from './titleCase.js';
|
|
7
|
+
export * from './excludeFilter.js';
|
|
8
|
+
export * from './pathUtils.js';
|
|
9
|
+
export * from './templates.js';
|
|
10
|
+
export * from './menu.js';
|
|
11
|
+
export * from './metadata.js';
|
|
12
|
+
export * from './footer.js';
|
|
13
|
+
export * from './autoIndex.js';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Menu helpers for build
|
|
2
|
+
import { getAutomenu } from "../automenu.js";
|
|
3
|
+
import { renderFile } from "../fileRenderer.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Get menu HTML and menu data from source directory
|
|
7
|
+
* @param {string[]} allSourceFilenames - All source file names
|
|
8
|
+
* @param {string} source - Source directory path
|
|
9
|
+
* @param {Set<string>} validPaths - Set of valid internal paths for link validation
|
|
10
|
+
* @returns {Promise<{html: string, menuData: Object}>} Menu HTML and menu data
|
|
11
|
+
*/
|
|
12
|
+
export async function getMenu(allSourceFilenames, source, validPaths) {
|
|
13
|
+
const menuResult = await getAutomenu(source, validPaths);
|
|
14
|
+
const menuBody = renderFile({ fileContents: menuResult.html, type: ".md" });
|
|
15
|
+
return {
|
|
16
|
+
html: menuBody,
|
|
17
|
+
menuData: menuResult.menuData
|
|
18
|
+
};
|
|
19
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// Metadata transformation helpers for build
|
|
2
|
+
import { join } from "path";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Get transformed metadata using custom or default transform function
|
|
6
|
+
* @param {string} dirname - Directory containing the file
|
|
7
|
+
* @param {Object} metadata - Raw metadata object
|
|
8
|
+
* @returns {Promise<string>} Transformed metadata string
|
|
9
|
+
*/
|
|
10
|
+
export async function getTransformedMetadata(dirname, metadata) {
|
|
11
|
+
// custom transform? else, use default
|
|
12
|
+
const customTransformFnFilename = join(dirname, "transformMetadata.js");
|
|
13
|
+
let transformFn = defaultTransformFn;
|
|
14
|
+
try {
|
|
15
|
+
const customTransformFn = (await import(customTransformFnFilename)).default;
|
|
16
|
+
if (typeof customTransformFn === "function")
|
|
17
|
+
transformFn = customTransformFn;
|
|
18
|
+
} catch (e) {
|
|
19
|
+
// No custom transform found, use default
|
|
20
|
+
}
|
|
21
|
+
try {
|
|
22
|
+
return transformFn(metadata);
|
|
23
|
+
} catch (e) {
|
|
24
|
+
return "error transforming metadata";
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function defaultTransformFn(metadata) {
|
|
28
|
+
return "default transform";
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Path utility helpers for build
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Add trailing slash to a path if not present
|
|
5
|
+
* @param {string} somePath - Path to modify
|
|
6
|
+
* @returns {string} Path with trailing slash
|
|
7
|
+
*/
|
|
8
|
+
export function addTrailingSlash(somePath) {
|
|
9
|
+
if (typeof somePath !== "string") return somePath;
|
|
10
|
+
if (somePath.length < 1) return somePath;
|
|
11
|
+
if (somePath[somePath.length - 1] === "/") return somePath;
|
|
12
|
+
return `${somePath}/`;
|
|
13
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// Progress reporter for build
|
|
2
|
+
|
|
3
|
+
export class ProgressReporter {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.lines = {};
|
|
6
|
+
this.isTTY = process.stdout.isTTY;
|
|
7
|
+
}
|
|
8
|
+
status(name, message) {
|
|
9
|
+
if (this.isTTY) {
|
|
10
|
+
const line = `${name}: ${message}`;
|
|
11
|
+
this.lines[name] = line;
|
|
12
|
+
process.stdout.write(`\r\x1b[K${line}`);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
done(name, message) {
|
|
16
|
+
if (this.isTTY) {
|
|
17
|
+
process.stdout.write(`\r\x1b[K${name}: ${message}\n`);
|
|
18
|
+
} else {
|
|
19
|
+
console.log(`${name}: ${message}`);
|
|
20
|
+
}
|
|
21
|
+
delete this.lines[name];
|
|
22
|
+
}
|
|
23
|
+
log(message) {
|
|
24
|
+
if (this.isTTY) {
|
|
25
|
+
process.stdout.write(`\r\x1b[K${message}\n`);
|
|
26
|
+
} else {
|
|
27
|
+
console.log(message);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
clear() {
|
|
31
|
+
if (this.isTTY) {
|
|
32
|
+
process.stdout.write(`\r\x1b[K`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// Template helpers for build
|
|
2
|
+
import { readFile } from "fs/promises";
|
|
3
|
+
import { parse } from "path";
|
|
4
|
+
import { recurse } from "../recursive-readdir.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Get all templates from meta directory
|
|
8
|
+
* @param {string} meta - Full path to meta files directory
|
|
9
|
+
* @returns {Promise<Object>} Map of templateName to templateBody
|
|
10
|
+
*/
|
|
11
|
+
export async function getTemplates(meta) {
|
|
12
|
+
const allMetaFilenames = await recurse(meta);
|
|
13
|
+
const allHtmlFilenames = allMetaFilenames.filter((filename) =>
|
|
14
|
+
filename.match(/\.html/)
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
let templates = {};
|
|
18
|
+
const templatesArray = await Promise.all(
|
|
19
|
+
allHtmlFilenames.map(async (filename) => {
|
|
20
|
+
const { name } = parse(filename);
|
|
21
|
+
const fileContent = await readFile(filename, "utf8");
|
|
22
|
+
return [name, fileContent];
|
|
23
|
+
})
|
|
24
|
+
);
|
|
25
|
+
templatesArray.forEach(
|
|
26
|
+
([templateName, templateText]) => (templates[templateName] = templateText)
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
return templates;
|
|
30
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// Watch mode cache and clear function for build
|
|
2
|
+
|
|
3
|
+
export const watchModeCache = {
|
|
4
|
+
templates: null,
|
|
5
|
+
menu: null,
|
|
6
|
+
footer: null,
|
|
7
|
+
validPaths: null,
|
|
8
|
+
source: null,
|
|
9
|
+
meta: null,
|
|
10
|
+
output: null,
|
|
11
|
+
hashCache: null,
|
|
12
|
+
cacheBustTimestamp: null,
|
|
13
|
+
lastFullBuild: 0,
|
|
14
|
+
isInitialized: false,
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export function clearWatchCache(cssPathCache) {
|
|
18
|
+
watchModeCache.templates = null;
|
|
19
|
+
watchModeCache.menu = null;
|
|
20
|
+
watchModeCache.footer = null;
|
|
21
|
+
watchModeCache.validPaths = null;
|
|
22
|
+
watchModeCache.hashCache = null;
|
|
23
|
+
watchModeCache.isInitialized = false;
|
|
24
|
+
if (cssPathCache) cssPathCache.clear();
|
|
25
|
+
console.log('Watch cache cleared');
|
|
26
|
+
}
|