mirror of
https://github.com/zed-industries/zed.git
synced 2025-02-03 17:44:30 +00:00
Write theme files atomically
This commit is contained in:
parent
47591ec9a7
commit
89e91939e4
1 changed files with 9 additions and 5 deletions
|
@ -1,23 +1,27 @@
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import * as path from "path";
|
import * as path from "path";
|
||||||
|
import { tmpdir } from 'os';
|
||||||
import app from "./styleTree/app";
|
import app from "./styleTree/app";
|
||||||
import themes from "./themes";
|
import themes from "./themes";
|
||||||
import snakeCase from "./utils/snakeCase";
|
import snakeCase from "./utils/snakeCase";
|
||||||
|
|
||||||
const themeDirectory = `${__dirname}/../../assets/themes/`;
|
const themeDirectory = `${__dirname}/../../assets/themes/`;
|
||||||
|
const tempDirectory = fs.mkdtempSync(path.join(tmpdir(), 'build-themes'));
|
||||||
|
|
||||||
// Clear existing themes
|
// Clear existing themes
|
||||||
for (const file of fs.readdirSync(themeDirectory)) {
|
for (const file of fs.readdirSync(themeDirectory)) {
|
||||||
fs.unlinkSync(path.join(themeDirectory, file));
|
if (file.endsWith('.json')) {
|
||||||
|
fs.unlinkSync(path.join(themeDirectory, file));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write new themes to theme directory
|
// Write new themes to theme directory
|
||||||
for (let theme of themes) {
|
for (let theme of themes) {
|
||||||
let styleTree = snakeCase(app(theme));
|
let styleTree = snakeCase(app(theme));
|
||||||
let styleTreeJSON = JSON.stringify(styleTree, null, 2);
|
let styleTreeJSON = JSON.stringify(styleTree, null, 2);
|
||||||
let outPath = path.resolve(
|
let tempPath = path.join(tempDirectory, `${theme.name}.json`);
|
||||||
`${__dirname}/../../assets/themes/${theme.name}.json`
|
let outPath = path.join(themeDirectory, `${theme.name}.json`);
|
||||||
);
|
fs.writeFileSync(tempPath, styleTreeJSON);
|
||||||
fs.writeFileSync(outPath, styleTreeJSON);
|
fs.renameSync(tempPath, outPath);
|
||||||
console.log(`- ${outPath} created`);
|
console.log(`- ${outPath} created`);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue