mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 15:05:39 +01:00
Fix #2843
This commit is contained in:
parent
3ad48dbde4
commit
a8878c8cfe
8 changed files with 118 additions and 79 deletions
|
|
@ -12,82 +12,11 @@ const esbuild = require('esbuild');
|
|||
/** @type {any} */
|
||||
const alias = require('esbuild-plugin-alias');
|
||||
const glob = require('glob');
|
||||
const { ensureDir } = require('./fs');
|
||||
|
||||
const REPO_ROOT = path.join(__dirname, '../');
|
||||
exports.REPO_ROOT = REPO_ROOT;
|
||||
|
||||
const existingDirCache = new Set();
|
||||
/**
|
||||
* @param {string} dirname
|
||||
*/
|
||||
function ensureDir(dirname) {
|
||||
/** @type {string[]} */
|
||||
const dirs = [];
|
||||
|
||||
while (dirname.length > REPO_ROOT.length) {
|
||||
dirs.push(dirname);
|
||||
dirname = path.dirname(dirname);
|
||||
}
|
||||
dirs.reverse();
|
||||
dirs.forEach((dir) => {
|
||||
if (!existingDirCache.has(dir)) {
|
||||
try {
|
||||
fs.mkdirSync(dir);
|
||||
} catch (err) {}
|
||||
existingDirCache.add(dir);
|
||||
}
|
||||
});
|
||||
}
|
||||
exports.ensureDir = ensureDir;
|
||||
|
||||
/**
|
||||
* Copy a file.
|
||||
*
|
||||
* @param {string} _source
|
||||
* @param {string} _destination
|
||||
*/
|
||||
function copyFile(_source, _destination) {
|
||||
const source = path.join(REPO_ROOT, _source);
|
||||
const destination = path.join(REPO_ROOT, _destination);
|
||||
|
||||
ensureDir(path.dirname(destination));
|
||||
fs.writeFileSync(destination, fs.readFileSync(source));
|
||||
|
||||
console.log(`Copied ${_source} to ${_destination}`);
|
||||
}
|
||||
exports.copyFile = copyFile;
|
||||
|
||||
/**
|
||||
* Remove a directory and all its contents.
|
||||
*
|
||||
* @param {string} _dirPath
|
||||
*/
|
||||
function removeDir(_dirPath) {
|
||||
const dirPath = path.join(REPO_ROOT, _dirPath);
|
||||
if (!fs.existsSync(dirPath)) {
|
||||
return;
|
||||
}
|
||||
rmDir(dirPath);
|
||||
console.log(`Deleted ${_dirPath}`);
|
||||
|
||||
/**
|
||||
* @param {string} dirPath
|
||||
*/
|
||||
function rmDir(dirPath) {
|
||||
const entries = fs.readdirSync(dirPath);
|
||||
for (const entry of entries) {
|
||||
const filePath = path.join(dirPath, entry);
|
||||
if (fs.statSync(filePath).isFile()) {
|
||||
fs.unlinkSync(filePath);
|
||||
} else {
|
||||
rmDir(filePath);
|
||||
}
|
||||
}
|
||||
fs.rmdirSync(dirPath);
|
||||
}
|
||||
}
|
||||
exports.removeDir = removeDir;
|
||||
|
||||
/**
|
||||
* Launch the typescript compiler synchronously over a project.
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue