@vention/vention-cli 0.38.41 → 0.38.42

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/main.esm.js CHANGED
@@ -5267,6 +5267,13 @@ const getExecutionState = async (connection, applicationId) => await fetchJson(l
5267
5267
  }, connection.headers),
5268
5268
  fetchImpl: connection.fetch
5269
5269
  });
5270
+ const startApplication = async (connection, applicationId) => await fetchJson(launcherUrl(connection, applicationId, "start"), {
5271
+ method: "POST",
5272
+ headers: Object.assign({
5273
+ Accept: "application/json"
5274
+ }, connection.headers),
5275
+ fetchImpl: connection.fetch
5276
+ });
5270
5277
  const stopApplication = async (connection, applicationId) => await fetchJson(launcherUrl(connection, applicationId, "stop"), {
5271
5278
  method: "POST",
5272
5279
  headers: Object.assign({
@@ -11246,6 +11253,56 @@ function createOpenCommand() {
11246
11253
  });
11247
11254
  }
11248
11255
 
11256
+ const WATCH_INTERVAL_MS = 500;
11257
+ const WATCH_WINDOW_MS = 10000;
11258
+ const isFailed = ({
11259
+ state,
11260
+ exitCode
11261
+ }) => describeRunState(state) === "error" || exitCode !== undefined && exitCode !== 0;
11262
+ const isSettled = ({
11263
+ state
11264
+ }) => describeRunState(state) !== "playing";
11265
+ const describeExit = ({
11266
+ exitCode
11267
+ }) => exitCode === undefined ? "" : exitCode === null ? "The app was killed. " : `The app exited with code ${exitCode}. `;
11268
+ const createPlayCommand = () => twinRunCommand("play").description("Play the linked app on the design's twin").option("--json", "Print the result as JSON").action(async ({
11269
+ json: _json = false
11270
+ }) => {
11271
+ var _a;
11272
+ let failed = false;
11273
+ try {
11274
+ const session = await loadTwinRunSession("play");
11275
+ const linkedApp = await readLinkedApp();
11276
+ const appTwins = await findAppTwins(session, linkedApp);
11277
+ if (appTwins.length === 0) {
11278
+ exitWithoutTwin(linkedApp.designId);
11279
+ }
11280
+ const toStart = appTwins.filter(({
11281
+ executionState
11282
+ }) => describeRunState(executionState.state) !== "playing");
11283
+ let states = toStart.length === 0 ? [appTwins[0].executionState] : await Promise.all(toStart.map(({
11284
+ connection
11285
+ }) => startApplication(connection, linkedApp.applicationId)));
11286
+ for (let elapsed = 0; toStart.length > 0 && elapsed < WATCH_WINDOW_MS && !states.some(isSettled); elapsed += WATCH_INTERVAL_MS) {
11287
+ await new Promise(resolve => setTimeout(resolve, WATCH_INTERVAL_MS));
11288
+ states = await Promise.all(toStart.map(({
11289
+ connection
11290
+ }) => getExecutionState(connection, linkedApp.applicationId)));
11291
+ }
11292
+ const reported = (_a = states.find(isFailed)) !== null && _a !== void 0 ? _a : states[0];
11293
+ printRunState(linkedApp, reported, _json);
11294
+ failed = isFailed(reported);
11295
+ if (failed) {
11296
+ console.error(chalk.red(`${describeExit(reported)}\`vention logs\` shows why. If it couldn't move, keep the design's MachineBuilder tab open on the MachineLogic page.`));
11297
+ }
11298
+ } catch (error) {
11299
+ handleTwinRunError(error, "Failed to play the app");
11300
+ }
11301
+ if (failed) {
11302
+ process.exit(1);
11303
+ }
11304
+ });
11305
+
11249
11306
  const createStateCommand = () => runStateCommand("state", "Show whether the linked app is playing, stopped or in error on the design's twin", "Failed to read the app's state", async ([appTwin]) => appTwin === null || appTwin === void 0 ? void 0 : appTwin.executionState);
11250
11307
 
11251
11308
  const createStopCommand = () => runStateCommand("stop", "Stop the linked app on the design's twin", "Failed to stop the app", async (appTwins, applicationId) => {
@@ -11321,6 +11378,9 @@ program.addCommand(createSkillsCommand());
11321
11378
  program.addCommand(createOpenCommand(), {
11322
11379
  hidden: true
11323
11380
  });
11381
+ program.addCommand(createPlayCommand(), {
11382
+ hidden: true
11383
+ });
11324
11384
  program.addCommand(createStateCommand(), {
11325
11385
  hidden: true
11326
11386
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vention/vention-cli",
3
- "version": "0.38.41",
3
+ "version": "0.38.42",
4
4
  "description": "CLI tool for Vention applications",
5
5
  "type": "module",
6
6
  "engines": {
@@ -0,0 +1 @@
1
+ export declare const createPlayCommand: () => import("commander").Command;
@@ -32,6 +32,7 @@ export interface ExecutionState {
32
32
  error?: {
33
33
  message: string;
34
34
  };
35
+ exitCode?: number | null;
35
36
  logging?: {
36
37
  logs: LogEntry[];
37
38
  }[] | null;
@@ -43,5 +44,6 @@ export declare const getLibraryAssets: (connection: DigitalTwinConnection) => Pr
43
44
  export declare const getMmConfiguration: (connection: DigitalTwinConnection) => Promise<unknown>;
44
45
  export declare const pushApplicationToDigitalTwin: <T = unknown>(connection: DigitalTwinConnection, application: PushApplicationRequest) => Promise<T>;
45
46
  export declare const getExecutionState: (connection: DigitalTwinConnection, applicationId: string) => Promise<ExecutionState>;
47
+ export declare const startApplication: (connection: DigitalTwinConnection, applicationId: string) => Promise<ExecutionState>;
46
48
  export declare const stopApplication: (connection: DigitalTwinConnection, applicationId: string) => Promise<ExecutionState>;
47
49
  export declare const getApplicationLogs: (connection: DigitalTwinConnection, applicationId: string) => Promise<string>;
@@ -90,4 +90,15 @@ export declare const StopApplication: {
90
90
  readonly Handler: ({ resolver, remoteHost }: HandlerParams<StopApplicationTypes["Resolver"]>, mswOptions?: RequestHandlerOptions) => HttpHandler;
91
91
  readonly SuccessResolver: ({ requestSpy }?: RawRequestSpyOptions) => StopApplicationTypes["Resolver"];
92
92
  };
93
+ export type StartApplicationTypes = {
94
+ Request: never;
95
+ Response: LauncherResponse;
96
+ Resolver: HttpResponseResolver<{
97
+ applicationId: string;
98
+ }, StartApplicationTypes["Request"], StartApplicationTypes["Response"]>;
99
+ };
100
+ export declare const StartApplication: {
101
+ readonly Handler: ({ resolver, remoteHost }: HandlerParams<StartApplicationTypes["Resolver"]>, mswOptions?: RequestHandlerOptions) => HttpHandler;
102
+ readonly SuccessResolver: ({ requestSpy }?: RawRequestSpyOptions) => StartApplicationTypes["Resolver"];
103
+ };
93
104
  export {};