portosaurus 1.16.0 → 1.16.2
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/bin/portosaurus.js
CHANGED
|
@@ -57,13 +57,13 @@ async function prepareDocusaurusRun(projectRoot) {
|
|
|
57
57
|
|
|
58
58
|
// Ensure internal files are synced to .portosaurus
|
|
59
59
|
const internalDir = path.join(__dirname, "../src/internal");
|
|
60
|
-
const
|
|
60
|
+
const runtimeDir = path.join(projectRoot, ".portosaurus");
|
|
61
61
|
|
|
62
62
|
// Ensure .portosaurus exists and is clean
|
|
63
|
-
fs.emptyDirSync(
|
|
63
|
+
fs.emptyDirSync(runtimeDir);
|
|
64
64
|
|
|
65
65
|
// 1. Copy everything from internal to .portosaurus
|
|
66
|
-
fs.copySync(internalDir,
|
|
66
|
+
fs.copySync(internalDir, runtimeDir);
|
|
67
67
|
|
|
68
68
|
// 2. Overwrite with user files if they exist in project root
|
|
69
69
|
const internalFiles = readdirSync(internalDir);
|
|
@@ -72,7 +72,7 @@ async function prepareDocusaurusRun(projectRoot) {
|
|
|
72
72
|
const userFile = path.join(projectRoot, file);
|
|
73
73
|
|
|
74
74
|
if (existsSync(userFile)) {
|
|
75
|
-
fs.copySync(userFile, path.join(
|
|
75
|
+
fs.copySync(userFile, path.join(runtimeDir, file), {
|
|
76
76
|
overwrite: true,
|
|
77
77
|
filter: (src) => {
|
|
78
78
|
// Ignore notes/index.md
|
|
@@ -120,7 +120,7 @@ async function prepareDocusaurusRun(projectRoot) {
|
|
|
120
120
|
const docusaurusConfig = createConfig(userConfig, projectRoot);
|
|
121
121
|
|
|
122
122
|
// Write temp config file INSIDE .portosaurus
|
|
123
|
-
const tempConfigPath = path.join(
|
|
123
|
+
const tempConfigPath = path.join(runtimeDir, "docusaurus.config.js");
|
|
124
124
|
|
|
125
125
|
const configContent = `// Auto-generated by Portosaurus
|
|
126
126
|
module.exports = ${JSON.stringify(docusaurusConfig, null, 2)};`;
|
|
@@ -128,10 +128,10 @@ module.exports = ${JSON.stringify(docusaurusConfig, null, 2)};`;
|
|
|
128
128
|
writeFileSync(tempConfigPath, configContent);
|
|
129
129
|
logger.success("Generated Docusaurus config in .portosaurus.");
|
|
130
130
|
|
|
131
|
-
return {
|
|
131
|
+
return { runtimeDir };
|
|
132
132
|
}
|
|
133
133
|
|
|
134
|
-
async function runDocusaurus(command, args,
|
|
134
|
+
async function runDocusaurus(command, args, runtimeDir, projectRoot) {
|
|
135
135
|
// Detect package manager and find docusaurus binary
|
|
136
136
|
const { findDocusaurusBin } = await import("../src/utils/packageManager.js");
|
|
137
137
|
const docusaurus = findDocusaurusBin(projectRoot || process.cwd());
|
|
@@ -142,7 +142,7 @@ async function runDocusaurus(command, args, dotPorto, projectRoot) {
|
|
|
142
142
|
|
|
143
143
|
const child = spawn(
|
|
144
144
|
docusaurus.command,
|
|
145
|
-
[...docusaurus.args, command,
|
|
145
|
+
[...docusaurus.args, command, runtimeDir, ...args],
|
|
146
146
|
{
|
|
147
147
|
stdio: "inherit",
|
|
148
148
|
cwd: projectRoot,
|
|
@@ -314,8 +314,8 @@ program
|
|
|
314
314
|
const projectRoot = process.cwd();
|
|
315
315
|
logger.info("Starting development server...");
|
|
316
316
|
try {
|
|
317
|
-
const {
|
|
318
|
-
await runDocusaurus("start", [],
|
|
317
|
+
const { runtimeDir } = await prepareDocusaurusRun(projectRoot);
|
|
318
|
+
await runDocusaurus("start", [], runtimeDir, projectRoot);
|
|
319
319
|
} catch (error) {
|
|
320
320
|
logger.error(`Failed to start: ${error.message}`);
|
|
321
321
|
process.exit(1);
|
|
@@ -334,12 +334,12 @@ program
|
|
|
334
334
|
logger.info("Building Portosaurus site...");
|
|
335
335
|
|
|
336
336
|
try {
|
|
337
|
-
const {
|
|
337
|
+
const { runtimeDir } = await prepareDocusaurusRun(projectRoot);
|
|
338
338
|
|
|
339
339
|
const buildDir = path.join(projectRoot, "build");
|
|
340
340
|
const args = ["--out-dir", buildDir];
|
|
341
341
|
|
|
342
|
-
await runDocusaurus("build", args,
|
|
342
|
+
await runDocusaurus("build", args, runtimeDir, projectRoot);
|
|
343
343
|
|
|
344
344
|
// Create .nojekyll for GitHub Pages compatibility
|
|
345
345
|
const nojekyllPath = path.join(buildDir, ".nojekyll");
|
|
@@ -368,7 +368,7 @@ program
|
|
|
368
368
|
logger.info("Serving Portosaurus site...");
|
|
369
369
|
|
|
370
370
|
try {
|
|
371
|
-
const {
|
|
371
|
+
const { runtimeDir } = await prepareDocusaurusRun(projectRoot);
|
|
372
372
|
const buildDir = path.join(projectRoot, "build");
|
|
373
373
|
|
|
374
374
|
if (!existsSync(buildDir)) {
|
|
@@ -378,7 +378,12 @@ program
|
|
|
378
378
|
process.exit(1);
|
|
379
379
|
}
|
|
380
380
|
|
|
381
|
-
await runDocusaurus(
|
|
381
|
+
await runDocusaurus(
|
|
382
|
+
"serve",
|
|
383
|
+
["--dir", buildDir],
|
|
384
|
+
runtimeDir,
|
|
385
|
+
projectRoot,
|
|
386
|
+
);
|
|
382
387
|
} catch (error) {
|
|
383
388
|
logger.error(`Failed to serve: ${error.message}`);
|
|
384
389
|
process.exit(1);
|
package/package.json
CHANGED
|
@@ -63,14 +63,11 @@ export function createConfig(userConfig, projectRoot = process.cwd()) {
|
|
|
63
63
|
const faviconPath =
|
|
64
64
|
usrConf.hero_section?.profile_pic || "https://github.com/soymadip.png";
|
|
65
65
|
|
|
66
|
-
const title = usrConf.hero_section?.title || projName;
|
|
67
|
-
const tagline = usrConf.hero_section?.description || projDesc;
|
|
68
|
-
|
|
69
66
|
// Resolve paths relative to .portosaurus (the build context)
|
|
70
|
-
const
|
|
71
|
-
const notesPath = path.resolve(
|
|
72
|
-
const blogPath = path.resolve(
|
|
73
|
-
const staticPath = path.resolve(
|
|
67
|
+
const runtimeDir = path.resolve(projectRoot, ".portosaurus");
|
|
68
|
+
const notesPath = path.resolve(runtimeDir, "notes");
|
|
69
|
+
const blogPath = path.resolve(runtimeDir, "blog");
|
|
70
|
+
const staticPath = path.resolve(runtimeDir, "static");
|
|
74
71
|
|
|
75
72
|
// ---------- Docusaurus Config -----------
|
|
76
73
|
const config = {
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
// Import the config
|
|
3
|
-
const rawConfig = require('../../config.js');
|
|
4
|
-
|
|
5
|
-
function resolvePath(obj, path) {
|
|
6
|
-
const parts = path.split('.');
|
|
7
|
-
let current = obj;
|
|
8
|
-
|
|
9
|
-
for (const part of parts) {
|
|
10
|
-
if (current === null || current === undefined || typeof current !== 'object') {
|
|
11
|
-
return undefined;
|
|
12
|
-
}
|
|
13
|
-
current = current[part];
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
return current;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function parseStringValue(value, config) {
|
|
20
|
-
|
|
21
|
-
if (typeof value !== 'string') {
|
|
22
|
-
return value;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// Find all ${...} references
|
|
26
|
-
return value.replace(/\${([^}]+)}/g, (match, path) => {
|
|
27
|
-
const resolvedValue = resolvePath(config, path);
|
|
28
|
-
|
|
29
|
-
if (resolvedValue === undefined) {
|
|
30
|
-
console.warn(`Warning: Could not resolve reference "${path}" in config value "${value}"`);
|
|
31
|
-
return match;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
if (typeof resolvedValue === 'string' && resolvedValue.includes('${')) {
|
|
35
|
-
return parseStringValue(resolvedValue, config);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return resolvedValue;
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
function parseConfigObject(obj, config) {
|
|
44
|
-
|
|
45
|
-
if (Array.isArray(obj)) {
|
|
46
|
-
return obj.map(item => parseConfigObject(item, config));
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (obj !== null && typeof obj === 'object') {
|
|
50
|
-
const result = {};
|
|
51
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
52
|
-
result[key] = parseConfigObject(value, config);
|
|
53
|
-
}
|
|
54
|
-
return result;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if (typeof obj === 'string') {
|
|
58
|
-
return parseStringValue(obj, config);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return obj;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
function parseConfig(config) {
|
|
66
|
-
|
|
67
|
-
const parsedConfig = JSON.parse(JSON.stringify(config));
|
|
68
|
-
return parseConfigObject(parsedConfig, config);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// Parse the raw config
|
|
72
|
-
const parsedExports = {};
|
|
73
|
-
for (const key in rawConfig) {
|
|
74
|
-
parsedExports[key] = parseConfig(rawConfig[key]);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
module.exports = {
|
|
78
|
-
...parsedExports,
|
|
79
|
-
parseConfig,
|
|
80
|
-
parseStringValue,
|
|
81
|
-
resolvePath,
|
|
82
|
-
}
|
|
File without changes
|