mirror of
https://github.com/facebook/lexical.git
synced 2025-06-27 17:27:22 +08:00
Refactor repo
WIP WIP Cleanup Cleanup eslint Fix Fix selection issues + text removal Fix a few bugs and add GCC compilation Remove node_modules Remove node_modules
This commit is contained in:

committed by
acywatson

parent
f62961a30d
commit
ce3520006e
.eslintignore.eslintrc.js.gitignore.prettierrc.jsREADME.mdpackage.json
packages
outline-emoji-plugin
outline-example
outline-mentions-plugin
outline-plain-text-plugin
outline-plugin-plain-text
outline-rich-text-plugin
outline
scripts
src
yarn.lock
35
scripts/plugins/closure-plugin.js
Normal file
35
scripts/plugins/closure-plugin.js
Normal file
@ -0,0 +1,35 @@
|
||||
'use strict';
|
||||
|
||||
const ClosureCompiler = require('google-closure-compiler').compiler;
|
||||
const {promisify} = require('util');
|
||||
const fs = require('fs');
|
||||
const tmp = require('tmp');
|
||||
const writeFileAsync = promisify(fs.writeFile);
|
||||
|
||||
function compile(flags) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const closureCompiler = new ClosureCompiler(flags);
|
||||
closureCompiler.run(function(exitCode, stdOut, stdErr) {
|
||||
if (!stdErr) {
|
||||
resolve(stdOut);
|
||||
} else {
|
||||
reject(new Error(stdErr));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = function closure(flags = {}) {
|
||||
return {
|
||||
name: 'scripts/plugins/closure-plugin',
|
||||
async renderChunk(code) {
|
||||
const inputFile = tmp.fileSync();
|
||||
const tempPath = inputFile.name;
|
||||
flags = Object.assign({}, flags, {js: tempPath});
|
||||
await writeFileAsync(tempPath, code, 'utf8');
|
||||
const compiledCode = await compile(flags);
|
||||
inputFile.removeCallback();
|
||||
return {code: compiledCode};
|
||||
},
|
||||
};
|
||||
};
|
Reference in New Issue
Block a user