@ms-cloudpack/cli 0.72.12 → 0.72.14
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/lib/commands/bundle/execute.d.ts.map +1 -1
- package/lib/commands/bundle/execute.js +7 -8
- package/lib/commands/bundle/execute.js.map +1 -1
- package/lib/commands/cache/clean.d.ts.map +1 -1
- package/lib/commands/cache/clean.js +6 -11
- package/lib/commands/cache/clean.js.map +1 -1
- package/lib/commands/config/delete.js +4 -4
- package/lib/commands/config/delete.js.map +1 -1
- package/lib/commands/config/get.js +5 -5
- package/lib/commands/config/get.js.map +1 -1
- package/lib/commands/config/list.js +5 -5
- package/lib/commands/config/list.js.map +1 -1
- package/lib/commands/config/set.js +4 -4
- package/lib/commands/config/set.js.map +1 -1
- package/lib/commands/info/lockFile/execute.d.ts.map +1 -1
- package/lib/commands/info/lockFile/execute.js +10 -14
- package/lib/commands/info/lockFile/execute.js.map +1 -1
- package/lib/commands/info/nonSemverDeps/execute.d.ts.map +1 -1
- package/lib/commands/info/nonSemverDeps/execute.js +8 -10
- package/lib/commands/info/nonSemverDeps/execute.js.map +1 -1
- package/lib/commands/init/evaluatePath.d.ts +2 -2
- package/lib/commands/init/evaluatePath.d.ts.map +1 -1
- package/lib/commands/init/evaluatePath.js +2 -2
- package/lib/commands/init/evaluatePath.js.map +1 -1
- package/lib/commands/init/execute.js +4 -4
- package/lib/commands/init/execute.js.map +1 -1
- package/lib/commands/init/init.js +148 -146
- package/lib/commands/init/init.js.map +1 -1
- package/lib/commands/link/execute.d.ts.map +1 -1
- package/lib/commands/link/execute.js +8 -4
- package/lib/commands/link/execute.js.map +1 -1
- package/lib/commands/link/getSessionToLink.d.ts +5 -4
- package/lib/commands/link/getSessionToLink.d.ts.map +1 -1
- package/lib/commands/link/getSessionToLink.js +36 -20
- package/lib/commands/link/getSessionToLink.js.map +1 -1
- package/lib/commands/setup/execute.js +2 -2
- package/lib/commands/setup/execute.js.map +1 -1
- package/lib/commands/start/execute.d.ts.map +1 -1
- package/lib/commands/start/execute.js +37 -21
- package/lib/commands/start/execute.js.map +1 -1
- package/lib/commands/start/getStartingAppPath.d.ts +5 -2
- package/lib/commands/start/getStartingAppPath.d.ts.map +1 -1
- package/lib/commands/start/getStartingAppPath.js +36 -9
- package/lib/commands/start/getStartingAppPath.js.map +1 -1
- package/lib/commands/sync/execute.d.ts.map +1 -1
- package/lib/commands/sync/execute.js +43 -42
- package/lib/commands/sync/execute.js.map +1 -1
- package/lib/commands/unlink/execute.d.ts.map +1 -1
- package/lib/commands/unlink/execute.js +8 -4
- package/lib/commands/unlink/execute.js.map +1 -1
- package/lib/types/CommandAction.d.ts +14 -8
- package/lib/types/CommandAction.d.ts.map +1 -1
- package/lib/types/CommandAction.js.map +1 -1
- package/lib/utilities/CommandExecutor.d.ts +8 -4
- package/lib/utilities/CommandExecutor.d.ts.map +1 -1
- package/lib/utilities/CommandExecutor.js +58 -49
- package/lib/utilities/CommandExecutor.js.map +1 -1
- package/lib/utilities/parseMatch.d.ts.map +1 -1
- package/lib/utilities/parseMatch.js +5 -0
- package/lib/utilities/parseMatch.js.map +1 -1
- package/lib/utilities/runPrerequisites.js +1 -1
- package/lib/utilities/runPrerequisites.js.map +1 -1
- package/package.json +13 -13
- package/lib/commands/link/getSessionFromUser.d.ts +0 -9
- package/lib/commands/link/getSessionFromUser.d.ts.map +0 -1
- package/lib/commands/link/getSessionFromUser.js +0 -26
- package/lib/commands/link/getSessionFromUser.js.map +0 -1
- package/lib/commands/start/createPathToChoiceMap.d.ts +0 -16
- package/lib/commands/start/createPathToChoiceMap.d.ts.map +0 -1
- package/lib/commands/start/createPathToChoiceMap.js +0 -29
- package/lib/commands/start/createPathToChoiceMap.js.map +0 -1
- package/lib/commands/start/getAppPathFromUser.d.ts +0 -9
- package/lib/commands/start/getAppPathFromUser.d.ts.map +0 -1
- package/lib/commands/start/getAppPathFromUser.js +0 -28
- package/lib/commands/start/getAppPathFromUser.js.map +0 -1
- package/lib/commands/start/getMatchingApps.d.ts +0 -9
- package/lib/commands/start/getMatchingApps.d.ts.map +0 -1
- package/lib/commands/start/getMatchingApps.js +0 -10
- package/lib/commands/start/getMatchingApps.js.map +0 -1
- package/lib/performance/registerPerformanceObservers.d.ts +0 -7
- package/lib/performance/registerPerformanceObservers.d.ts.map +0 -1
- package/lib/performance/registerPerformanceObservers.js +0 -20
- package/lib/performance/registerPerformanceObservers.js.map +0 -1
- package/lib/utilities/stopServers.d.ts +0 -13
- package/lib/utilities/stopServers.d.ts.map +0 -1
- package/lib/utilities/stopServers.js +0 -18
- package/lib/utilities/stopServers.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"execute.js","sourceRoot":"","sources":["../../../src/commands/setup/execute.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,+BAA+B,CAAC;AAMtD,oCAAoC;AACpC,MAAM,CAAC,MAAM,OAAO,GAAgC,KAAK,EAAE,MAAM,EAAE,EAAE;IACnE,MAAM,EAAE,GAAG,EAAE,UAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"execute.js","sourceRoot":"","sources":["../../../src/commands/setup/execute.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,+BAA+B,CAAC;AAMtD,oCAAoC;AACpC,MAAM,CAAC,MAAM,OAAO,GAAgC,KAAK,EAAE,MAAM,EAAE,EAAE;IACnE,MAAM,EAAE,GAAG,EAAE,UAAU,EAAE,GAAG,MAAM,CAAC;IACnC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,UAAU,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,CAAC;IACtD,MAAM,EAAE,MAAM,GAAG,EAAE,EAAE,GAAG,MAAM,CAAC;IAC/B,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,CAAC;IAEjC,IAAI,MAAM,IAAI,KAAK,EAAE,CAAC;QACpB,MAAM,KAAK,CAAC;YACV,MAAM;YACN,uBAAuB,EAAE,KAAK,KAAK,IAAI;YACvC,GAAG;SACJ,CAAC,CAAC;IACL,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,iBAAiB,EAAE,CAAC;AACxC,CAAC,CAAC","sourcesContent":["import type { CommandAction } from '../../types/CommandAction.js';\nimport { setup } from '@ms-cloudpack/setup-utilities';\n\nexport interface SetupOptions {\n force?: boolean;\n}\n\n/** Executor for the \"setup\" verb */\nexport const execute: CommandAction<SetupOptions> = async (params) => {\n const { cwd, initialize } = params;\n const { config } = await initialize({ appPath: cwd });\n const { server = {} } = config;\n const { domain, https } = server;\n\n if (domain || https) {\n await setup({\n domain,\n shouldCreateCertificate: https === true,\n cwd,\n });\n }\n\n return { message: 'Setup complete.' };\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"execute.d.ts","sourceRoot":"","sources":["../../../src/commands/start/execute.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAKlE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"execute.d.ts","sourceRoot":"","sources":["../../../src/commands/start/execute.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAKlE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAG5D;;GAEG;AACH,eAAO,MAAM,OAAO,EAAE,aAAa,CAAC,YAAY,CAsH/C,CAAC"}
|
|
@@ -5,22 +5,24 @@ import { makeUrl } from '@ms-cloudpack/path-string-parsing';
|
|
|
5
5
|
import { cyan, yellow, bold } from '@ms-cloudpack/task-reporter';
|
|
6
6
|
import path from 'path';
|
|
7
7
|
import { fileURLToPath } from 'url';
|
|
8
|
-
import { PerfMarkerCliEntry
|
|
8
|
+
import { PerfMarkerCliEntry } from '../../performance/markers.js';
|
|
9
9
|
import { runPrerequisites } from '../../utilities/runPrerequisites.js';
|
|
10
10
|
import { getStartingAppPath } from './getStartingAppPath.js';
|
|
11
11
|
import { openBrowser } from './openBrowser.js';
|
|
12
12
|
import { trackSession } from './trackSession.js';
|
|
13
13
|
import { getCertificate } from '@ms-cloudpack/setup-utilities';
|
|
14
|
-
import { setStopServersFunction } from '../../utilities/stopServers.js';
|
|
15
14
|
/**
|
|
16
15
|
* Defines the "start" verb entry point.
|
|
17
16
|
*/
|
|
18
17
|
export const execute = async (params) => {
|
|
19
|
-
const { options, cwd, initialize, autoDispose
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
const { options, cwd, initialize, autoDispose } = params;
|
|
19
|
+
const appPathResult = await getStartingAppPath(cwd, options.app);
|
|
20
|
+
if (typeof appPathResult !== 'string') {
|
|
21
|
+
return appPathResult;
|
|
22
|
+
}
|
|
23
|
+
const appPath = appPathResult;
|
|
22
24
|
const apiContextOptions = await initialize({ appPath, configOptions: { mode: options.mode } });
|
|
23
|
-
const { config } = apiContextOptions;
|
|
25
|
+
const { config, telemetryClient } = apiContextOptions;
|
|
24
26
|
console.log('App path:', yellow(appPath));
|
|
25
27
|
console.log('Bundle mode:', yellow(options.mode));
|
|
26
28
|
runPrerequisites(apiContextOptions);
|
|
@@ -49,12 +51,11 @@ export const execute = async (params) => {
|
|
|
49
51
|
await writeJson(path.join(appPath, 'resolve-map.json'), session.resolveMap);
|
|
50
52
|
}
|
|
51
53
|
// Start api server for tracking status and handling remote requests.
|
|
52
|
-
const
|
|
53
|
-
if (
|
|
54
|
-
|
|
55
|
-
return;
|
|
54
|
+
const apiServerResult = await createApiServer(options, apiContext);
|
|
55
|
+
if (apiServerResult.hasErrors) {
|
|
56
|
+
return apiServerResult;
|
|
56
57
|
}
|
|
57
|
-
const apiServer =
|
|
58
|
+
const { apiServer } = apiServerResult;
|
|
58
59
|
// Kick off bundling app package as soon as api server is ready.
|
|
59
60
|
void ensurePackageBundled({
|
|
60
61
|
input: { name: definition.name, version: definition.version },
|
|
@@ -88,7 +89,13 @@ export const execute = async (params) => {
|
|
|
88
89
|
};
|
|
89
90
|
autoDispose({ dispose: cleanup });
|
|
90
91
|
const defaultUrl = makeUrl(config.server?.defaultPath || '', session.urls.appServer).href;
|
|
91
|
-
performance.
|
|
92
|
+
const cliEntryMarker = performance.getEntriesByName(PerfMarkerCliEntry, 'mark')[0];
|
|
93
|
+
if (cliEntryMarker) {
|
|
94
|
+
telemetryClient.tracer.startSpan('TIME_TO_OPEN_BROWSER', { startTime: cliEntryMarker.startTime }).end();
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
throw new Error('TIME_TO_OPEN_BROWSER marker not found');
|
|
98
|
+
}
|
|
92
99
|
// Open the browser.
|
|
93
100
|
if (options.open !== false) {
|
|
94
101
|
openBrowser(defaultUrl).catch((err) => {
|
|
@@ -100,6 +107,7 @@ export const execute = async (params) => {
|
|
|
100
107
|
else {
|
|
101
108
|
console.log('Please open the browser manually to:', defaultUrl);
|
|
102
109
|
}
|
|
110
|
+
return null; // the command should keep running
|
|
103
111
|
};
|
|
104
112
|
/**
|
|
105
113
|
* Create the API server, or return an error message if the server could not be created.
|
|
@@ -110,22 +118,30 @@ async function createApiServer(options, apiContext) {
|
|
|
110
118
|
const { server, appPath } = config;
|
|
111
119
|
// If a cert is needed, check that it exists.
|
|
112
120
|
if (server?.https === true && !(await getCertificate({ domain: server?.domain, cwd: appPath }))) {
|
|
113
|
-
return
|
|
114
|
-
|
|
121
|
+
return {
|
|
122
|
+
hasErrors: true,
|
|
123
|
+
message: `The local site is configured to use https in cloudpack.config.json, but is missing a cert.\n\n` +
|
|
124
|
+
`Run "${cyan(bold('cloudpack setup'))}" to create the required certificate and try start again.\n`,
|
|
125
|
+
};
|
|
115
126
|
}
|
|
116
127
|
const { createCloudpackServer } = await import('@ms-cloudpack/api-server');
|
|
117
128
|
try {
|
|
118
|
-
|
|
129
|
+
const apiServer = await createCloudpackServer({ port: options.apiServerPort }, apiContext);
|
|
130
|
+
return { hasErrors: false, apiServer };
|
|
119
131
|
}
|
|
120
132
|
catch (err) {
|
|
121
|
-
|
|
122
|
-
if (
|
|
133
|
+
let message;
|
|
134
|
+
if (err.code === 'EADDRNOTAVAIL' && server?.domain) {
|
|
123
135
|
const primaryDomain = (Array.isArray(server.domain) ? server.domain : [server.domain])[0];
|
|
124
|
-
|
|
125
|
-
`
|
|
126
|
-
|
|
136
|
+
message =
|
|
137
|
+
`The domain "${cyan(bold(primaryDomain))}" in cloudpack.config.json is not resolvable.\n\n` +
|
|
138
|
+
`Run "${cyan(bold('cloudpack setup'))}" to add the appropriate entries to your hosts file and ` +
|
|
139
|
+
`try start again.\n`;
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
message = `Error creating API server: ${err.stack || err}`;
|
|
127
143
|
}
|
|
128
|
-
return
|
|
144
|
+
return { hasErrors: true, message };
|
|
129
145
|
}
|
|
130
146
|
}
|
|
131
147
|
// cspell:ignore Prereqs
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"execute.js","sourceRoot":"","sources":["../../../src/commands/start/execute.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EACvB,oBAAoB,GAGrB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAC;AAC7E,OAAO,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAC;AAC5D,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,EAAE,kBAAkB,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAE9F,OAAO,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AACvE,OA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B,CAAC,CAAC,6DAA6D,CACnG,CAAC;IACJ,CAAC;IAED,MAAM,EAAE,qBAAqB,EAAE,GAAG,MAAM,MAAM,CAAC,0BAA0B,CAAC,CAAC;IAE3E,IAAI,CAAC;QACH,OAAO,MAAM,qBAAqB,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,aAAa,EAAE,EAAE,UAAU,CAAC,CAAC;IAClF,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,KAAK,GAAG,GAAuB,CAAC;QAEtC,IAAI,KAAK,CAAC,IAAI,KAAK,eAAe,IAAI,MAAM,EAAE,MAAM,EAAE,CAAC;YACrD,MAAM,aAAa,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAE1F,OAAO,CACL,eAAe,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,mDAAmD;gBAC3F,QAAQ,IAAI,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,0DAA0D;gBAC/F,oBAAoB,CACrB,CAAC;QACJ,CAAC;QAED,OAAO,8BAA+B,GAAa,CAAC,KAAK,IAAI,GAAG,EAAE,CAAC;IACrE,CAAC;AACH,CAAC;AAED,wBAAwB","sourcesContent":["import {\n createPartialApiContext,\n ensurePackageBundled,\n type CloudpackServer,\n type Context,\n} from '@ms-cloudpack/api-server';\nimport { writeJson } from '@ms-cloudpack/json-utilities';\nimport { isExternalPackage, resolve } from '@ms-cloudpack/package-utilities';\nimport { makeUrl } from '@ms-cloudpack/path-string-parsing';\nimport { cyan, yellow, bold } from '@ms-cloudpack/task-reporter';\nimport path from 'path';\nimport { fileURLToPath } from 'url';\nimport { PerfMarkerCliEntry, PerfMeasurementOpenBrowser } from '../../performance/markers.js';\nimport type { CommandAction } from '../../types/CommandAction.js';\nimport { runPrerequisites } from '../../utilities/runPrerequisites.js';\nimport { getStartingAppPath } from './getStartingAppPath.js';\nimport { openBrowser } from './openBrowser.js';\nimport { trackSession } from './trackSession.js';\nimport type { StartOptions } from './types/StartOptions.js';\nimport { getCertificate } from '@ms-cloudpack/setup-utilities';\nimport { setStopServersFunction } from '../../utilities/stopServers.js';\n\n/**\n * Defines the \"start\" verb entry point.\n */\nexport const execute: CommandAction<StartOptions> = async (params) => {\n const { options, cwd, initialize, autoDispose, exit } = params;\n setStopServersFunction(exit);\n\n const appPath = await getStartingAppPath(cwd, options.app);\n const apiContextOptions = await initialize({ appPath, configOptions: { mode: options.mode } });\n const { config } = apiContextOptions;\n\n console.log('App path:', yellow(appPath));\n console.log('Bundle mode:', yellow(options.mode));\n\n runPrerequisites(apiContextOptions);\n\n const currentDir = path.dirname(fileURLToPath(import.meta.url));\n let overlayPath = await resolve('@ms-cloudpack/overlay', currentDir);\n\n // If overlay is an internal package, resolve the overlay from the current package's linked node modules\n // to \"externalize\" it, so that we always use the bundled version of the overlay instead of the source.\n if (overlayPath && !isExternalPackage(overlayPath)) {\n const cliPath = await resolve('@ms-cloudpack/cli', currentDir);\n overlayPath = cliPath ? path.join(cliPath, 'node_modules', '@ms-cloudpack/overlay') : undefined;\n }\n\n const [apiContext] = autoDispose(\n await createPartialApiContext({\n ...apiContextOptions,\n items: ['bus', 'watcher', 'taskRunner', 'packages', 'session', 'packageImportPaths', 'packageHashes'],\n overlayPath,\n }),\n );\n const { packages, session } = apiContext;\n\n // Increment the session version if caching is disabled.\n if (options.cache === false) {\n session.incrementSessionVersion();\n }\n\n // Make sure the package has a valid definition.\n const definition = await packages.get(appPath);\n\n if (options.logResolveMap) {\n // Write the resolve map to disk.\n await writeJson(path.join(appPath, 'resolve-map.json'), session.resolveMap);\n }\n\n // Start api server for tracking status and handling remote requests.\n const serverOrError = await createApiServer(options, apiContext);\n if (typeof serverOrError === 'string') {\n await exit({ exitCode: 1, message: serverOrError });\n return;\n }\n const apiServer = serverOrError;\n\n // Kick off bundling app package as soon as api server is ready.\n void ensurePackageBundled({\n input: { name: definition.name, version: definition.version },\n ctx: apiContext,\n });\n\n // Then start bundle and app servers for hosting the app.\n const { startServers } = await import('@ms-cloudpack/app-server');\n const servers = await startServers(\n {\n definition,\n bundleServerOptions: { disableCache: !options.cache, port: options.bundleServerPort },\n port: options.appServerPort,\n },\n apiContext,\n );\n\n // Save the session to active sessions.\n const sessionTracker = await trackSession(session);\n\n const cleanup = async () => {\n // Stop tracking the session.\n await sessionTracker.close();\n\n await Promise.all(\n Object.entries({ apiServer, ...servers }).map(async ([name, server]) => {\n if (!server) return;\n\n const desc = `${name} (${server.url})`;\n console.info(`Closing ${desc}`);\n try {\n await server.close();\n console.info(`Closed ${desc}`);\n } catch (err) {\n console.warn(`Error closing ${desc}:`, err);\n }\n }),\n );\n };\n\n autoDispose({ dispose: cleanup });\n\n const defaultUrl = makeUrl(config.server?.defaultPath || '', session.urls.appServer).href;\n\n performance.measure(PerfMeasurementOpenBrowser, PerfMarkerCliEntry);\n\n // Open the browser.\n if (options.open !== false) {\n openBrowser(defaultUrl).catch((err) => {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n console.warn('Error opening browser:', err?.stack || err);\n console.warn('Please open the browser manually to:', defaultUrl);\n });\n } else {\n console.log('Please open the browser manually to:', defaultUrl);\n }\n};\n\n/**\n * Create the API server, or return an error message if the server could not be created.\n */\nasync function createApiServer(options: StartOptions, apiContext: Context): Promise<CloudpackServer | string> {\n const { session } = apiContext;\n const { config } = session;\n const { server, appPath } = config;\n\n // If a cert is needed, check that it exists.\n if (server?.https === true && !(await getCertificate({ domain: server?.domain, cwd: appPath }))) {\n return (\n `The local site is configured to use https in cloudpack.config.json, but is missing a cert.\\n\\n` +\n `Run \"${cyan(bold('cloudpack setup'))}\" to create the required certificate and try start again.\\n`\n );\n }\n\n const { createCloudpackServer } = await import('@ms-cloudpack/api-server');\n\n try {\n return await createCloudpackServer({ port: options.apiServerPort }, apiContext);\n } catch (err) {\n const error = err as { code: string };\n\n if (error.code === 'EADDRNOTAVAIL' && server?.domain) {\n const primaryDomain = (Array.isArray(server.domain) ? server.domain : [server.domain])[0];\n\n return (\n `The domain \"${cyan(bold(primaryDomain))}\" in cloudpack.config.json is not resolvable.\\n\\n` +\n `Run \"${cyan(bold('cloudpack setup'))}\" to add the appropriate entries to your hosts file and ` +\n `try start again.\\n`\n );\n }\n\n return `Error creating API server: ${(err as Error).stack || err}`;\n }\n}\n\n// cspell:ignore Prereqs\n"]}
|
|
1
|
+
{"version":3,"file":"execute.js","sourceRoot":"","sources":["../../../src/commands/start/execute.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EACvB,oBAAoB,GAGrB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAC;AAC7E,OAAO,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAC;AAC5D,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAElE,OAAO,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AACvE,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAE/D;;GAEG;AACH,MAAM,CAAC,MAAM,OAAO,GAAgC,KAAK,EAAE,MAAM,EAAE,EAAE;IACnE,MAAM,EAAE,OAAO,EAAE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AAiB,CAAC,CAAC,6DAA6D;SACrG,CAAC;IACJ,CAAC;IAED,MAAM,EAAE,qBAAqB,EAAE,GAAG,MAAM,MAAM,CAAC,0BAA0B,CAAC,CAAC;IAE3E,IAAI,CAAC;QACH,MAAM,SAAS,GAAG,MAAM,qBAAqB,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,aAAa,EAAE,EAAE,UAAU,CAAC,CAAC;QAC3F,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;IACzC,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,OAAe,CAAC;QACpB,IAAK,GAAwB,CAAC,IAAI,KAAK,eAAe,IAAI,MAAM,EAAE,MAAM,EAAE,CAAC;YACzE,MAAM,aAAa,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAC1F,OAAO;gBACL,eAAe,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,mDAAmD;oBAC3F,QAAQ,IAAI,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,0DAA0D;oBAC/F,oBAAoB,CAAC;QACzB,CAAC;aAAM,CAAC;YACN,OAAO,GAAG,8BAA+B,GAAa,CAAC,KAAK,IAAI,GAAG,EAAE,CAAC;QACxE,CAAC;QACD,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;IACtC,CAAC;AACH,CAAC;AAED,wBAAwB","sourcesContent":["import {\n createPartialApiContext,\n ensurePackageBundled,\n type CloudpackServer,\n type Context,\n} from '@ms-cloudpack/api-server';\nimport { writeJson } from '@ms-cloudpack/json-utilities';\nimport { isExternalPackage, resolve } from '@ms-cloudpack/package-utilities';\nimport { makeUrl } from '@ms-cloudpack/path-string-parsing';\nimport { cyan, yellow, bold } from '@ms-cloudpack/task-reporter';\nimport path from 'path';\nimport { fileURLToPath } from 'url';\nimport { PerfMarkerCliEntry } from '../../performance/markers.js';\nimport type { CommandAction } from '../../types/CommandAction.js';\nimport { runPrerequisites } from '../../utilities/runPrerequisites.js';\nimport { getStartingAppPath } from './getStartingAppPath.js';\nimport { openBrowser } from './openBrowser.js';\nimport { trackSession } from './trackSession.js';\nimport type { StartOptions } from './types/StartOptions.js';\nimport { getCertificate } from '@ms-cloudpack/setup-utilities';\n\n/**\n * Defines the \"start\" verb entry point.\n */\nexport const execute: CommandAction<StartOptions> = async (params) => {\n const { options, cwd, initialize, autoDispose } = params;\n\n const appPathResult = await getStartingAppPath(cwd, options.app);\n if (typeof appPathResult !== 'string') {\n return appPathResult;\n }\n const appPath = appPathResult;\n const apiContextOptions = await initialize({ appPath, configOptions: { mode: options.mode } });\n const { config, telemetryClient } = apiContextOptions;\n\n console.log('App path:', yellow(appPath));\n console.log('Bundle mode:', yellow(options.mode));\n\n runPrerequisites(apiContextOptions);\n\n const currentDir = path.dirname(fileURLToPath(import.meta.url));\n let overlayPath = await resolve('@ms-cloudpack/overlay', currentDir);\n\n // If overlay is an internal package, resolve the overlay from the current package's linked node modules\n // to \"externalize\" it, so that we always use the bundled version of the overlay instead of the source.\n if (overlayPath && !isExternalPackage(overlayPath)) {\n const cliPath = await resolve('@ms-cloudpack/cli', currentDir);\n overlayPath = cliPath ? path.join(cliPath, 'node_modules', '@ms-cloudpack/overlay') : undefined;\n }\n\n const [apiContext] = autoDispose(\n await createPartialApiContext({\n ...apiContextOptions,\n items: ['bus', 'watcher', 'taskRunner', 'packages', 'session', 'packageImportPaths', 'packageHashes'],\n overlayPath,\n }),\n );\n const { packages, session } = apiContext;\n\n // Increment the session version if caching is disabled.\n if (options.cache === false) {\n session.incrementSessionVersion();\n }\n\n // Make sure the package has a valid definition.\n const definition = await packages.get(appPath);\n\n if (options.logResolveMap) {\n // Write the resolve map to disk.\n await writeJson(path.join(appPath, 'resolve-map.json'), session.resolveMap);\n }\n\n // Start api server for tracking status and handling remote requests.\n const apiServerResult = await createApiServer(options, apiContext);\n if (apiServerResult.hasErrors) {\n return apiServerResult;\n }\n const { apiServer } = apiServerResult;\n\n // Kick off bundling app package as soon as api server is ready.\n void ensurePackageBundled({\n input: { name: definition.name, version: definition.version },\n ctx: apiContext,\n });\n\n // Then start bundle and app servers for hosting the app.\n const { startServers } = await import('@ms-cloudpack/app-server');\n const servers = await startServers(\n {\n definition,\n bundleServerOptions: { disableCache: !options.cache, port: options.bundleServerPort },\n port: options.appServerPort,\n },\n apiContext,\n );\n\n // Save the session to active sessions.\n const sessionTracker = await trackSession(session);\n\n const cleanup = async () => {\n // Stop tracking the session.\n await sessionTracker.close();\n\n await Promise.all(\n Object.entries({ apiServer, ...servers }).map(async ([name, server]) => {\n if (!server) return;\n\n const desc = `${name} (${server.url})`;\n console.info(`Closing ${desc}`);\n try {\n await server.close();\n console.info(`Closed ${desc}`);\n } catch (err) {\n console.warn(`Error closing ${desc}:`, err);\n }\n }),\n );\n };\n\n autoDispose({ dispose: cleanup });\n\n const defaultUrl = makeUrl(config.server?.defaultPath || '', session.urls.appServer).href;\n\n const cliEntryMarker = performance.getEntriesByName(PerfMarkerCliEntry, 'mark')[0];\n if (cliEntryMarker) {\n telemetryClient.tracer.startSpan('TIME_TO_OPEN_BROWSER', { startTime: cliEntryMarker.startTime }).end();\n } else {\n throw new Error('TIME_TO_OPEN_BROWSER marker not found');\n }\n\n // Open the browser.\n if (options.open !== false) {\n openBrowser(defaultUrl).catch((err) => {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n console.warn('Error opening browser:', err?.stack || err);\n console.warn('Please open the browser manually to:', defaultUrl);\n });\n } else {\n console.log('Please open the browser manually to:', defaultUrl);\n }\n\n return null; // the command should keep running\n};\n\n/**\n * Create the API server, or return an error message if the server could not be created.\n */\nasync function createApiServer(\n options: StartOptions,\n apiContext: Context,\n): Promise<{ hasErrors: false; apiServer: CloudpackServer } | { hasErrors: true; message: string }> {\n const { session } = apiContext;\n const { config } = session;\n const { server, appPath } = config;\n\n // If a cert is needed, check that it exists.\n if (server?.https === true && !(await getCertificate({ domain: server?.domain, cwd: appPath }))) {\n return {\n hasErrors: true,\n message:\n `The local site is configured to use https in cloudpack.config.json, but is missing a cert.\\n\\n` +\n `Run \"${cyan(bold('cloudpack setup'))}\" to create the required certificate and try start again.\\n`,\n };\n }\n\n const { createCloudpackServer } = await import('@ms-cloudpack/api-server');\n\n try {\n const apiServer = await createCloudpackServer({ port: options.apiServerPort }, apiContext);\n return { hasErrors: false, apiServer };\n } catch (err) {\n let message: string;\n if ((err as { code: string }).code === 'EADDRNOTAVAIL' && server?.domain) {\n const primaryDomain = (Array.isArray(server.domain) ? server.domain : [server.domain])[0];\n message =\n `The domain \"${cyan(bold(primaryDomain))}\" in cloudpack.config.json is not resolvable.\\n\\n` +\n `Run \"${cyan(bold('cloudpack setup'))}\" to add the appropriate entries to your hosts file and ` +\n `try start again.\\n`;\n } else {\n message = `Error creating API server: ${(err as Error).stack || err}`;\n }\n return { hasErrors: true, message };\n }\n}\n\n// cspell:ignore Prereqs\n"]}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
+
import type { CommandExitParams } from '../../types/CommandAction.js';
|
|
2
|
+
export declare const appPromptQuestionName = "app";
|
|
3
|
+
export type AppPromptKeys = typeof appPromptQuestionName;
|
|
1
4
|
/**
|
|
2
5
|
* Gets the appPath from which Cloudpack will start. If the CWD is a Cloudpack-enabled app,
|
|
3
6
|
* we'll start there; otherwise, we'll scan for Cloudpack-enabled app and present the user
|
|
4
7
|
* with a menu. If no app are found, Cloudpack will just try to start the CWD anyway.
|
|
5
8
|
* @param cwd - The current working directory to start in when finding the starting app path
|
|
6
9
|
* @param desiredApp - The app that should be started as specified via --app arg
|
|
7
|
-
* @returns The app path of the app that Cloudpack should start
|
|
10
|
+
* @returns The app path of the app that Cloudpack should start, or an exit options object if the user cancels
|
|
8
11
|
*/
|
|
9
|
-
export declare function getStartingAppPath(cwd: string, desiredApp?: string): Promise<string>;
|
|
12
|
+
export declare function getStartingAppPath(cwd: string, desiredApp?: string): Promise<string | CommandExitParams>;
|
|
10
13
|
//# sourceMappingURL=getStartingAppPath.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getStartingAppPath.d.ts","sourceRoot":"","sources":["../../../src/commands/start/getStartingAppPath.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getStartingAppPath.d.ts","sourceRoot":"","sources":["../../../src/commands/start/getStartingAppPath.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAEtE,eAAO,MAAM,qBAAqB,QAAQ,CAAC;AAC3C,MAAM,MAAM,aAAa,GAAG,OAAO,qBAAqB,CAAC;AAEzD;;;;;;;GAOG;AACH,wBAAsB,kBAAkB,CAAC,GAAG,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,iBAAiB,CAAC,CAoD9G"}
|
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PackageDefinitions } from '@ms-cloudpack/package-utilities';
|
|
2
2
|
import fs from 'fs';
|
|
3
3
|
import path from 'path';
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
4
|
+
import prompts from 'prompts';
|
|
5
|
+
import { findCloudpackAppPaths } from '../../utilities/findCloudpackAppPaths.js';
|
|
6
|
+
export const appPromptQuestionName = 'app';
|
|
6
7
|
/**
|
|
7
8
|
* Gets the appPath from which Cloudpack will start. If the CWD is a Cloudpack-enabled app,
|
|
8
9
|
* we'll start there; otherwise, we'll scan for Cloudpack-enabled app and present the user
|
|
9
10
|
* with a menu. If no app are found, Cloudpack will just try to start the CWD anyway.
|
|
10
11
|
* @param cwd - The current working directory to start in when finding the starting app path
|
|
11
12
|
* @param desiredApp - The app that should be started as specified via --app arg
|
|
12
|
-
* @returns The app path of the app that Cloudpack should start
|
|
13
|
+
* @returns The app path of the app that Cloudpack should start, or an exit options object if the user cancels
|
|
13
14
|
*/
|
|
14
15
|
export async function getStartingAppPath(cwd, desiredApp) {
|
|
15
16
|
const cwdIsCloudpackApp = fs.existsSync(path.resolve(path.join(cwd, 'cloudpack.config.json')));
|
|
@@ -20,13 +21,39 @@ export async function getStartingAppPath(cwd, desiredApp) {
|
|
|
20
21
|
if (folderPaths.length === 0) {
|
|
21
22
|
return cwd;
|
|
22
23
|
}
|
|
23
|
-
|
|
24
|
+
if (folderPaths.length === 1) {
|
|
24
25
|
return folderPaths[0];
|
|
25
26
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
return
|
|
27
|
+
const packages = new PackageDefinitions();
|
|
28
|
+
const choices = await Promise.all(folderPaths.map(async (dir) => {
|
|
29
|
+
const pkg = await packages.get(dir);
|
|
30
|
+
return {
|
|
31
|
+
title: pkg.name,
|
|
32
|
+
description: pkg?.description ?? 'An awesome app that would be even more awesome with a proper description',
|
|
33
|
+
value: dir,
|
|
34
|
+
};
|
|
35
|
+
}));
|
|
36
|
+
choices.sort((c1, c2) => c1.title.localeCompare(c2.title));
|
|
37
|
+
if (desiredApp) {
|
|
38
|
+
const matchingApps = choices.filter((choice) => choice.title.includes(desiredApp));
|
|
39
|
+
if (matchingApps.length === 1) {
|
|
40
|
+
return matchingApps[0].value;
|
|
41
|
+
}
|
|
42
|
+
const exactMatch = matchingApps.find((choice) => choice.title === desiredApp);
|
|
43
|
+
if (exactMatch) {
|
|
44
|
+
return exactMatch.value;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const response = await prompts({
|
|
48
|
+
type: 'select',
|
|
49
|
+
name: appPromptQuestionName,
|
|
50
|
+
message: 'Select the app you want to start',
|
|
51
|
+
choices,
|
|
52
|
+
});
|
|
53
|
+
// This will be undefined if the user cancels the prompt
|
|
54
|
+
if (!response.app) {
|
|
55
|
+
return { isInterrupted: true, message: '' };
|
|
30
56
|
}
|
|
57
|
+
return response.app;
|
|
31
58
|
}
|
|
32
59
|
//# sourceMappingURL=getStartingAppPath.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getStartingAppPath.js","sourceRoot":"","sources":["../../../src/commands/start/getStartingAppPath.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"getStartingAppPath.js","sourceRoot":"","sources":["../../../src/commands/start/getStartingAppPath.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,OAAwB,MAAM,SAAS,CAAC;AAC/C,OAAO,EAAE,qBAAqB,EAAE,MAAM,0CAA0C,CAAC;AAGjF,MAAM,CAAC,MAAM,qBAAqB,GAAG,KAAK,CAAC;AAG3C;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,GAAW,EAAE,UAAmB;IACvE,MAAM,iBAAiB,GAAG,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,uBAAuB,CAAC,CAAC,CAAC,CAAC;IAC/F,IAAI,iBAAiB,EAAE,CAAC;QACtB,OAAO,GAAG,CAAC;IACb,CAAC;IAED,MAAM,WAAW,GAAG,qBAAqB,CAAC,GAAG,CAAC,CAAC;IAC/C,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC7B,OAAO,GAAG,CAAC;IACb,CAAC;IACD,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC7B,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC;IACxB,CAAC;IAED,MAAM,QAAQ,GAAG,IAAI,kBAAkB,EAAE,CAAC;IAE1C,MAAM,OAAO,GAAG,MAAM,OAAO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AE,CAAC;IAC9C,CAAC;IAED,OAAO,QAAQ,CAAC,GAAa,CAAC;AAChC,CAAC","sourcesContent":["import { PackageDefinitions } from '@ms-cloudpack/package-utilities';\nimport fs from 'fs';\nimport path from 'path';\nimport prompts, { type Choice } from 'prompts';\nimport { findCloudpackAppPaths } from '../../utilities/findCloudpackAppPaths.js';\nimport type { CommandExitParams } from '../../types/CommandAction.js';\n\nexport const appPromptQuestionName = 'app';\nexport type AppPromptKeys = typeof appPromptQuestionName;\n\n/**\n * Gets the appPath from which Cloudpack will start. If the CWD is a Cloudpack-enabled app,\n * we'll start there; otherwise, we'll scan for Cloudpack-enabled app and present the user\n * with a menu. If no app are found, Cloudpack will just try to start the CWD anyway.\n * @param cwd - The current working directory to start in when finding the starting app path\n * @param desiredApp - The app that should be started as specified via --app arg\n * @returns The app path of the app that Cloudpack should start, or an exit options object if the user cancels\n */\nexport async function getStartingAppPath(cwd: string, desiredApp?: string): Promise<string | CommandExitParams> {\n const cwdIsCloudpackApp = fs.existsSync(path.resolve(path.join(cwd, 'cloudpack.config.json')));\n if (cwdIsCloudpackApp) {\n return cwd;\n }\n\n const folderPaths = findCloudpackAppPaths(cwd);\n if (folderPaths.length === 0) {\n return cwd;\n }\n if (folderPaths.length === 1) {\n return folderPaths[0];\n }\n\n const packages = new PackageDefinitions();\n\n const choices = await Promise.all<Choice>(\n folderPaths.map(async (dir) => {\n const pkg = await packages.get(dir);\n return {\n title: pkg.name,\n description: pkg?.description ?? 'An awesome app that would be even more awesome with a proper description',\n value: dir,\n };\n }),\n );\n choices.sort((c1, c2) => c1.title.localeCompare(c2.title));\n\n if (desiredApp) {\n const matchingApps = choices.filter((choice) => choice.title.includes(desiredApp));\n if (matchingApps.length === 1) {\n return matchingApps[0].value as string;\n }\n const exactMatch = matchingApps.find((choice) => choice.title === desiredApp);\n if (exactMatch) {\n return exactMatch.value as string;\n }\n }\n\n const response = await prompts<AppPromptKeys>({\n type: 'select',\n name: appPromptQuestionName,\n message: 'Select the app you want to start',\n choices,\n });\n\n // This will be undefined if the user cancels the prompt\n if (!response.app) {\n return { isInterrupted: true, message: '' };\n }\n\n return response.app as string;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"execute.d.ts","sourceRoot":"","sources":["../../../src/commands/sync/execute.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,
|
|
1
|
+
{"version":3,"file":"execute.d.ts","sourceRoot":"","sources":["../../../src/commands/sync/execute.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAGL,KAAK,aAAa,EAEnB,MAAM,8BAA8B,CAAC;AAUtC,eAAO,MAAM,OAAO,EAAE,aAAa,CAAC,WAAW,CAiF9C,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ExitCodeAuthenticationError, ExitCodeGenericError } from '../../types/CommandAction.js';
|
|
1
|
+
import { ExitCodeAuthenticationError, ExitCodeGenericError, } from '../../types/CommandAction.js';
|
|
2
2
|
import { createPartialApiContext, syncDownload, syncUpload } from '@ms-cloudpack/api-server';
|
|
3
3
|
import { runPrerequisites } from '../../utilities/runPrerequisites.js';
|
|
4
4
|
import { isSyncDisabledByUser } from './isSyncDisabledByUser.js';
|
|
@@ -7,66 +7,67 @@ function checkErrorCode(error, code) {
|
|
|
7
7
|
return error instanceof Error && 'code' in error && error.code === code;
|
|
8
8
|
}
|
|
9
9
|
export const execute = async (params) => {
|
|
10
|
-
const { options, cwd, initialize,
|
|
10
|
+
const { options, cwd, initialize, autoDispose } = params;
|
|
11
11
|
const { login, upload } = options;
|
|
12
12
|
const apiContextOptions = await initialize({ appPath: cwd });
|
|
13
13
|
const { config, telemetryClient } = apiContextOptions;
|
|
14
|
-
if (!config.features?.syncBundles) {
|
|
15
|
-
await exit({ message: 'Sync is disabled' });
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
if (isSyncDisabledByUser()) {
|
|
19
|
-
telemetryClient.rootSpan.setAttribute('syncDisabled', true);
|
|
20
|
-
return exit({ message: 'CLOUDPACK_SYNC environment variable is set. Sync is disabled by the user.' });
|
|
21
|
-
}
|
|
22
14
|
try {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
message: '
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
15
|
+
// Await here to ensure that try-catch block catches any errors thrown inside the async function
|
|
16
|
+
return await telemetryClient.tracer.startActiveSpan('SYNC_EXECUTE', async (span) => {
|
|
17
|
+
if (!config.features?.syncBundles) {
|
|
18
|
+
return { message: 'Sync is disabled' };
|
|
19
|
+
}
|
|
20
|
+
if (isSyncDisabledByUser()) {
|
|
21
|
+
span.setAttribute('syncDisabled', true);
|
|
22
|
+
return { message: 'CLOUDPACK_SYNC environment variable is set. Sync is disabled by the user.' };
|
|
23
|
+
}
|
|
24
|
+
const remoteCacheConfig = config.remoteCache;
|
|
25
|
+
if (!remoteCacheConfig) {
|
|
26
|
+
return {
|
|
27
|
+
message: 'Remote cache is not configured. Please add remoteCache to your cloudpack.config.json file to use this feature.',
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
const input = {
|
|
31
|
+
loginMethod: login,
|
|
32
|
+
};
|
|
33
|
+
if (upload) {
|
|
34
|
+
runPrerequisites(apiContextOptions);
|
|
35
|
+
const [ctx] = autoDispose(await createPartialApiContext({
|
|
36
|
+
...apiContextOptions,
|
|
37
|
+
items: ['bus', 'taskRunner', 'watcher', 'packages', 'session', 'packageImportPaths', 'packageHashes'],
|
|
38
|
+
}));
|
|
39
|
+
await syncUpload({ input, ctx });
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
const [ctx] = autoDispose(await createPartialApiContext({
|
|
43
|
+
...apiContextOptions,
|
|
44
|
+
items: ['packages', 'session', 'packageHashes'],
|
|
45
|
+
}));
|
|
46
|
+
await syncDownload({ input, ctx });
|
|
47
|
+
}
|
|
48
|
+
return { message: 'Sync complete' };
|
|
49
|
+
});
|
|
48
50
|
}
|
|
49
51
|
catch (error) {
|
|
50
52
|
if (error instanceof Error) {
|
|
51
|
-
telemetryClient.rootSpan.recordException(error);
|
|
52
53
|
if (error.name === 'AuthenticationRequiredError' && error.message.includes('CrossPlatformLockError')) {
|
|
53
|
-
return
|
|
54
|
+
return {
|
|
54
55
|
message: red(`Cloudpack encountered an issue acquiring authentication lock. It seems Cloudpack Sync may already be active in another process. Please wait for the current process to complete and then try again`),
|
|
55
56
|
exitCode: ExitCodeGenericError,
|
|
56
|
-
}
|
|
57
|
+
};
|
|
57
58
|
}
|
|
58
59
|
if (error.name === 'AuthenticationRequiredError' ||
|
|
59
60
|
('statusCode' in error && (error.statusCode === '401' || error.statusCode === '403'))) {
|
|
60
|
-
return
|
|
61
|
+
return {
|
|
61
62
|
message: red('Authentication error. Please check your credentials and try again.'),
|
|
62
63
|
exitCode: ExitCodeAuthenticationError,
|
|
63
|
-
}
|
|
64
|
+
};
|
|
64
65
|
}
|
|
65
66
|
if (checkErrorCode(error, 'REQUEST_SEND_ERROR')) {
|
|
66
|
-
return
|
|
67
|
+
return {
|
|
67
68
|
message: red('Connection error. Please check your connection and try again.'),
|
|
68
69
|
exitCode: ExitCodeGenericError,
|
|
69
|
-
}
|
|
70
|
+
};
|
|
70
71
|
}
|
|
71
72
|
}
|
|
72
73
|
throw error;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"execute.js","sourceRoot":"","sources":["../../../src/commands/sync/execute.ts"],"names":[],"mappings":"AACA,OAAO,
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AO,EAAE,GAAG,CACV,oMAAoM,CACrM;oBACD,QAAQ,EAAE,oBAAoB;iBAC/B,CAAC;YACJ,CAAC;YACD,IACE,KAAK,CAAC,IAAI,KAAK,6BAA6B;gBAC5C,CAAC,YAAY,IAAI,KAAK,IAAI,CAAC,KAAK,CAAC,UAAU,KAAK,KAAK,IAAI,KAAK,CAAC,UAAU,KAAK,KAAK,CAAC,CAAC,EACrF,CAAC;gBACD,OAAO;oBACL,OAAO,EAAE,GAAG,CAAC,oEAAoE,CAAC;oBAClF,QAAQ,EAAE,2BAA2B;iBACtC,CAAC;YACJ,CAAC;YAED,IAAI,cAAc,CAAC,KAAK,EAAE,oBAAoB,CAAC,EAAE,CAAC;gBAChD,OAAO;oBACL,OAAO,EAAE,GAAG,CAAC,+DAA+D,CAAC;oBAC7E,QAAQ,EAAE,oBAAoB;iBAC/B,CAAC;YACJ,CAAC;QACH,CAAC;QAED,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC,CAAC","sourcesContent":["import type { SyncOptions } from './types/SyncOptions.js';\nimport {\n ExitCodeAuthenticationError,\n ExitCodeGenericError,\n type CommandAction,\n type CommandExitParams,\n} from '../../types/CommandAction.js';\nimport { createPartialApiContext, syncDownload, syncUpload } from '@ms-cloudpack/api-server';\nimport { runPrerequisites } from '../../utilities/runPrerequisites.js';\nimport { isSyncDisabledByUser } from './isSyncDisabledByUser.js';\nimport { red } from '@ms-cloudpack/task-reporter';\n\nfunction checkErrorCode(error: unknown, code: string) {\n return error instanceof Error && 'code' in error && error.code === code;\n}\n\nexport const execute: CommandAction<SyncOptions> = async (params) => {\n const { options, cwd, initialize, autoDispose } = params;\n const { login, upload } = options;\n const apiContextOptions = await initialize({ appPath: cwd });\n const { config, telemetryClient } = apiContextOptions;\n try {\n // Await here to ensure that try-catch block catches any errors thrown inside the async function\n return await telemetryClient.tracer.startActiveSpan('SYNC_EXECUTE', async (span): Promise<CommandExitParams> => {\n if (!config.features?.syncBundles) {\n return { message: 'Sync is disabled' };\n }\n\n if (isSyncDisabledByUser()) {\n span.setAttribute('syncDisabled', true);\n return { message: 'CLOUDPACK_SYNC environment variable is set. Sync is disabled by the user.' };\n }\n\n const remoteCacheConfig = config.remoteCache;\n if (!remoteCacheConfig) {\n return {\n message:\n 'Remote cache is not configured. Please add remoteCache to your cloudpack.config.json file to use this feature.',\n };\n }\n\n const input = {\n loginMethod: login,\n };\n\n if (upload) {\n runPrerequisites(apiContextOptions);\n\n const [ctx] = autoDispose(\n await createPartialApiContext({\n ...apiContextOptions,\n items: ['bus', 'taskRunner', 'watcher', 'packages', 'session', 'packageImportPaths', 'packageHashes'],\n }),\n );\n await syncUpload({ input, ctx });\n } else {\n const [ctx] = autoDispose(\n await createPartialApiContext({\n ...apiContextOptions,\n items: ['packages', 'session', 'packageHashes'],\n }),\n );\n await syncDownload({ input, ctx });\n }\n\n return { message: 'Sync complete' };\n });\n } catch (error) {\n if (error instanceof Error) {\n if (error.name === 'AuthenticationRequiredError' && error.message.includes('CrossPlatformLockError')) {\n return {\n message: red(\n `Cloudpack encountered an issue acquiring authentication lock. It seems Cloudpack Sync may already be active in another process. Please wait for the current process to complete and then try again`,\n ),\n exitCode: ExitCodeGenericError,\n };\n }\n if (\n error.name === 'AuthenticationRequiredError' ||\n ('statusCode' in error && (error.statusCode === '401' || error.statusCode === '403'))\n ) {\n return {\n message: red('Authentication error. Please check your credentials and try again.'),\n exitCode: ExitCodeAuthenticationError,\n };\n }\n\n if (checkErrorCode(error, 'REQUEST_SEND_ERROR')) {\n return {\n message: red('Connection error. Please check your connection and try again.'),\n exitCode: ExitCodeGenericError,\n };\n }\n }\n\n throw error;\n }\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"execute.d.ts","sourceRoot":"","sources":["../../../src/commands/unlink/execute.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAO9D;;GAEG;AACH,eAAO,MAAM,OAAO,EAAE,aAAa,CAAC,aAAa,
|
|
1
|
+
{"version":3,"file":"execute.d.ts","sourceRoot":"","sources":["../../../src/commands/unlink/execute.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAO9D;;GAEG;AACH,eAAO,MAAM,OAAO,EAAE,aAAa,CAAC,aAAa,CA0ChD,CAAC"}
|
|
@@ -8,11 +8,15 @@ import path from 'path';
|
|
|
8
8
|
*/
|
|
9
9
|
export const execute = async (params) => {
|
|
10
10
|
// Use the current directory as the default package path.
|
|
11
|
-
const { options, cwd: appPath, reporter, initialize
|
|
11
|
+
const { options, cwd: appPath, reporter, initialize } = params;
|
|
12
12
|
const { logResolveMap, cachePath } = options;
|
|
13
13
|
await initialize({ appPath });
|
|
14
14
|
console.debug('Unlinking packages...');
|
|
15
|
-
const
|
|
15
|
+
const sessionResult = await getSessionToLink({ reporter, cachePath });
|
|
16
|
+
if (!sessionResult.session) {
|
|
17
|
+
return sessionResult;
|
|
18
|
+
}
|
|
19
|
+
const { session } = sessionResult;
|
|
16
20
|
const client = await createCloudpackClient({ url: session.urls.apiServer, reporter });
|
|
17
21
|
const message = `Unlinking paths for ${session.projectName} at "${appPath}"`;
|
|
18
22
|
const task = reporter.addTask(message);
|
|
@@ -26,7 +30,7 @@ export const execute = async (params) => {
|
|
|
26
30
|
if (linkedPaths.some((p) => p.path === appPath)) {
|
|
27
31
|
// Close down with an error.
|
|
28
32
|
task.complete({ status: 'fail', message: `Failed to unlink paths.`, forceShow: true });
|
|
29
|
-
|
|
33
|
+
return { hasErrors: true, message: 'Failed to unlink paths.' };
|
|
30
34
|
}
|
|
31
35
|
if (logResolveMap) {
|
|
32
36
|
// Write the unlinked resolve map to disk.
|
|
@@ -35,6 +39,6 @@ export const execute = async (params) => {
|
|
|
35
39
|
// Close down successfully.
|
|
36
40
|
task.complete({ status: 'complete', message: `Unlinked paths`, forceShow: true });
|
|
37
41
|
const linkSummary = formatLinkSummary({ session, resolveMap, linkedPaths });
|
|
38
|
-
|
|
42
|
+
return { message: linkSummary };
|
|
39
43
|
};
|
|
40
44
|
//# sourceMappingURL=execute.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"execute.js","sourceRoot":"","sources":["../../../src/commands/unlink/execute.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACzD,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB;;GAEG;AACH,MAAM,CAAC,MAAM,OAAO,GAAiC,KAAK,EAAE,MAAM,EAAE,EAAE;IACpE,yDAAyD;IACzD,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"execute.js","sourceRoot":"","sources":["../../../src/commands/unlink/execute.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACzD,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB;;GAEG;AACH,MAAM,CAAC,MAAM,OAAO,GAAiC,KAAK,EAAE,MAAM,EAAE,EAAE;IACpE,yDAAyD;IACzD,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,QAAQ,EAAE,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E,CAAC;IAED,IAAI,aAAa,EAAE,CAAC;QAClB,0CAA0C;QAC1C,MAAM,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,2BAA2B,CAAC,EAAE,UAAU,CAAC,CAAC;IAC/E,CAAC;IAED,2BAA2B;IAC3B,IAAI,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAClF,MAAM,WAAW,GAAG,iBAAiB,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,CAAC,CAAC;IAE5E,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC;AAClC,CAAC,CAAC","sourcesContent":["import type { CommandAction } from '../../types/CommandAction.js';\nimport type { UnlinkOptions } from './types/UnlinkOptions.js';\nimport { getSessionToLink } from '../link/getSessionToLink.js';\nimport { createCloudpackClient } from '@ms-cloudpack/api-server';\nimport { formatLinkSummary } from '../link/formatLinkSummary.js';\nimport { writeJson } from '@ms-cloudpack/json-utilities';\nimport path from 'path';\n\n/**\n * Defines the \"unlink\" verb entry point.\n */\nexport const execute: CommandAction<UnlinkOptions> = async (params) => {\n // Use the current directory as the default package path.\n const { options, cwd: appPath, reporter, initialize } = params;\n const { logResolveMap, cachePath } = options;\n await initialize({ appPath });\n\n console.debug('Unlinking packages...');\n\n const sessionResult = await getSessionToLink({ reporter, cachePath });\n if (!sessionResult.session) {\n return sessionResult;\n }\n const { session } = sessionResult;\n const client = await createCloudpackClient({ url: session.urls.apiServer, reporter });\n\n const message = `Unlinking paths for ${session.projectName} at \"${appPath}\"`;\n const task = reporter.addTask(message);\n\n // Send request to api server to link paths.\n const { resolveMap, linkedPaths } = await client.unlinkPath.query({\n linkedPath: {\n path: appPath,\n },\n });\n await client.close();\n\n if (linkedPaths.some((p) => p.path === appPath)) {\n // Close down with an error.\n task.complete({ status: 'fail', message: `Failed to unlink paths.`, forceShow: true });\n return { hasErrors: true, message: 'Failed to unlink paths.' };\n }\n\n if (logResolveMap) {\n // Write the unlinked resolve map to disk.\n await writeJson(path.join(appPath, 'resolve-map-unlinked.json'), resolveMap);\n }\n\n // Close down successfully.\n task.complete({ status: 'complete', message: `Unlinked paths`, forceShow: true });\n const linkSummary = formatLinkSummary({ session, resolveMap, linkedPaths });\n\n return { message: linkSummary };\n};\n"]}
|
|
@@ -18,9 +18,17 @@ export declare const ExitCodeGenericError = 1;
|
|
|
18
18
|
export declare const ExitCodeAuthenticationError = 2;
|
|
19
19
|
export type ExitCode = typeof ExitCodeSuccessful | typeof ExitCodeGenericError | typeof ExitCodeAuthenticationError;
|
|
20
20
|
export interface CommandExitParams {
|
|
21
|
+
/**
|
|
22
|
+
* Message to show on exit.
|
|
23
|
+
* If `isInterrupted` is true, use an empty string (it will show a default interrupt message).
|
|
24
|
+
*/
|
|
21
25
|
message: string;
|
|
26
|
+
/** Whether there are errors. By default, checks the reporter for failed tasks. */
|
|
22
27
|
hasErrors?: boolean;
|
|
28
|
+
/** Exit code to use. Defaults to 1 if there are errors, 0 if not. */
|
|
23
29
|
exitCode?: ExitCode;
|
|
30
|
+
/** True if the user interrupted an operation (ctrl+C). Sets the message automatically. */
|
|
31
|
+
isInterrupted?: true;
|
|
24
32
|
}
|
|
25
33
|
export interface CommandActionParams<TOptions extends object> {
|
|
26
34
|
/**
|
|
@@ -62,21 +70,19 @@ export interface CommandActionParams<TOptions extends object> {
|
|
|
62
70
|
appPaths: string[];
|
|
63
71
|
}): Promise<AppCommandContext[]>;
|
|
64
72
|
};
|
|
65
|
-
/**
|
|
66
|
-
* This should be called at the end of the action to dispose resources, log completion,
|
|
67
|
-
* and exit the program. (See `CommandExecutor._exit` for implementation.)
|
|
68
|
-
*/
|
|
69
|
-
exit: (result: CommandExitParams) => Promise<void>;
|
|
70
73
|
/**
|
|
71
74
|
* Set a callback to get the message to display if ctrl+C is pressed.
|
|
72
75
|
*/
|
|
73
76
|
setInterruptMessageHandler: (getMessage: () => string) => void;
|
|
74
77
|
}
|
|
75
78
|
/**
|
|
76
|
-
* Command action function. This is the type of the `execute` function which should
|
|
77
|
-
* from each command's `src/commands/<name>/execute.ts` module.
|
|
79
|
+
* Command action function (executor). This is the type of the `execute` function which should
|
|
80
|
+
* be exported from each command's `src/commands/<name>/execute.ts` module.
|
|
81
|
+
*
|
|
82
|
+
* If it returns an object, the command wrapper will call the exit handler with that object.
|
|
83
|
+
* If it returns null, it's assumed that this command is meant to keep running, such as `start`.
|
|
78
84
|
*/
|
|
79
|
-
export type CommandAction<TOptions> = (params: CommandActionParams<TOptions & SharedOptions>) => Promise<
|
|
85
|
+
export type CommandAction<TOptions> = (params: CommandActionParams<TOptions & SharedOptions>) => Promise<CommandExitParams | null>;
|
|
80
86
|
export type CommandActionModule<TOptions> = {
|
|
81
87
|
execute: CommandAction<TOptions>;
|
|
82
88
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CommandAction.d.ts","sourceRoot":"","sources":["../../src/types/CommandAction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACtE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAExD;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GAAG,IAAI,CAClC,qBAAqB,EACrB,SAAS,GAAG,WAAW,GAAG,QAAQ,GAAG,UAAU,GAAG,iBAAiB,CACpE,CAAC;AAEF,8CAA8C;AAC9C,MAAM,WAAW,wBAAwB;IACvC,+DAA+D;IAC/D,aAAa,CAAC,EAAE,iBAAiB,CAAC;CACnC;AAED,eAAO,MAAM,kBAAkB,IAAI,CAAC;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AAC,CAAC;AACpC,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAC;AACtC,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,CAAC","sourcesContent":["import type { LazyApiContextOptions } from '@ms-cloudpack/api-server';\nimport type { ReadConfigOptions } from '@ms-cloudpack/config';\nimport type { TaskReporter } from '@ms-cloudpack/task-reporter';\nimport type { AutoDispose } from './AutoDispose.js';\nimport type { SharedOptions } from './SharedOptions.js';\n\n/**\n * Context for running a command in a specific app (after initialization).\n * For convenience, this can be passed/spread directly to `createPartialApiContext`.\n */\nexport type AppCommandContext = Pick<\n LazyApiContextOptions,\n 'appPath' | 'cachePath' | 'config' | 'reporter' | 'telemetryClient'\n>;\n\n/** Initialize options excluding `appPaths` */\nexport interface CommandInitializeOptions {\n /** Additional options to merge in while reading the config. */\n configOptions?: ReadConfigOptions;\n}\n\nexport const ExitCodeSuccessful = 0;\nexport const ExitCodeGenericError = 1;\nexport const ExitCodeAuthenticationError = 2;\nexport type ExitCode = typeof ExitCodeSuccessful | typeof ExitCodeGenericError | typeof ExitCodeAuthenticationError;\n\nexport interface CommandExitParams {\n message: string;\n hasErrors?: boolean;\n exitCode?: ExitCode;\n}\n\nexport interface CommandActionParams<TOptions extends object> {\n /**\n * Initial working directory (usually `process.cwd()` except in tests).\n * Note that this may differ from the `appPath` used by individual commands.\n */\n cwd: string;\n\n /**\n * Command-specific options, parsed from `process.argv`.\n * Types are generally defined in each command's `src/commands/<name>/types/<Name>Types.ts` module.\n * The command line options are defined in each command's `src/commands/<name>/index.ts` module.\n */\n options: TOptions;\n\n /**\n * Command-specific arguments. Arguments in commander are positional arguments that are not options.\n * For example, in `echo somestring`, `somestring` is an argument.\n */\n args: string[];\n\n reporter: TaskReporter;\n\n abortSignal: AbortSignal;\n\n /**\n * Function that can be called with any `Disposable`s that should be cleaned up automatically\n * when the program exits. (See `AutoDisposableList.add` for implementation.)\n */\n autoDispose: AutoDispose;\n\n /**\n * This should be called at or near the beginning of the action to initialize the config,\n * telemetry, and reporting. (See `CommandExecutor._initialize` for implementation.)\n * `initialize` can be called with either a single string, `appPath` or an a string[], `appPaths`.\n *\n * If it is called with a single string, it returns `Promise<AppCommandContext>`\n * If it is called with a string[], it returns `Promise<AppCommandContext[]>`\n */\n initialize: {\n (initializeOptions: CommandInitializeOptions & { appPath: string }): Promise<AppCommandContext>;\n (initializeOptions: CommandInitializeOptions & { appPaths: string[] }): Promise<AppCommandContext[]>;\n };\n\n /**\n *
|
|
1
|
+
{"version":3,"file":"CommandAction.js","sourceRoot":"","sources":["../../src/types/CommandAction.ts"],"names":[],"mappings":"AAqBA,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,CAAC;AACpC,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAC;AACtC,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,CAAC","sourcesContent":["import type { LazyApiContextOptions } from '@ms-cloudpack/api-server';\nimport type { ReadConfigOptions } from '@ms-cloudpack/config';\nimport type { TaskReporter } from '@ms-cloudpack/task-reporter';\nimport type { AutoDispose } from './AutoDispose.js';\nimport type { SharedOptions } from './SharedOptions.js';\n\n/**\n * Context for running a command in a specific app (after initialization).\n * For convenience, this can be passed/spread directly to `createPartialApiContext`.\n */\nexport type AppCommandContext = Pick<\n LazyApiContextOptions,\n 'appPath' | 'cachePath' | 'config' | 'reporter' | 'telemetryClient'\n>;\n\n/** Initialize options excluding `appPaths` */\nexport interface CommandInitializeOptions {\n /** Additional options to merge in while reading the config. */\n configOptions?: ReadConfigOptions;\n}\n\nexport const ExitCodeSuccessful = 0;\nexport const ExitCodeGenericError = 1;\nexport const ExitCodeAuthenticationError = 2;\nexport type ExitCode = typeof ExitCodeSuccessful | typeof ExitCodeGenericError | typeof ExitCodeAuthenticationError;\n\nexport interface CommandExitParams {\n /**\n * Message to show on exit.\n * If `isInterrupted` is true, use an empty string (it will show a default interrupt message).\n */\n message: string;\n /** Whether there are errors. By default, checks the reporter for failed tasks. */\n hasErrors?: boolean;\n /** Exit code to use. Defaults to 1 if there are errors, 0 if not. */\n exitCode?: ExitCode;\n /** True if the user interrupted an operation (ctrl+C). Sets the message automatically. */\n isInterrupted?: true;\n}\n\nexport interface CommandActionParams<TOptions extends object> {\n /**\n * Initial working directory (usually `process.cwd()` except in tests).\n * Note that this may differ from the `appPath` used by individual commands.\n */\n cwd: string;\n\n /**\n * Command-specific options, parsed from `process.argv`.\n * Types are generally defined in each command's `src/commands/<name>/types/<Name>Types.ts` module.\n * The command line options are defined in each command's `src/commands/<name>/index.ts` module.\n */\n options: TOptions;\n\n /**\n * Command-specific arguments. Arguments in commander are positional arguments that are not options.\n * For example, in `echo somestring`, `somestring` is an argument.\n */\n args: string[];\n\n reporter: TaskReporter;\n\n abortSignal: AbortSignal;\n\n /**\n * Function that can be called with any `Disposable`s that should be cleaned up automatically\n * when the program exits. (See `AutoDisposableList.add` for implementation.)\n */\n autoDispose: AutoDispose;\n\n /**\n * This should be called at or near the beginning of the action to initialize the config,\n * telemetry, and reporting. (See `CommandExecutor._initialize` for implementation.)\n * `initialize` can be called with either a single string, `appPath` or an a string[], `appPaths`.\n *\n * If it is called with a single string, it returns `Promise<AppCommandContext>`\n * If it is called with a string[], it returns `Promise<AppCommandContext[]>`\n */\n initialize: {\n (initializeOptions: CommandInitializeOptions & { appPath: string }): Promise<AppCommandContext>;\n (initializeOptions: CommandInitializeOptions & { appPaths: string[] }): Promise<AppCommandContext[]>;\n };\n\n /**\n * Set a callback to get the message to display if ctrl+C is pressed.\n */\n setInterruptMessageHandler: (getMessage: () => string) => void;\n}\n\n/**\n * Command action function (executor). This is the type of the `execute` function which should\n * be exported from each command's `src/commands/<name>/execute.ts` module.\n *\n * If it returns an object, the command wrapper will call the exit handler with that object.\n * If it returns null, it's assumed that this command is meant to keep running, such as `start`.\n */\nexport type CommandAction<TOptions> = (\n params: CommandActionParams<TOptions & SharedOptions>,\n) => Promise<CommandExitParams | null>;\n\nexport type CommandActionModule<TOptions> = {\n execute: CommandAction<TOptions>;\n};\n"]}
|