Socialify

Folder ..

Viewing README.md
308 lines (215 loc) • 8.5 KB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
Run Live on: https://maps.backslashlinux.com


# BackSlash Maps

A Simple Maps Application via Electron Framework

## Prerequisites:

- NodeJS with NPM. Check your version of NodeJS by running `node -v` in a terminal.
- A PC running macOS or Linux (For release build).
- Can be started live on Windows

## How to start:

- Install git on your Linux by running one of the following commands. Git comes pre-installed on macOS. 

  - #### Ubuntu/Debian:

    `sudo apt-get install git`

  - #### Arch

    `sudo pacman -S git`

  - #### Fedora

    `sudo dnf install git`

  - #### CentOS

    `sudo yum install git`

- Start a Terminal and clone the repository:

  ```
  git clone https://github.com/luciferreeves/backslash-maps.git
  ```

- Navigate to the repo folder:

  ```
  cd backslash-maps
  ```

- Install Node Modules and Dependencies:

  ```
  npm install
  ```

- Start the App via terminal:

  ```
  npm start
  ```

## How to build:

You can build the app for either macOS or Linux. To build for any or all of the platforms, run the following commands based upon your needs:

```
npm run package-mac
npm run package-linux
```

## How to create DEB file:

The app creates an unpackaged version of Linux build. What you may be interested in is creating a DEB file for Ubuntu and Debian Systems. Start this by installing *electron-installer-debian* package. You might want to run the command as administrator using **sudo** before the command:

```
npm install -g electron-installer-debian
```

Next, create a file called **debian.json** in the root directory (where **index.js** is located). Write the following contents in there:

```json
{
  "dest": "release-builds/",
  "icon": "assets/icon.png",
  "categories": [
    "Utility"
  ],
  "lintianOverrides": [
    "changelog-file-missing-in-native-package"
  ]
}
```

Now update the following code in the **package.json** already present in the folder, in the scripts section:

```json
...

"scripts": {
    "start": "electron .",
    "package-mac": "electron-packager . --overwrite --platform=darwin --arch=x64 --icon=assets/icon.icns --prune=true --out=release-builds",
    "package-linux": "electron-packager . backslash-maps --overwrite --asar=true --platform=linux --arch=x64 --icon=assets/icon.png --prune=true --out=release-builds",
  "create-debian-installer": "electron-installer-debian --src release-builds/backslash-maps-linux-x64/ --arch amd64 --config debian.json"
  },

...
```

To create a debian installer, first package the app as per regular method by running `npm run package-linux` and then run the following command:

```
npm run create-debian-installer
```



## Packaging the App for Windows:

Packaging for Windows is not included in the scripts currently but this can be done quite, easily. You will need a Windows machine for this with NodeJS installed. First download an icon for the app by [clicking here](https://cloud.backslashlinux.com/index.php/s/TZb9sZCLS58ZCGE/download) and move the icon to **assets** folder Now update the following code in the **package.json** already present in the folder, in the scripts section:

```json
...

"scripts": {
 "start": "electron .",
 "package-mac": "electron-packager . --overwrite --platform=darwin --arch=x64 --icon=assets/icon.icns --prune=true --out=release-builds",
 "package-linux": "electron-packager . backslash-maps --overwrite --asar=true --platform=linux --arch=x64 --icon=assets/icon.png --prune=true --out=release-builds",
 "create-debian-installer": "electron-installer-debian --src release-builds/backslash-maps-linux-x64/ --arch amd64 --config debian.json",
  "package-win": "electron-packager . backslash-maps --overwrite --asar=true --platform=win32 --arch=ia32 --icon=assets/icon.ico --prune=true --out=release-builds --version-string.CompanyName=\"BackSlash Linux\" --version-string.FileDescription=BackSlashMaps --version-string.ProductName=\"BackSlash Maps\"",  
 },

...
```

After updating the code, run:

```
npm run package-win
```



## Creating Windows .exe installer:

Start by installing the following package by running the command in your terminal:

```
npm install --save-dev electron-winstaller
```

Create a new file called **createinstaller.js** in **installers/windows/** (you would need to create the folder) and write the following code in it:

```javascript
const createWindowsInstaller = require('electron-winstaller').createWindowsInstaller
const path = require('path')

getInstallerConfig()
  .then(createWindowsInstaller)
  .catch((error) => {
    console.error(error.message || error)
    process.exit(1)
  })

function getInstallerConfig () {
  console.log('creating windows installer')
  const rootPath = path.join('./')
  const outPath = path.join(rootPath, 'release-builds')

  return Promise.resolve({
    appDirectory: path.join(outPath, 'BackSlash-Maps-win32-ia32/'),
    authors: 'BackSlash Linux',
    noMsi: true,
    outputDirectory: path.join(outPath, 'windows-installer'),
    exe: 'backslash-maps.exe',
    setupExe: 'BackSlashMapsInstaller.exe',
    setupIcon: path.join(rootPath, 'assets', 'icon.ico')
  })
}
```

Now to handle squirrel events, create a file called **setupEvents.js** in the folder **installers/** and write the following code in it:

```javascript
const electron = require('electron')
const app = electron.app

module.exports = {
handleSquirrelEvent: function() {
 if (process.argv.length === 1) {
 return false;
 }

 const ChildProcess = require('child_process');
 const path = require('path');

 const appFolder = path.resolve(process.execPath, '..');
 const rootAtomFolder = path.resolve(appFolder, '..');
 const updateDotExe = path.resolve(path.join(rootAtomFolder, 'Update.exe'));
 const exeName = path.basename(process.execPath);
 const spawn = function(command, args) {
 let spawnedProcess, error;

 try {
 spawnedProcess = ChildProcess.spawn(command, args, {detached: true});
 } catch (error) {}

 return spawnedProcess;
 };

 const spawnUpdate = function(args) {
 return spawn(updateDotExe, args);
 };

 const squirrelEvent = process.argv[1];
switch (squirrelEvent) {
 case '--squirrel-install':
 case '--squirrel-updated':
 // Optionally do things such as:
 // - Add your .exe to the PATH
 // - Write to the registry for things like file associations and
 // explorer context menus

 // Install desktop and start menu shortcuts
 spawnUpdate(['--createShortcut', exeName]);

 setTimeout(app.quit, 1000);
 return true;

 case '--squirrel-uninstall':
 // Undo anything you did in the --squirrel-install and
 // --squirrel-updated handlers

 // Remove desktop and start menu shortcuts
 spawnUpdate(['--removeShortcut', exeName]);

 setTimeout(app.quit, 1000);
 return true;

 case '--squirrel-obsolete':
 // This is called on the outgoing version of your app before
 // we update to the new version - it's the opposite of
 // --squirrel-updated

 app.quit();
 return true;
}
}
}
```

Now go to **index.js** and add the following code in the beginning:

```javascript
//handle setupevents as quickly as possible
 const setupEvents = require('./installers/setupEvents')
 if (setupEvents.handleSquirrelEvent()) {
    // squirrel event handled and app will exit in 1000ms, so don't do anything else
    return;
 }

const electron = require('electron')

...
```

Update the scripts section in **package.json** as follows:

```
...

"scripts": {
 "start": "electron .",
 "package-mac": "electron-packager . --overwrite --platform=darwin --arch=x64 --icon=assets/icon.icns --prune=true --out=release-builds",
 "package-linux": "electron-packager . backslash-maps --overwrite --asar=true --platform=linux --arch=x64 --icon=assets/icon.png --prune=true --out=release-builds",
 "create-debian-installer": "electron-installer-debian --src release-builds/backslash-maps-linux-x64/ --arch amd64 --config debian.json",
  "package-win": "electron-packager . backslash-maps --overwrite --asar=true --platform=win32 --arch=ia32 --icon=assets/icon.ico --prune=true --out=release-builds --version-string.CompanyName=\"BackSlash Linux\" --version-string.FileDescription=BackSlashMaps --version-string.ProductName=\"BackSlash Maps\"",  
 },
   "create-installer-win": "node installers/windows/createinstaller.js",

...
```

Finally run the following commands to create a Windows installer:

```
npm run package-win
npm run create-installer-win
```



## Creating DMG installer for macOS

Start by running the following command in the terminal:

```
npm install electron-installer-dmg --save-dev
```

Next, create the macOS package:

```
npm run package-mac
```

Run the following command to generate the dmg installer:

```
electron-installer-dmg ./release-builds/BackSlash\ Maps-darwin-x64/BackSlash\ Maps.app backslash-maps
```