Initial commit of 001code-html Scratch frontend project.
Includes scratch-gui, scratch-vm, scratch-blocks, scratch-render, scratch-l10n, and deployment config. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
57
scratch-gui/scripts/patch-config.js
Normal file
57
scratch-gui/scripts/patch-config.js
Normal file
@@ -0,0 +1,57 @@
|
||||
// patch-config.js: replace DataServerBaseUrl and disabledev before dev server or build
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const targetFile = path.join(__dirname, '..', 'src', 'playground', 'config.js');
|
||||
|
||||
function decideEnv() {
|
||||
const ev = (process.env.npm_lifecycle_event || '').toLowerCase();
|
||||
if (ev.includes('build:prod')) return 'prod';
|
||||
if (ev.includes('build:test')) return 'test';
|
||||
if (ev.includes('start')) return 'start';
|
||||
if (ev.includes('dev')) return 'dev';
|
||||
// default
|
||||
return 'start';
|
||||
}
|
||||
|
||||
function getConfigForEnv(env) {
|
||||
switch (env) {
|
||||
case 'dev':
|
||||
case 'test':
|
||||
return { url: 'https://test.server.001code.com', disabledev: false };
|
||||
case 'prod':
|
||||
return { url: 'https://server.001code.com', disabledev: true };
|
||||
case 'start':
|
||||
default:
|
||||
return { url: 'http://127.0.0.1:8000', disabledev: false };
|
||||
}
|
||||
}
|
||||
|
||||
function replaceContent(src, url, disabledev) {
|
||||
let out = src;
|
||||
out = out.replace(/DataServerBaseUrl\s*:\s*[^,]+/g, `DataServerBaseUrl: "${url}"`);
|
||||
out = out.replace(/disabledev\s*:\s*[^,]+/g, `disabledev: ${disabledev}`);
|
||||
return out;
|
||||
}
|
||||
|
||||
(function run() {
|
||||
const env = decideEnv();
|
||||
const cfg = getConfigForEnv(env);
|
||||
console.log(`[patch-config] Env=${env} -> DataServerBaseUrl="${cfg.url}", disabledev=${cfg.disabledev}`);
|
||||
|
||||
try {
|
||||
const original = fs.readFileSync(targetFile, 'utf8');
|
||||
const patched = replaceContent(original, cfg.url, cfg.disabledev);
|
||||
|
||||
if (patched !== original) {
|
||||
fs.writeFileSync(targetFile, patched, 'utf8');
|
||||
console.log('[patch-config] Applied replacements to', targetFile);
|
||||
} else {
|
||||
console.warn('[patch-config] No changes applied. Patterns not found or already set.');
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('[patch-config] Failed to patch', targetFile, err);
|
||||
process.exit(1);
|
||||
}
|
||||
})();
|
||||
Reference in New Issue
Block a user