Skip to content

Commit 3e78cb2

Browse files
committed
Added functionality for building multiple editors via separate build commands
1 parent 25631ae commit 3e78cb2

13 files changed

+450
-45
lines changed

.gitattributes

-1
This file was deleted.

README.md

+20-6
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,37 @@
1-
# Config Editor - Load & Modify CANedge Config Files
1+
# Config Editor - Load & Modify Configuration Files
22

3-
This simple config editor lets you load JSON configuration files from the [CANedge](https://www.csselectronics.com/) CAN bus data logger and related modules. The tool lets you simply load your `config-XX.YY.json` via the Configuration File dropdown to initialize the editor. Alternatively, you can also manually load a 'Rule Schema' and 'UIschema' in the editor.
3+
This simple config editor lets you load JSON configuration files from the [CANedge](https://www.csselectronics.com/) CAN bus data logger and related modules. The tool lets you load your `config-XX.YY.json` via the Configuration File dropdown to initialize the editor. Alternatively, you can manually load a 'Rule Schema' and 'UIschema' in the editor.
44

5-
The editor can be used offline, or you can upload it to a web server to use it online. You can of course also simply use our [hosted CANedge config editor](https://canlogger.csselectronics.com/simple-editor/#/), which always features the latest version.
5+
The editor can be used offline, or you can upload it to a web server to use it online. You can also simply use our [hosted CANedge config editor](https://canlogger.csselectronics.com/simple-editor/#/), which always features the latest version.
6+
7+
See also our [documentation](https://www.csselectronics.com/screen/page/can-logger-resources) for further details on configuration.
68

79
----
810

911
## How to install
1012
Clone this repository and run `npm install`.
1113

12-
To build the editor, run `npm run simple`.
14+
----
15+
16+
## How to build
17+
The config editor supports building various editor variants:
18+
```
19+
npm run canedge
20+
npm run gps
21+
...
22+
```
23+
24+
For a list of available builds, see the `package.json` scripts list.
25+
26+
For each build, the `TYPE` variable can be used within the `Editor.js` file to change settings - e.g. modifying the title, which schema files to use and which editor tools to include.
1327

1428
----
1529

1630
## Regarding sub modules
1731
The CANedge config editor is very light and is based on two imported modules:
1832

19-
1. [config-editor-base](https://github.com/CSS-Electronics/config-editor-base): This module serves as the "core" editor and includes the JSON Schema loader tool, as well as the 'partial config loader' tool.
20-
2. [config-editor-tools](https://github.com/CSS-Electronics/config-editor-tools): This module contains various "extra" editor tools, which can be imported and parsed to the base editor. The extra tools will be available from the editor submenu
33+
1. [config-editor-base](https://github.com/CSS-Electronics/config-editor-base): This module serves as the "core" editor and includes the JSON Schema loader tool
34+
2. [config-editor-tools](https://github.com/CSS-Electronics/config-editor-tools): This module contains various "extra" editor tools, which can be imported and parsed to the editor
2135

2236
These sub modules are also used in other projects by CSS Electronics, for example [CANcloud](https://github.com/CSS-Electronics/cancloud).
2337

analyse.js

-15
This file was deleted.

canedge-editor.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const fs = require("fs-extra");
2+
const path = require("path");
3+
4+
const bundlePath = path.join(__dirname, "/canedge-editor/bundle.js");
5+
const htmlPath = path.join(__dirname, "/canedge-editor/index.html");
6+
try {
7+
const html = fs.openSync(htmlPath, "a");
8+
const bundle = fs.readFileSync(bundlePath, "utf8");
9+
fs.appendFileSync(html, `<script>${bundle}</script>`, "utf8");
10+
fs.unlinkSync(bundlePath);
11+
console.log("CANedge editor build successfully");
12+
} catch (error) {
13+
console.log(error);
14+
process.exit(0);
15+
}

canedge-editor/index.html

+119
Large diffs are not rendered by default.

simple-editor.js gps-editor.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
const fs = require("fs-extra");
22
const path = require("path");
33

4-
const bundlePath = path.join(__dirname, "/simple/bundle.js");
5-
const htmlPath = path.join(__dirname, "/simple/index.html");
4+
const bundlePath = path.join(__dirname, "/gps-editor/bundle.js");
5+
const htmlPath = path.join(__dirname, "/gps-editor/index.html");
66
try {
77
const html = fs.openSync(htmlPath, "a");
88
const bundle = fs.readFileSync(bundlePath, "utf8");
99
fs.appendFileSync(html, `<script>${bundle}</script>`, "utf8");
1010
fs.unlinkSync(bundlePath);
11-
console.log("Simple editor build successfully");
11+
console.log("CANmod.gps editor build successfully");
1212
} catch (error) {
1313
console.log(error);
1414
process.exit(0);

gps-editor/index.html

+119
Large diffs are not rendered by default.

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "config-editor",
3-
"version": "1.0.0",
3+
"version": "01.01.00",
44
"description": "A React based JSON Schema editor",
55
"author": "CSS Electronics",
66
"license": "MIT",
@@ -9,12 +9,11 @@
99
"scripts": {
1010
"start": "webpack-dev-server --config webpack.simple.js --mode production --open --progress --colors --hot",
1111
"build": "webpack --mode production",
12-
"simple": "webpack --config webpack.simple.js --mode production",
12+
"canedge": "webpack --config webpack.canedge.js --mode production",
13+
"gps": "webpack --config webpack.gps.js --mode production",
1314
"test": "jest"
1415
},
1516
"keywords": [],
16-
"author": "CSS Electronics",
17-
"license": "ISC",
1817
"devDependencies": {
1918
"babel-core": "^6.26.3",
2019
"babel-loader": "^7.1.5",

src/browser/js/editor/Editor.js

+20-9
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,27 @@ import {EditorSection} from "config-editor-base";
1212
import * as actionsAlert from "../alert/actions";
1313
import AlertContainer from "../alert/AlertContainer";
1414

15+
// define editor title and version
16+
const title = TYPE + " config editor"
17+
const version = "v01.01.00"
18+
1519
// define UIschema and Rule Schema names for auto-loading purposes
16-
export const uiSchemaAry = [
20+
export const uiSchemaAry = {"CANedge": [
1721
"uischema-01.02.json | Simple",
1822
"uischema-01.02.json | Advanced",
19-
];
23+
], "CANmod.gps": []}
2024

21-
export const schemaAry = [
25+
export const schemaAry = {"CANedge": [
2226
"schema-01.02.json | CANedge2",
2327
"schema-01.02.json | CANedge1",
2428
"schema-00.07.json | CANedge2",
2529
"schema-00.07.json | CANedge1",
26-
];
30+
], "CANmod.gps":[]}
2731

2832

2933
class Editor extends React.Component {
3034
render() {
31-
let editorTools = [
35+
let editorTools = {"CANedge": [
3236
{
3337
name: "encryption-modal",
3438
comment: "Encryption tool",
@@ -47,17 +51,24 @@ class Editor extends React.Component {
4751
class: "fa fa-calculator",
4852
modal: <BitRateModal showAlert={this.props.showAlert} />,
4953
},
50-
];
54+
], "CANmod.gps": []};
5155

5256
return (
5357
<div className="file-explorer">
58+
59+
<header className="fe-header top-header">
60+
<div className="header-text">
61+
<span className="editor-title">{title}</span><br/>
62+
<span className="editor-version">{version}</span>
63+
</div>
64+
</header>
5465
<div className="fe-body fe-body-offline" >
5566
<AlertContainer />
5667
<EditorSection
57-
editorTools={editorTools}
68+
editorTools={editorTools[TYPE]}
5869
showAlert={this.props.showAlert}
59-
uiSchemaAry={uiSchemaAry}
60-
schemaAry={schemaAry}
70+
uiSchemaAry={uiSchemaAry[TYPE]}
71+
schemaAry={schemaAry[TYPE]}
6172
/>
6273
</div>
6374
</div>

src/browser/less/inc/editor.less

+16
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
.header-text{
2+
left:20px;
3+
top:10px;
4+
position:absolute;
5+
line-height:15px;
6+
}
7+
.editor-title{
8+
font-size:20px;
9+
color:rgb(237, 237, 237);
10+
}
11+
12+
.editor-version{
13+
font-size: 10px;
14+
color:rgb(237, 237, 237);
15+
font-family: Consolas;
16+
}
117

218
/*--------------------------
319
Hidden

webpack.canedge.js

+128
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
/*
2+
* CSS Cloud Storage browser.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
const webpack = require("webpack");
18+
const HtmlWebPackPlugin = require("html-webpack-plugin");
19+
const WebpackShellPlugin = require("webpack-shell-plugin");
20+
const path = require("path");
21+
const nodeExternals = require("webpack-node-externals");
22+
23+
const definePlugin = new webpack.DefinePlugin({
24+
TYPE: JSON.stringify("CANedge")
25+
});
26+
27+
const progressPlugin = new webpack.ProgressPlugin();
28+
29+
const shellPlugin = new WebpackShellPlugin({
30+
onBuildStart: ['echo "CANedge editor build starts"'],
31+
onBuildEnd: ['echo "CANedge editor build complete"'],
32+
onBuildExit: ["node canedge-editor.js"]
33+
});
34+
35+
const htmlPlugin = new HtmlWebPackPlugin({
36+
template: "./src/browser/index.html",
37+
filename: "./index.html",
38+
title: "CANedge Config Editor",
39+
inject: false,
40+
minify: true
41+
});
42+
43+
module.exports = {
44+
context: __dirname,
45+
entry: [path.resolve(__dirname, "src/browser/simple.js")],
46+
output: {
47+
path: __dirname + "/canedge-editor",
48+
filename: "bundle.js"
49+
},
50+
resolve: {
51+
extensions: [".js", ".jsx", ".less"]
52+
},
53+
module: {
54+
rules: [
55+
{
56+
test: /\.(js|jsx)$/,
57+
exclude: /(node_modules|bower_components)/,
58+
use: {
59+
loader: "babel-loader"
60+
}
61+
},
62+
{
63+
test: /\.less$/,
64+
use: [
65+
{
66+
loader: "style-loader"
67+
},
68+
{
69+
loader: "css-loader"
70+
},
71+
{
72+
loader: "less-loader"
73+
}
74+
]
75+
},
76+
{
77+
test: /\.css$/,
78+
use: [
79+
{
80+
loader: "style-loader"
81+
},
82+
{
83+
loader: "css-loader"
84+
}
85+
]
86+
},
87+
{
88+
test: /\.(png|jpg|gif|svg|ico)$/,
89+
use: [
90+
{
91+
loader: "url-loader",
92+
options: {
93+
limit: 800192
94+
}
95+
}
96+
]
97+
},
98+
{
99+
test: /\.svg/,
100+
use: {
101+
loader: "svg-url-loader",
102+
options: {}
103+
}
104+
},
105+
{
106+
test: /\.(eot|woff|woff2|ttf|svg)/,
107+
use: [
108+
{
109+
loader: "url-loader?limit=445000"
110+
}
111+
]
112+
}
113+
]
114+
},
115+
node: {
116+
fs: "empty"
117+
},
118+
externals: [
119+
nodeExternals({
120+
whitelist: [/^((?!aws-sdk|react-chartjs-2).)*$/]
121+
})
122+
],
123+
plugins: [progressPlugin, htmlPlugin, definePlugin, shellPlugin],
124+
devServer: {
125+
historyApiFallback: true,
126+
contentBase: "./"
127+
}
128+
};

webpack.simple.js webpack.gps.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,21 @@ const path = require("path");
2121
const nodeExternals = require("webpack-node-externals");
2222

2323
const definePlugin = new webpack.DefinePlugin({
24-
EDITOR: JSON.stringify({ offline: true })
24+
TYPE: JSON.stringify("CANmod.gps")
2525
});
2626

2727
const progressPlugin = new webpack.ProgressPlugin();
2828

2929
const shellPlugin = new WebpackShellPlugin({
30-
onBuildStart: ['echo "Simple editor build starts"'],
31-
onBuildEnd: ['echo "Simple editor build complete"'],
32-
onBuildExit: ["node simple-editor.js"]
30+
onBuildStart: ['echo "GPS editor build starts"'],
31+
onBuildEnd: ['echo "GPS editor build complete"'],
32+
onBuildExit: ["node gps-editor.js"]
3333
});
3434

3535
const htmlPlugin = new HtmlWebPackPlugin({
3636
template: "./src/browser/index.html",
3737
filename: "./index.html",
38-
title: "Configuration Editor",
38+
title: "CANmod.gps Config Editor",
3939
inject: false,
4040
minify: true
4141
});
@@ -44,7 +44,7 @@ module.exports = {
4444
context: __dirname,
4545
entry: [path.resolve(__dirname, "src/browser/simple.js")],
4646
output: {
47-
path: __dirname + "/simple",
47+
path: __dirname + "/gps-editor",
4848
filename: "bundle.js"
4949
},
5050
resolve: {

0 commit comments

Comments
 (0)