@litodocs/cli 0.5.0 ā 0.5.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/README.md +60 -63
- package/package.json +1 -1
- package/src/cli.js +10 -1
- package/src/core/update-check.js +138 -0
package/README.md
CHANGED
|
@@ -2,15 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
Beautiful documentation sites from Markdown. Fast, simple, and open-source.
|
|
4
4
|
|
|
5
|
+
> **Note:** This package was previously published as `@devrohit06/superdocs`. It has been renamed to `@litodocs/cli`.
|
|
6
|
+
|
|
5
7
|
## Features
|
|
6
8
|
|
|
7
|
-
⨠**Simple Setup** - Point to your docs folder and go
|
|
8
|
-
š **Astro-Powered** - Leverages Astro's speed and SEO optimization
|
|
9
|
-
š **Markdown & MDX** - Full support for both formats with frontmatter
|
|
10
|
-
šØ **Customizable Templates** - Use GitHub-hosted or local templates
|
|
11
|
-
š„ **Hot Reload** - Dev server with live file watching
|
|
12
|
-
ā” **Fast Builds** - Static site generation for optimal performance
|
|
13
|
-
šÆ **SEO Optimized** - Meta tags, semantic HTML, and proper structure
|
|
9
|
+
- ⨠**Simple Setup** - Point to your docs folder and go
|
|
10
|
+
- š **Astro-Powered** - Leverages Astro's speed and SEO optimization
|
|
11
|
+
- š **Markdown & MDX** - Full support for both formats with frontmatter
|
|
12
|
+
- šØ **Customizable Templates** - Use GitHub-hosted or local templates
|
|
13
|
+
- š„ **Hot Reload** - Dev server with live file watching
|
|
14
|
+
- ā” **Fast Builds** - Static site generation for optimal performance
|
|
15
|
+
- šÆ **SEO Optimized** - Meta tags, semantic HTML, and proper structure
|
|
16
|
+
- š **i18n Support** - Built-in internationalization with 40+ languages
|
|
17
|
+
- š **Versioning** - Documentation versioning with version switcher
|
|
18
|
+
- šØ **Dynamic Theming** - OKLCH color palette generation from primary color
|
|
14
19
|
|
|
15
20
|
## Installation
|
|
16
21
|
|
|
@@ -20,14 +25,36 @@ Beautiful documentation sites from Markdown. Fast, simple, and open-source.
|
|
|
20
25
|
npm install -g @litodocs/cli
|
|
21
26
|
# or
|
|
22
27
|
pnpm add -g @litodocs/cli
|
|
28
|
+
# or
|
|
29
|
+
yarn global add @litodocs/cli
|
|
23
30
|
```
|
|
24
31
|
|
|
25
32
|
### Local Development
|
|
26
33
|
|
|
34
|
+
Clone the repository and link it locally:
|
|
35
|
+
|
|
27
36
|
```bash
|
|
28
|
-
|
|
37
|
+
git clone https://github.com/Lito-docs/cli.git
|
|
38
|
+
cd cli
|
|
29
39
|
pnpm install
|
|
30
40
|
chmod +x bin/cli.js
|
|
41
|
+
npm link
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Now you can use `lito` command globally from your terminal.
|
|
45
|
+
|
|
46
|
+
## Quick Start
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
# Create a docs folder with markdown files
|
|
50
|
+
mkdir my-docs
|
|
51
|
+
echo "# Hello World" > my-docs/index.md
|
|
52
|
+
|
|
53
|
+
# Start dev server
|
|
54
|
+
lito dev -i ./my-docs
|
|
55
|
+
|
|
56
|
+
# Build for production
|
|
57
|
+
lito build -i ./my-docs -o ./dist
|
|
31
58
|
```
|
|
32
59
|
|
|
33
60
|
## Usage
|
|
@@ -42,14 +69,16 @@ lito build --input ./my-docs --output ./dist
|
|
|
42
69
|
|
|
43
70
|
**Options:**
|
|
44
71
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
-
|
|
51
|
-
|
|
52
|
-
|
|
72
|
+
| Option | Description | Default |
|
|
73
|
+
|--------|-------------|---------|
|
|
74
|
+
| `-i, --input <path>` | Path to your docs folder (required) | - |
|
|
75
|
+
| `-o, --output <path>` | Output directory | `./dist` |
|
|
76
|
+
| `-t, --template <name>` | Template to use | `default` |
|
|
77
|
+
| `-b, --base-url <url>` | Base URL for the site | `/` |
|
|
78
|
+
| `--provider <name>` | Hosting provider (vercel, netlify, cloudflare, static) | `static` |
|
|
79
|
+
| `--rendering <mode>` | Rendering mode (static, server, hybrid) | `static` |
|
|
80
|
+
| `--search` | Enable search functionality | `false` |
|
|
81
|
+
| `--refresh` | Force re-download template | `false` |
|
|
53
82
|
|
|
54
83
|
### Dev Command
|
|
55
84
|
|
|
@@ -61,12 +90,14 @@ lito dev --input ./my-docs
|
|
|
61
90
|
|
|
62
91
|
**Options:**
|
|
63
92
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
93
|
+
| Option | Description | Default |
|
|
94
|
+
|--------|-------------|---------|
|
|
95
|
+
| `-i, --input <path>` | Path to your docs folder (required) | - |
|
|
96
|
+
| `-t, --template <name>` | Template to use | `default` |
|
|
97
|
+
| `-b, --base-url <url>` | Base URL for the site | `/` |
|
|
98
|
+
| `-p, --port <number>` | Port for dev server | `4321` |
|
|
99
|
+
| `--search` | Enable search functionality | `false` |
|
|
100
|
+
| `--refresh` | Force re-download template | `false` |
|
|
70
101
|
|
|
71
102
|
### Eject Command
|
|
72
103
|
|
|
@@ -81,21 +112,27 @@ lito eject --input ./my-docs --output ./my-project
|
|
|
81
112
|
Lito includes built-in optimizations for major hosting providers. Use the `--provider` flag during build:
|
|
82
113
|
|
|
83
114
|
### Vercel
|
|
115
|
+
|
|
84
116
|
```bash
|
|
85
117
|
lito build -i ./docs --provider vercel
|
|
86
118
|
```
|
|
119
|
+
|
|
87
120
|
Generates `vercel.json` and optimizes for Vercel's edge network.
|
|
88
121
|
|
|
89
122
|
### Netlify
|
|
123
|
+
|
|
90
124
|
```bash
|
|
91
125
|
lito build -i ./docs --provider netlify
|
|
92
126
|
```
|
|
127
|
+
|
|
93
128
|
Generates `netlify.toml` with security headers.
|
|
94
129
|
|
|
95
130
|
### Cloudflare Pages
|
|
131
|
+
|
|
96
132
|
```bash
|
|
97
133
|
lito build -i ./docs --provider cloudflare --rendering server
|
|
98
134
|
```
|
|
135
|
+
|
|
99
136
|
Configures the project for Cloudflare's edge runtime with SSR support.
|
|
100
137
|
|
|
101
138
|
## Analytics
|
|
@@ -198,7 +235,7 @@ Your content here...
|
|
|
198
235
|
|
|
199
236
|
## Architecture
|
|
200
237
|
|
|
201
|
-
The CLI tool:
|
|
238
|
+
The CLI tool follows this pipeline:
|
|
202
239
|
|
|
203
240
|
1. **Resolves Template** - Fetches from GitHub or uses local template
|
|
204
241
|
2. **Scaffolds** - Creates a temporary Astro project from the template
|
|
@@ -207,46 +244,6 @@ The CLI tool:
|
|
|
207
244
|
5. **Builds/Serves** - Spawns native Astro CLI commands
|
|
208
245
|
6. **Watches** (dev mode) - Uses `chokidar` to monitor file changes
|
|
209
246
|
|
|
210
|
-
## Development
|
|
211
|
-
|
|
212
|
-
### Project Structure
|
|
213
|
-
|
|
214
|
-
```
|
|
215
|
-
lito/
|
|
216
|
-
āāā bin/
|
|
217
|
-
ā āāā cli.js # CLI entry point
|
|
218
|
-
āāā src/
|
|
219
|
-
ā āāā cli.js # Commander setup
|
|
220
|
-
ā āāā commands/
|
|
221
|
-
ā ā āāā build.js # Build command
|
|
222
|
-
ā ā āāā dev.js # Dev command with watcher
|
|
223
|
-
ā ā āāā eject.js # Eject command
|
|
224
|
-
ā ā āāā template.js # Template management
|
|
225
|
-
ā āāā core/
|
|
226
|
-
ā ā āāā scaffold.js # Project scaffolding
|
|
227
|
-
ā ā āāā sync.js # File syncing
|
|
228
|
-
ā ā āāā config.js # Config generation
|
|
229
|
-
ā ā āāā astro.js # Astro CLI spawning
|
|
230
|
-
ā ā āāā template-fetcher.js # GitHub template fetching
|
|
231
|
-
ā ā āāā template-registry.js # Template name registry
|
|
232
|
-
ā āāā template/ # Bundled fallback template
|
|
233
|
-
āāā package.json
|
|
234
|
-
```
|
|
235
|
-
|
|
236
|
-
### Running Tests
|
|
237
|
-
|
|
238
|
-
```bash
|
|
239
|
-
# Create sample docs
|
|
240
|
-
mkdir sample-docs
|
|
241
|
-
echo "# Hello\n\nWelcome!" > sample-docs/index.md
|
|
242
|
-
|
|
243
|
-
# Test build
|
|
244
|
-
node bin/cli.js build -i sample-docs -o test-output
|
|
245
|
-
|
|
246
|
-
# Test dev server
|
|
247
|
-
node bin/cli.js dev -i sample-docs
|
|
248
|
-
```
|
|
249
|
-
|
|
250
247
|
## Contributing
|
|
251
248
|
|
|
252
249
|
Contributions are welcome! Please feel free to submit a Pull Request.
|
package/package.json
CHANGED
package/src/cli.js
CHANGED
|
@@ -7,16 +7,20 @@ import {
|
|
|
7
7
|
templateListCommand,
|
|
8
8
|
templateCacheCommand,
|
|
9
9
|
} from "./commands/template.js";
|
|
10
|
+
import { checkForUpdates, upgradeCommand } from "./core/update-check.js";
|
|
10
11
|
|
|
11
12
|
export async function cli() {
|
|
12
13
|
const program = new Command();
|
|
13
14
|
|
|
15
|
+
// Check for updates in the background (non-blocking)
|
|
16
|
+
checkForUpdates();
|
|
17
|
+
|
|
14
18
|
program
|
|
15
19
|
.name("lito")
|
|
16
20
|
.description(
|
|
17
21
|
"Beautiful documentation sites from Markdown. Fast, simple, and open-source."
|
|
18
22
|
)
|
|
19
|
-
.version("0.5.
|
|
23
|
+
.version("0.5.2");
|
|
20
24
|
|
|
21
25
|
program
|
|
22
26
|
.command("build")
|
|
@@ -107,6 +111,11 @@ export async function cli() {
|
|
|
107
111
|
.option("--clear", "Clear all cached templates")
|
|
108
112
|
.action(templateCacheCommand);
|
|
109
113
|
|
|
114
|
+
program
|
|
115
|
+
.command("upgrade")
|
|
116
|
+
.description("Check for updates and upgrade to the latest version")
|
|
117
|
+
.action(upgradeCommand);
|
|
118
|
+
|
|
110
119
|
try {
|
|
111
120
|
await program.parseAsync(process.argv);
|
|
112
121
|
} catch (error) {
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { exec } from 'child_process';
|
|
2
|
+
import { promisify } from 'util';
|
|
3
|
+
import pc from 'picocolors';
|
|
4
|
+
import { confirm } from '@clack/prompts';
|
|
5
|
+
|
|
6
|
+
const execAsync = promisify(exec);
|
|
7
|
+
|
|
8
|
+
const PACKAGE_NAME = '@litodocs/cli';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Get the current installed version from package.json
|
|
12
|
+
*/
|
|
13
|
+
export function getCurrentVersion() {
|
|
14
|
+
return '0.5.2';
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Fetch the latest version from npm registry
|
|
19
|
+
*/
|
|
20
|
+
async function getLatestVersion() {
|
|
21
|
+
try {
|
|
22
|
+
const { stdout } = await execAsync(`npm view ${PACKAGE_NAME} version`, {
|
|
23
|
+
timeout: 5000,
|
|
24
|
+
});
|
|
25
|
+
return stdout.trim();
|
|
26
|
+
} catch {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Compare two semver versions
|
|
33
|
+
* Returns: 1 if v1 > v2, -1 if v1 < v2, 0 if equal
|
|
34
|
+
*/
|
|
35
|
+
function compareVersions(v1, v2) {
|
|
36
|
+
const parts1 = v1.split('.').map(Number);
|
|
37
|
+
const parts2 = v2.split('.').map(Number);
|
|
38
|
+
|
|
39
|
+
for (let i = 0; i < 3; i++) {
|
|
40
|
+
const p1 = parts1[i] || 0;
|
|
41
|
+
const p2 = parts2[i] || 0;
|
|
42
|
+
if (p1 > p2) return 1;
|
|
43
|
+
if (p1 < p2) return -1;
|
|
44
|
+
}
|
|
45
|
+
return 0;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Upgrade the package using the detected package manager
|
|
50
|
+
*/
|
|
51
|
+
async function upgradePackage() {
|
|
52
|
+
const packageManagers = ['pnpm', 'yarn', 'npm'];
|
|
53
|
+
|
|
54
|
+
for (const pm of packageManagers) {
|
|
55
|
+
try {
|
|
56
|
+
await execAsync(`${pm} --version`, { timeout: 2000 });
|
|
57
|
+
|
|
58
|
+
console.log(pc.cyan(`\nUpgrading using ${pm}...`));
|
|
59
|
+
|
|
60
|
+
const command = pm === 'yarn'
|
|
61
|
+
? `yarn global add ${PACKAGE_NAME}@latest`
|
|
62
|
+
: `${pm} install -g ${PACKAGE_NAME}@latest`;
|
|
63
|
+
|
|
64
|
+
const { stdout, stderr } = await execAsync(command, { timeout: 60000 });
|
|
65
|
+
|
|
66
|
+
if (stdout) console.log(stdout);
|
|
67
|
+
|
|
68
|
+
console.log(pc.green(`\nā Successfully upgraded ${PACKAGE_NAME}!`));
|
|
69
|
+
console.log(pc.dim('Please restart your terminal or run the command again.\n'));
|
|
70
|
+
return true;
|
|
71
|
+
} catch {
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
console.log(pc.yellow('\nCould not auto-upgrade. Please run manually:'));
|
|
77
|
+
console.log(pc.cyan(` npm install -g ${PACKAGE_NAME}@latest\n`));
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Check for updates and prompt user to upgrade
|
|
83
|
+
*/
|
|
84
|
+
export async function checkForUpdates() {
|
|
85
|
+
try {
|
|
86
|
+
const currentVersion = getCurrentVersion();
|
|
87
|
+
const latestVersion = await getLatestVersion();
|
|
88
|
+
|
|
89
|
+
if (!latestVersion) {
|
|
90
|
+
return; // Silently fail if we can't check
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (compareVersions(latestVersion, currentVersion) > 0) {
|
|
94
|
+
console.log('');
|
|
95
|
+
console.log(pc.yellow('āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā®'));
|
|
96
|
+
console.log(pc.yellow('ā') + ' Update available! ' + pc.dim(`${currentVersion}`) + ' ā ' + pc.green(`${latestVersion}`) + pc.yellow(' ā'));
|
|
97
|
+
console.log(pc.yellow('ā') + pc.dim(` Run: lito upgrade`) + pc.yellow(' ā'));
|
|
98
|
+
console.log(pc.yellow('ā°āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāÆ'));
|
|
99
|
+
console.log('');
|
|
100
|
+
}
|
|
101
|
+
} catch {
|
|
102
|
+
// Silently fail - don't interrupt the user's workflow
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Upgrade command handler
|
|
108
|
+
*/
|
|
109
|
+
export async function upgradeCommand() {
|
|
110
|
+
console.log(pc.cyan('\nš Checking for updates...\n'));
|
|
111
|
+
|
|
112
|
+
const currentVersion = getCurrentVersion();
|
|
113
|
+
const latestVersion = await getLatestVersion();
|
|
114
|
+
|
|
115
|
+
if (!latestVersion) {
|
|
116
|
+
console.log(pc.yellow('Could not check for updates. Please check your internet connection.\n'));
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
console.log(` Current version: ${pc.dim(currentVersion)}`);
|
|
121
|
+
console.log(` Latest version: ${pc.green(latestVersion)}\n`);
|
|
122
|
+
|
|
123
|
+
if (compareVersions(latestVersion, currentVersion) <= 0) {
|
|
124
|
+
console.log(pc.green('ā You are already on the latest version!\n'));
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const shouldUpgrade = await confirm({
|
|
129
|
+
message: `Upgrade from ${currentVersion} to ${latestVersion}?`,
|
|
130
|
+
initialValue: true,
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
if (shouldUpgrade) {
|
|
134
|
+
await upgradePackage();
|
|
135
|
+
} else {
|
|
136
|
+
console.log(pc.dim('\nUpgrade cancelled.\n'));
|
|
137
|
+
}
|
|
138
|
+
}
|