2017-11-15 01:01:19 +02:00
|
|
|
const fs = require('fs-extra');
|
|
|
|
const spawnSync = require('child_process').spawnSync;
|
|
|
|
|
2020-02-21 00:59:18 +02:00
|
|
|
const babelPath = `${__dirname}/../node_modules/.bin/babel${process.platform === 'win32' ? '.cmd' : ''}`;
|
2019-09-19 23:51:18 +02:00
|
|
|
const basePath = `${__dirname}/../..`;
|
2017-11-15 01:01:19 +02:00
|
|
|
|
|
|
|
function fileIsNewerThan(path1, path2) {
|
|
|
|
if (!fs.existsSync(path2)) return true;
|
|
|
|
|
|
|
|
const stat1 = fs.statSync(path1);
|
|
|
|
const stat2 = fs.statSync(path2);
|
|
|
|
|
|
|
|
return stat1.mtime > stat2.mtime;
|
|
|
|
}
|
|
|
|
|
2019-04-01 21:43:13 +02:00
|
|
|
function convertJsx(path) {
|
|
|
|
fs.readdirSync(path).forEach((filename) => {
|
2019-09-19 23:51:18 +02:00
|
|
|
const jsxPath = `${path}/${filename}`;
|
2019-04-01 21:43:13 +02:00
|
|
|
const p = jsxPath.split('.');
|
|
|
|
if (p.length <= 1) return;
|
|
|
|
const ext = p[p.length - 1];
|
|
|
|
if (ext !== 'jsx') return;
|
|
|
|
p.pop();
|
|
|
|
|
|
|
|
const basePath = p.join('.');
|
|
|
|
|
2019-09-19 23:51:18 +02:00
|
|
|
const jsPath = `${basePath}.min.js`;
|
2019-04-01 21:43:13 +02:00
|
|
|
|
|
|
|
if (fileIsNewerThan(jsxPath, jsPath)) {
|
2019-09-19 23:51:18 +02:00
|
|
|
console.info(`Compiling ${jsxPath}...`);
|
2019-04-01 21:43:13 +02:00
|
|
|
const result = spawnSync(babelPath, ['--presets', 'react', '--out-file', jsPath, jsxPath]);
|
|
|
|
if (result.status !== 0) {
|
|
|
|
const msg = [];
|
|
|
|
if (result.stdout) msg.push(result.stdout.toString());
|
|
|
|
if (result.stderr) msg.push(result.stderr.toString());
|
|
|
|
console.error(msg.join('\n'));
|
|
|
|
if (result.error) console.error(result.error);
|
|
|
|
process.exit(result.status);
|
|
|
|
}
|
2017-11-15 01:01:19 +02:00
|
|
|
}
|
2019-04-01 21:43:13 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-02-21 00:59:18 +02:00
|
|
|
module.exports = function() {
|
|
|
|
convertJsx(`${__dirname}/../gui`);
|
2020-07-03 23:32:39 +02:00
|
|
|
convertJsx(`${__dirname}/../gui/SideBar`);
|
|
|
|
convertJsx(`${__dirname}/../gui/MainScreen`);
|
|
|
|
convertJsx(`${__dirname}/../gui/Header`);
|
|
|
|
convertJsx(`${__dirname}/../gui/NoteList`);
|
2020-02-21 00:59:18 +02:00
|
|
|
convertJsx(`${__dirname}/../plugins`);
|
2019-01-17 21:01:35 +02:00
|
|
|
|
2020-02-21 00:59:18 +02:00
|
|
|
const libContent = [
|
|
|
|
fs.readFileSync(`${basePath}/ReactNativeClient/lib/string-utils-common.js`, 'utf8'),
|
|
|
|
fs.readFileSync(`${basePath}/ReactNativeClient/lib/markJsUtils.js`, 'utf8'),
|
|
|
|
fs.readFileSync(`${basePath}/ReactNativeClient/lib/renderers/webviewLib.js`, 'utf8'),
|
|
|
|
];
|
2019-01-18 19:56:56 +02:00
|
|
|
|
2020-02-21 00:59:18 +02:00
|
|
|
fs.writeFileSync(`${__dirname}/../gui/note-viewer/lib.js`, libContent.join('\n'), 'utf8');
|
|
|
|
|
|
|
|
return Promise.resolve();
|
|
|
|
};
|