mirror of
https://github.com/tengge1/ShadowEditor.git
synced 2026-01-18 15:02:09 +00:00
73 lines
2.3 KiB
JavaScript
73 lines
2.3 KiB
JavaScript
/*
|
|
* Copyright 2017-2020 The ShadowEditor Authors. All rights reserved.
|
|
*
|
|
* Use of this source code is governed by a MIT-style
|
|
* license that can be found in the LICENSE file.
|
|
*
|
|
* For more information, please visit: https://github.com/tengge1/ShadowEditor
|
|
* You can also visit: https://gitee.com/tengge1/ShadowEditor
|
|
*/
|
|
|
|
const subprocess = require('child_process');
|
|
const path = require('path');
|
|
const fs = require('fs-extra');
|
|
const os = require('os');
|
|
|
|
/**
|
|
* Execute a command
|
|
* @param {String} cmd bat of shell command
|
|
* @param {Boolean} showCmd whether to print the command
|
|
* @returns the result of the command
|
|
*/
|
|
function exec(cmd, showCmd = true) {
|
|
showCmd && console.log(cmd);
|
|
return subprocess.execSync(cmd).toString().trimRight('\n');
|
|
}
|
|
|
|
/**
|
|
* The main function
|
|
*/
|
|
async function main() {
|
|
const rootDir = process.cwd(); // The root dir that contains `README.md`.
|
|
const buildDir = path.join(rootDir, 'build'); // The build dir.
|
|
const mongoDir = path.join(rootDir, 'utils', 'mongodb'); // Download and unzip mongodb here.
|
|
|
|
console.log(`root dir: ${rootDir}`);
|
|
console.log(`build dir: ${buildDir}`);
|
|
console.log(`mongo dir: ${mongoDir}`);
|
|
|
|
// check build
|
|
if (!fs.existsSync(buildDir)) {
|
|
console.warn('You should run `npm run build` first.');
|
|
return;
|
|
}
|
|
|
|
// check mongodb
|
|
const isWin32 = os.platform() === 'win32';
|
|
const mongoPath = path.join(mongoDir, isWin32 ? 'mongo.exe' : 'mongo');
|
|
const mongodPath = path.join(mongoDir, isWin32 ? 'mongod.exe' : 'mongod');
|
|
if (!fs.existsSync(mongoPath) || !fs.existsSync(mongodPath)) {
|
|
console.warn('You should download mongodb first. See `utils/mongodb/README.md` for detail.');
|
|
return;
|
|
}
|
|
|
|
// copy files needed by desktop app
|
|
fs.copySync(mongoDir, 'build/mongo');
|
|
fs.copySync('scripts/electron/main.js', 'build/main.js');
|
|
|
|
// Build desktop package
|
|
console.log('enter build');
|
|
process.chdir(buildDir);
|
|
|
|
exec('electron-packager . ShadowEditor --platform=win32 ' +
|
|
'--arch=x64 --icon=../web/favicon.ico --out=desktop --app-version=0.0.1 ' +
|
|
'--overwrite --no-prune --ignore=public/Upload|public/Upload2 ' +
|
|
'--electron-version 9.0.4');
|
|
|
|
console.log('leave build');
|
|
process.chdir(rootDir);
|
|
|
|
console.log('Done!');
|
|
}
|
|
|
|
main(); |