Last commit july 5th

This commit is contained in:
2024-07-05 13:46:23 +02:00
parent dad0d86e8c
commit b0e4dfbb76
24982 changed files with 2621219 additions and 413 deletions

234
spa/node_modules/cordova-serve/src/browser.js generated vendored Normal file
View File

@@ -0,0 +1,234 @@
/**
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
/* globals Promise: true */
const child_process = require('child_process');
const fs = require('fs');
const open = require('open');
const which = require('which');
const exec = require('./exec');
const NOT_INSTALLED = 'The browser target is not installed: %target%';
const NOT_SUPPORTED = 'The browser target is not supported: %target%';
/**
* Launches the specified browser with the given URL.
* Based on https://github.com/domenic/opener
* @param {{target: ?string, url: ?string, dataDir: ?string}} opts - parameters:
* target - the target browser - ie, chrome, safari, opera, firefox or chromium
* url - the url to open in the browser
* dataDir - a data dir to provide to Chrome (can be used to force it to open in a new window)
* @return {Promise} Promise to launch the specified browser
*/
module.exports = function (opts) {
opts = opts || {};
let target = opts.target || 'default';
const url = opts.url || '';
target = target.toLowerCase();
if (target === 'default') {
open(url);
return Promise.resolve();
} else {
return getBrowser(target, opts.dataDir).then(browser => {
let args;
let urlAdded = false;
switch (process.platform) {
case 'darwin':
args = ['open'];
if (target === 'chrome') {
// Chrome needs to be launched in a new window. Other browsers, particularly, opera does not work with this.
args.push('-n');
}
args.push('-a', browser);
break;
case 'win32':
// On Windows, we really want to use the "start" command. But, the rules regarding arguments with spaces, and
// escaping them with quotes, can get really arcane. So the easiest way to deal with this is to pass off the
// responsibility to "cmd /c", which has that logic built in.
//
// Furthermore, if "cmd /c" double-quoted the first parameter, then "start" will interpret it as a window title,
// so we need to add a dummy empty-string window title: http://stackoverflow.com/a/154090/3191
if (target === 'edge') {
browser += `:${url}`;
urlAdded = true;
}
args = ['cmd /c start ""', browser];
break;
case 'linux':
// if a browser is specified, launch it with the url as argument
// otherwise, use xdg-open.
args = [browser];
break;
}
if (!urlAdded) {
args.push(url);
}
const command = args.join(' ');
const result = exec(command);
result.catch(() => {
// Assume any error means that the browser is not installed and display that as a more friendly error.
throw new Error(NOT_INSTALLED.replace('%target%', target));
});
return result;
// return exec(command).catch(function (error) {
// // Assume any error means that the browser is not installed and display that as a more friendly error.
// throw new Error(NOT_INSTALLED.replace('%target%', target));
// });
});
}
};
function getBrowser (target, dataDir) {
dataDir = dataDir || 'temp_chrome_user_data_dir_for_cordova';
const chromeArgs = ` --user-data-dir=/tmp/${dataDir}`;
const browsers = {
win32: {
ie: 'iexplore',
chrome: `chrome --user-data-dir=%TEMP%\\${dataDir}`,
safari: 'safari',
opera: 'opera',
firefox: 'firefox',
edge: 'microsoft-edge'
},
darwin: {
chrome: `"Google Chrome" --args${chromeArgs}`,
safari: 'safari',
firefox: 'firefox',
opera: 'opera'
},
linux: {
chrome: `google-chrome${chromeArgs}`,
chromium: `chromium-browser${chromeArgs}`,
firefox: 'firefox',
opera: 'opera'
}
};
if (target in browsers[process.platform]) {
const browser = browsers[process.platform][target];
return checkBrowserExistsWindows(browser, target).then(() => browser);
} else {
return Promise.reject(NOT_SUPPORTED.replace('%target%', target));
}
}
// err might be null, in which case defaultMsg is used.
// target MUST be defined or an error is thrown.
function getErrorMessage (err, target, defaultMsg) {
let errMessage;
if (err) {
errMessage = err.toString();
} else {
errMessage = defaultMsg;
}
return errMessage.replace('%target%', target);
}
function checkBrowserExistsWindows (browser, target) {
const promise = new Promise((resolve, reject) => {
// Windows displays a dialog if the browser is not installed. We'd prefer to avoid that.
if (process.platform === 'win32') {
if (target === 'edge') {
edgeSupported().then(() => {
resolve();
})
.catch(err => {
const errMessage = getErrorMessage(err, target, NOT_INSTALLED);
reject(errMessage);
});
} else {
browserInstalled(browser).then(() => {
resolve();
})
.catch(err => {
const errMessage = getErrorMessage(err, target, NOT_INSTALLED);
reject(errMessage);
});
}
} else {
resolve();
}
});
return promise;
}
function edgeSupported () {
const prom = new Promise((resolve, reject) => {
child_process.exec('ver', (err, stdout, stderr) => {
if (err || stderr) {
reject(err || stderr);
} else {
const windowsVersion = stdout.match(/([0-9.])+/g)[0];
if (parseInt(windowsVersion) < 10) {
reject(new Error('The browser target is not supported on this version of Windows: %target%'));
} else {
resolve();
}
}
});
});
return prom;
}
const regItemPattern = /\s*\([^)]+\)\s+(REG_SZ)\s+([^\s].*)\s*/;
function browserInstalled (browser) {
// On Windows, the 'start' command searches the path then 'App Paths' in the registry.
// We do the same here. Note that the start command uses the PATHEXT environment variable
// for the list of extensions to use if no extension is provided. We simplify that to just '.EXE'
// since that is what all the supported browsers use. Check path (simple but usually won't get a hit)
const promise = new Promise((resolve, reject) => {
if (which.sync(browser, { nothrow: true })) {
return resolve();
} else {
const regQPre = 'reg QUERY "HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\';
const regQPost = '.EXE" /v ""';
const regQuery = regQPre + browser.split(' ')[0] + regQPost;
child_process.exec(regQuery, (err, stdout, stderr) => {
if (err) {
// The registry key does not exist, which just means the app is not installed.
reject(err);
} else {
const result = regItemPattern.exec(stdout);
if (fs.existsSync(trimRegPath(result[2]))) {
resolve();
} else {
// The default value is not a file that exists, which means the app is not installed.
reject(new Error(NOT_INSTALLED));
}
}
});
}
});
return promise;
}
function trimRegPath (path) {
// Trim quotes and whitespace
return path.replace(/^[\s"]+|[\s"]+$/g, '');
}

53
spa/node_modules/cordova-serve/src/exec.js generated vendored Normal file
View File

@@ -0,0 +1,53 @@
/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
/* globals Promise: true */
const child_process = require('child_process');
/**
* Executes the command specified.
* @param {string} cmd Command to execute
* @param {[string]} opt_cwd Current working directory
* @return {Promise} a promise that either resolves with the stdout, or rejects with an error message and the stderr.
*/
module.exports = function (cmd, opt_cwd) {
return new Promise((resolve, reject) => {
try {
const opt = { cwd: opt_cwd, maxBuffer: 1024000 };
let timerID = 0;
if (process.platform === 'linux') {
timerID = setTimeout(() => {
resolve('linux-timeout');
}, 5000);
}
child_process.exec(cmd, opt, (err, stdout, stderr) => {
clearTimeout(timerID);
if (err) {
reject(new Error(`Error executing "${cmd}": ${stderr}`));
} else {
resolve(stdout);
}
});
} catch (e) {
console.error(`error caught: ${e}`);
reject(e);
}
});
};

57
spa/node_modules/cordova-serve/src/main.js generated vendored Normal file
View File

@@ -0,0 +1,57 @@
/**
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
'License'); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
const chalk = require('chalk');
const compression = require('compression');
const express = require('express');
module.exports = function () {
return new CordovaServe();
};
function CordovaServe () {
this.app = express();
// Attach this before anything else to provide status output
this.app.use((req, res, next) => {
res.on('finish', function () {
const color = this.statusCode === 404 ? chalk.red : chalk.green;
let msg = `${color(this.statusCode)} ${this.req.originalUrl}`;
const encoding = this.getHeader('content-encoding');
if (encoding) {
msg += chalk.gray(` (${encoding})`);
}
require('./server').log(msg);
});
next();
});
// Turn on compression
this.app.use(compression());
this.servePlatform = require('./platform');
this.launchServer = require('./server');
this.launchBrowser = require('./browser');
}
module.exports.launchBrowser = require('./browser');
// Expose some useful express statics
module.exports.Router = express.Router;
module.exports.static = express.static;

66
spa/node_modules/cordova-serve/src/platform.js generated vendored Normal file
View File

@@ -0,0 +1,66 @@
/**
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
/* globals Promise: true */
const fs = require('fs');
const util = require('./util');
/**
* Launches a server where the root points to the specified platform in a Cordova project.
* @param {string} platform - Cordova platform to serve.
* @param {{root: ?string, port: ?number, urlPathProcessor: ?function, streamHandler: ?function, serverExtender: ?function}} opts
* root - cordova project directory, or any directory within it. If not specified, cwd is used. This will be modified to point to the platform's www_dir.
* All other values are passed unaltered to launchServer().
* @returns {*|promise}
*/
module.exports = function (platform, opts) {
// note: `this` is actually an instance of main.js CordovaServe
// this module is a mixin
const that = this;
const retPromise = new Promise((resolve, reject) => {
if (!platform) {
reject(new Error('Error: A platform must be specified'));
} else {
opts = opts || {};
const projectRoot = findProjectRoot(opts.root);
that.projectRoot = projectRoot;
opts.root = util.getPlatformWwwRoot(projectRoot, platform);
if (!fs.existsSync(opts.root)) {
reject(new Error(`Error: Project does not include the specified platform: ${platform}`));
} else {
return resolve(that.launchServer(opts));
}
}
});
return retPromise;
};
function findProjectRoot (path) {
const projectRoot = util.cordovaProjectRoot(path);
if (!projectRoot) {
if (!path) {
throw new Error('Current directory does not appear to be in a Cordova project.');
} else {
throw new Error(`Directory "${path}" does not appear to be in a Cordova project.`);
}
}
return projectRoot;
}

85
spa/node_modules/cordova-serve/src/server.js generated vendored Normal file
View File

@@ -0,0 +1,85 @@
/**
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
/* globals Promise: true */
const chalk = require('chalk');
const express = require('express');
/**
* @desc Launches a server with the specified options and optional custom handlers.
* @param {{root: ?string, port: ?number, noLogOutput: ?bool, noServerInfo: ?bool, router: ?express.Router, events: EventEmitter}} opts
* @returns {*|promise}
*/
module.exports = function (opts) {
const that = this;
const promise = new Promise((resolve, reject) => {
opts = opts || {};
let port = opts.port || 8000;
const log = module.exports.log = msg => {
if (!opts.noLogOutput) {
if (opts.events) {
opts.events.emit('log', msg);
} else {
console.log(msg);
}
}
};
const app = that.app;
const server = require('http').Server(app);
that.server = server;
if (opts.router) {
app.use(opts.router);
}
if (opts.root) {
that.root = opts.root;
app.use(express.static(opts.root));
}
// If we have a project root, make that available as a static root also. This can be useful in cases where source
// files that have been transpiled (such as TypeScript) are located under the project root on a path that mirrors
// the the transpiled file's path under the platform root and is pointed to by a map file.
if (that.projectRoot) {
app.use(express.static(that.projectRoot));
}
const listener = server.listen(port);
listener.on('listening', () => {
that.port = port;
const message = `Static file server running on: ${chalk.green(`http://localhost:${port}`)} (CTRL + C to shut down)`;
if (!opts.noServerInfo) {
log(message);
}
resolve(message);
});
listener.on('error', e => {
if (e && e.toString().indexOf('EADDRINUSE') > -1) {
port++;
server.listen(port);
} else {
reject(e);
}
});
});
return promise;
};

112
spa/node_modules/cordova-serve/src/util.js generated vendored Normal file
View File

@@ -0,0 +1,112 @@
/**
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
const fs = require('fs');
const path = require('path');
// Some helpful utility stuff copied from cordova-lib. This is a bit nicer than taking a dependency on cordova-lib just
// to get this minimal stuff. Hopefully we won't need the platform stuff (finding platform www_dir) once it is moved
// into the actual platform.
const platforms = {
amazon_fireos: { www_dir: 'assets/www' },
android: { www_dir: 'assets/www' },
blackberry10: { www_dir: 'www' },
browser: { www_dir: 'www' },
firefoxos: { www_dir: 'www' },
ios: { www_dir: 'www' },
ubuntu: { www_dir: 'www' },
windows: { www_dir: 'www' },
wp8: { www_dir: 'www' }
};
/**
* @desc Look for a Cordova project's root directory, starting at the specified directory (or CWD if none specified).
* @param {string=} dir - the directory to start from (we check this directory then work up), or CWD if none specified.
* @returns {string} - the Cordova project's root directory, or null if not found.
*/
function cordovaProjectRoot (dir) {
if (!dir) {
// Prefer PWD over cwd so that symlinked dirs within your PWD work correctly.
const pwd = process.env.PWD;
const cwd = process.cwd();
if (pwd && pwd !== cwd && pwd !== 'undefined') {
return cordovaProjectRoot(pwd) || cordovaProjectRoot(cwd);
}
return cordovaProjectRoot(cwd);
}
let bestReturnValueSoFar = null;
for (let i = 0; i < 1000; ++i) {
const result = isRootDir(dir);
if (result === 2) {
return dir;
}
if (result === 1) {
bestReturnValueSoFar = dir;
}
const parentDir = path.normalize(path.join(dir, '..'));
// Detect fs root.
if (parentDir === dir) {
return bestReturnValueSoFar;
}
dir = parentDir;
}
return null;
}
function getPlatformWwwRoot (cordovaProjectRoot, platformName) {
const platform = platforms[platformName];
if (!platform) {
throw new Error(`Unrecognized platform: ${platformName}`);
}
try {
const platformRootFolder = path.join(cordovaProjectRoot, 'platforms', platformName);
const Api = require(path.join(platformRootFolder, 'cordova/Api'));
return new Api(platformName, platformRootFolder).locations.www;
} catch (e) {
// Fallback on hardcoded paths if platform api not found
return path.join(cordovaProjectRoot, 'platforms', platformName, platform.www_dir);
}
}
function isRootDir (dir) {
if (fs.existsSync(path.join(dir, 'www'))) {
if (fs.existsSync(path.join(dir, 'config.xml'))) {
// For sure is.
if (fs.existsSync(path.join(dir, 'platforms'))) {
return 2;
} else {
return 1;
}
}
// Might be (or may be under platforms/).
if (fs.existsSync(path.join(dir, 'www', 'config.xml'))) {
return 1;
}
}
return 0;
}
module.exports = {
cordovaProjectRoot,
getPlatformWwwRoot,
platforms
};