mirror of https://github.com/sveltejs/svelte
parent
490ef83adc
commit
a894dd939c
@ -1,16 +1,16 @@
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { get_examples_data } from '../src/lib/server/examples/index.js';
|
||||
import fs from 'node:fs';
|
||||
import { mkdir, writeFile } from 'node:fs/promises';
|
||||
|
||||
const examples_data = await get_examples_data(
|
||||
fileURLToPath(new URL('../../../documentation/examples', import.meta.url))
|
||||
);
|
||||
|
||||
try {
|
||||
fs.mkdirSync(new URL('../src/lib/generated/', import.meta.url), { recursive: true });
|
||||
await mkdir(new URL('../src/lib/generated/', import.meta.url), { recursive: true });
|
||||
} catch {}
|
||||
|
||||
fs.writeFileSync(
|
||||
writeFile(
|
||||
new URL('../src/lib/generated/examples-data.js', import.meta.url),
|
||||
`export default ${JSON.stringify(examples_data)}`
|
||||
);
|
||||
|
||||
@ -1,36 +1,45 @@
|
||||
// @ts-check
|
||||
import { lstat, readFile, stat, writeFile } from 'node:fs/promises';
|
||||
import path, { dirname } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import sh from 'shelljs';
|
||||
import fs from 'fs';
|
||||
import path, { dirname } from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
|
||||
const force = process.env.FORCE_UPDATE === 'true';
|
||||
try {
|
||||
const force = process.env.FORCE_UPDATE === 'true';
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
sh.cd(path.join(__dirname, '..'));
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
sh.cd(path.join(__dirname, '..'));
|
||||
|
||||
const outputFile = 'static/svelte-app.json';
|
||||
if (!force && fs.existsSync(outputFile)) {
|
||||
console.info(`[update/template] ${outputFile} exists. Skipping`);
|
||||
process.exit(0);
|
||||
}
|
||||
const outputFile = 'static/svelte-app.json';
|
||||
if (!force && (await stat(outputFile))) {
|
||||
console.info(`[update/template] ${outputFile} exists. Skipping`);
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
// fetch svelte app
|
||||
sh.rm('-rf', 'scripts/svelte-app');
|
||||
sh.exec('npx degit sveltejs/template scripts/svelte-app');
|
||||
// fetch svelte app
|
||||
sh.rm('-rf', 'scripts/svelte-app');
|
||||
sh.exec('npx degit sveltejs/template scripts/svelte-app');
|
||||
|
||||
// remove src (will be recreated client-side) and node_modules
|
||||
sh.rm('-rf', 'scripts/svelte-app/src');
|
||||
sh.rm('-rf', 'scripts/svelte-app/node_modules');
|
||||
// remove src (will be recreated client-side) and node_modules
|
||||
sh.rm('-rf', 'scripts/svelte-app/src');
|
||||
sh.rm('-rf', 'scripts/svelte-app/node_modules');
|
||||
|
||||
// build svelte-app.json
|
||||
const appPath = 'scripts/svelte-app';
|
||||
const files = [];
|
||||
// build svelte-app.json
|
||||
const appPath = 'scripts/svelte-app';
|
||||
const files = [];
|
||||
|
||||
for (const path of sh.find(appPath).filter((p) => fs.lstatSync(p).isFile())) {
|
||||
const bytes = fs.readFileSync(path);
|
||||
const string = bytes.toString();
|
||||
const data = bytes.compare(Buffer.from(string)) === 0 ? string : [...bytes];
|
||||
files.push({ path: path.slice(appPath.length + 1), data });
|
||||
}
|
||||
for (const path of sh.find(appPath)) {
|
||||
// Skip directories
|
||||
if (!(await lstat(path)).isFile()) continue;
|
||||
|
||||
fs.writeFileSync(outputFile, JSON.stringify(files));
|
||||
const bytes = await readFile(path);
|
||||
const string = bytes.toString();
|
||||
const data = bytes.compare(Buffer.from(string)) === 0 ? string : [...bytes];
|
||||
files.push({ path: path.slice(appPath.length + 1), data });
|
||||
}
|
||||
|
||||
writeFile(outputFile, JSON.stringify(files));
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
Loading…
Reference in new issue