Skip to content

Commit bcc7550

Browse files
committed
Support markdown editor packaging for mac and Windows platforms
1 parent 1c1b53d commit bcc7550

File tree

7 files changed

+122
-13
lines changed

7 files changed

+122
-13
lines changed

README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ Lilt Breast App Repo.
1919

2020
* [Users Spreadsheet](#users-spreadsheet)
2121

22+
* [App Content Editor](#app-content-editor)
23+
2224
## [Mac Dev Environment Setup](#index)
2325

2426
The following guide assumes that `node` and `npm` commands are available in the system, and Xcode is installed.
@@ -277,3 +279,40 @@ If you want to deploy the webapp elsewhere in order to use another spreadsheet,
277279
* "Esegui l'applicazione come": selezionare "Io" o comunque un account che ha i diritti necessari in lettura/scrittura sullo spreadsheet;
278280
* In "Chi accede all'applicazione" selezionare "Chiunque, inclusi utenti anonimi";
279281
* premere "Implementa" ed accettare eventuali richieste di autorizzazioni.
282+
283+
284+
## [App Content Editor](#index)
285+
286+
The repository contains a simple markdown editor based on [electron](http://electron.atom.io/) inside the `markdown-editor` folder.
287+
288+
To launch the editor from scratch:
289+
290+
```bash
291+
cd markdown-editor
292+
npm install
293+
npm start
294+
```
295+
296+
Next time you will use the `npm start` command only.
297+
298+
The markdown editor allows you to edit `md` documents inside a folder.
299+
By default, the `./markdown` folder is used (relative to the app directory), but you can pass another folder via command-line (if you take a look at the `package.json` file you will see that `npm start` executes the editor passing the `./testdir` directory).
300+
301+
Optionally you can show the developer tools specifying the `LILT_EDITOR_SHOW_DEVTOOLS` environment variable, and setting its value to 1.
302+
303+
To deploy a new editor version from a Mac, make sure you have `electron-packager` installed globally:
304+
305+
```bash
306+
npm install -g electron-packager
307+
```
308+
309+
The `wine` command must be available too, because we are going to generate a Windows executable.
310+
311+
At this point:
312+
313+
* adjust the editor version in `package.json` file
314+
* run the `deploy.sh` script
315+
316+
The `deploy.sh` script packages the app for mac (x64) and Windows platform.
317+
If everything goes well an `out` folder containing two zip files (one per platform) will be created.
318+
You can now git-tag the new version and upload the new release on github.

markdown-editor/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
node_modules
2+
out

markdown-editor/deploy.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
3+
# TODO: use this script's directory instead of "./"
4+
# TODO: add verbose mode?
5+
6+
# extract version from package.json
7+
# (https://gist.github.com/DarrenN/8c6a5b969481725a4413)
8+
PACKAGE_VERSION=$(cat package.json \
9+
| grep version \
10+
| head -1 \
11+
| awk -F: '{ print $2 }' \
12+
| sed 's/[",]//g' \
13+
| tr -d '[[:space:]]')
14+
15+
# create packages
16+
echo "Packaging app v.${PACKAGE_VERSION}.."
17+
electron-packager ./ --platform=darwin --arch=x64 --overwrite --out out
18+
electron-packager ./ --platform=win32 --arch=ia32 --overwrite --out out
19+
20+
# zip packages
21+
printf "\nZipping Packages..\n"
22+
cd out
23+
for i in */; do zip -r "${i%/}-${PACKAGE_VERSION}.zip" "$i"; done
24+
25+
printf "\nOK!"

markdown-editor/index.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
<html>
33
<head>
44
<meta charset="UTF-8">
5-
<title>LILT App Content Editor</title>
65

76
<!-- stylesheets -->
87
<link rel="stylesheet" type="text/css" href="./node_modules/bootstrap/dist/css/bootstrap.css">

markdown-editor/index.js

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
const fs = require('fs');
2-
const marked = require('./ckeditor/plugins/markdown/js/marked');
3-
2+
const marked = require('marked');
3+
const remote = require('electron').remote;
44

55
/* ---------------- state --------------------------------------------------- */
6+
// default markdown directory
7+
const defaultMarkdownDir = './markdown';
8+
69
// when the overlay text is specified the editor is hidden
710
let overlayText = 'Please select a document.';
811

@@ -35,13 +38,45 @@ let tree = null;
3538
// timer id for same tree node reselection upon multiple clicks
3639
let reselectTimerId = -1;
3740

41+
// remote process variable
42+
const remoteProcess = remote.getGlobal('sharedArgs').proc;
43+
3844
// shortcut method to obtain the ckeditor instance
3945
const editor = () => CKEDITOR.instances.editor1;
4046

47+
// app environment detection (https://github.com/electron/electron/pull/5421)
48+
const isProdEnvironment = () => (remoteProcess.defaultApp === undefined);
49+
50+
51+
// return the markdown directory
52+
const getMarkdownDir = () => {
53+
// obtain command line arguments
54+
const args = remoteProcess.argv.slice(isProdEnvironment() ? 1 : 2);
55+
56+
if (args.length === 0) {
57+
if (args.length > 1)
58+
console.error('wrong arguments'); // eslint-disable-line no-console
59+
return defaultMarkdownDir;
60+
}
61+
62+
// we expect the markdown dir as the only parameter
63+
return args[0];
64+
};
65+
66+
4167
// walk through a directory tree and return a JS object that will be used to
4268
// initialize the treeview sidebar
4369
const walk = (dir) => {
4470
const tree = [];
71+
72+
try {
73+
fs.statSync(dir).isDirectory();
74+
}
75+
catch (err) {
76+
overlayText = 'Cannot find markdown directory';
77+
return tree;
78+
}
79+
4580
fs.readdirSync(dir).forEach((f) => {
4681
const path = dir + '/' + f;
4782
if (fs.statSync(path).isDirectory())
@@ -194,7 +229,7 @@ $(document).ready(() => {
194229
color: "#428BCA",
195230
expandIcon: 'glyphicon glyphicon-folder-close',
196231
collapseIcon: 'glyphicon glyphicon-folder-open',
197-
data: walk('./testdir'),
232+
data: walk(getMarkdownDir()),
198233
onNodeSelected,
199234
onNodeUnselected,
200235
onNodeCollapsed: update,

markdown-editor/main.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
const { app, BrowserWindow } = require('electron');
44

5+
// sharedArgs is a global object shared with browser windows
6+
global.sharedArgs = { proc: process };
7+
58

69
// Keep a global reference of the window object, if you don't, the window will
710
// be closed automatically when the JavaScript object is garbage collected.
@@ -10,13 +13,19 @@ let win;
1013

1114
function createWindow() {
1215
// Create the browser window.
13-
win = new BrowserWindow({ width: 800, height: 600 });
16+
win = new BrowserWindow({
17+
width: 800,
18+
height: 600,
19+
title: 'LILT App Content Editor v.' + app.getVersion(),
20+
});
1421

1522
// and load the index.html of the app.
1623
win.loadURL(`file://${__dirname}/index.html`);
1724

1825
// Open the DevTools.
19-
win.webContents.openDevTools();
26+
if (process.env.LILT_EDITOR_SHOW_DEVTOOLS &&
27+
process.env.LILT_EDITOR_SHOW_DEVTOOLS === 1)
28+
win.webContents.openDevTools();
2029

2130
// Emitted when the window is closed.
2231
win.on('closed', () => {

markdown-editor/package.json

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
{
2-
"name": "lilt-markdown-editor",
3-
"version": "0.1.0",
2+
"name": "lilt_app_content_editor",
3+
"version": "1.0.0",
44
"main": "main.js",
55
"scripts": {
6-
"start": "./node_modules/.bin/electron ."
6+
"start": "LILT_EDITOR_SHOW_DEVTOOLS=1 ./node_modules/.bin/electron . ./testdir"
77
},
88
"devDependencies": {
9-
"electron-prebuilt": "~1.2.0",
9+
"electron-prebuilt": "1.2.8",
1010
"babel-eslint": "^6.1.0",
1111
"eslint": "^3.1.1"
1212
},
1313
"dependencies": {
14-
"bootstrap": "^3.3.7",
15-
"bootstrap-treeview": "^1.2.0",
16-
"jquery": "^3.1.0"
14+
"bootstrap": "~3.3.7",
15+
"bootstrap-treeview": "~1.2.0",
16+
"jquery": "~3.1.0",
17+
"marked": "~0.3.6"
1718
}
1819
}

0 commit comments

Comments
 (0)