Преглед изворни кода

Fixed first run, started fix ui after copy

Andrew Chalkley пре 8 година
родитељ
комит
682cf6e83a
9 измењених фајлова са 46 додато и 7 уклоњено
  1. 4 1
      DEVELOPING.md
  2. 1 1
      package.json
  3. 3 0
      scripts/fix-index.js
  4. 12 0
      scripts/helpers.js
  5. 1 1
      scripts/pre-rebuild.js
  6. 1 0
      test/index.html
  7. 13 0
      test/test_fix_index.js
  8. 1 1
      ui/package.json
  9. 10 3
      ui/src/App.js

+ 4 - 1
DEVELOPING.md

@@ -4,6 +4,7 @@
 
 
 ```bash
 ```bash
 npm install
 npm install
+npm run start-ui
 npm start
 npm start
 ```
 ```
 
 
@@ -17,6 +18,7 @@ You'll need installed:
 ```
 ```
 npm install
 npm install
 npm run pre-rebuild && npm run rebuild
 npm run pre-rebuild && npm run rebuild
+npm run start-ui
 npm start
 npm start
 ```
 ```
 
 
@@ -25,5 +27,6 @@ npm start
 ```
 ```
 npm install
 npm install
 npm run pre-rebuild && npm run rebuild
 npm run pre-rebuild && npm run rebuild
-sudo npm start
+npm run start-ui
+npm start
 ```
 ```

+ 1 - 1
package.json

@@ -11,7 +11,7 @@
 
 
     "build-ui": "cd ui && npm run build && cd .. && npm run copy-ui && npm run fix-index",
     "build-ui": "cd ui && npm run build && cd .. && npm run copy-ui && npm run fix-index",
     "copy-ui": "ncp ui/build front-end/",
     "copy-ui": "ncp ui/build front-end/",
-    "fix-index": "",
+    "fix-index": "node ./scripts/fix-index.js",
 
 
     "pre-rebuild": "node ./scripts/pre-rebuild.js",
     "pre-rebuild": "node ./scripts/pre-rebuild.js",
     "rebuild": "cd node_modules/serialport && node-gyp rebuild --target=1.4.8 --arch=x64 --dist-url=https://atom.io/download/atom-shell",
     "rebuild": "cd node_modules/serialport && node-gyp rebuild --target=1.4.8 --arch=x64 --dist-url=https://atom.io/download/atom-shell",

+ 3 - 0
scripts/fix-index.js

@@ -0,0 +1,3 @@
+const path = require('path');
+
+const rootPath = path.join(__dirname, '..');

+ 12 - 0
scripts/helpers.js

@@ -0,0 +1,12 @@
+const fs = require('fs');
+
+function openAndFix(file) {
+    const fileContent = fs.readFileSync(file, 'utf-8').toString();
+    const replaced = fileContent.replace(/\/static/g,'static');
+    return replaced;
+}
+
+
+module.exports = {
+    openAndFix
+};

+ 1 - 1
scripts/pre-rebuild.js

@@ -1,6 +1,6 @@
 const fs = require('fs');
 const fs = require('fs');
 const path = require('path');
 const path = require('path');
-const rootPath = path.join(__dirname, '..')
+const rootPath = path.join(__dirname, '..');
 const nslog = path.join(rootPath, 'node_modules', 'nslog', 'build', 'Release', 'nslog.node');
 const nslog = path.join(rootPath, 'node_modules', 'nslog', 'build', 'Release', 'nslog.node');
 const serial_port = path.join(rootPath, 'node_modules', 'serialport', 'build', 'Release', 'serialport.node');
 const serial_port = path.join(rootPath, 'node_modules', 'serialport', 'build', 'Release', 'serialport.node');
 
 

+ 1 - 0
test/index.html

@@ -0,0 +1 @@
+<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="shortcut icon" href="/favicon.ico"><title>Flasher.js</title><link href="/static/css/main.d1281cb5.css" rel="stylesheet"></head><body><div id="root"></div><script type="text/javascript" src="/static/js/main.26d69339.js"></script></body></html>

+ 13 - 0
test/test_fix_index.js

@@ -0,0 +1,13 @@
+const path = require('path');
+
+const assert = require('chai').assert;
+
+const {openAndFix} = require('../scripts/helpers');
+
+describe('npm run fix-index', () => {
+    it('should remove / in front of /static', () => {
+        const updatedFileContents = openAndFix(path.join(__dirname, 'index.html'));
+        const expectedContents = '<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="shortcut icon" href="/favicon.ico"><title>Flasher.js</title><link href="static/css/main.d1281cb5.css" rel="stylesheet"></head><body><div id="root"></div><script type="text/javascript" src="static/js/main.26d69339.js"></script></body></html>';
+        assert(updatedFileContents === expectedContents, "expectedContents didn't match the updatedFileContents");
+    });
+});

+ 1 - 1
ui/package.json

@@ -1,6 +1,6 @@
 {
 {
   "name": "ui",
   "name": "ui",
-  "version": "0.1.0",
+  "version": "1.0.0",
   "private": true,
   "private": true,
   "devDependencies": {
   "devDependencies": {
     "react-scripts": "0.7.0"
     "react-scripts": "0.7.0"

+ 10 - 3
ui/src/App.js

@@ -44,6 +44,7 @@ class App extends Component {
       manifests: [],
       manifests: [],
       readyToFlash: false,
       readyToFlash: false,
       isFlashing: false,
       isFlashing: false,
+      firstRun: true,
       percent: 100,
       percent: 100,
       status: 'Finding ports and manifests...'
       status: 'Finding ports and manifests...'
     };
     };
@@ -64,9 +65,15 @@ class App extends Component {
   }
   }
 
 
   currentClass() {
   currentClass() {
-    return this.state.isFlashing ? 'flashing' : 'finished';
+    if (this.state.firstRun) {
+      return '';
+    } else {
+      return this.state.isFlashing ? 'flashing' : 'finished';
+    }
   }
   }
 
 
+
+
   prepareEventHandlers() {
   prepareEventHandlers() {
     ipcRenderer.on('portsFound', (event, ports) => this.portsFound(ports));
     ipcRenderer.on('portsFound', (event, ports) => this.portsFound(ports));
     ipcRenderer.on('noPortError', (event, error) => {
     ipcRenderer.on('noPortError', (event, error) => {
@@ -91,7 +98,7 @@ class App extends Component {
 
 
     ipcRenderer.on('flashProgress', (event, progress) => {
     ipcRenderer.on('flashProgress', (event, progress) => {
       const {percent, message} = progress;
       const {percent, message} = progress;
-      let humanReadablePercent =  Math.round(percent * 100);
+      let humanReadablePercent = Math.round(percent * 100);
 
 
       this.setState({
       this.setState({
         percent: humanReadablePercent,
         percent: humanReadablePercent,
@@ -195,7 +202,7 @@ class App extends Component {
   }
   }
 
 
   flash() {
   flash() {
-    this.setState({ isFlashing: true });
+    this.setState({ isFlashing: true, firstRun: false });
     ipcRenderer.send('flash', this.state.selectedPort, this.state.selectedManifest);
     ipcRenderer.send('flash', this.state.selectedPort, this.state.selectedManifest);
   }
   }