2
2
mirror of https://github.com/Llewellynvdm/nativefier.git synced 2024-12-23 02:28:55 +00:00

Lint all files

This commit is contained in:
Jia Hao 2016-01-24 02:02:23 +08:00
parent b7433dfc3b
commit 82c29de231
12 changed files with 132 additions and 79 deletions

39
.eslintrc.js Normal file
View File

@ -0,0 +1,39 @@
module.exports = {
rules: {
indent: [
2,
4,
{"SwitchCase": 1}
],
quotes: [
2,
'single'
],
'linebreak-style': [
2,
'unix'
],
semi: [
2,
'always'
],
'max-len': 0,
'require-jsdoc': 0,
'padded-blocks': 0,
'no-throw-literal': 0,
camelcase: 0,
'valid-jsdoc': 0,
'no-unused-vars': 1,
'no-path-concat': 1,
'quote-props': [2, 'as-needed']
},
env: {
es6: true,
browser: true,
node: true
},
ecmaFeatures: {
modules: true
},
extends: 'google'
};

View File

@ -35,18 +35,19 @@ function createMainWindow(options, onAppQuit, setDockBadge) {
nodeIntegration: false,
preload: path.join(__dirname, 'static', 'preload.js')
},
icon: options.icon || path.join(__dirname, '/icon.png') // hardcoded by default until you decide how to pass in an icon
// hardcoded by default until you decide how to pass in an icon
icon: options.icon || path.join(__dirname, '/icon.png')
}
);
var currentZoom = 1;
var onZoomIn = function () {
var onZoomIn = function() {
currentZoom += ZOOM_INTERVAL;
mainWindow.webContents.send('change-zoom', currentZoom);
};
var onZoomOut = function () {
var onZoomOut = function() {
currentZoom -= ZOOM_INTERVAL;
mainWindow.webContents.send('change-zoom', currentZoom);
};
@ -57,12 +58,12 @@ function createMainWindow(options, onAppQuit, setDockBadge) {
mainWindow.webContents.setUserAgent(options.userAgent);
}
mainWindow.webContents.on('did-finish-load', function () {
mainWindow.webContents.on('did-finish-load', function() {
mainWindow.webContents.send('params', JSON.stringify(options));
});
if (options.counter) {
mainWindow.on('page-title-updated', function () {
mainWindow.on('page-title-updated', function() {
if (mainWindow.isFocused()) {
return;
@ -81,7 +82,7 @@ function createMainWindow(options, onAppQuit, setDockBadge) {
});
}
mainWindow.webContents.on('new-window', function (event, urlToGo) {
mainWindow.webContents.on('new-window', function(event, urlToGo) {
if (linkIsInternal(options.targetUrl, urlToGo)) {
return;
}
@ -91,7 +92,7 @@ function createMainWindow(options, onAppQuit, setDockBadge) {
mainWindow.loadURL(options.targetUrl);
mainWindow.on('focus', function () {
mainWindow.on('focus', function() {
setDockBadge('');
});
@ -100,7 +101,7 @@ function createMainWindow(options, onAppQuit, setDockBadge) {
mainWindow.setFullScreen(false);
mainWindow.once('leave-full-screen', maybeHideWindow.bind(this, mainWindow, event));
}
maybeHideWindow(mainWindow, event)
maybeHideWindow(mainWindow, event);
});
mainWindowState.manage(mainWindow);

View File

@ -12,8 +12,9 @@ var shell = electron.shell;
* @param {function} onZoomOut
*/
function createMenu(nativefierVersion, onQuit, onGoBack, onGoForward, onZoomIn, onZoomOut) {
if (Menu.getApplicationMenu())
if (Menu.getApplicationMenu()) {
return;
}
var template = [
{
@ -51,7 +52,7 @@ function createMenu(nativefierVersion, onQuit, onGoBack, onGoForward, onZoomIn,
label: 'Select All',
accelerator: 'CmdOrCtrl+A',
role: 'selectall'
},
}
]
},
{
@ -59,22 +60,23 @@ function createMenu(nativefierVersion, onQuit, onGoBack, onGoForward, onZoomIn,
submenu: [
{
label: 'Back',
click: function () {
click: function() {
onGoBack();
}
},
{
label: 'Forward',
click: function () {
click: function() {
onGoForward();
}
},
{
label: 'Reload',
accelerator: 'CmdOrCtrl+R',
click: function (item, focusedWindow) {
if (focusedWindow)
click: function(item, focusedWindow) {
if (focusedWindow) {
focusedWindow.reload();
}
}
},
{
@ -82,52 +84,54 @@ function createMenu(nativefierVersion, onQuit, onGoBack, onGoForward, onZoomIn,
},
{
label: 'Toggle Full Screen',
accelerator: (function () {
if (process.platform == 'darwin')
accelerator: (function() {
if (process.platform === 'darwin') {
return 'Ctrl+Command+F';
else
return 'F11';
}
return 'F11';
})(),
click: function (item, focusedWindow) {
if (focusedWindow)
click: function(item, focusedWindow) {
if (focusedWindow) {
focusedWindow.setFullScreen(!focusedWindow.isFullScreen());
}
}
},
{
label: 'Zoom In',
accelerator: (function () {
if (process.platform == 'darwin')
accelerator: (function() {
if (process.platform === 'darwin') {
return 'Command+=';
else
return 'Ctrl+=';
}
return 'Ctrl+=';
})(),
click: function () {
click: function() {
onZoomIn();
}
},
{
label: 'Zoom Out',
accelerator: (function () {
if (process.platform == 'darwin')
accelerator: (function() {
if (process.platform === 'darwin') {
return 'Command+-';
else
return 'Ctrl+-';
}
return 'Ctrl+-';
})(),
click: function () {
click: function() {
onZoomOut();
}
},
{
label: 'Toggle Window Developer Tools',
accelerator: (function () {
if (process.platform == 'darwin')
accelerator: (function() {
if (process.platform === 'darwin') {
return 'Alt+Command+I';
else
return 'Ctrl+Shift+I';
}
return 'Ctrl+Shift+I';
})(),
click: function (item, focusedWindow) {
if (focusedWindow)
click: function(item, focusedWindow) {
if (focusedWindow) {
focusedWindow.toggleDevTools();
}
}
}
]
@ -145,7 +149,7 @@ function createMenu(nativefierVersion, onQuit, onGoBack, onGoForward, onZoomIn,
label: 'Close',
accelerator: 'CmdOrCtrl+W',
role: 'close'
},
}
]
},
{
@ -154,21 +158,21 @@ function createMenu(nativefierVersion, onQuit, onGoBack, onGoForward, onZoomIn,
submenu: [
{
label: `Built with Nativefier v${nativefierVersion}`,
click: function () {
shell.openExternal('https://github.com/jiahaog/nativefier')
click: function() {
shell.openExternal('https://github.com/jiahaog/nativefier');
}
},
{
label: 'Report an Issue',
click: function () {
shell.openExternal('https://github.com/jiahaog/nativefier/issues')
click: function() {
shell.openExternal('https://github.com/jiahaog/nativefier/issues');
}
}
]
}
];
if (process.platform == 'darwin') {
if (process.platform === 'darwin') {
template.unshift({
label: 'Electron',
submenu: [
@ -200,10 +204,10 @@ function createMenu(nativefierVersion, onQuit, onGoBack, onGoForward, onZoomIn,
{
label: 'Quit',
accelerator: 'Command+Q',
click: function () {
click: function() {
onQuit();
}
},
}
]
});
template[3].submenu.push(

View File

@ -20,17 +20,18 @@ var mainWindow;
// do nothing for setDockBadge if not OSX
let setDockBadge = () => {};
if (isOSX()) {
setDockBadge = app.dock.setBadge;
}
app.on('window-all-closed', function () {
app.on('window-all-closed', function() {
if (!isOSX()) {
app.quit();
}
});
app.on('activate', function (event, hasVisibleWindows) {
app.on('activate', function(event, hasVisibleWindows) {
if (isOSX()) {
// this is called when the dock is clicked
if (!hasVisibleWindows) {
@ -39,7 +40,7 @@ app.on('activate', function (event, hasVisibleWindows) {
}
});
app.on('before-quit', function () {
app.on('before-quit', function() {
// not fired when the close button on the window is clicked
if (isOSX()) {
// need to force a quit as a workaround here to simulate the osx app hiding behaviour
@ -51,7 +52,7 @@ app.on('before-quit', function () {
}
});
app.on('ready', function () {
app.on('ready', function() {
mainWindow = createMainWindow(appArgs, app.quit, setDockBadge);
});

View File

@ -2,7 +2,7 @@ var ipcRenderer = require('electron').ipcRenderer;
var form = document.getElementById('login-form');
form.addEventListener('submit', function (event) {
form.addEventListener('submit', function(event) {
event.preventDefault();
var username = document.getElementById('username-input').value;
var password = document.getElementById('password-input').value;

View File

@ -6,39 +6,38 @@ var electron = require('electron');
var ipc = electron.ipcRenderer;
var webFrame = electron.webFrame;
setNotificationCallback(function (title, opt) {
setNotificationCallback(function(title, opt) {
ipc.send('notification', title, opt);
});
document.addEventListener("DOMContentLoaded", function (event) {
document.addEventListener('DOMContentLoaded', function(event) {
// do things
});
ipc.on('params', function (event, message) {
ipc.on('params', function(event, message) {
var appArgs = JSON.parse(message);
console.log('nativefier.json', appArgs);
});
ipc.on('change-zoom', function (event, message) {
ipc.on('change-zoom', function(event, message) {
webFrame.setZoomFactor(message);
});
/**
* Patches window.Notification to set a callback on a new Notification
* @param callback
*/
function setNotificationCallback(callback) {
var oldNotify = window.Notification;
var newNotify = function (title, opt) {
var OldNotify = window.Notification;
var newNotify = function(title, opt) {
callback(title, opt);
return new oldNotify(title, opt);
return new OldNotify(title, opt);
};
newNotify.requestPermission = oldNotify.requestPermission.bind(oldNotify);
newNotify.requestPermission = OldNotify.requestPermission.bind(OldNotify);
Object.defineProperty(newNotify, 'permission', {
get: function () {
return oldNotify.permission;
get: function() {
return OldNotify.permission;
}
});

View File

@ -6,6 +6,7 @@ import babel from 'gulp-babel';
import runSequence from 'run-sequence';
import path from 'path';
import childProcess from 'child_process';
import eslint from 'gulp-eslint';
const PATHS = setUpPaths();
@ -45,7 +46,7 @@ gulp.task('build-static', () => {
});
gulp.task('watch', ['build'], () => {
var handleError = function (error) {
var handleError = function(error) {
console.error(error);
};
gulp.watch(PATHS.APP_ALL, ['build-app'])
@ -61,9 +62,18 @@ gulp.task('publish', done => {
});
gulp.task('release', callback => {
return runSequence('build', 'publish', callback);
return runSequence('test', 'build', 'publish', callback);
});
gulp.task('lint', function() {
return gulp.src(['**/*.js', '!node_modules/**', '!app/node_modules/**', '!app/lib/**', '!lib/**'])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});
gulp.task('test', ['lint']);
function setUpPaths() {
const paths = {
WEBPACK_CONFIG: './webpack.config.js',

View File

@ -12,11 +12,11 @@
"main": "lib/buildApp.js",
"scripts": {
"dev-up": "npm install && (cd app && npm install)",
"test": "echo \"Error: no test specified\" && exit 1",
"test": "gulp test",
"clean": "gulp clean",
"build": "gulp build",
"watch": "while true ; do gulp watch ; done",
"package-placeholder": "npm run build && node lib/cli.js http://www.medium.com ~/Desktop --overwrite && open ~/Desktop/Medium-darwin-x64/Medium.app",
"package-placeholder": "npm run build && node lib/cli.js http://www.bennish.net/web-notifications.html ~/Desktop --overwrite --app-name notification-test && open ~/Desktop/notification-test-darwin-x64/notification-test.app",
"start-placeholder": "npm run build && electron app",
"release": "gulp release"
},
@ -55,8 +55,10 @@
"babel-preset-es2015": "^6.3.13",
"del": "^2.2.0",
"electron-prebuilt": "^0.36.5",
"eslint-config-google": "^0.3.0",
"gulp": "^3.9.0",
"gulp-babel": "^6.1.1",
"gulp-eslint": "^1.1.1",
"gulp-sourcemaps": "^1.6.0",
"run-sequence": "^1.1.5",
"webpack-stream": "^3.1.0"

View File

@ -20,7 +20,7 @@ const copy = ncp.ncp;
/**
*
* @param options
* @param {{}} options
* @param {buildAppCallback} callback
*/
function buildApp(options, callback) {
@ -45,7 +45,6 @@ function buildApp(options, callback) {
], callback);
}
/**
* @callback tempDirCallback
* @param error

View File

@ -10,7 +10,6 @@ import buildApp from './buildApp';
const packageJson = require(path.join('..', 'package'));
function main(program) {
async.waterfall([
callback => {
optionsFactory(
@ -48,7 +47,7 @@ if (require.main === module) {
program
.version(packageJson.version)
.arguments('<targetUrl> [dest]')
.action(function (targetUrl, appDir) {
.action(function(targetUrl, appDir) {
program.targetUrl = targetUrl;
program.outDir = appDir;
})

View File

@ -25,7 +25,6 @@ function optionsFactory(name,
userAgent,
honest = false,
callback) {
targetUrl = normalizeUrl(targetUrl);
if (!width) {
@ -70,7 +69,7 @@ function optionsFactory(name,
return;
}
getTitle(options.targetUrl, function (error, pageTitle) {
getTitle(options.targetUrl, function(error, pageTitle) {
if (error) {
console.warn(`Unable to automatically determine app name, falling back to '${DEFAULT_APP_NAME}'`);
options.name = DEFAULT_APP_NAME;
@ -116,7 +115,7 @@ function getTitle(url, callback) {
}
const $ = cheerio.load(body);
const pageTitle = $("title").text().replace(/\//g, "");
const pageTitle = $('title').text().replace(/\//g, '');
callback(null, pageTitle);
});
}
@ -146,6 +145,8 @@ function getFakeUserAgent() {
case 'linux':
userAgent = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2227.0 Safari/537.36';
break;
default:
break;
}
return userAgent;
}

View File

@ -1,20 +1,18 @@
var path = require('path');
var fs = require('fs');
//http://jlongster.com/Backend-Apps-with-Webpack--Part-I
// http://jlongster.com/Backend-Apps-with-Webpack--Part-I
// set all modules in node_modules as external
var nodeModules = {};
fs
.readdirSync('./app/node_modules')
.filter(function (x) {
fs.readdirSync('./app/node_modules')
.filter(function(x) {
return ['.bin'].indexOf(x) === -1;
})
.forEach(function (mod) {
.forEach(function(mod) {
nodeModules[mod] = 'commonjs ' + mod;
});
// add electron to external module
nodeModules['electron'] = 'commonjs electron';
nodeModules.electron = 'commonjs electron';
module.exports = {
target: 'node',
@ -28,7 +26,7 @@ module.exports = {
externals: nodeModules,
module: {
loaders: [
{ test: /\.js$/, exclude: /node_modules/, loader: "babel-loader"}
{test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader'}
]
}
};