mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 10:25:42 +01:00
Improve monaco-css scripts
This commit is contained in:
parent
67a240a269
commit
e441fd4498
6 changed files with 81 additions and 70 deletions
|
|
@ -5,10 +5,13 @@
|
|||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const cp = require('child_process');
|
||||
|
||||
const REPO_ROOT = path.join(__dirname, '..');
|
||||
|
||||
/**
|
||||
* Copy a file.
|
||||
*
|
||||
* @param {string} _source
|
||||
* @param {string} _destination
|
||||
*/
|
||||
|
|
@ -41,6 +44,8 @@ function copyFile(_source, _destination) {
|
|||
exports.copyFile = copyFile;
|
||||
|
||||
/**
|
||||
* Remove a directory and all its contents.
|
||||
*
|
||||
* @param {string} _dirPath
|
||||
*/
|
||||
function removeDir(_dirPath) {
|
||||
|
|
@ -68,3 +73,60 @@ function removeDir(_dirPath) {
|
|||
}
|
||||
}
|
||||
exports.removeDir = removeDir;
|
||||
|
||||
/**
|
||||
* Launch the typescript compiler synchronously over a project.
|
||||
*
|
||||
* @param {string} projectPath
|
||||
*/
|
||||
function tsc(_projectPath) {
|
||||
const projectPath = path.join(REPO_ROOT, _projectPath);
|
||||
cp.spawnSync(process.execPath, [path.join(__dirname, '../node_modules/typescript/lib/tsc.js'), '-p', projectPath], { stdio: 'inherit', stderr: 'inherit' });
|
||||
|
||||
console.log(`Compiled ${_projectPath}`);
|
||||
}
|
||||
exports.tsc = tsc;
|
||||
|
||||
/**
|
||||
* Transform an external .d.ts file to an internal .d.ts file
|
||||
*
|
||||
* @param {string} _source
|
||||
* @param {string} _destination
|
||||
* @param {string} namespace
|
||||
*/
|
||||
function dts(_source, _destination, namespace) {
|
||||
const source = path.join(REPO_ROOT, _source);
|
||||
const destination = path.join(REPO_ROOT, _destination);
|
||||
|
||||
const lines = fs
|
||||
.readFileSync(source)
|
||||
.toString()
|
||||
.split(/\r\n|\r|\n/);
|
||||
|
||||
let result = [
|
||||
`/*---------------------------------------------------------------------------------------------`,
|
||||
` * Copyright (c) Microsoft Corporation. All rights reserved.`,
|
||||
` * Licensed under the MIT License. See License.txt in the project root for license information.`,
|
||||
` *--------------------------------------------------------------------------------------------*/`,
|
||||
``,
|
||||
`/// <reference path="../node_modules/monaco-editor-core/monaco.d.ts" />`,
|
||||
``,
|
||||
`declare namespace ${namespace} {`
|
||||
];
|
||||
for (let line of lines) {
|
||||
if (/^import/.test(line)) {
|
||||
continue;
|
||||
}
|
||||
line = line.replace(/ /g, '\t');
|
||||
line = line.replace(/declare /g, '');
|
||||
if (line.length > 0) {
|
||||
line = `\t${line}`;
|
||||
result.push(line);
|
||||
}
|
||||
}
|
||||
result.push(`}`);
|
||||
result.push(``);
|
||||
|
||||
fs.writeFileSync(destination, result.join('\n'));
|
||||
}
|
||||
exports.dts = dts;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue