Skip to content

Commit

Permalink
fix: scripts can't run in the productin mode
Browse files Browse the repository at this point in the history
  • Loading branch information
lin.zhou committed Nov 12, 2018
1 parent e522663 commit 59fdc73
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 58 deletions.
2 changes: 1 addition & 1 deletion .electron-vue/webpack.renderer.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ if (process.env.NODE_ENV === 'production') {
'process.env.NODE_ENV': '"production"'
}),
new webpack.LoaderOptionsPlugin({
minimize: false
minimize: true
})
)
}
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "IoT-Dashboard",
"version": "0.1.8",
"version": "0.1.9",
"author": "Pansila <[email protected]>",
"description": "An integrated debug tool for IOT devices, powered by electron, bootstrap, vue, xterm, G2, etc.",
"license": "MIT",
Expand Down Expand Up @@ -77,12 +77,12 @@
"axios": "^0.18.0",
"babel-core": "^6.26.3",
"babel-preset-env": "^1.7.0",
"babel-preset-stage-0": "^6.24.1",
"babel-register": "^6.26.0",
"bootstrap-vue": "^2.0.0-rc.11",
"electron-log": "^2.2.17",
"electron-settings": "^3.2.0",
"electron-updater": "^3.1.2",
"requirejs": "^2.3.6",
"serialport": "^6.2.2",
"through2": "^2.0.3",
"vue": "^2.5.16",
Expand All @@ -97,7 +97,6 @@
"babel-loader": "^7.1.4",
"babel-plugin-istanbul": "^4.1.6",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-stage-0": "^6.24.1",
"babili-webpack-plugin": "^0.1.2",
"cfonts": "^2.1.2",
"chai": "^4.1.2",
Expand Down
10 changes: 5 additions & 5 deletions src/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { app, BrowserWindow, ipcMain } from 'electron'
import path from 'path'
import fs from 'fs'
import {fork} from 'child_process'
import * as constant from '@utils/Constant'
import constant from '@utils/Constant'
import { autoUpdater } from 'electron-updater'
import log from 'electron-log'
import settings from '@utils/Settings'
Expand Down Expand Up @@ -79,10 +79,10 @@ function runScript (caller, scriptName) {

const child = fork(runnerPath,
{
env: Object.assign({
NODE_DEBUG: 'module',
NODE_PATH: process.cwd()
}, process.env),
// env: Object.assign({
// NODE_DEBUG: 'module',
// NODE_PATH: process.cwd()
// }, process.env),
stdio: [0, 1, 2, 'ipc']
})
child.on('message', function (m) {
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/ConsolePage/CodeEditorModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ start()</div>
import fs from 'fs'
import ace from 'ace-builds/src-noconflict/ace'
import setupAce from '@utils/ace-webpack-resolver'
import * as constant from '@utils/Constant'
import constant from '@utils/Constant'
import scripts from '@utils/Scripts'
setupAce(ace)
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/ConsolePage/Console.vue
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
import fs from 'fs'
import path from 'path'
import Vue from 'vue'
import * as constant from '@utils/Constant'
import constant from '@utils/Constant'
import scripts from '@utils/Scripts'
export default {
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/ConsolePage/ScriptTerminal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import 'xterm/dist/xterm.css'
import resizesensor from '@components/ResizeSensor'
import {execFile} from 'child_process'
import * as constant from '@utils/Constant'
import constant from '@utils/Constant'
Terminal.applyAddon(fit)
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/ConsolePage/Terminal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {LineParser, LineBuffer, TimestampPrefix, KeywordFilter} from '@utils/Com
import {PassThrough} from 'stream'
import fs from 'fs'
import path from 'path'
import * as constant from '@utils/Constant'
import constant from '@utils/Constant'
import settings from '@utils/Settings'
Terminal.applyAddon(fit)
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/TabBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
<script>
import {ipcRenderer} from 'electron'
import Console from '@components/ConsolePage/Console'
import * as constant from '@utils/Constant'
import constant from '@utils/Constant'
import settings from '@utils/Settings'
import scripts from '@utils/Scripts'
Expand Down
2 changes: 1 addition & 1 deletion src/utils/Constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const MSG_UPDATE_NOW = 0
const MSG_UPDATE_ON_QUIT = 1
const MSG_NO_UPDATE = 2

export {
export default {
EVENT_ASYNC_MSG,
EVENT_ASYNC_REPLY,
EVENT_RUN_SCRIPT,
Expand Down
2 changes: 1 addition & 1 deletion src/utils/test-helper.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {exec} from 'child_process'
import * as constant from './Constant'
import constant from './Constant'

let script

Expand Down
60 changes: 22 additions & 38 deletions src/utils/test-runner.js
Original file line number Diff line number Diff line change
@@ -1,76 +1,60 @@
import path from 'path'
import fs from 'fs'
import * as constant from './Constant'
import scripts from './Scripts'
import {print, scriptInit} from './test-helper'
import log from 'electron-log'
// import requirejs from 'requirejs'
/* use commonjs module syntax to work both in the development and production mode */
const path = require('path')
const fs = require('fs')
const log = require('electron-log')

log.transports.file.level = 'debug'
// log.transports.file.level = 'debug'

/* ugly: point the path of babel presets to the right position in the production mode */
const presetEnv = path.join(__dirname, '../../node_modules/babel-preset-env')
const presetStage0 = path.join(__dirname, '../../node_modules/babel-preset-stage-0')

require('babel-register')({
'presets': [
['env', {
[presetEnv, {
'targets': { 'node': 8 }
}],
'stage-0'
presetStage0
]
})

const logStream = fs.createWriteStream('d:/test.log', {flags: 'a'})
process.stdout.write = process.stderr.write = logStream.write.bind(logStream)
/* require them after registration of babel to work in the development mode */
const constant = require('./Constant').default
const scripts = require('./Scripts').default
const print = require('./test-helper').print
const scriptInit = require('./test-helper').scriptInit

// requirejs.config({
// // Use node's special variable __dirname to
// // get the directory containing this file.
// // Useful if building a library that will
// // be used in node but does not require the
// // use of node outside
// baseUrl: 'junk', // anything to overshadow the file
// // Pass the top-level main.js/index.js require
// // function to requirejs so that node modules
// // are loaded relative to the top-level JS file.
// nodeRequire: require
// })
// const logStream = fs.createWriteStream('d:/test.log', {flags: 'a'})
// process.stdout.write = process.stderr.write = logStream.write.bind(logStream)

process.on('message', function (m) {
const {event, data} = m

if (event === constant.EVENT_RUN_SCRIPT) {
print('\n=> start the script "' + data + '"')

scriptInit(data)

const scriptPath = path.join(process.cwd(), 'scripts')
const tempScript = path.join(scriptPath, data)
const helperPathSrc = path.join(__dirname, '../../dist/electron/testhelper.js')
const helperPathDst = path.join(process.cwd(), 'test-helper.js')
log.debug(tempScript, helperPathSrc, helperPathDst)
// log.debug(tempScript, helperPathSrc, helperPathDst)

fs.createReadStream(helperPathSrc).pipe(fs.createWriteStream(helperPathDst)).on('close', () => {
try {
fs.unlinkSync(tempScript)
} catch (err) {
// print(JSON.stringify(err))
// log.error(err)
}

const { build: { productName: appName } } = require('../../package.json')
const testScript = scripts.getScriptFilePath(data, appName)

// try {
// // requirejs(test)
// // script ends in .js will ignore baseURL
// requirejs(data.slice(0, -3))
// } catch (err) {
// log.error(err)
// }

fs.createReadStream(testScript).pipe(fs.createWriteStream(tempScript)).on('close', () => {
try {
// script ends in .js will ignore baseURL
// requirejs('./scripts/' + data.slice(0, -3))
const scriptEval = tempScript.replace(/\\/g, '\\$&')
log.debug(scriptEval)
eval(`require('${scriptEval}')`)
// requirejs(tempScript.slice(0, -3))
} catch (err) {
log.error(err)
}
Expand Down
4 changes: 0 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8412,10 +8412,6 @@ require-uncached@^1.0.3:
caller-path "^0.1.0"
resolve-from "^1.0.0"

requirejs@^2.3.6:
version "2.3.6"
resolved "http://r.cnpmjs.org/requirejs/download/requirejs-2.3.6.tgz#e5093d9601c2829251258c0b9445d4d19fa9e7c9"

requires-port@^1.0.0:
version "1.0.0"
resolved "http://r.cnpmjs.org/requires-port/download/requires-port-1.0.0.tgz#925d2601d39ac485e091cf0da5c6e694dc3dcaff"
Expand Down

0 comments on commit 59fdc73

Please sign in to comment.