freertc 0.1.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 +246 -0
- package/bin/freertc.mjs +106 -0
- package/package.json +68 -0
- package/public/app.js +2851 -0
- package/public/index.html +821 -0
- package/scripts/d1-schema.sql +44 -0
- package/scripts/dev-server.mjs +129 -0
- package/scripts/non-cloudflare-server.mjs +427 -0
- package/scripts/postinstall-message.mjs +19 -0
- package/scripts/project-bootstrap.mjs +113 -0
- package/scripts/wrangler-install-wizard.mjs +697 -0
- package/src/index.js +690 -0
- package/wrangler.template.jsonc +71 -0
- package/wrangler.workers-dev.jsonc +19 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { spawnSync } from 'node:child_process';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
|
|
6
|
+
const SCRIPT_DIR = path.dirname(fileURLToPath(import.meta.url));
|
|
7
|
+
|
|
8
|
+
export const PACKAGE_ROOT = path.resolve(SCRIPT_DIR, '..');
|
|
9
|
+
|
|
10
|
+
const PROJECT_FILE_MAPPINGS = [
|
|
11
|
+
['src/index.js', 'src/index.js'],
|
|
12
|
+
['public/index.html', 'public/index.html'],
|
|
13
|
+
['public/app.js', 'public/app.js'],
|
|
14
|
+
['scripts/d1-schema.sql', 'scripts/d1-schema.sql'],
|
|
15
|
+
['wrangler.template.jsonc', 'wrangler.template.jsonc'],
|
|
16
|
+
['wrangler.workers-dev.jsonc', 'wrangler.workers-dev.jsonc']
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
function looksLikeProjectRoot(dir) {
|
|
20
|
+
const hasPackage = fs.existsSync(path.join(dir, 'package.json'));
|
|
21
|
+
const hasWranglerConfig = fs.existsSync(path.join(dir, 'wrangler.jsonc'));
|
|
22
|
+
const hasWranglerTemplate = fs.existsSync(path.join(dir, 'wrangler.template.jsonc'));
|
|
23
|
+
return hasPackage && (hasWranglerConfig || hasWranglerTemplate);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function findProjectRoot(startDir) {
|
|
27
|
+
let dir = path.resolve(startDir);
|
|
28
|
+
while (true) {
|
|
29
|
+
if (looksLikeProjectRoot(dir)) {
|
|
30
|
+
return dir;
|
|
31
|
+
}
|
|
32
|
+
const parent = path.dirname(dir);
|
|
33
|
+
if (parent === dir) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
dir = parent;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function findNearestPackageRoot(startDir) {
|
|
41
|
+
let dir = path.resolve(startDir);
|
|
42
|
+
while (true) {
|
|
43
|
+
if (fs.existsSync(path.join(dir, 'package.json'))) {
|
|
44
|
+
return dir;
|
|
45
|
+
}
|
|
46
|
+
const parent = path.dirname(dir);
|
|
47
|
+
if (parent === dir) {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
dir = parent;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function resolveProjectRoot(startDir = process.cwd()) {
|
|
55
|
+
return (
|
|
56
|
+
findProjectRoot(startDir) ||
|
|
57
|
+
findNearestPackageRoot(startDir) ||
|
|
58
|
+
path.resolve(startDir)
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function ensureProjectFiles(projectRoot) {
|
|
63
|
+
const targetRoot = path.resolve(projectRoot);
|
|
64
|
+
if (targetRoot === PACKAGE_ROOT) {
|
|
65
|
+
return [];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const copied = [];
|
|
69
|
+
|
|
70
|
+
for (const [sourceRelativePath, targetRelativePath] of PROJECT_FILE_MAPPINGS) {
|
|
71
|
+
const sourcePath = path.join(PACKAGE_ROOT, sourceRelativePath);
|
|
72
|
+
const targetPath = path.join(targetRoot, targetRelativePath);
|
|
73
|
+
|
|
74
|
+
if (fs.existsSync(targetPath) || !fs.existsSync(sourcePath)) {
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
fs.mkdirSync(path.dirname(targetPath), { recursive: true });
|
|
79
|
+
fs.copyFileSync(sourcePath, targetPath);
|
|
80
|
+
copied.push(targetRelativePath);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return copied;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function resolveWranglerCommand(cwd = process.cwd()) {
|
|
87
|
+
const packageBinary = path.join(
|
|
88
|
+
PACKAGE_ROOT,
|
|
89
|
+
'node_modules',
|
|
90
|
+
'.bin',
|
|
91
|
+
process.platform === 'win32' ? 'wrangler.cmd' : 'wrangler'
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
if (fs.existsSync(packageBinary)) {
|
|
95
|
+
const packageCheck = spawnSync(packageBinary, ['--version'], {
|
|
96
|
+
cwd,
|
|
97
|
+
stdio: 'ignore'
|
|
98
|
+
});
|
|
99
|
+
if (packageCheck.status === 0) {
|
|
100
|
+
return { command: packageBinary, baseArgs: [], source: 'package' };
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const globalCheck = spawnSync('wrangler', ['--version'], {
|
|
105
|
+
cwd,
|
|
106
|
+
stdio: 'ignore'
|
|
107
|
+
});
|
|
108
|
+
if (globalCheck.status === 0) {
|
|
109
|
+
return { command: 'wrangler', baseArgs: [], source: 'global' };
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return { command: 'npx', baseArgs: ['wrangler'], source: 'npx' };
|
|
113
|
+
}
|