Skip to content

Commit c4e7af1

Browse files
authored
delete old files when running sync-docs - closes #251 (#291)
1 parent 6159be9 commit c4e7af1

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

apps/svelte.dev/scripts/sync-docs/index.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { preprocess } from '@sveltejs/site-kit/markdown/preprocess';
22
import path from 'node:path';
3-
import { cpSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from 'node:fs';
3+
import fs from 'node:fs';
44
import ts from 'typescript';
55
import glob from 'tiny-glob/sync';
66
import { fileURLToPath } from 'node:url';
@@ -67,7 +67,7 @@ const packages: Package[] = [
6767
}
6868

6969
const dir = kit_base + 'src/types/synthetic';
70-
for (const file of readdirSync(dir)) {
70+
for (const file of fs.readdirSync(dir)) {
7171
if (!file.endsWith('.md')) continue;
7272

7373
const comment = strip_origin(read_d_ts_file(`${dir}/${file}`));
@@ -133,7 +133,7 @@ const packages: Package[] = [
133133
*/
134134
if (process.env.USE_GIT === 'true') {
135135
try {
136-
mkdirSync(REPOS);
136+
fs.mkdirSync(REPOS);
137137
} catch {
138138
// ignore if it already exists
139139
}
@@ -142,16 +142,19 @@ if (process.env.USE_GIT === 'true') {
142142
}
143143

144144
for (const pkg of packages) {
145-
cpSync(`${pkg.local}/${pkg.docs}`, `${DOCS}/${pkg.name}`, { recursive: true });
146-
migrate_meta_json(`${DOCS}/${pkg.name}`);
145+
const dest = `${DOCS}/${pkg.name}`;
146+
147+
fs.rmSync(dest, { force: true, recursive: true });
148+
fs.cpSync(`${pkg.local}/${pkg.docs}`, dest, { recursive: true });
149+
migrate_meta_json(dest);
147150

148151
const modules = await pkg.process_modules(await read_types(`${pkg.local}/${pkg.pkg}/`, []), pkg);
149152

150-
const files = glob(`${DOCS}/${pkg.name}/**/*.md`);
153+
const files = glob(`${dest}/**/*.md`);
151154

152155
for (const file of files) {
153-
const content = await preprocess(readFileSync(file, 'utf-8'), modules);
156+
const content = await preprocess(fs.readFileSync(file, 'utf-8'), modules);
154157

155-
writeFileSync(file, content);
158+
fs.writeFileSync(file, content);
156159
}
157160
}

packages/site-kit/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
"default": "./src/lib/markdown/index.ts"
8181
},
8282
"./markdown/preprocess": {
83-
"default": "./src/lib/markdown/preprocess/index.ts"
83+
"default": "./src/lib/markdown/preprocess.ts"
8484
},
8585
"./nav": {
8686
"default": "./src/lib/nav/index.ts",

0 commit comments

Comments
 (0)