Skip to content

Commit 920af3f

Browse files
committed
Update deploy-script.js
1 parent e89bb93 commit 920af3f

File tree

1 file changed

+32
-34
lines changed

1 file changed

+32
-34
lines changed

deploy-script.js

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,49 @@
11
// deploy-script.js
2+
23
const fs = require('fs');
34
const path = require('path');
45

56
async function deploy() {
67
console.log('🔍 Locating docmd engine...');
78

8-
// 1. Find the internal build script inside node_modules
9-
// We look for package.json first to find the root of the package
10-
const docmdPkgPath = require.resolve('@mgks/docmd/package.json');
11-
const docmdRoot = path.dirname(docmdPkgPath);
12-
13-
// The builder is located at src/commands/live.js in the package
14-
const internalBuilderPath = path.join(docmdRoot, 'src/commands/live.js');
9+
try {
10+
const mainEntryPath = require.resolve('@mgks/docmd');
11+
const srcDir = path.dirname(mainEntryPath);
12+
const internalBuilderPath = path.join(srcDir, 'commands', 'live.js');
1513

16-
if (!fs.existsSync(internalBuilderPath)) {
17-
throw new Error(`Could not find builder at ${internalBuilderPath}`);
18-
}
14+
const docmdRoot = path.resolve(srcDir, '..');
1915

20-
console.log('🚀 Triggering internal build...');
16+
if (!fs.existsSync(internalBuilderPath)) {
17+
throw new Error(`Could not find builder at ${internalBuilderPath}`);
18+
}
2119

22-
// 2. Import the build function
23-
const { build } = require(internalBuilderPath);
20+
console.log('🚀 Triggering internal build...');
2421

25-
// 3. Execute Build
26-
// This will generate files into node_modules/@mgks/docmd/dist
27-
await build();
22+
const { build } = require(internalBuilderPath);
2823

29-
// 4. Move artifacts to project root 'dist' for GitHub Pages
30-
const sourceDist = path.join(docmdRoot, 'dist');
31-
const targetDist = path.join(__dirname, 'dist');
24+
await build();
3225

33-
console.log(`📦 Moving artifacts from ${sourceDist} to ${targetDist}...`);
34-
35-
// Clean target
36-
if (fs.existsSync(targetDist)) {
37-
fs.rmSync(targetDist, { recursive: true, force: true });
38-
}
39-
40-
// Copy built assets
41-
fs.cpSync(sourceDist, targetDist, { recursive: true });
42-
43-
// Copy CNAME to dist (Required because GH Pages serves from root of the artifact)
44-
if (fs.existsSync(path.join(__dirname, 'CNAME'))) {
45-
fs.copyFileSync(path.join(__dirname, 'CNAME'), path.join(targetDist, 'CNAME'));
26+
const sourceDist = path.join(docmdRoot, 'dist');
27+
const targetDist = path.join(__dirname, 'dist');
28+
29+
console.log(`📦 Moving artifacts from ${sourceDist} to ${targetDist}...`);
30+
31+
if (fs.existsSync(targetDist)) {
32+
fs.rmSync(targetDist, { recursive: true, force: true });
33+
}
34+
35+
fs.cpSync(sourceDist, targetDist, { recursive: true });
36+
37+
if (fs.existsSync(path.join(__dirname, 'CNAME'))) {
38+
fs.copyFileSync(path.join(__dirname, 'CNAME'), path.join(targetDist, 'CNAME'));
39+
}
40+
41+
console.log('✅ Ready for deployment.');
42+
43+
} catch (e) {
44+
console.error('❌ Error locating or running docmd:', e);
45+
process.exit(1);
4646
}
47-
48-
console.log('✅ Ready for deployment.');
4947
}
5048

5149
deploy().catch(err => {

0 commit comments

Comments
 (0)