|
1 | 1 | // deploy-script.js |
| 2 | + |
2 | 3 | const fs = require('fs'); |
3 | 4 | const path = require('path'); |
4 | 5 |
|
5 | 6 | async function deploy() { |
6 | 7 | console.log('🔍 Locating docmd engine...'); |
7 | 8 |
|
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'); |
15 | 13 |
|
16 | | - if (!fs.existsSync(internalBuilderPath)) { |
17 | | - throw new Error(`Could not find builder at ${internalBuilderPath}`); |
18 | | - } |
| 14 | + const docmdRoot = path.resolve(srcDir, '..'); |
19 | 15 |
|
20 | | - console.log('🚀 Triggering internal build...'); |
| 16 | + if (!fs.existsSync(internalBuilderPath)) { |
| 17 | + throw new Error(`Could not find builder at ${internalBuilderPath}`); |
| 18 | + } |
21 | 19 |
|
22 | | - // 2. Import the build function |
23 | | - const { build } = require(internalBuilderPath); |
| 20 | + console.log('🚀 Triggering internal build...'); |
24 | 21 |
|
25 | | - // 3. Execute Build |
26 | | - // This will generate files into node_modules/@mgks/docmd/dist |
27 | | - await build(); |
| 22 | + const { build } = require(internalBuilderPath); |
28 | 23 |
|
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(); |
32 | 25 |
|
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); |
46 | 46 | } |
47 | | - |
48 | | - console.log('✅ Ready for deployment.'); |
49 | 47 | } |
50 | 48 |
|
51 | 49 | deploy().catch(err => { |
|
0 commit comments