-
-
Notifications
You must be signed in to change notification settings - Fork 262
Expand file tree
/
Copy pathcopy-php.js
More file actions
68 lines (63 loc) · 2.22 KB
/
Copy pathcopy-php.js
File metadata and controls
68 lines (63 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
const esbuild = require('esbuild');
const fs = require('fs');
const os = require('os');
const path = require('path');
const root = path.resolve(__dirname, '..');
const outDir = path.resolve(root, 'build');
const phpDir = path.resolve(root, 'server/php');
const sandboxSrcDir = path.resolve(root, 'src/livecodes/html/sandbox');
/**
* Extracts a name → title map of starter templates as JSON,
* using the same technique as `functionsBuild` in scripts/build.js.
*/
const generateStarterTemplates = async () => {
const tmpFile = path.join(os.tmpdir(), `livecodes-starter-templates-${Date.now()}.cjs`);
await esbuild.build({
bundle: true,
minify: true,
format: 'cjs',
target: 'es2020',
logLevel: 'error',
loader: { '.html': 'text', '.ttf': 'file' },
entryPoints: [path.resolve(root, 'src/livecodes/templates/starter/index.ts')],
outfile: tmpFile,
define: {
'window.deps.translateString': 'getTemplateName',
},
});
fs.writeFileSync(
tmpFile,
`var getTemplateName = (_, templateName) => templateName;\n${fs.readFileSync(tmpFile, 'utf8')}`,
'utf8',
);
const { starterTemplates } = require(tmpFile);
fs.unlinkSync(tmpFile);
const map = {};
for (const template of starterTemplates) {
if (template && template.name) {
map[template.name] = template.title || '';
}
}
fs.writeFileSync(path.resolve(outDir, 'inc/starter-templates.json'), JSON.stringify(map), 'utf8');
};
const main = async () => {
if (!fs.existsSync(outDir)) {
throw new Error('build/ directory not found. Run `npm run build:app` first.');
}
// PHP server files (index.php, oembed.php, .htaccess, api/, broadcast/, sandbox/index.php, inc/, vendor/)
// README.md is repo documentation and is not deployed
fs.cpSync(phpDir, outDir, {
recursive: true,
filter: (src) => !src.endsWith('README.md'),
});
// sandbox static content (version directories), like the Dockerfile does
fs.cpSync(sandboxSrcDir, path.resolve(outDir, 'sandbox'), { recursive: true });
await generateStarterTemplates();
// eslint-disable-next-line no-console
console.log('PHP server files copied to build/');
};
main().catch((err) => {
// eslint-disable-next-line no-console
console.error(err);
process.exit(1);
});