@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.
Files changed (2) hide show
  1. package/bin/dory.js +57 -32
  2. 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('๐Ÿ—๏ธ Starting Dory build...');
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 not found in current directory');
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(`๐Ÿ“‹ Using config: ${config.name || 'Unnamed project'}`);
36
+ console.log(`๐Ÿ“‹ Building: ${config.name || 'Your awesome project'}`);
30
37
  } catch (error) {
31
- console.error('โŒ Invalid dory.json file:', error.message);
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
- // Copy dory.json to docs folder
44
+ console.log('๐Ÿ“ Gathering your project files...');
44
45
  cpSync(doryConfigPath, resolve(docsDir, 'dory.json'));
45
- console.log('๐Ÿ“„ Copied dory.json to docs folder');
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('โšก Running build command...');
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('โœ… Build completed successfully!');
60
- console.log(`๐Ÿ“ฆ Build output available in: ${distDir}`);
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(`๐Ÿ“ฆ Build output moved to: ${resolve(currentDir, 'dist')}`);
85
+ console.log('โœจ Your docs are ready in the dist folder!');
64
86
  } else {
65
- console.log('โš ๏ธ Build completed but no dist folder found');
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 Dory preview...');
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(`๐Ÿš€ Serving Dory at http://localhost:${port}`);
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 Build Tool
122
+ ๐ŸŸ Dory CLI - Your Friendly Documentation Builder
96
123
 
97
124
  Usage:
98
125
  dory <command>
99
126
 
100
127
  Commands:
101
- build Build the documentation site
102
- - Requires dory.json in current directory
103
- - Clears and copies to docs folder
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 the built documentation site
108
- - Requires dist folder (run build first)
109
- - Starts preview server
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 the documentation
115
- dory preview # Preview the built site
139
+ dory build # Build your docs
140
+ dory preview # Preview your docs
116
141
  `);
117
142
  }
118
143
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@clidey/dory",
3
3
  "private": false,
4
- "version": "0.3.0",
4
+ "version": "0.4.0",
5
5
  "type": "module",
6
6
  "description": "A CLI tool for building and previewing documentation sites",
7
7
  "keywords": [