chore: modernize create-electron-documentation script (#601)

This commit is contained in:
David Sanders 2024-07-10 13:51:01 -07:00 коммит произвёл GitHub
Родитель c3c1078169
Коммит 1df831fe5f
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
1 изменённых файлов: 3 добавлений и 23 удалений

Просмотреть файл

@ -1,9 +1,8 @@
#!/usr/bin/env node
//@ts-check
const fs = require('fs').promises;
const { existsSync } = require('fs');
const path = require('path');
const { promises: fs } = require('node:fs');
const path = require('node:path');
const loadContent = (route) => {
const finalPath = path.join(__dirname, route);
@ -59,24 +58,6 @@ const interpolate = (content, values) => {
return interpolated;
};
/**
* Naively creates all the necessary folders for the given `route`.
* @param {string} route The route to create, has to be absolute and no filename
*/
const mkdirp = async (route) => {
if (existsSync(route)) {
return;
}
const parent = path.dirname(route);
if (!existsSync(parent)) {
await mkdirp(parent);
}
await fs.mkdir(route);
};
/**
* Writes the files interpolating the different values
* @param {{content: string;destination: string;}[]} templates
@ -93,8 +74,7 @@ const writeFiles = async (templates, information, docsRoot) => {
interpolate(destination, information)
);
await mkdirp(path.dirname(finalDestination));
await fs.mkdir(path.dirname(finalDestination), { recursive: true });
await fs.writeFile(finalDestination, finalContent, 'utf-8');
createdFiles.push(finalDestination);