Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support previewing with LWC Dev Server and LWR Server #78

Merged
merged 5 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 22 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@salesforce/lwc-dev-mobile-core",
"description": "Core module supporting Salesforce CLI mobile extension plug-ins",
"version": "3.2.1",
"version": "3.3.0",
"author": {
"name": "Meisam Seyed Aliroteh",
"email": "[email protected]",
Expand Down Expand Up @@ -31,40 +31,39 @@
],
"bugs": "https://github.com/forcedotcom/lwc-dev-mobile-core/issues",
"dependencies": {
"@oclif/core": "^2.11.8",
"@oclif/plugin-version": "^1.3.8",
"@salesforce/sf-plugins-core": "^3.1.15",
"@salesforce/core": "^5.2.1",
"@oclif/core": "^3.8.0",
"@oclif/plugin-version": "^2.0.3",
"@salesforce/core": "^5.3.12",
"@salesforce/sf-plugins-core": "^4.0.0",
"ajv": "^8.12.0",
"chalk": "^4.1.2",
"enquirer": "^2.4.1",
"listr2": "^6.6.1"
"listr2": "^7.0.2"
},
"devDependencies": {
"@types/inquirer": "^9.0.3",
"@types/jest": "^29.5.3",
"@types/node": "^20.5.0",
"@types/sinon": "^10.0.16",
"@typescript-eslint/eslint-plugin": "^6.4.0",
"@typescript-eslint/parser": "^6.4.0",
"eslint": "^8.47.0",
"@types/inquirer": "^9.0.6",
"@types/jest": "^29.5.6",
"@types/node": "^20.8.9",
"@types/sinon": "^10.0.20",
"@typescript-eslint/eslint-plugin": "^6.9.0",
"@typescript-eslint/parser": "^6.9.0",
"eslint": "^8.52.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-import": "^2.28.0",
"eslint-plugin-jsdoc": "^46.4.6",
"eslint-plugin-import": "^2.29.0",
"eslint-plugin-jsdoc": "^46.8.2",
"eslint-plugin-prefer-arrow": "^1.2.3",
"eslint-plugin-prettier": "^5.0.0",
"eslint-plugin-prettier": "^5.0.1",
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-unicorn": "^48.0.1",
"husky": "^8.0.3",
"jest": "^29.6.2",
"jest": "^29.7.0",
"jest-chain": "^1.1.6",
"jest-extended": "^4.0.1",
"jest-extended": "^4.0.2",
"jest-junit": "^16.0.0",
"lint-staged": "^14.0.0",
"oclif": "^3.11.3",
"prettier": "^3.0.2",
"lint-staged": "^15.0.2",
"oclif": "^4.0.3",
"prettier": "^3.0.3",
"ts-jest": "^29.1.1",
"typescript": "^5.1.6"
"typescript": "^5.2.2"
},
"engines": {
"node": ">=18"
Expand Down
19 changes: 14 additions & 5 deletions src/common/AndroidLauncher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,16 @@ export class AndroidLauncher {
* @param targetApp The bundle ID of the app to be launched.
* @param appConfig An AndroidAppPreviewConfig object containing app configuration info.
* @param serverPort The port for local dev server.
* @param targetingLwrServer Indicates whether we're previewing using LWC Dev Server (default behavior) or LWR Server.
*/
public async launchPreview(
compName: string,
projectDir: string,
appBundlePath: string | undefined,
targetApp: string,
appConfig: AndroidAppPreviewConfig | undefined,
serverPort: string
serverPort: string,
targetingLwrServer: boolean = false
): Promise<void> {
const preferredPack =
await AndroidUtils.fetchSupportedEmulatorImagePackage();
Expand Down Expand Up @@ -103,17 +105,24 @@ export class AndroidLauncher {
const port = useServer ? serverPort : undefined;

if (PreviewUtils.isTargetingBrowser(targetApp)) {
const compPath = PreviewUtils.prefixRouteIfNeeded(compName);
const url = `${address}:${port}/lwc/preview/${compPath}`;
CommonUtils.stopCliAction(
let url = '';
if (targetingLwrServer) {
url = `${address}:${port}`;
} else {
const compPath =
PreviewUtils.prefixRouteIfNeeded(compName);
url = `${address}:${port}/lwc/preview/${compPath}`;
}

CommonUtils.updateCliAction(
util.format(
messages.getMessage('launchBrowserStatus'),
url
)
);
return AndroidUtils.launchURLIntent(url, emulatorPort);
} else {
CommonUtils.stopCliAction(
CommonUtils.updateCliAction(
util.format(
messages.getMessage('launchAppStatus'),
targetApp
Expand Down
19 changes: 14 additions & 5 deletions src/common/IOSLauncher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,16 @@ export class IOSLauncher {
* @param targetApp The bundle ID of the app to be launched.
* @param appConfig An AndroidAppPreviewConfig object containing app configuration info.
* @param serverPort The port for local dev server.
* @param targetingLwrServer Indicates whether we're previewing using LWC Dev Server (default behavior) or LWR Server.
*/
public async launchPreview(
compName: string,
projectDir: string,
appBundlePath: string | undefined,
targetApp: string,
appConfig: IOSAppPreviewConfig | undefined,
serverPort: string
serverPort: string,
targetingLwrServer: boolean = false
): Promise<void> {
const availableDevices: string[] = await IOSUtils.getSupportedDevices();
const supportedRuntimes: string[] =
Expand Down Expand Up @@ -104,17 +106,24 @@ export class IOSLauncher {
const port = useServer ? serverPort : undefined;

if (PreviewUtils.isTargetingBrowser(targetApp)) {
const compPath = PreviewUtils.prefixRouteIfNeeded(compName);
const url = `${address}:${port}/lwc/preview/${compPath}`;
CommonUtils.stopCliAction(
let url = '';
if (targetingLwrServer) {
url = `${address}:${port}`;
} else {
const compPath =
PreviewUtils.prefixRouteIfNeeded(compName);
url = `${address}:${port}/lwc/preview/${compPath}`;
}

CommonUtils.updateCliAction(
util.format(
messages.getMessage('launchBrowserStatus'),
url
)
);
return IOSUtils.launchURLInBootedSimulator(deviceUDID, url);
} else {
CommonUtils.stopCliAction(
CommonUtils.updateCliAction(
util.format(
messages.getMessage('launchAppStatus'),
targetApp
Expand Down
7 changes: 3 additions & 4 deletions src/common/PreviewUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,9 @@ export class PreviewUtils {
): string | undefined {
if (appConfig.get_app_bundle) {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const module = require(path.resolve(
basePath,
appConfig.get_app_bundle
));
const module = require(
path.resolve(basePath, appConfig.get_app_bundle)
);
return module.run();
} else {
return undefined;
Expand Down
2 changes: 1 addition & 1 deletion src/common/Requirements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export class RequirementProcessor {
});
for (const requirement of enabledRequirements) {
subTasks.add({
options: { persistentOutput: true },
rendererOptions: { persistentOutput: true },
task: (_subCtx, subTask): Promise<void> =>
WrappedPromise(requirement).then((result) => {
testResult.tests.push(result);
Expand Down
22 changes: 21 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,24 @@
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
export default {};

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re-exporting everything b/c almost all of them are used in our other projects.

export * from './cli/commands/force/lightning/local/setup';

export * from './common/AndroidEnvironmentRequirements';
export * from './common/AndroidLauncher';
export * from './common/AndroidTypes';
export * from './common/AndroidUtils';
export * from './common/BaseCommand';
export * from './common/Common';
export * from './common/CommonUtils';
export * from './common/IOSEnvironmentRequirements';
export * from './common/IOSLauncher';
export * from './common/IOSTypes';
export * from './common/IOSUtils';
export * from './common/LoggerSetup';
export * from './common/MacNetworkUtils';
export * from './common/PerformanceMarkers';
export * from './common/PlatformConfig';
export * from './common/PreviewConfigFile';
export * from './common/PreviewUtils';
export * from './common/Requirements';
Loading