-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 738cc76
Showing
9 changed files
with
266 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules | ||
template/node_modules | ||
template/prefs.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# PWAify | ||
|
||
> Convert your PWA (Progressive Web App) into a cross-platform Electron App. | ||
|
||
## Usage | ||
|
||
> Node 4+ required. | ||
Install: | ||
|
||
``` | ||
npm install -g pwaify | ||
``` | ||
|
||
## Run against your PWA app | ||
|
||
``` | ||
pwaify https://airhorner.com | ||
``` | ||
|
||
Open the app on your platform, test and send it to your friends! | ||
|
||
## Changelog | ||
|
||
* 1.0.0 - First experimental release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/usr/bin/env node | ||
|
||
const meow = require('meow'); | ||
const cli = meow(` | ||
Usage | ||
$ pwaify <input> | ||
Options | ||
--platforms Platforms to build the app. | ||
Examples | ||
$ pwaify https://airhorner.com --platforms=darwin | ||
`); | ||
|
||
require('../index')({ | ||
appUrl: cli.input[0], | ||
platforms: cli.flags.platforms || 'all' | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
const debug = require('debug')('index'); | ||
const packager = require('electron-packager'); | ||
const fs = require('fs'); | ||
const chalk = require('chalk'); | ||
const path = require('path'); | ||
const manifest = require('./lib/manifest'); | ||
|
||
module.exports = function (options) { | ||
options = options || {}; | ||
debug('options', options); | ||
const appUrl = options.appUrl; | ||
return manifest.fetchManifestDetails(appUrl) | ||
.then(function (manifestJson) { | ||
debug('manifestJson', manifestJson); | ||
var name = manifestJson.name || manifestJson.short_name; | ||
var start_url = appUrl + manifestJson.start_url ; | ||
var appData = { | ||
appUrl: start_url | ||
}; | ||
fs.writeFileSync(path.join(__dirname, 'template', 'prefs.json'), JSON.stringify(appData)); | ||
var packagerOpts = { | ||
name: name, | ||
arch: 'all', | ||
overwrite: true, | ||
dir: path.join(__dirname, 'template'), | ||
platform: options.platforms || 'all' | ||
}; | ||
|
||
return new Promise(function (resolve) { | ||
packager(packagerOpts, function done_callback(err, appPaths) { | ||
if (err) { | ||
throw err; | ||
} | ||
|
||
resolve({ | ||
appPaths: appPaths | ||
}) | ||
}) | ||
}) | ||
|
||
}) | ||
.then(function (result) { | ||
console.log(chalk.green('Your app is ready!'), result); | ||
}).catch(function (err) { | ||
throw err; | ||
}) | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
const got = require('got'); | ||
const debug = require('debug')('manifest'); | ||
const Xray = require('x-ray'); | ||
|
||
module.exports = { | ||
fetchManifestDetails: function fetchManifestDetails (appUrl) { | ||
return new Promise(function (resolve, reject) { | ||
var xray = Xray(); | ||
xray(appUrl, 'link[rel=manifest]@href')(function(err, manifestTarget) { | ||
debug(err, manifestTarget); | ||
|
||
if (err) { | ||
return reject(err); | ||
} | ||
|
||
return resolve({ | ||
manifestTarget: manifestTarget | ||
}); | ||
}); | ||
}).then(function (result) { | ||
if (result.manifestTarget) { | ||
// found manifest via html | ||
return got(result.manifestTarget) | ||
} else { | ||
// no manifest in html, fetch at root | ||
return got(appUrl + '/manifest.json') | ||
} | ||
}).then(function (result) { | ||
var manifestResponse = result.body; | ||
var manifestJson = null; | ||
try { | ||
manifestJson = JSON.parse(manifestResponse); | ||
} catch (e) { | ||
throw new Error('Failed to parse manifest.json') | ||
} | ||
|
||
return manifestJson; | ||
}) | ||
.catch(function (err) { | ||
throw err; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"name": "pwaify", | ||
"version": "1.0.0", | ||
"description": "Electron PWA (Progressive Web App) Generator", | ||
"main": "index.js", | ||
"scripts": { | ||
"postinstall": "cd template && npm install" | ||
}, | ||
"bin": { | ||
"pwaify": "bin/pwaify" | ||
}, | ||
"author": { | ||
"name": "vladikoff", | ||
"email": "[email protected]", | ||
"url": "http://vf.io" | ||
}, | ||
"license": "MIT", | ||
"devDependencies": {}, | ||
"dependencies": { | ||
"chalk": "1.1.3", | ||
"debug": "2.2.0", | ||
"electron-packager": "7.0.2", | ||
"got": "6.3.0", | ||
"icon-gen": "1.0.2", | ||
"meow": "3.7.0", | ||
"x-ray": "2.3.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>PWAify</title> | ||
</head> | ||
<body> | ||
<h1>Loading app...</h1> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
const electron = require('electron') | ||
const fs = require('fs') | ||
// Module to control application life. | ||
const app = electron.app; | ||
// Module to create native browser window. | ||
const BrowserWindow = electron.BrowserWindow; | ||
|
||
// Keep a global reference of the window object, if you don't, the window will | ||
// be closed automatically when the JavaScript object is garbage collected. | ||
let mainWindow | ||
|
||
function createWindow() { | ||
// Create the browser window. | ||
mainWindow = new BrowserWindow({ | ||
width: 800, | ||
height: 600, | ||
webPreferences: { | ||
// disable node for security reasons | ||
nodeIntegration: false | ||
} | ||
}); | ||
|
||
// and load the index.html of the app. | ||
mainWindow.loadURL(require('./prefs.json').appUrl) | ||
|
||
// Open the DevTools. | ||
//mainWindow.webContents.openDevTools() | ||
|
||
// Emitted when the window is closed. | ||
mainWindow.on('closed', function () { | ||
// Dereference the window object, usually you would store windows | ||
// in an array if your app supports multi windows, this is the time | ||
// when you should delete the corresponding element. | ||
mainWindow = null | ||
}) | ||
} | ||
|
||
// This method will be called when Electron has finished | ||
// initialization and is ready to create browser windows. | ||
// Some APIs can only be used after this event occurs. | ||
app.on('ready', createWindow) | ||
|
||
// Quit when all windows are closed. | ||
app.on('window-all-closed', function () { | ||
// On OS X it is common for applications and their menu bar | ||
// to stay active until the user quits explicitly with Cmd + Q | ||
if (process.platform !== 'darwin') { | ||
app.quit() | ||
} | ||
}) | ||
|
||
app.on('activate', function () { | ||
// On OS X it's common to re-create a window in the app when the | ||
// dock icon is clicked and there are no other windows open. | ||
if (mainWindow === null) { | ||
createWindow() | ||
} | ||
}) | ||
|
||
// In this file you can include the rest of your app's specific main process | ||
// code. You can also put them in separate files and require them here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
|
||
{ | ||
"name": "electron-quick-start", | ||
"version": "1.0.0", | ||
"description": "A minimal Electron application", | ||
"productName": "Foo Bar", | ||
"main": "main.js", | ||
"scripts": { | ||
"start": "electron main.js" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/electron/electron-quick-start.git" | ||
}, | ||
"keywords": [ | ||
"Electron", | ||
"quick", | ||
"start", | ||
"tutorial" | ||
], | ||
"author": "GitHub", | ||
"license": "CC0-1.0", | ||
"bugs": { | ||
"url": "https://github.com/electron/electron-quick-start/issues" | ||
}, | ||
"homepage": "https://github.com/electron/electron-quick-start#readme", | ||
"devDependencies": { | ||
"electron-prebuilt": "^1.1.2" | ||
} | ||
} |