@clidey/dory 0.3.0 โ 0.4.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/bin/dory.js +57 -32
- package/package.json +1 -1
package/bin/dory.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
import { execSync } from 'child_process';
|
|
4
|
-
import { existsSync, rmSync, mkdirSync, cpSync, readFileSync } from 'fs';
|
|
4
|
+
import { existsSync, rmSync, mkdirSync, cpSync, readFileSync, readdirSync } from 'fs';
|
|
5
5
|
import { resolve, dirname } from 'path';
|
|
6
6
|
import { fileURLToPath } from 'url'
|
|
7
7
|
import http from 'http';
|
|
@@ -12,40 +12,63 @@ const __dirname = dirname(__filename);
|
|
|
12
12
|
|
|
13
13
|
const commands = {
|
|
14
14
|
build: () => {
|
|
15
|
-
console.log('
|
|
15
|
+
console.log('๐ Dory is ready to build your docs!');
|
|
16
|
+
|
|
17
|
+
// Clear the docs folder if it exists
|
|
18
|
+
const docsDir = resolve(__dirname, '..', 'docs');
|
|
19
|
+
if (existsSync(docsDir)) {
|
|
20
|
+
console.log('๐งน Tidying up the workspace...');
|
|
21
|
+
rmSync(docsDir, { recursive: true, force: true });
|
|
22
|
+
}
|
|
16
23
|
|
|
17
24
|
// Check if dory.json exists in current directory
|
|
18
25
|
const currentDir = process.cwd();
|
|
19
26
|
const doryConfigPath = resolve(currentDir, 'dory.json');
|
|
20
27
|
|
|
21
28
|
if (!existsSync(doryConfigPath)) {
|
|
22
|
-
console.error('โ dory.json
|
|
29
|
+
console.error('โ Oops! dory.json is missing from your project');
|
|
23
30
|
process.exit(1);
|
|
24
31
|
}
|
|
25
32
|
|
|
26
33
|
// Read and validate dory.json
|
|
27
34
|
try {
|
|
28
35
|
const config = JSON.parse(readFileSync(doryConfigPath, 'utf8'));
|
|
29
|
-
console.log(`๐
|
|
36
|
+
console.log(`๐ Building: ${config.name || 'Your awesome project'}`);
|
|
30
37
|
} catch (error) {
|
|
31
|
-
console.error('โ
|
|
38
|
+
console.error('โ Your dory.json seems to have some issues:', error.message);
|
|
32
39
|
process.exit(1);
|
|
33
40
|
}
|
|
34
41
|
|
|
35
|
-
// Clear and prepare docs folder
|
|
36
|
-
const docsDir = resolve(currentDir, 'docs');
|
|
37
|
-
if (existsSync(docsDir)) {
|
|
38
|
-
console.log('๐งน Clearing docs folder...');
|
|
39
|
-
rmSync(docsDir, { recursive: true, force: true });
|
|
40
|
-
}
|
|
41
42
|
mkdirSync(docsDir, { recursive: true });
|
|
42
43
|
|
|
43
|
-
|
|
44
|
+
console.log('๐ Gathering your project files...');
|
|
44
45
|
cpSync(doryConfigPath, resolve(docsDir, 'dory.json'));
|
|
45
|
-
|
|
46
|
+
|
|
47
|
+
const copyFiles = (src, dest) => {
|
|
48
|
+
if (existsSync(src)) {
|
|
49
|
+
if (existsSync(dest)) {
|
|
50
|
+
rmSync(dest, { recursive: true, force: true });
|
|
51
|
+
}
|
|
52
|
+
cpSync(src, dest, { recursive: true });
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
// Copy all files and directories except node_modules, dist, and .git
|
|
57
|
+
const excludeDirs = ['node_modules', 'dist', '.git', 'docs', 'pnpm-lock.yaml'];
|
|
58
|
+
|
|
59
|
+
const items = readdirSync(currentDir);
|
|
60
|
+
for (const item of items) {
|
|
61
|
+
if (!excludeDirs.includes(item)) {
|
|
62
|
+
const srcPath = resolve(currentDir, item);
|
|
63
|
+
const destPath = resolve(docsDir, item);
|
|
64
|
+
copyFiles(srcPath, destPath);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
console.log('โ
All files gathered successfully!');
|
|
46
69
|
|
|
47
70
|
// Run the build command
|
|
48
|
-
console.log('โก
|
|
71
|
+
console.log('โก Magic is happening...');
|
|
49
72
|
try {
|
|
50
73
|
execSync('npm run build', { stdio: 'inherit', cwd: __dirname });
|
|
51
74
|
} catch (error) {
|
|
@@ -56,19 +79,23 @@ const commands = {
|
|
|
56
79
|
// Check if dist folder was created
|
|
57
80
|
const distDir = resolve(__dirname, '..', 'dist');
|
|
58
81
|
if (existsSync(distDir)) {
|
|
59
|
-
console.log('
|
|
60
|
-
console.log(
|
|
61
|
-
console.log('๐ Moving build output to current directory...');
|
|
82
|
+
console.log('๐ Build completed successfully!');
|
|
83
|
+
console.log('๐ฆ Moving your docs to the right place...');
|
|
62
84
|
cpSync(distDir, resolve(currentDir, 'dist'), { recursive: true });
|
|
63
|
-
console.log(
|
|
85
|
+
console.log('โจ Your docs are ready in the dist folder!');
|
|
64
86
|
} else {
|
|
65
|
-
console.log('โ ๏ธ Build completed but no
|
|
87
|
+
console.log('โ ๏ธ Build completed but no output found');
|
|
66
88
|
}
|
|
67
89
|
rmSync(distDir, { recursive: true, force: true });
|
|
90
|
+
|
|
91
|
+
// Revert docs folder back to original state
|
|
92
|
+
console.log('๐งน Cleaning up...');
|
|
93
|
+
rmSync(docsDir, { recursive: true, force: true });
|
|
94
|
+
console.log('โ
All done!');
|
|
68
95
|
},
|
|
69
96
|
|
|
70
97
|
preview: () => {
|
|
71
|
-
console.log('๐ Starting
|
|
98
|
+
console.log('๐ Starting your docs preview...');
|
|
72
99
|
const currentDir = process.cwd();
|
|
73
100
|
const distDir = resolve(currentDir, 'dist');
|
|
74
101
|
const port = process.env.PORT || 3000;
|
|
@@ -86,33 +113,31 @@ const commands = {
|
|
|
86
113
|
});
|
|
87
114
|
|
|
88
115
|
server.listen(port, () => {
|
|
89
|
-
console.log(`๐
|
|
116
|
+
console.log(`๐ Your docs are live at http://localhost:${port}`);
|
|
90
117
|
});
|
|
91
118
|
},
|
|
92
119
|
|
|
93
120
|
help: () => {
|
|
94
121
|
console.log(`
|
|
95
|
-
๐ Dory CLI - Documentation
|
|
122
|
+
๐ Dory CLI - Your Friendly Documentation Builder
|
|
96
123
|
|
|
97
124
|
Usage:
|
|
98
125
|
dory <command>
|
|
99
126
|
|
|
100
127
|
Commands:
|
|
101
|
-
build Build
|
|
102
|
-
-
|
|
103
|
-
-
|
|
104
|
-
- Runs build command
|
|
105
|
-
- Creates dist folder with build output
|
|
128
|
+
build Build your documentation site
|
|
129
|
+
- Needs dory.json in your project
|
|
130
|
+
- Creates a beautiful dist folder
|
|
106
131
|
|
|
107
|
-
preview Preview
|
|
108
|
-
-
|
|
109
|
-
-
|
|
132
|
+
preview Preview your built documentation
|
|
133
|
+
- Shows your docs in the browser
|
|
134
|
+
- Run build first!
|
|
110
135
|
|
|
111
136
|
help Show this help message
|
|
112
137
|
|
|
113
138
|
Examples:
|
|
114
|
-
dory build # Build
|
|
115
|
-
dory preview # Preview
|
|
139
|
+
dory build # Build your docs
|
|
140
|
+
dory preview # Preview your docs
|
|
116
141
|
`);
|
|
117
142
|
}
|
|
118
143
|
};
|