-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
905 additions
and
983 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"presets": ["@babel/preset-env"], | ||
"plugins": ["@babel/plugin-transform-destructuring"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
node_modules | ||
out | ||
packaged |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"files": { | ||
"src/index.js": "out/index.js", | ||
"src/main-process/app-compiler.js": "out/main-process/app-compiler.js", | ||
"src/main-process/gamepath-util.js": "out/main-process/gamepath-util.js" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
const { exec } = require('child_process') | ||
const packager = require('electron-packager') | ||
const path = require('path') | ||
const fs = require('fs-extra') | ||
const rimraf = require('rimraf') | ||
const escape = require('escape-string-regexp') | ||
const colors = require('colors/safe') | ||
const babel = require('@babel/core') | ||
|
||
const outDir = path.join(__dirname, 'out') | ||
const srcDir = path.join(__dirname, 'src') | ||
const appDir = path.join(srcDir, 'app') | ||
const packagedDir = path.join(__dirname, 'packaged') | ||
const angularAppDir = path.join(appDir, 'papyrus-compiler-app') | ||
const packageJsonFile = path.join(__dirname, 'package.json') | ||
const packageLockJsonFile = path.join(__dirname, 'yarn.lock') | ||
const packageJsonFileOutDir = path.join(outDir, 'package.json') | ||
const packageLockJsonFileOutDir = path.join(outDir, 'yarn.lock') | ||
const electronSourcesFile = path.join(__dirname, 'electron-sources.json') | ||
|
||
function execAsync(...args) { | ||
return new Promise((resolve, reject) => { | ||
exec(...args, (err, stdout) => { | ||
if (err) { | ||
reject(err) | ||
|
||
return | ||
} | ||
|
||
resolve(stdout) | ||
}) | ||
}) | ||
} | ||
|
||
function filterFilesNotToCopy(src, dest) { | ||
const regex = new RegExp('^.*node_modules.*$') | ||
const regexApp = new RegExp('^' + escape(appDir) + '$') | ||
|
||
if (!regex.test(src) && !regexApp.test(src)) { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
async function compileElectronSource() { | ||
//const { code: codeIndex } = await babel.transformFileAsync(path.join(srcDir, 'index.js')) | ||
//await fs.writeFile(path.join(outDir, 'index.js'), codeIndex) | ||
const { files } = await fs.readJson(electronSourcesFile) | ||
|
||
const iterable = Object.entries(files).map(objArray => { | ||
return objArray.map(obj => path.join(__dirname, obj)) | ||
}) | ||
|
||
for (const [src, dest] of iterable) { | ||
const { code } = await babel.transformFileAsync(src) | ||
await fs.writeFile(dest, code) | ||
} | ||
} | ||
|
||
const bootstrap = async () => { | ||
try { | ||
console.log(colors.blue('Build Angular application')) | ||
const stdout = await execAsync('yarn build-electron', { cwd: angularAppDir }) | ||
console.log(stdout) | ||
|
||
console.log(colors.blue('Copying source files...')) | ||
await fs.copy(srcDir, outDir, { filter: filterFilesNotToCopy }) | ||
await fs.copy(packageJsonFile, packageJsonFileOutDir) | ||
await fs.copy(packageLockJsonFile, packageLockJsonFileOutDir) | ||
const json = await fs.readJson(packageJsonFileOutDir) | ||
json.main = 'index.js' | ||
await fs.writeFile(packageJsonFileOutDir, JSON.stringify(json)) | ||
await compileElectronSource() | ||
const stdoutYarn = await execAsync('yarn install --production', { cwd: outDir }) | ||
console.log(stdoutYarn) | ||
console.log("\n\n" + colors.green('Done copying source files')) | ||
await fs.ensureDir(packagedDir) | ||
const r = await packager({ | ||
name: 'papyrus-compiler-app', | ||
icon: path.join(srcDir, 'papyrus-compiler-app.ico'), | ||
dir: outDir, | ||
out: packagedDir, | ||
platform: 'win32', | ||
arch: 'ia32', | ||
asar: true, | ||
overwrite: true, | ||
}) | ||
console.log(colors.green('Done packaging app')) | ||
} catch (e) { | ||
console.error(colors.red('Error during packaging.')) | ||
console.error(e) | ||
process.exit(1) | ||
} | ||
} | ||
|
||
bootstrap() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule papyrus-compiler-app
updated
from ca2593 to bb0103
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { app, BrowserWindow, ipcMain } from 'electron'; | ||
import { AppCompiler } from './main-process/app-compiler'; | ||
import GamePathUtil from './main-process/gamepath-util'; | ||
|
||
// Handle creating/removing shortcuts on Windows when installing/uninstalling. | ||
if (require('electron-squirrel-startup')) { // eslint-disable-line global-require | ||
app.quit(); | ||
} | ||
|
||
// Keep a global reference of the window object, if you don't, the window will | ||
// be closed automatically when the JavaScript object is garbage collected. | ||
let mainWindow; | ||
|
||
const createWindow = () => { | ||
// Create the browser window. | ||
mainWindow = new BrowserWindow({ | ||
width: 800, | ||
height: 600, | ||
webPreferences: { | ||
nodeIntegration: true, | ||
}, | ||
titleBarStyle: 'hidden', | ||
}); | ||
|
||
// and load the index.html of the app. | ||
mainWindow.loadURL('http://localhost:4200'); | ||
|
||
// Open the DevTools. | ||
mainWindow.webContents.openDevTools(); | ||
|
||
ipcMain.on('compile-script', (event, { script, output, imports, flag, gamePath }) => { | ||
const gamePathUtil = new GamePathUtil({ | ||
imports, | ||
output, | ||
gamePath, | ||
flag, | ||
}); | ||
const appCompiler = new AppCompiler(gamePathUtil); | ||
|
||
console.log('on compile'); | ||
|
||
appCompiler.compile(script) | ||
.then(result => { | ||
console.log('good ' + script); | ||
event.sender.send('compile-success', result) | ||
}) | ||
.catch(e => { | ||
console.log('' + e.message); | ||
event.sender.send('compile-failed', e.message); | ||
}); | ||
}); | ||
|
||
// Emitted when the window is closed. | ||
mainWindow.on('closed', () => { | ||
// Dereference the window object, usually you would store windows | ||
// in an array if your app supports multi windows, this is the time | ||
// when you should delete the corresponding element. | ||
mainWindow = null; | ||
}); | ||
}; | ||
|
||
// This method will be called when Electron has finished | ||
// initialization and is ready to create browser windows. | ||
// Some APIs can only be used after this event occurs. | ||
app.on('ready', createWindow); | ||
|
||
// Quit when all windows are closed. | ||
app.on('window-all-closed', () => { | ||
// On OS X it is common for applications and their menu bar | ||
// to stay active until the user quits explicitly with Cmd + Q | ||
if (process.platform !== 'darwin') { | ||
app.quit(); | ||
} | ||
}); | ||
|
||
app.on('activate', () => { | ||
// On OS X it's common to re-create a window in the app when the | ||
// dock icon is clicked and there are no other windows open. | ||
if (mainWindow === null) { | ||
createWindow(); | ||
} | ||
}); | ||
|
||
// In this file you can include the rest of your app's specific main process | ||
// code. You can also put them in separate files and import them here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Oops, something went wrong.