mirror of
https://github.com/novnc/noVNC.git
synced 2026-06-05 03:49:39 +00:00
Prefer const/let over var
This commit is contained in:
@@ -8,13 +8,12 @@
|
||||
|
||||
"use strict";
|
||||
|
||||
var fs = require('fs');
|
||||
const fs = require('fs');
|
||||
|
||||
var show_help = process.argv.length === 2;
|
||||
var filename;
|
||||
let show_help = process.argv.length === 2;
|
||||
let filename;
|
||||
|
||||
var i;
|
||||
for (i = 2; i < process.argv.length; ++i) {
|
||||
for (let i = 2; i < process.argv.length; ++i) {
|
||||
switch (process.argv[i]) {
|
||||
case "--help":
|
||||
case "-h":
|
||||
@@ -40,25 +39,25 @@ if (show_help) {
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
var buf = fs.readFileSync(filename);
|
||||
var str = buf.toString('utf8');
|
||||
const buf = fs.readFileSync(filename);
|
||||
const str = buf.toString('utf8');
|
||||
|
||||
var re = /^#define XK_([a-zA-Z_0-9]+)\s+0x([0-9a-fA-F]+)\s*(\/\*\s*(.*)\s*\*\/)?\s*$/m;
|
||||
const re = /^#define XK_([a-zA-Z_0-9]+)\s+0x([0-9a-fA-F]+)\s*(\/\*\s*(.*)\s*\*\/)?\s*$/m;
|
||||
|
||||
var arr = str.split('\n');
|
||||
const arr = str.split('\n');
|
||||
|
||||
var codepoints = {};
|
||||
const codepoints = {};
|
||||
|
||||
for (i = 0; i < arr.length; ++i) {
|
||||
var result = re.exec(arr[i]);
|
||||
for (let i = 0; i < arr.length; ++i) {
|
||||
const result = re.exec(arr[i]);
|
||||
if (result){
|
||||
var keyname = result[1];
|
||||
var keysym = parseInt(result[2], 16);
|
||||
var remainder = result[3];
|
||||
const keyname = result[1];
|
||||
const keysym = parseInt(result[2], 16);
|
||||
const remainder = result[3];
|
||||
|
||||
var unicodeRes = /U\+([0-9a-fA-F]+)/.exec(remainder);
|
||||
const unicodeRes = /U\+([0-9a-fA-F]+)/.exec(remainder);
|
||||
if (unicodeRes) {
|
||||
var unicode = parseInt(unicodeRes[1], 16);
|
||||
const unicode = parseInt(unicodeRes[1], 16);
|
||||
// The first entry is the preferred one
|
||||
if (!codepoints[unicode]){
|
||||
codepoints[unicode] = { keysym: keysym, name: keyname };
|
||||
@@ -67,7 +66,7 @@ for (i = 0; i < arr.length; ++i) {
|
||||
}
|
||||
}
|
||||
|
||||
var out =
|
||||
let out =
|
||||
"/*\n" +
|
||||
" * Mapping from Unicode codepoints to X11/RFB keysyms\n" +
|
||||
" *\n" +
|
||||
@@ -77,17 +76,17 @@ var out =
|
||||
"\n" +
|
||||
"/* Functions at the bottom */\n" +
|
||||
"\n" +
|
||||
"var codepoints = {\n";
|
||||
"const codepoints = {\n";
|
||||
|
||||
function toHex(num) {
|
||||
var s = num.toString(16);
|
||||
let s = num.toString(16);
|
||||
if (s.length < 4) {
|
||||
s = ("0000" + s).slice(-4);
|
||||
}
|
||||
return "0x" + s;
|
||||
}
|
||||
|
||||
for (var codepoint in codepoints) {
|
||||
for (let codepoint in codepoints) {
|
||||
codepoint = parseInt(codepoint);
|
||||
|
||||
// Latin-1?
|
||||
@@ -116,7 +115,7 @@ out +=
|
||||
" }\n" +
|
||||
"\n" +
|
||||
" // Lookup table (fairly random)\n" +
|
||||
" var keysym = codepoints[u];\n" +
|
||||
" const keysym = codepoints[u];\n" +
|
||||
" if (keysym !== undefined) {\n" +
|
||||
" return keysym;\n" +
|
||||
" }\n" +
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var path = require('path');
|
||||
var program = require('commander');
|
||||
var fs = require('fs');
|
||||
var fse = require('fs-extra');
|
||||
var babel = require('babel-core');
|
||||
const path = require('path');
|
||||
const program = require('commander');
|
||||
const fs = require('fs');
|
||||
const fse = require('fs-extra');
|
||||
const babel = require('babel-core');
|
||||
|
||||
const SUPPORTED_FORMATS = new Set(['amd', 'commonjs', 'systemjs', 'umd']);
|
||||
|
||||
@@ -44,8 +44,8 @@ no_copy_files.forEach((file) => no_transform_files.add(file));
|
||||
// util.promisify requires Node.js 8.x, so we have our own
|
||||
function promisify(original) {
|
||||
return function () {
|
||||
let obj = this;
|
||||
let args = Array.prototype.slice.call(arguments);
|
||||
const obj = this;
|
||||
const args = Array.prototype.slice.call(arguments);
|
||||
return new Promise((resolve, reject) => {
|
||||
original.apply(obj, args.concat((err, value) => {
|
||||
if (err) return reject(err);
|
||||
@@ -70,10 +70,10 @@ const babelTransformFile = promisify(babel.transformFile);
|
||||
|
||||
// walkDir *recursively* walks directories trees,
|
||||
// calling the callback for all normal files found.
|
||||
var walkDir = function (base_path, cb, filter) {
|
||||
const walkDir = function (base_path, cb, filter) {
|
||||
return readdir(base_path)
|
||||
.then(files => {
|
||||
let paths = files.map(filename => path.join(base_path, filename));
|
||||
const paths = files.map(filename => path.join(base_path, filename));
|
||||
return Promise.all(paths.map((filepath) => {
|
||||
return lstat(filepath)
|
||||
.then(stats => {
|
||||
@@ -87,20 +87,20 @@ var walkDir = function (base_path, cb, filter) {
|
||||
});
|
||||
};
|
||||
|
||||
var transform_html = function (legacy_scripts, only_legacy) {
|
||||
const transform_html = function (legacy_scripts, only_legacy) {
|
||||
// write out the modified vnc.html file that works with the bundle
|
||||
var src_html_path = path.resolve(__dirname, '..', 'vnc.html');
|
||||
var out_html_path = path.resolve(paths.out_dir_base, 'vnc.html');
|
||||
const src_html_path = path.resolve(__dirname, '..', 'vnc.html');
|
||||
const out_html_path = path.resolve(paths.out_dir_base, 'vnc.html');
|
||||
return readFile(src_html_path)
|
||||
.then(contents_raw => {
|
||||
var contents = contents_raw.toString();
|
||||
let contents = contents_raw.toString();
|
||||
|
||||
var start_marker = '<!-- begin scripts -->\n';
|
||||
var end_marker = '<!-- end scripts -->';
|
||||
var start_ind = contents.indexOf(start_marker) + start_marker.length;
|
||||
var end_ind = contents.indexOf(end_marker, start_ind);
|
||||
const start_marker = '<!-- begin scripts -->\n';
|
||||
const end_marker = '<!-- end scripts -->';
|
||||
const start_ind = contents.indexOf(start_marker) + start_marker.length;
|
||||
const end_ind = contents.indexOf(end_marker, start_ind);
|
||||
|
||||
var new_script = '';
|
||||
let new_script = '';
|
||||
|
||||
if (only_legacy) {
|
||||
// Only legacy version, so include things directly
|
||||
@@ -141,7 +141,7 @@ var transform_html = function (legacy_scripts, only_legacy) {
|
||||
});
|
||||
}
|
||||
|
||||
var make_lib_files = function (import_format, source_maps, with_app_dir, only_legacy) {
|
||||
const make_lib_files = function (import_format, source_maps, with_app_dir, only_legacy) {
|
||||
if (!import_format) {
|
||||
throw new Error("you must specify an import format to generate compiled noVNC libraries");
|
||||
} else if (!SUPPORTED_FORMATS.has(import_format)) {
|
||||
@@ -161,8 +161,8 @@ var make_lib_files = function (import_format, source_maps, with_app_dir, only_le
|
||||
only_legacy = true;
|
||||
}
|
||||
|
||||
var in_path;
|
||||
var out_path_base;
|
||||
let in_path;
|
||||
let out_path_base;
|
||||
if (with_app_dir) {
|
||||
out_path_base = paths.out_dir_base;
|
||||
in_path = paths.main;
|
||||
@@ -178,7 +178,7 @@ var make_lib_files = function (import_format, source_maps, with_app_dir, only_le
|
||||
|
||||
const outFiles = [];
|
||||
|
||||
var handleDir = (js_only, vendor_rewrite, in_path_base, filename) => Promise.resolve()
|
||||
const handleDir = (js_only, vendor_rewrite, in_path_base, filename) => Promise.resolve()
|
||||
.then(() => {
|
||||
if (no_copy_files.has(filename)) return;
|
||||
|
||||
@@ -225,7 +225,8 @@ var make_lib_files = function (import_format, source_maps, with_app_dir, only_le
|
||||
return babelTransformFile(filename, opts)
|
||||
.then(res => {
|
||||
console.log(`Writing ${legacy_path}`);
|
||||
var {code, map} = res;
|
||||
const {map} = res;
|
||||
let {code} = res;
|
||||
if (source_maps === true) {
|
||||
// append URL for external source map
|
||||
code += `\n//# sourceMappingURL=${path.basename(legacy_path)}.map\n`;
|
||||
@@ -249,19 +250,19 @@ var make_lib_files = function (import_format, source_maps, with_app_dir, only_le
|
||||
|
||||
Promise.resolve()
|
||||
.then(() => {
|
||||
let handler = handleDir.bind(null, true, false, in_path || paths.main);
|
||||
let filter = (filename, stats) => !no_copy_files.has(filename);
|
||||
const handler = handleDir.bind(null, true, false, in_path || paths.main);
|
||||
const filter = (filename, stats) => !no_copy_files.has(filename);
|
||||
return walkDir(paths.vendor, handler, filter);
|
||||
})
|
||||
.then(() => {
|
||||
let handler = handleDir.bind(null, true, !in_path, in_path || paths.core);
|
||||
let filter = (filename, stats) => !no_copy_files.has(filename);
|
||||
const handler = handleDir.bind(null, true, !in_path, in_path || paths.core);
|
||||
const filter = (filename, stats) => !no_copy_files.has(filename);
|
||||
return walkDir(paths.core, handler, filter);
|
||||
})
|
||||
.then(() => {
|
||||
if (!with_app_dir) return;
|
||||
let handler = handleDir.bind(null, false, false, in_path);
|
||||
let filter = (filename, stats) => !no_copy_files.has(filename);
|
||||
const handler = handleDir.bind(null, false, false, in_path);
|
||||
const filter = (filename, stats) => !no_copy_files.has(filename);
|
||||
return walkDir(paths.app, handler, filter);
|
||||
})
|
||||
.then(() => {
|
||||
@@ -275,8 +276,8 @@ var make_lib_files = function (import_format, source_maps, with_app_dir, only_le
|
||||
console.log(`Writing ${out_app_path}`);
|
||||
return helper.appWriter(out_path_base, legacy_path_base, out_app_path)
|
||||
.then(extra_scripts => {
|
||||
let rel_app_path = path.relative(out_path_base, out_app_path);
|
||||
let legacy_scripts = extra_scripts.concat([rel_app_path]);
|
||||
const rel_app_path = path.relative(out_path_base, out_app_path);
|
||||
const legacy_scripts = extra_scripts.concat([rel_app_path]);
|
||||
transform_html(legacy_scripts, only_legacy);
|
||||
})
|
||||
.then(() => {
|
||||
@@ -287,7 +288,7 @@ var make_lib_files = function (import_format, source_maps, with_app_dir, only_le
|
||||
.then(() => {
|
||||
// Try to clean up any empty directories if this
|
||||
// was the last file in there
|
||||
let rmdir_r = dir => {
|
||||
const rmdir_r = dir => {
|
||||
return rmdir(dir)
|
||||
.then(() => rmdir_r(path.dirname(dir)))
|
||||
.catch(() => {
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
// writes helpers require for vnc.html (they should output app.js)
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
// util.promisify requires Node.js 8.x, so we have our own
|
||||
function promisify(original) {
|
||||
return function () {
|
||||
let obj = this;
|
||||
let args = Array.prototype.slice.call(arguments);
|
||||
const obj = this;
|
||||
const args = Array.prototype.slice.call(arguments);
|
||||
return new Promise((resolve, reject) => {
|
||||
original.apply(obj, args.concat((err, value) => {
|
||||
if (err) return reject(err);
|
||||
@@ -22,12 +22,12 @@ module.exports = {
|
||||
'amd': {
|
||||
appWriter: (base_out_path, script_base_path, out_path) => {
|
||||
// setup for requirejs
|
||||
let ui_path = path.relative(base_out_path,
|
||||
const ui_path = path.relative(base_out_path,
|
||||
path.join(script_base_path, 'app', 'ui'));
|
||||
return writeFile(out_path, `requirejs(["${ui_path}"], function (ui) {});`)
|
||||
.then(() => {
|
||||
console.log(`Please place RequireJS in ${path.join(script_base_path, 'require.js')}`);
|
||||
let require_path = path.relative(base_out_path,
|
||||
const require_path = path.relative(base_out_path,
|
||||
path.join(script_base_path, 'require.js'))
|
||||
return [ require_path ];
|
||||
});
|
||||
@@ -40,8 +40,8 @@ module.exports = {
|
||||
opts.plugins.unshift("add-module-exports");
|
||||
},
|
||||
appWriter: (base_out_path, script_base_path, out_path) => {
|
||||
var browserify = require('browserify');
|
||||
var b = browserify(path.join(script_base_path, 'app/ui.js'), {});
|
||||
const browserify = require('browserify');
|
||||
const b = browserify(path.join(script_base_path, 'app/ui.js'), {});
|
||||
return promisify(b.bundle).call(b)
|
||||
.then((buf) => writeFile(out_path, buf))
|
||||
.then(() => []);
|
||||
@@ -51,15 +51,15 @@ module.exports = {
|
||||
},
|
||||
'systemjs': {
|
||||
appWriter: (base_out_path, script_base_path, out_path) => {
|
||||
let ui_path = path.relative(base_out_path,
|
||||
const ui_path = path.relative(base_out_path,
|
||||
path.join(script_base_path, 'app', 'ui.js'));
|
||||
return writeFile(out_path, `SystemJS.import("${ui_path}");`)
|
||||
.then(() => {
|
||||
console.log(`Please place SystemJS in ${path.join(script_base_path, 'system-production.js')}`);
|
||||
// FIXME: Should probably be in the legacy directory
|
||||
let promise_path = path.relative(base_out_path,
|
||||
const promise_path = path.relative(base_out_path,
|
||||
path.join(base_out_path, 'vendor', 'promise.js'))
|
||||
let systemjs_path = path.relative(base_out_path,
|
||||
const systemjs_path = path.relative(base_out_path,
|
||||
path.join(script_base_path, 'system-production.js'))
|
||||
return [ promise_path, systemjs_path ];
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user