vscode-cordova/test/testUtils.ts

88 строки
2.8 KiB
TypeScript
Исходник Постоянная ссылка Обычный вид История

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for details.
import * as child_process from "child_process";
import * as fs from "fs";
import * as http from "http";
import * as os from "os";
import { CordovaProjectHelper } from "../src/utils/cordovaProjectHelper";
export function executeCordovaCommand(cwd: string, command: string): Promise<any> {
return new Promise((resolve, reject) => {
2022-07-18 11:21:26 +03:00
const cordovaCmd = os.platform() === "win32" ? "cordova.cmd" : "cordova";
const commandToExecute = `${cordovaCmd} ${command}`;
const process = child_process.exec(commandToExecute, { cwd });
let stderr = "";
process.stderr.on("data", (data: Buffer) => {
stderr += data.toString();
});
process.stdout.on("data", (data: Buffer) => {
console.log(data.toString());
});
process.on("error", function (err: any): void {
reject(err);
});
process.on("close", exitCode => {
if (exitCode !== 0) {
return reject(
`Cordova command failed with exit code ${exitCode}. Error: ${stderr}`,
);
}
resolve({});
});
});
}
export function createCordovaProject(cwd: string, projectName: string): Promise<any> {
2022-07-18 11:21:26 +03:00
const cordovaCommandToRun = `create ${projectName}`;
return executeCordovaCommand(cwd, cordovaCommandToRun);
}
export function addCordovaComponents(
componentName: string,
projectRoot: string,
componentsToAdd: string[],
): Promise<any> {
2022-07-18 11:21:26 +03:00
const cordovaCommandToRun = `${componentName} add ${componentsToAdd.join(" ")}`;
return executeCordovaCommand(projectRoot, cordovaCommandToRun);
}
export function removeCordovaComponents(
componentName: string,
projectRoot: string,
componentsToRemove: string[],
): Promise<any> {
2022-07-18 11:21:26 +03:00
const cordovaCommandToRun = `${componentName} remove ${componentsToRemove.join(" ")}`;
return executeCordovaCommand(projectRoot, cordovaCommandToRun);
}
export function enumerateListOfTypeDefinitions(projectRoot: string): string[] {
2022-07-18 11:21:26 +03:00
const typeDefsFolder = CordovaProjectHelper.getCordovaPluginTypeDefsPath(projectRoot);
// look for all the type defs in the typings folder
if (!CordovaProjectHelper.existsSync(typeDefsFolder)) {
return [];
}
2022-07-18 11:21:26 +03:00
return fs.readdirSync(typeDefsFolder);
}
2016-04-19 02:09:13 +03:00
export function isUrlReachable(url: string): Promise<boolean> {
return new Promise((resolve, reject) => {
http.get(url, res => {
resolve(true);
res.resume();
}).on("error", (_err: Error) => {
resolve(false);
});
2016-04-19 02:09:13 +03:00
});
}
js-debug migration (#673) * Prepare for migration to js-debug (#614) * Restore simulate scenarios functionality (#618) * Fix multiroot projects processing (#625) * Improve extension stability (#627) * Implement CDP proxy logger (#635) * Enhance js-debug debugging configuration (#636) * Add CDP message handler to proxy (#640) * Implement Safari CDP message handler (#641) * Improve async functions control (#647) * Implement Cordova Debug Config Provider (#648) * Implement cordova webviews recognition (#649) * Migrate unit tests from vscode to vscode-test package (#650) * Migrate unit tests from vscode to vscode-test package (#645) * Add tools for vscode-nls package support (#651) * Add extension bundling with Webpack (#653) * Add i18n for common and debugger folders (#654) * Add i18n to extension and utils folders (#655) * Externalized package.json strings for further localization (#656) * Add cordova simulate localization according to VS Code language (#657) * Fix minor i18n export issue (#658) * Fix localization import errors (#660) * Commit first version of localized json files (#661) * Ignore i18n file while packaging the extension (#662) * Change parent session stop command (#663) * Fix simulator viewport handling (#664) * Fix breakpoints activation for Cordova on Windows (#665) * ESLint migration (#666) * Add integration tests for Cordova CDP Proxy (#668) * Add unit tests (#669) * Fix iOS 14 debugging (#671) * Add 'livereloadDelay' parameter to attach args (#672) Co-authored-by: Yuri Skorokhodov <v-yuskor@microsoft.com> Co-authored-by: Daniel Ye <danyeh@microsoft.com> Co-authored-by: Mikhail Suendukov <43934531+JiglioNero@users.noreply.github.com>
2020-10-09 17:36:39 +03:00
2022-07-18 11:21:26 +03:00
export function convertWindowsPathToUnixOne(path: string): string {
js-debug migration (#673) * Prepare for migration to js-debug (#614) * Restore simulate scenarios functionality (#618) * Fix multiroot projects processing (#625) * Improve extension stability (#627) * Implement CDP proxy logger (#635) * Enhance js-debug debugging configuration (#636) * Add CDP message handler to proxy (#640) * Implement Safari CDP message handler (#641) * Improve async functions control (#647) * Implement Cordova Debug Config Provider (#648) * Implement cordova webviews recognition (#649) * Migrate unit tests from vscode to vscode-test package (#650) * Migrate unit tests from vscode to vscode-test package (#645) * Add tools for vscode-nls package support (#651) * Add extension bundling with Webpack (#653) * Add i18n for common and debugger folders (#654) * Add i18n to extension and utils folders (#655) * Externalized package.json strings for further localization (#656) * Add cordova simulate localization according to VS Code language (#657) * Fix minor i18n export issue (#658) * Fix localization import errors (#660) * Commit first version of localized json files (#661) * Ignore i18n file while packaging the extension (#662) * Change parent session stop command (#663) * Fix simulator viewport handling (#664) * Fix breakpoints activation for Cordova on Windows (#665) * ESLint migration (#666) * Add integration tests for Cordova CDP Proxy (#668) * Add unit tests (#669) * Fix iOS 14 debugging (#671) * Add 'livereloadDelay' parameter to attach args (#672) Co-authored-by: Yuri Skorokhodov <v-yuskor@microsoft.com> Co-authored-by: Daniel Ye <danyeh@microsoft.com> Co-authored-by: Mikhail Suendukov <43934531+JiglioNero@users.noreply.github.com>
2020-10-09 17:36:39 +03:00
return path.replace(/\\/g, "/");
}