@discoverworthy/deploy 1.0.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/README.md +62 -0
- package/index.js +109 -0
- package/package.json +32 -0
package/README.md
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# @discoverworthy/deploy
|
|
2
|
+
|
|
3
|
+
Deploy static sites to [DiscoverWorthy](https://discoverworthy.com) hosting.
|
|
4
|
+
|
|
5
|
+
Works with any framework that outputs static files — React, Next.js, Vue, Angular, Blazor WASM, Hugo, Jekyll, plain HTML, and more.
|
|
6
|
+
|
|
7
|
+
## Quick Start
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
DISCOVERWORTHY_DEPLOY_TOKEN=your-token npx @discoverworthy/deploy --dir=out
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
### Environment Variable (recommended)
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
export DISCOVERWORTHY_DEPLOY_TOKEN=your-token
|
|
19
|
+
npx @discoverworthy/deploy --dir=dist
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### CLI Flag
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
npx @discoverworthy/deploy --dir=out --token=your-token
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### CI/CD
|
|
29
|
+
|
|
30
|
+
**GitHub Actions**
|
|
31
|
+
|
|
32
|
+
```yaml
|
|
33
|
+
- name: Deploy to DiscoverWorthy
|
|
34
|
+
run: npx @discoverworthy/deploy --dir=out
|
|
35
|
+
env:
|
|
36
|
+
DISCOVERWORTHY_DEPLOY_TOKEN: ${{ secrets.DISCOVERWORTHY_DEPLOY_TOKEN }}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
**Azure DevOps Pipelines**
|
|
40
|
+
|
|
41
|
+
```yaml
|
|
42
|
+
- script: npx @discoverworthy/deploy --dir=out
|
|
43
|
+
displayName: 'Deploy to DiscoverWorthy'
|
|
44
|
+
env:
|
|
45
|
+
DISCOVERWORTHY_DEPLOY_TOKEN: $(DISCOVERWORTHY_DEPLOY_TOKEN)
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Options
|
|
49
|
+
|
|
50
|
+
| Flag | Default | Description |
|
|
51
|
+
|------|---------|-------------|
|
|
52
|
+
| `--dir` | `out` | Directory containing your built site |
|
|
53
|
+
| `--token` | — | Deploy token (or set `DISCOVERWORTHY_DEPLOY_TOKEN`) |
|
|
54
|
+
|
|
55
|
+
## Get Your Deploy Token
|
|
56
|
+
|
|
57
|
+
Your deploy token is available in the DiscoverWorthy dashboard under **Website Hosting → Connection Details**, or ask your client to send you the setup link.
|
|
58
|
+
|
|
59
|
+
## Limits
|
|
60
|
+
|
|
61
|
+
- Maximum upload size: 25 MB
|
|
62
|
+
- Supports any static files (HTML, CSS, JS, images, WASM, fonts, etc.)
|
package/index.js
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const { createReadStream } = require('fs');
|
|
6
|
+
|
|
7
|
+
const API_URL = process.env.DISCOVERWORTHY_API_URL || 'https://discoverworthy.com';
|
|
8
|
+
const DEPLOY_ENDPOINT = `${API_URL}/api/v1/hosting/deploy`;
|
|
9
|
+
|
|
10
|
+
function parseArgs(args) {
|
|
11
|
+
const parsed = { dir: 'out', token: null };
|
|
12
|
+
for (let i = 0; i < args.length; i++) {
|
|
13
|
+
if (args[i] === '--dir' && args[i + 1]) parsed.dir = args[++i];
|
|
14
|
+
else if (args[i].startsWith('--dir=')) parsed.dir = args[i].split('=')[1];
|
|
15
|
+
else if (args[i] === '--token' && args[i + 1]) parsed.token = args[++i];
|
|
16
|
+
else if (args[i].startsWith('--token=')) parsed.token = args[i].split('=')[1];
|
|
17
|
+
}
|
|
18
|
+
return parsed;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function collectFiles(dir, base) {
|
|
22
|
+
const entries = [];
|
|
23
|
+
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
24
|
+
const fullPath = path.join(dir, entry.name);
|
|
25
|
+
const relativePath = path.join(base, entry.name).replace(/\\/g, '/');
|
|
26
|
+
if (entry.isDirectory()) {
|
|
27
|
+
entries.push(...collectFiles(fullPath, relativePath));
|
|
28
|
+
} else {
|
|
29
|
+
entries.push({ path: relativePath, fullPath });
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return entries;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async function deploy() {
|
|
36
|
+
const { dir, token: argToken } = parseArgs(process.argv.slice(2));
|
|
37
|
+
const token = argToken || process.env.DISCOVERWORTHY_DEPLOY_TOKEN;
|
|
38
|
+
|
|
39
|
+
if (!token) {
|
|
40
|
+
console.error('Error: Deploy token required. Set DISCOVERWORTHY_DEPLOY_TOKEN or use --token');
|
|
41
|
+
process.exit(1);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const outputDir = path.resolve(dir);
|
|
45
|
+
if (!fs.existsSync(outputDir)) {
|
|
46
|
+
console.error(`Error: Directory "${dir}" not found`);
|
|
47
|
+
process.exit(1);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
console.log(`Collecting files from ${outputDir}...`);
|
|
51
|
+
const files = collectFiles(outputDir, '');
|
|
52
|
+
|
|
53
|
+
if (files.length === 0) {
|
|
54
|
+
console.error('Error: No files found in output directory');
|
|
55
|
+
process.exit(1);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const totalSize = files.reduce((sum, f) => sum + fs.statSync(f.fullPath).size, 0);
|
|
59
|
+
console.log(`Found ${files.length} files (${(totalSize / 1024 / 1024).toFixed(2)} MB)`);
|
|
60
|
+
|
|
61
|
+
// Build multipart form data
|
|
62
|
+
const boundary = '----DWDeploy' + Date.now();
|
|
63
|
+
const parts = [];
|
|
64
|
+
|
|
65
|
+
for (const file of files) {
|
|
66
|
+
const content = fs.readFileSync(file.fullPath);
|
|
67
|
+
parts.push(
|
|
68
|
+
`--${boundary}\r\n` +
|
|
69
|
+
`Content-Disposition: form-data; name="${file.path}"; filename="${file.path}"\r\n` +
|
|
70
|
+
`Content-Type: application/octet-stream\r\n\r\n`
|
|
71
|
+
);
|
|
72
|
+
parts.push(content);
|
|
73
|
+
parts.push('\r\n');
|
|
74
|
+
}
|
|
75
|
+
parts.push(`--${boundary}--\r\n`);
|
|
76
|
+
|
|
77
|
+
// Combine into a single buffer
|
|
78
|
+
const bodyParts = parts.map(p => typeof p === 'string' ? Buffer.from(p) : p);
|
|
79
|
+
const body = Buffer.concat(bodyParts);
|
|
80
|
+
|
|
81
|
+
console.log('Uploading to DiscoverWorthy...');
|
|
82
|
+
|
|
83
|
+
const res = await fetch(DEPLOY_ENDPOINT, {
|
|
84
|
+
method: 'POST',
|
|
85
|
+
headers: {
|
|
86
|
+
'Authorization': `Bearer ${token}`,
|
|
87
|
+
'Content-Type': `multipart/form-data; boundary=${boundary}`,
|
|
88
|
+
'x-deploy-source': 'cli',
|
|
89
|
+
},
|
|
90
|
+
body,
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
const data = await res.json();
|
|
94
|
+
|
|
95
|
+
if (!res.ok) {
|
|
96
|
+
console.error(`Deploy failed: ${data.error || res.statusText}`);
|
|
97
|
+
process.exit(1);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
console.log(`\nDeployed successfully!`);
|
|
101
|
+
console.log(`URL: ${data.url}`);
|
|
102
|
+
console.log(`Files: ${data.fileCount}`);
|
|
103
|
+
console.log(`Size: ${(data.totalSizeBytes / 1024 / 1024).toFixed(2)} MB`);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
deploy().catch((err) => {
|
|
107
|
+
console.error('Deploy failed:', err.message);
|
|
108
|
+
process.exit(1);
|
|
109
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@discoverworthy/deploy",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Deploy static sites to DiscoverWorthy hosting",
|
|
5
|
+
"bin": {
|
|
6
|
+
"dw-deploy": "./index.js"
|
|
7
|
+
},
|
|
8
|
+
"main": "index.js",
|
|
9
|
+
"files": [
|
|
10
|
+
"index.js",
|
|
11
|
+
"README.md"
|
|
12
|
+
],
|
|
13
|
+
"keywords": [
|
|
14
|
+
"discoverworthy",
|
|
15
|
+
"deploy",
|
|
16
|
+
"static-site",
|
|
17
|
+
"hosting",
|
|
18
|
+
"blazor",
|
|
19
|
+
"react",
|
|
20
|
+
"nextjs",
|
|
21
|
+
"vue",
|
|
22
|
+
"angular"
|
|
23
|
+
],
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "https://github.com/discoverworthy/deploy"
|
|
27
|
+
},
|
|
28
|
+
"license": "MIT",
|
|
29
|
+
"engines": {
|
|
30
|
+
"node": ">=18"
|
|
31
|
+
}
|
|
32
|
+
}
|