@sanity/cli-core 0.0.2-alpha.0
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/LICENSE +21 -0
- package/README.md +3 -0
- package/dist/SanityCommand.d.ts +56 -0
- package/dist/SanityCommand.js +72 -0
- package/dist/SanityCommand.js.map +1 -0
- package/dist/config/__tests__/cliToken.test.js +74 -0
- package/dist/config/__tests__/cliToken.test.js.map +1 -0
- package/dist/config/__tests__/cliUserConfig.test.js +131 -0
- package/dist/config/__tests__/cliUserConfig.test.js.map +1 -0
- package/dist/config/__tests__/findProjectRoot.test.js +159 -0
- package/dist/config/__tests__/findProjectRoot.test.js.map +1 -0
- package/dist/config/cli/getCliConfig.d.ts +16 -0
- package/dist/config/cli/getCliConfig.js +67 -0
- package/dist/config/cli/getCliConfig.js.map +1 -0
- package/dist/config/cli/getCliConfig.worker.d.ts +1 -0
- package/dist/config/cli/getCliConfig.worker.js +14 -0
- package/dist/config/cli/getCliConfig.worker.js.map +1 -0
- package/dist/config/cli/schemas.d.ts +204 -0
- package/dist/config/cli/schemas.js +77 -0
- package/dist/config/cli/schemas.js.map +1 -0
- package/dist/config/cli/types.d.ts +13 -0
- package/dist/config/cli/types.js +3 -0
- package/dist/config/cli/types.js.map +1 -0
- package/dist/config/findProjectRoot.d.ts +14 -0
- package/dist/config/findProjectRoot.js +56 -0
- package/dist/config/findProjectRoot.js.map +1 -0
- package/dist/config/studio/getStudioConfig.d.ts +14 -0
- package/dist/config/studio/getStudioConfig.js +16 -0
- package/dist/config/studio/getStudioConfig.js.map +1 -0
- package/dist/config/studio/readStudioConfig.d.ts +190 -0
- package/dist/config/studio/readStudioConfig.js +45 -0
- package/dist/config/studio/readStudioConfig.js.map +1 -0
- package/dist/config/studio/readStudioConfig.worker.d.ts +1 -0
- package/dist/config/studio/readStudioConfig.worker.js +64 -0
- package/dist/config/studio/readStudioConfig.worker.js.map +1 -0
- package/dist/config/util/findAppConfigPath.d.ts +8 -0
- package/dist/config/util/findAppConfigPath.js +22 -0
- package/dist/config/util/findAppConfigPath.js.map +1 -0
- package/dist/config/util/findConfigsPaths.d.ts +16 -0
- package/dist/config/util/findConfigsPaths.js +21 -0
- package/dist/config/util/findConfigsPaths.js.map +1 -0
- package/dist/config/util/findStudioConfigPath.d.ts +9 -0
- package/dist/config/util/findStudioConfigPath.js +31 -0
- package/dist/config/util/findStudioConfigPath.js.map +1 -0
- package/dist/config/util/isSanityV2StudioRoot.d.ts +8 -0
- package/dist/config/util/isSanityV2StudioRoot.js +19 -0
- package/dist/config/util/isSanityV2StudioRoot.js.map +1 -0
- package/dist/config/util/recursivelyResolveProjectRoot.d.ts +27 -0
- package/dist/config/util/recursivelyResolveProjectRoot.js +28 -0
- package/dist/config/util/recursivelyResolveProjectRoot.js.map +1 -0
- package/dist/debug.d.ts +15 -0
- package/dist/debug.js +15 -0
- package/dist/debug.js.map +1 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -0
- package/dist/loaders/studio/stubs.d.ts +254 -0
- package/dist/loaders/studio/stubs.js +257 -0
- package/dist/loaders/studio/stubs.js.map +1 -0
- package/dist/loaders/studio/studioWorkerLoader.worker.d.ts +1 -0
- package/dist/loaders/studio/studioWorkerLoader.worker.js +117 -0
- package/dist/loaders/studio/studioWorkerLoader.worker.js.map +1 -0
- package/dist/loaders/studio/studioWorkerTask.d.ts +40 -0
- package/dist/loaders/studio/studioWorkerTask.js +69 -0
- package/dist/loaders/studio/studioWorkerTask.js.map +1 -0
- package/dist/loaders/tsx/tsxWorkerLoader.worker.d.ts +1 -0
- package/dist/loaders/tsx/tsxWorkerLoader.worker.js +12 -0
- package/dist/loaders/tsx/tsxWorkerLoader.worker.js.map +1 -0
- package/dist/loaders/tsx/tsxWorkerTask.d.ts +28 -0
- package/dist/loaders/tsx/tsxWorkerTask.js +61 -0
- package/dist/loaders/tsx/tsxWorkerTask.js.map +1 -0
- package/dist/services/apiClient.d.ts +39 -0
- package/dist/services/apiClient.js +88 -0
- package/dist/services/apiClient.js.map +1 -0
- package/dist/services/cliUserConfig.d.ts +57 -0
- package/dist/services/cliUserConfig.js +103 -0
- package/dist/services/cliUserConfig.js.map +1 -0
- package/dist/services/getCliToken.d.ts +7 -0
- package/dist/services/getCliToken.js +21 -0
- package/dist/services/getCliToken.js.map +1 -0
- package/dist/types.d.ts +7 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/util/NotFoundError.d.ts +20 -0
- package/dist/util/NotFoundError.js +27 -0
- package/dist/util/NotFoundError.js.map +1 -0
- package/dist/util/__tests__/createExpiringConfig.test.js +309 -0
- package/dist/util/__tests__/createExpiringConfig.test.js.map +1 -0
- package/dist/util/createExpiringConfig.d.ts +32 -0
- package/dist/util/createExpiringConfig.js +35 -0
- package/dist/util/createExpiringConfig.js.map +1 -0
- package/dist/util/fileExists.d.ts +9 -0
- package/dist/util/fileExists.js +13 -0
- package/dist/util/fileExists.js.map +1 -0
- package/dist/util/generateHelpUrl.d.ts +8 -0
- package/dist/util/generateHelpUrl.js +11 -0
- package/dist/util/generateHelpUrl.js.map +1 -0
- package/dist/util/getSanityEnvVar.d.ts +19 -0
- package/dist/util/getSanityEnvVar.js +24 -0
- package/dist/util/getSanityEnvVar.js.map +1 -0
- package/dist/util/getSanityUrl.d.ts +5 -0
- package/dist/util/getSanityUrl.js +8 -0
- package/dist/util/getSanityUrl.js.map +1 -0
- package/dist/util/getUserConfig.d.ts +2 -0
- package/dist/util/getUserConfig.js +15 -0
- package/dist/util/getUserConfig.js.map +1 -0
- package/dist/util/isCi.d.ts +1 -0
- package/dist/util/isCi.js +7 -0
- package/dist/util/isCi.js.map +1 -0
- package/dist/util/isHttpError.d.ts +29 -0
- package/dist/util/isHttpError.js +18 -0
- package/dist/util/isHttpError.js.map +1 -0
- package/dist/util/isInteractive.d.ts +1 -0
- package/dist/util/isInteractive.js +5 -0
- package/dist/util/isInteractive.js.map +1 -0
- package/dist/util/isRecord.d.ts +8 -0
- package/dist/util/isRecord.js +11 -0
- package/dist/util/isRecord.js.map +1 -0
- package/dist/util/isTrueish.d.ts +1 -0
- package/dist/util/isTrueish.js +10 -0
- package/dist/util/isTrueish.js.map +1 -0
- package/dist/util/readJsonFile.d.ts +8 -0
- package/dist/util/readJsonFile.js +26 -0
- package/dist/util/readJsonFile.js.map +1 -0
- package/dist/util/safeStructuredClone.d.ts +8 -0
- package/dist/util/safeStructuredClone.js +40 -0
- package/dist/util/safeStructuredClone.js.map +1 -0
- package/dist/util/writeJsonFile.d.ts +9 -0
- package/dist/util/writeJsonFile.js +19 -0
- package/dist/util/writeJsonFile.js.map +1 -0
- package/dist/ux/colorizeJson.d.ts +1 -0
- package/dist/ux/colorizeJson.js +32 -0
- package/dist/ux/colorizeJson.js.map +1 -0
- package/dist/ux/formatObject.d.ts +1 -0
- package/dist/ux/formatObject.js +9 -0
- package/dist/ux/formatObject.js.map +1 -0
- package/dist/ux/logSymbols.d.ts +1 -0
- package/dist/ux/logSymbols.js +3 -0
- package/dist/ux/logSymbols.js.map +1 -0
- package/dist/ux/printKeyValue.d.ts +1 -0
- package/dist/ux/printKeyValue.js +16 -0
- package/dist/ux/printKeyValue.js.map +1 -0
- package/dist/ux/spinner.d.ts +1 -0
- package/dist/ux/spinner.js +3 -0
- package/dist/ux/spinner.js.map +1 -0
- package/dist/ux/timer.d.ts +12 -0
- package/dist/ux/timer.js +29 -0
- package/dist/ux/timer.js.map +1 -0
- package/package.json +81 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if a file exists and can be "accessed".
|
|
3
|
+
* Prone to race conditions, but good enough for our use cases.
|
|
4
|
+
*
|
|
5
|
+
* @param filePath - The path to the file to check
|
|
6
|
+
* @returns A promise that resolves to true if the file exists, false otherwise
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export declare function fileExists(filePath: string): Promise<boolean>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { access } from 'node:fs/promises';
|
|
2
|
+
/**
|
|
3
|
+
* Checks if a file exists and can be "accessed".
|
|
4
|
+
* Prone to race conditions, but good enough for our use cases.
|
|
5
|
+
*
|
|
6
|
+
* @param filePath - The path to the file to check
|
|
7
|
+
* @returns A promise that resolves to true if the file exists, false otherwise
|
|
8
|
+
* @internal
|
|
9
|
+
*/ export function fileExists(filePath) {
|
|
10
|
+
return access(filePath).then(()=>true, ()=>false);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=fileExists.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/util/fileExists.ts"],"sourcesContent":["import {access} from 'node:fs/promises'\n\n/**\n * Checks if a file exists and can be \"accessed\".\n * Prone to race conditions, but good enough for our use cases.\n *\n * @param filePath - The path to the file to check\n * @returns A promise that resolves to true if the file exists, false otherwise\n * @internal\n */\nexport function fileExists(filePath: string): Promise<boolean> {\n return access(filePath).then(\n () => true,\n () => false,\n )\n}\n"],"names":["access","fileExists","filePath","then"],"mappings":"AAAA,SAAQA,MAAM,QAAO,mBAAkB;AAEvC;;;;;;;CAOC,GACD,OAAO,SAASC,WAAWC,QAAgB;IACzC,OAAOF,OAAOE,UAAUC,IAAI,CAC1B,IAAM,MACN,IAAM;AAEV"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generate a help URL for the given slug
|
|
3
|
+
*
|
|
4
|
+
* @param slug - The slug to generate a help URL for
|
|
5
|
+
* @returns The generated help URL
|
|
6
|
+
* @internal
|
|
7
|
+
*/ export function generateHelpUrl(slug) {
|
|
8
|
+
return `https://www.sanity.io/help/${slug}`;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=generateHelpUrl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/util/generateHelpUrl.ts"],"sourcesContent":["/**\n * Generate a help URL for the given slug\n *\n * @param slug - The slug to generate a help URL for\n * @returns The generated help URL\n * @internal\n */\nexport function generateHelpUrl(slug: string): string {\n return `https://www.sanity.io/help/${slug}`\n}\n"],"names":["generateHelpUrl","slug"],"mappings":"AAAA;;;;;;CAMC,GACD,OAAO,SAASA,gBAAgBC,IAAY;IAC1C,OAAO,CAAC,2BAA2B,EAAEA,MAAM;AAC7C"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gets an environment variable with the appropriate Sanity prefix based on whether it's an app or studio.
|
|
3
|
+
*
|
|
4
|
+
* @param suffix - The suffix for the environment variable (e.g., 'SERVER_HOSTNAME')
|
|
5
|
+
* @param isApp - Whether to use the app prefix (SANITY_APP_) or studio prefix (SANITY_STUDIO_)
|
|
6
|
+
* @returns The value of the environment variable, or undefined if not set
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* // For studio: SANITY_STUDIO_SERVER_HOSTNAME
|
|
11
|
+
* const studioHostname = getSanityEnvVar('SERVER_HOSTNAME', false)
|
|
12
|
+
*
|
|
13
|
+
* // For app: SANITY_APP_SERVER_HOSTNAME
|
|
14
|
+
* const appHostname = getSanityEnvVar('SERVER_HOSTNAME', true)
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
export declare function getSanityEnvVar(suffix: string, isApp: boolean): string | undefined;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gets an environment variable with the appropriate Sanity prefix based on whether it's an app or studio.
|
|
3
|
+
*
|
|
4
|
+
* @param suffix - The suffix for the environment variable (e.g., 'SERVER_HOSTNAME')
|
|
5
|
+
* @param isApp - Whether to use the app prefix (SANITY_APP_) or studio prefix (SANITY_STUDIO_)
|
|
6
|
+
* @returns The value of the environment variable, or undefined if not set
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* // For studio: SANITY_STUDIO_SERVER_HOSTNAME
|
|
11
|
+
* const studioHostname = getSanityEnvVar('SERVER_HOSTNAME', false)
|
|
12
|
+
*
|
|
13
|
+
* // For app: SANITY_APP_SERVER_HOSTNAME
|
|
14
|
+
* const appHostname = getSanityEnvVar('SERVER_HOSTNAME', true)
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @internal
|
|
18
|
+
*/ export function getSanityEnvVar(suffix, isApp) {
|
|
19
|
+
const prefix = isApp ? 'SANITY_APP_' : 'SANITY_STUDIO_';
|
|
20
|
+
const envVarName = `${prefix}${suffix}`;
|
|
21
|
+
return process.env[envVarName];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
//# sourceMappingURL=getSanityEnvVar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/util/getSanityEnvVar.ts"],"sourcesContent":["/**\n * Gets an environment variable with the appropriate Sanity prefix based on whether it's an app or studio.\n *\n * @param suffix - The suffix for the environment variable (e.g., 'SERVER_HOSTNAME')\n * @param isApp - Whether to use the app prefix (SANITY_APP_) or studio prefix (SANITY_STUDIO_)\n * @returns The value of the environment variable, or undefined if not set\n *\n * @example\n * ```ts\n * // For studio: SANITY_STUDIO_SERVER_HOSTNAME\n * const studioHostname = getSanityEnvVar('SERVER_HOSTNAME', false)\n *\n * // For app: SANITY_APP_SERVER_HOSTNAME\n * const appHostname = getSanityEnvVar('SERVER_HOSTNAME', true)\n * ```\n *\n * @internal\n */\nexport function getSanityEnvVar(suffix: string, isApp: boolean): string | undefined {\n const prefix = isApp ? 'SANITY_APP_' : 'SANITY_STUDIO_'\n const envVarName = `${prefix}${suffix}`\n return process.env[envVarName]\n}\n"],"names":["getSanityEnvVar","suffix","isApp","prefix","envVarName","process","env"],"mappings":"AAAA;;;;;;;;;;;;;;;;;CAiBC,GACD,OAAO,SAASA,gBAAgBC,MAAc,EAAEC,KAAc;IAC5D,MAAMC,SAASD,QAAQ,gBAAgB;IACvC,MAAME,aAAa,GAAGD,SAASF,QAAQ;IACvC,OAAOI,QAAQC,GAAG,CAACF,WAAW;AAChC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @internal
|
|
3
|
+
* @returns The domain for sanity depending on the environment
|
|
4
|
+
*/ export function getSanityUrl() {
|
|
5
|
+
return process.env.SANITY_INTERNAL_ENV === 'staging' ? 'https://www.sanity.work' : 'https://www.sanity.io';
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
//# sourceMappingURL=getSanityUrl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/util/getSanityUrl.ts"],"sourcesContent":["/**\n * @internal\n * @returns The domain for sanity depending on the environment\n */\nexport function getSanityUrl() {\n return process.env.SANITY_INTERNAL_ENV === 'staging'\n ? 'https://www.sanity.work'\n : 'https://www.sanity.io'\n}\n"],"names":["getSanityUrl","process","env","SANITY_INTERNAL_ENV"],"mappings":"AAAA;;;CAGC,GACD,OAAO,SAASA;IACd,OAAOC,QAAQC,GAAG,CAACC,mBAAmB,KAAK,YACvC,4BACA;AACN"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import ConfigStore from 'configstore';
|
|
2
|
+
const sanityEnv = (process.env.SANITY_INTERNAL_ENV || '').toLowerCase();
|
|
3
|
+
const configName = sanityEnv && sanityEnv !== 'production' ? `sanity-${sanityEnv}` : 'sanity';
|
|
4
|
+
const defaults = {};
|
|
5
|
+
let config;
|
|
6
|
+
export const getUserConfig = ()=>{
|
|
7
|
+
if (!config) {
|
|
8
|
+
config = new ConfigStore(configName, defaults, {
|
|
9
|
+
globalConfigPath: true
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
return config;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=getUserConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/util/getUserConfig.ts"],"sourcesContent":["import ConfigStore from 'configstore'\n\nconst sanityEnv = (process.env.SANITY_INTERNAL_ENV || '').toLowerCase()\nconst configName = sanityEnv && sanityEnv !== 'production' ? `sanity-${sanityEnv}` : 'sanity'\nconst defaults = {}\nlet config: ConfigStore\n\nexport const getUserConfig = (): ConfigStore => {\n if (!config) {\n config = new ConfigStore(configName, defaults, {globalConfigPath: true})\n }\n\n return config\n}\n"],"names":["ConfigStore","sanityEnv","process","env","SANITY_INTERNAL_ENV","toLowerCase","configName","defaults","config","getUserConfig","globalConfigPath"],"mappings":"AAAA,OAAOA,iBAAiB,cAAa;AAErC,MAAMC,YAAY,AAACC,CAAAA,QAAQC,GAAG,CAACC,mBAAmB,IAAI,EAAC,EAAGC,WAAW;AACrE,MAAMC,aAAaL,aAAaA,cAAc,eAAe,CAAC,OAAO,EAAEA,WAAW,GAAG;AACrF,MAAMM,WAAW,CAAC;AAClB,IAAIC;AAEJ,OAAO,MAAMC,gBAAgB;IAC3B,IAAI,CAACD,QAAQ;QACXA,SAAS,IAAIR,YAAYM,YAAYC,UAAU;YAACG,kBAAkB;QAAI;IACxE;IAEA,OAAOF;AACT,EAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const isCi: () => boolean;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { isTrueish } from './isTrueish.js';
|
|
2
|
+
export const isCi = ()=>isTrueish(process.env.CI) || // Travis CI, CircleCI, Gitlab CI, Appveyor, CodeShip
|
|
3
|
+
isTrueish(process.env.CONTINUOUS_INTEGRATION) || // Travis CI
|
|
4
|
+
isTrueish(process.env.BUILD_NUMBER) // Jenkins, TeamCity
|
|
5
|
+
;
|
|
6
|
+
|
|
7
|
+
//# sourceMappingURL=isCi.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/util/isCi.ts"],"sourcesContent":["import {isTrueish} from './isTrueish.js'\n\nexport const isCi = (): boolean =>\n isTrueish(process.env.CI) || // Travis CI, CircleCI, Gitlab CI, Appveyor, CodeShip\n isTrueish(process.env.CONTINUOUS_INTEGRATION) || // Travis CI\n isTrueish(process.env.BUILD_NUMBER) // Jenkins, TeamCity\n"],"names":["isTrueish","isCi","process","env","CI","CONTINUOUS_INTEGRATION","BUILD_NUMBER"],"mappings":"AAAA,SAAQA,SAAS,QAAO,iBAAgB;AAExC,OAAO,MAAMC,OAAO,IAClBD,UAAUE,QAAQC,GAAG,CAACC,EAAE,KAAK,qDAAqD;IAClFJ,UAAUE,QAAQC,GAAG,CAACE,sBAAsB,KAAK,YAAY;IAC7DL,UAAUE,QAAQC,GAAG,CAACG,YAAY,EAAE,oBAAoB;CAArB"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Incomplete error type for [get-it](https://github.com/sanity-io/get-it)
|
|
3
|
+
* `httpError` middleware. Should preferably be tidied up and exported
|
|
4
|
+
* from that module. Feel free to do so if you've got time! 🙏
|
|
5
|
+
*
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
interface HttpError {
|
|
9
|
+
request: {
|
|
10
|
+
headers: unknown;
|
|
11
|
+
};
|
|
12
|
+
response: {
|
|
13
|
+
body: unknown;
|
|
14
|
+
method: string;
|
|
15
|
+
statusCode: number;
|
|
16
|
+
statusMessage: string;
|
|
17
|
+
url: string;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Checks if the given `err` is an instance of `HttpError` from `get-it`
|
|
22
|
+
* (request library used by `@sanity/client`).
|
|
23
|
+
*
|
|
24
|
+
* @param err - The error to check
|
|
25
|
+
* @returns `true` if the error is an instance of `HttpError`, otherwise `false`
|
|
26
|
+
* @internal
|
|
27
|
+
*/
|
|
28
|
+
export declare function isHttpError(err: unknown): err is HttpError;
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Incomplete error type for [get-it](https://github.com/sanity-io/get-it)
|
|
3
|
+
* `httpError` middleware. Should preferably be tidied up and exported
|
|
4
|
+
* from that module. Feel free to do so if you've got time! 🙏
|
|
5
|
+
*
|
|
6
|
+
* @internal
|
|
7
|
+
*/ /**
|
|
8
|
+
* Checks if the given `err` is an instance of `HttpError` from `get-it`
|
|
9
|
+
* (request library used by `@sanity/client`).
|
|
10
|
+
*
|
|
11
|
+
* @param err - The error to check
|
|
12
|
+
* @returns `true` if the error is an instance of `HttpError`, otherwise `false`
|
|
13
|
+
* @internal
|
|
14
|
+
*/ export function isHttpError(err) {
|
|
15
|
+
return err instanceof Error && 'request' in err && 'response' in err && typeof err.response === 'object' && err.response !== null && 'statusCode' in err.response && typeof err.response.statusCode === 'number';
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
//# sourceMappingURL=isHttpError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/util/isHttpError.ts"],"sourcesContent":["/**\n * Incomplete error type for [get-it](https://github.com/sanity-io/get-it)\n * `httpError` middleware. Should preferably be tidied up and exported\n * from that module. Feel free to do so if you've got time! 🙏\n *\n * @internal\n */\ninterface HttpError {\n request: {\n headers: unknown\n }\n response: {\n body: unknown\n method: string\n statusCode: number\n statusMessage: string\n url: string\n }\n}\n\n/**\n * Checks if the given `err` is an instance of `HttpError` from `get-it`\n * (request library used by `@sanity/client`).\n *\n * @param err - The error to check\n * @returns `true` if the error is an instance of `HttpError`, otherwise `false`\n * @internal\n */\nexport function isHttpError(err: unknown): err is HttpError {\n return (\n err instanceof Error &&\n 'request' in err &&\n 'response' in err &&\n typeof err.response === 'object' &&\n err.response !== null &&\n 'statusCode' in err.response &&\n typeof err.response.statusCode === 'number'\n )\n}\n"],"names":["isHttpError","err","Error","response","statusCode"],"mappings":"AAAA;;;;;;CAMC,GAcD;;;;;;;CAOC,GACD,OAAO,SAASA,YAAYC,GAAY;IACtC,OACEA,eAAeC,SACf,aAAaD,OACb,cAAcA,OACd,OAAOA,IAAIE,QAAQ,KAAK,YACxBF,IAAIE,QAAQ,KAAK,QACjB,gBAAgBF,IAAIE,QAAQ,IAC5B,OAAOF,IAAIE,QAAQ,CAACC,UAAU,KAAK;AAEvC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isInteractive(): boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/util/isInteractive.ts"],"sourcesContent":["export function isInteractive(): boolean {\n return process.stdout.isTTY && process.env.TERM !== 'dumb' && !('CI' in process.env)\n}\n"],"names":["isInteractive","process","stdout","isTTY","env","TERM"],"mappings":"AAAA,OAAO,SAASA;IACd,OAAOC,QAAQC,MAAM,CAACC,KAAK,IAAIF,QAAQG,GAAG,CAACC,IAAI,KAAK,UAAU,CAAE,CAAA,QAAQJ,QAAQG,GAAG,AAAD;AACpF"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if the given value is a record (javascript objectish)
|
|
3
|
+
*
|
|
4
|
+
* @param value - Value to check
|
|
5
|
+
* @returns True if the value is a record, false otherwise
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
export declare function isRecord(value: unknown): value is Record<string, unknown>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if the given value is a record (javascript objectish)
|
|
3
|
+
*
|
|
4
|
+
* @param value - Value to check
|
|
5
|
+
* @returns True if the value is a record, false otherwise
|
|
6
|
+
* @internal
|
|
7
|
+
*/ export function isRecord(value) {
|
|
8
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=isRecord.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/util/isRecord.ts"],"sourcesContent":["/**\n * Checks if the given value is a record (javascript objectish)\n *\n * @param value - Value to check\n * @returns True if the value is a record, false otherwise\n * @internal\n */\nexport function isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value)\n}\n"],"names":["isRecord","value","Array","isArray"],"mappings":"AAAA;;;;;;CAMC,GACD,OAAO,SAASA,SAASC,KAAc;IACrC,OAAO,OAAOA,UAAU,YAAYA,UAAU,QAAQ,CAACC,MAAMC,OAAO,CAACF;AACvE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isTrueish(value: string | undefined): boolean;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export function isTrueish(value) {
|
|
2
|
+
if (value === undefined) return false;
|
|
3
|
+
if (value.toLowerCase() === 'true') return true;
|
|
4
|
+
if (value.toLowerCase() === 'false') return false;
|
|
5
|
+
const number = Number.parseInt(value, 10);
|
|
6
|
+
if (Number.isNaN(number)) return false;
|
|
7
|
+
return number > 0;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
//# sourceMappingURL=isTrueish.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/util/isTrueish.ts"],"sourcesContent":["export function isTrueish(value: string | undefined) {\n if (value === undefined) return false\n if (value.toLowerCase() === 'true') return true\n if (value.toLowerCase() === 'false') return false\n const number = Number.parseInt(value, 10)\n if (Number.isNaN(number)) return false\n return number > 0\n}\n"],"names":["isTrueish","value","undefined","toLowerCase","number","Number","parseInt","isNaN"],"mappings":"AAAA,OAAO,SAASA,UAAUC,KAAyB;IACjD,IAAIA,UAAUC,WAAW,OAAO;IAChC,IAAID,MAAME,WAAW,OAAO,QAAQ,OAAO;IAC3C,IAAIF,MAAME,WAAW,OAAO,SAAS,OAAO;IAC5C,MAAMC,SAASC,OAAOC,QAAQ,CAACL,OAAO;IACtC,IAAII,OAAOE,KAAK,CAACH,SAAS,OAAO;IACjC,OAAOA,SAAS;AAClB"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
/**
|
|
3
|
+
* Read the file at the given path and parse it as JSON.
|
|
4
|
+
*
|
|
5
|
+
* @param filePath - Path to JSON file to read
|
|
6
|
+
* @returns The parsed file
|
|
7
|
+
* @internal
|
|
8
|
+
*/ export async function readJsonFile(filePath) {
|
|
9
|
+
let content;
|
|
10
|
+
try {
|
|
11
|
+
content = await readFile(filePath, 'utf8');
|
|
12
|
+
} catch (err) {
|
|
13
|
+
throw new Error(`Failed to read "${filePath}"`, {
|
|
14
|
+
cause: err
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
try {
|
|
18
|
+
return JSON.parse(content);
|
|
19
|
+
} catch (err) {
|
|
20
|
+
throw new Error(`Failed to parse "${filePath}" as JSON`, {
|
|
21
|
+
cause: err
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=readJsonFile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/util/readJsonFile.ts"],"sourcesContent":["import {readFile} from 'node:fs/promises'\n\n/**\n * Read the file at the given path and parse it as JSON.\n *\n * @param filePath - Path to JSON file to read\n * @returns The parsed file\n * @internal\n */\nexport async function readJsonFile(filePath: string): Promise<any> {\n let content: string\n try {\n content = await readFile(filePath, 'utf8')\n } catch (err: unknown) {\n throw new Error(`Failed to read \"${filePath}\"`, {cause: err})\n }\n\n try {\n return JSON.parse(content)\n } catch (err: unknown) {\n throw new Error(`Failed to parse \"${filePath}\" as JSON`, {cause: err})\n }\n}\n"],"names":["readFile","readJsonFile","filePath","content","err","Error","cause","JSON","parse"],"mappings":"AAAA,SAAQA,QAAQ,QAAO,mBAAkB;AAEzC;;;;;;CAMC,GACD,OAAO,eAAeC,aAAaC,QAAgB;IACjD,IAAIC;IACJ,IAAI;QACFA,UAAU,MAAMH,SAASE,UAAU;IACrC,EAAE,OAAOE,KAAc;QACrB,MAAM,IAAIC,MAAM,CAAC,gBAAgB,EAAEH,SAAS,CAAC,CAAC,EAAE;YAACI,OAAOF;QAAG;IAC7D;IAEA,IAAI;QACF,OAAOG,KAAKC,KAAK,CAACL;IACpB,EAAE,OAAOC,KAAc;QACrB,MAAM,IAAIC,MAAM,CAAC,iBAAiB,EAAEH,SAAS,SAAS,CAAC,EAAE;YAACI,OAAOF;QAAG;IACtE;AACF"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `structuredClone()`, but doesn't throw on non-clonable values - instead it drops them.
|
|
3
|
+
*
|
|
4
|
+
* @param obj - The object to clone.
|
|
5
|
+
* @returns The cloned object.
|
|
6
|
+
* @internal
|
|
7
|
+
*/ export function safeStructuredClone(obj) {
|
|
8
|
+
const seen = new WeakMap();
|
|
9
|
+
function clone(value) {
|
|
10
|
+
if (typeof value === 'function' || typeof value === 'symbol') {
|
|
11
|
+
return undefined; // Drop non-clonable values
|
|
12
|
+
}
|
|
13
|
+
if (value !== null && typeof value === 'object') {
|
|
14
|
+
if (seen.has(value)) return seen.get(value);
|
|
15
|
+
if (value instanceof Date) return new Date(value);
|
|
16
|
+
if (value instanceof RegExp) return new RegExp(value);
|
|
17
|
+
if (value instanceof Set) return new Set([
|
|
18
|
+
...value
|
|
19
|
+
].map((item)=>clone(item)));
|
|
20
|
+
if (value instanceof Map) return new Map([
|
|
21
|
+
...value.entries()
|
|
22
|
+
].map(([k, v])=>[
|
|
23
|
+
clone(k),
|
|
24
|
+
clone(v)
|
|
25
|
+
]));
|
|
26
|
+
if (ArrayBuffer.isView(value)) return new value.constructor(value);
|
|
27
|
+
const result = Array.isArray(value) ? [] : {};
|
|
28
|
+
seen.set(value, result);
|
|
29
|
+
for(const key in value){
|
|
30
|
+
const clonedValue = clone(value[key]);
|
|
31
|
+
if (clonedValue !== undefined) result[key] = clonedValue;
|
|
32
|
+
}
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
35
|
+
return value;
|
|
36
|
+
}
|
|
37
|
+
return clone(obj);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
//# sourceMappingURL=safeStructuredClone.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/util/safeStructuredClone.ts"],"sourcesContent":["/**\n * `structuredClone()`, but doesn't throw on non-clonable values - instead it drops them.\n *\n * @param obj - The object to clone.\n * @returns The cloned object.\n * @internal\n */\nexport function safeStructuredClone<T>(obj: T): T {\n const seen = new WeakMap<object, any>()\n\n function clone<T>(value: T): T {\n if (typeof value === 'function' || typeof value === 'symbol') {\n return undefined as unknown as T // Drop non-clonable values\n }\n if (value !== null && typeof value === 'object') {\n if (seen.has(value)) return seen.get(value)\n\n if (value instanceof Date) return new Date(value) as T\n if (value instanceof RegExp) return new RegExp(value) as T\n if (value instanceof Set) return new Set([...value].map((item) => clone(item))) as T\n if (value instanceof Map)\n return new Map([...value.entries()].map(([k, v]) => [clone(k), clone(v)])) as T\n if (ArrayBuffer.isView(value)) return new (value.constructor as any)(value) as T\n\n const result: any = Array.isArray(value) ? [] : {}\n seen.set(value, result)\n\n for (const key in value) {\n const clonedValue = clone(value[key])\n if (clonedValue !== undefined) result[key] = clonedValue\n }\n return result as T\n }\n return value\n }\n\n return clone(obj)\n}\n"],"names":["safeStructuredClone","obj","seen","WeakMap","clone","value","undefined","has","get","Date","RegExp","Set","map","item","Map","entries","k","v","ArrayBuffer","isView","result","Array","isArray","set","key","clonedValue"],"mappings":"AAAA;;;;;;CAMC,GACD,OAAO,SAASA,oBAAuBC,GAAM;IAC3C,MAAMC,OAAO,IAAIC;IAEjB,SAASC,MAASC,KAAQ;QACxB,IAAI,OAAOA,UAAU,cAAc,OAAOA,UAAU,UAAU;YAC5D,OAAOC,WAA0B,2BAA2B;QAC9D;QACA,IAAID,UAAU,QAAQ,OAAOA,UAAU,UAAU;YAC/C,IAAIH,KAAKK,GAAG,CAACF,QAAQ,OAAOH,KAAKM,GAAG,CAACH;YAErC,IAAIA,iBAAiBI,MAAM,OAAO,IAAIA,KAAKJ;YAC3C,IAAIA,iBAAiBK,QAAQ,OAAO,IAAIA,OAAOL;YAC/C,IAAIA,iBAAiBM,KAAK,OAAO,IAAIA,IAAI;mBAAIN;aAAM,CAACO,GAAG,CAAC,CAACC,OAAST,MAAMS;YACxE,IAAIR,iBAAiBS,KACnB,OAAO,IAAIA,IAAI;mBAAIT,MAAMU,OAAO;aAAG,CAACH,GAAG,CAAC,CAAC,CAACI,GAAGC,EAAE,GAAK;oBAACb,MAAMY;oBAAIZ,MAAMa;iBAAG;YAC1E,IAAIC,YAAYC,MAAM,CAACd,QAAQ,OAAO,IAAKA,MAAM,WAAW,CAASA;YAErE,MAAMe,SAAcC,MAAMC,OAAO,CAACjB,SAAS,EAAE,GAAG,CAAC;YACjDH,KAAKqB,GAAG,CAAClB,OAAOe;YAEhB,IAAK,MAAMI,OAAOnB,MAAO;gBACvB,MAAMoB,cAAcrB,MAAMC,KAAK,CAACmB,IAAI;gBACpC,IAAIC,gBAAgBnB,WAAWc,MAAM,CAACI,IAAI,GAAGC;YAC/C;YACA,OAAOL;QACT;QACA,OAAOf;IACT;IAEA,OAAOD,MAAMH;AACf"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Serialize the given `data` as JSON and write it to the given path.
|
|
3
|
+
*
|
|
4
|
+
* @param filePath - Path to JSON file to read
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
export declare function writeJsonFile(filePath: string, data: unknown, options?: {
|
|
8
|
+
pretty?: boolean;
|
|
9
|
+
}): Promise<void>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { writeFile } from 'node:fs/promises';
|
|
2
|
+
/**
|
|
3
|
+
* Serialize the given `data` as JSON and write it to the given path.
|
|
4
|
+
*
|
|
5
|
+
* @param filePath - Path to JSON file to read
|
|
6
|
+
* @internal
|
|
7
|
+
*/ export async function writeJsonFile(filePath, data, options = {}) {
|
|
8
|
+
const { pretty = false } = options;
|
|
9
|
+
try {
|
|
10
|
+
const stringified = pretty ? JSON.stringify(data, null, 2) : JSON.stringify(data);
|
|
11
|
+
await writeFile(filePath, stringified, 'utf8');
|
|
12
|
+
} catch (err) {
|
|
13
|
+
throw new Error(`Failed to write "${filePath}"`, {
|
|
14
|
+
cause: err
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=writeJsonFile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/util/writeJsonFile.ts"],"sourcesContent":["import {writeFile} from 'node:fs/promises'\n\n/**\n * Serialize the given `data` as JSON and write it to the given path.\n *\n * @param filePath - Path to JSON file to read\n * @internal\n */\nexport async function writeJsonFile(\n filePath: string,\n data: unknown,\n options: {pretty?: boolean} = {},\n): Promise<void> {\n const {pretty = false} = options\n try {\n const stringified = pretty ? JSON.stringify(data, null, 2) : JSON.stringify(data)\n await writeFile(filePath, stringified, 'utf8')\n } catch (err: unknown) {\n throw new Error(`Failed to write \"${filePath}\"`, {cause: err})\n }\n}\n"],"names":["writeFile","writeJsonFile","filePath","data","options","pretty","stringified","JSON","stringify","err","Error","cause"],"mappings":"AAAA,SAAQA,SAAS,QAAO,mBAAkB;AAE1C;;;;;CAKC,GACD,OAAO,eAAeC,cACpBC,QAAgB,EAChBC,IAAa,EACbC,UAA8B,CAAC,CAAC;IAEhC,MAAM,EAACC,SAAS,KAAK,EAAC,GAAGD;IACzB,IAAI;QACF,MAAME,cAAcD,SAASE,KAAKC,SAAS,CAACL,MAAM,MAAM,KAAKI,KAAKC,SAAS,CAACL;QAC5E,MAAMH,UAAUE,UAAUI,aAAa;IACzC,EAAE,OAAOG,KAAc;QACrB,MAAM,IAAIC,MAAM,CAAC,iBAAiB,EAAER,SAAS,CAAC,CAAC,EAAE;YAACS,OAAOF;QAAG;IAC9D;AACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function colorizeJson(input: unknown): string;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import tokenize from 'json-lexer';
|
|
3
|
+
/**
|
|
4
|
+
* Colorize JSON output for better readability using simple regex patterns
|
|
5
|
+
*/ const identity = (inp)=>inp;
|
|
6
|
+
export function colorizeJson(input) {
|
|
7
|
+
const formatters = {
|
|
8
|
+
key: chalk.white,
|
|
9
|
+
literal: chalk.bold,
|
|
10
|
+
number: chalk.yellow,
|
|
11
|
+
punctuator: chalk.white,
|
|
12
|
+
string: chalk.green,
|
|
13
|
+
whitespace: identity
|
|
14
|
+
};
|
|
15
|
+
const json = JSON.stringify(input, null, 2);
|
|
16
|
+
return tokenize(json).map((token, i, arr)=>{
|
|
17
|
+
// Note how the following only works because we pretty-print the JSON
|
|
18
|
+
const prevToken = i === 0 ? token : arr[i - 1];
|
|
19
|
+
if (token.type === 'string' && prevToken.type === 'whitespace' && /^\n\s+$/.test(prevToken.value)) {
|
|
20
|
+
return {
|
|
21
|
+
...token,
|
|
22
|
+
type: 'key'
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
return token;
|
|
26
|
+
}).map((token)=>{
|
|
27
|
+
const formatter = formatters[token.type] || identity;
|
|
28
|
+
return formatter(token.raw);
|
|
29
|
+
}).join('');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=colorizeJson.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/ux/colorizeJson.ts"],"sourcesContent":["import chalk from 'chalk'\nimport tokenize, {type LexerToken} from 'json-lexer'\n\ninterface KeyToken {\n raw: string\n type: 'key'\n value: string\n}\n\ntype ExtendedLexerToken = KeyToken | LexerToken\n\n/**\n * Colorize JSON output for better readability using simple regex patterns\n */\nconst identity = (inp: string): string => inp\n\nexport function colorizeJson(input: unknown): string {\n const formatters: Record<ExtendedLexerToken['type'], (str: string) => string> = {\n key: chalk.white,\n literal: chalk.bold,\n number: chalk.yellow,\n punctuator: chalk.white,\n string: chalk.green,\n whitespace: identity,\n }\n\n const json = JSON.stringify(input, null, 2)\n\n return tokenize(json)\n .map((token, i, arr): ExtendedLexerToken => {\n // Note how the following only works because we pretty-print the JSON\n const prevToken = i === 0 ? token : arr[i - 1]\n if (\n token.type === 'string' &&\n prevToken.type === 'whitespace' &&\n /^\\n\\s+$/.test(prevToken.value)\n ) {\n return {...token, type: 'key'}\n }\n\n return token\n })\n .map((token) => {\n const formatter = formatters[token.type] || identity\n return formatter(token.raw)\n })\n .join('')\n}\n"],"names":["chalk","tokenize","identity","inp","colorizeJson","input","formatters","key","white","literal","bold","number","yellow","punctuator","string","green","whitespace","json","JSON","stringify","map","token","i","arr","prevToken","type","test","value","formatter","raw","join"],"mappings":"AAAA,OAAOA,WAAW,QAAO;AACzB,OAAOC,cAAiC,aAAY;AAUpD;;CAEC,GACD,MAAMC,WAAW,CAACC,MAAwBA;AAE1C,OAAO,SAASC,aAAaC,KAAc;IACzC,MAAMC,aAA0E;QAC9EC,KAAKP,MAAMQ,KAAK;QAChBC,SAAST,MAAMU,IAAI;QACnBC,QAAQX,MAAMY,MAAM;QACpBC,YAAYb,MAAMQ,KAAK;QACvBM,QAAQd,MAAMe,KAAK;QACnBC,YAAYd;IACd;IAEA,MAAMe,OAAOC,KAAKC,SAAS,CAACd,OAAO,MAAM;IAEzC,OAAOJ,SAASgB,MACbG,GAAG,CAAC,CAACC,OAAOC,GAAGC;QACd,qEAAqE;QACrE,MAAMC,YAAYF,MAAM,IAAID,QAAQE,GAAG,CAACD,IAAI,EAAE;QAC9C,IACED,MAAMI,IAAI,KAAK,YACfD,UAAUC,IAAI,KAAK,gBACnB,UAAUC,IAAI,CAACF,UAAUG,KAAK,GAC9B;YACA,OAAO;gBAAC,GAAGN,KAAK;gBAAEI,MAAM;YAAK;QAC/B;QAEA,OAAOJ;IACT,GACCD,GAAG,CAAC,CAACC;QACJ,MAAMO,YAAYtB,UAAU,CAACe,MAAMI,IAAI,CAAC,IAAIvB;QAC5C,OAAO0B,UAAUP,MAAMQ,GAAG;IAC5B,GACCC,IAAI,CAAC;AACV"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function formatObject(obj: unknown): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/ux/formatObject.ts"],"sourcesContent":["import {inspect} from 'node:util'\n\nexport function formatObject(obj: unknown): string {\n return inspect(obj, {colors: true, depth: +Infinity})\n}\n"],"names":["inspect","formatObject","obj","colors","depth","Infinity"],"mappings":"AAAA,SAAQA,OAAO,QAAO,YAAW;AAEjC,OAAO,SAASC,aAAaC,GAAY;IACvC,OAAOF,QAAQE,KAAK;QAACC,QAAQ;QAAMC,OAAO,CAACC;IAAQ;AACrD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as logSymbols } from 'log-symbols';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/ux/logSymbols.ts"],"sourcesContent":["export {default as logSymbols} from 'log-symbols'\n"],"names":["default","logSymbols"],"mappings":"AAAA,SAAQA,WAAWC,UAAU,QAAO,cAAa"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function printKeyValue(obj: Record<string, unknown>): void;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ux } from '@oclif/core';
|
|
2
|
+
import { formatObject } from './formatObject.js';
|
|
3
|
+
export function printKeyValue(obj) {
|
|
4
|
+
let printedLines = 0;
|
|
5
|
+
for (const key of Object.keys(obj)){
|
|
6
|
+
if (obj[key] !== undefined) {
|
|
7
|
+
ux.stdout(` ${key}: ${formatObject(obj[key])}`);
|
|
8
|
+
printedLines++;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
if (printedLines > 0) {
|
|
12
|
+
ux.stdout('');
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
//# sourceMappingURL=printKeyValue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/ux/printKeyValue.ts"],"sourcesContent":["import {ux} from '@oclif/core'\n\nimport {formatObject} from './formatObject.js'\n\nexport function printKeyValue(obj: Record<string, unknown>): void {\n let printedLines = 0\n for (const key of Object.keys(obj)) {\n if (obj[key] !== undefined) {\n ux.stdout(` ${key}: ${formatObject(obj[key])}`)\n printedLines++\n }\n }\n\n if (printedLines > 0) {\n ux.stdout('')\n }\n}\n"],"names":["ux","formatObject","printKeyValue","obj","printedLines","key","Object","keys","undefined","stdout"],"mappings":"AAAA,SAAQA,EAAE,QAAO,cAAa;AAE9B,SAAQC,YAAY,QAAO,oBAAmB;AAE9C,OAAO,SAASC,cAAcC,GAA4B;IACxD,IAAIC,eAAe;IACnB,KAAK,MAAMC,OAAOC,OAAOC,IAAI,CAACJ,KAAM;QAClC,IAAIA,GAAG,CAACE,IAAI,KAAKG,WAAW;YAC1BR,GAAGS,MAAM,CAAC,CAAC,EAAE,EAAEJ,IAAI,EAAE,EAAEJ,aAAaE,GAAG,CAACE,IAAI,GAAG;YAC/CD;QACF;IACF;IAEA,IAAIA,eAAe,GAAG;QACpBJ,GAAGS,MAAM,CAAC;IACZ;AACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as spinner } from 'ora';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/ux/spinner.ts"],"sourcesContent":["export {default as spinner} from 'ora'\n"],"names":["default","spinner"],"mappings":"AAAA,SAAQA,WAAWC,OAAO,QAAO,MAAK"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
interface TimeMeasurer {
|
|
2
|
+
end: (name: string) => number;
|
|
3
|
+
getTimings: () => Record<string, number>;
|
|
4
|
+
start: (name: string) => void;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Starts a terminal timer
|
|
8
|
+
*
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
export declare function getTimer(): TimeMeasurer;
|
|
12
|
+
export {};
|
package/dist/ux/timer.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { performance } from 'node:perf_hooks';
|
|
2
|
+
/**
|
|
3
|
+
* Starts a terminal timer
|
|
4
|
+
*
|
|
5
|
+
* @internal
|
|
6
|
+
*/ export function getTimer() {
|
|
7
|
+
const timings = {};
|
|
8
|
+
const startTimes = {};
|
|
9
|
+
function start(name) {
|
|
10
|
+
if (startTimes[name] !== undefined) {
|
|
11
|
+
throw new TypeError(`Timer "${name}" already started, cannot overwrite`);
|
|
12
|
+
}
|
|
13
|
+
startTimes[name] = performance.now();
|
|
14
|
+
}
|
|
15
|
+
function end(name) {
|
|
16
|
+
if (startTimes[name] === undefined) {
|
|
17
|
+
throw new TypeError(`Timer "${name}" never started, cannot end`);
|
|
18
|
+
}
|
|
19
|
+
timings[name] = performance.now() - startTimes[name];
|
|
20
|
+
return timings[name];
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
end,
|
|
24
|
+
getTimings: ()=>timings,
|
|
25
|
+
start
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
//# sourceMappingURL=timer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/ux/timer.ts"],"sourcesContent":["import {performance} from 'node:perf_hooks'\n\ninterface TimeMeasurer {\n end: (name: string) => number\n getTimings: () => Record<string, number>\n start: (name: string) => void\n}\n\n/**\n * Starts a terminal timer\n *\n * @internal\n */\nexport function getTimer(): TimeMeasurer {\n const timings: Record<string, number> = {}\n const startTimes: Record<string, number> = {}\n\n function start(name: string): void {\n if (startTimes[name] !== undefined) {\n throw new TypeError(`Timer \"${name}\" already started, cannot overwrite`)\n }\n\n startTimes[name] = performance.now()\n }\n\n function end(name: string): number {\n if (startTimes[name] === undefined) {\n throw new TypeError(`Timer \"${name}\" never started, cannot end`)\n }\n\n timings[name] = performance.now() - startTimes[name]\n return timings[name]\n }\n\n return {end, getTimings: () => timings, start}\n}\n"],"names":["performance","getTimer","timings","startTimes","start","name","undefined","TypeError","now","end","getTimings"],"mappings":"AAAA,SAAQA,WAAW,QAAO,kBAAiB;AAQ3C;;;;CAIC,GACD,OAAO,SAASC;IACd,MAAMC,UAAkC,CAAC;IACzC,MAAMC,aAAqC,CAAC;IAE5C,SAASC,MAAMC,IAAY;QACzB,IAAIF,UAAU,CAACE,KAAK,KAAKC,WAAW;YAClC,MAAM,IAAIC,UAAU,CAAC,OAAO,EAAEF,KAAK,mCAAmC,CAAC;QACzE;QAEAF,UAAU,CAACE,KAAK,GAAGL,YAAYQ,GAAG;IACpC;IAEA,SAASC,IAAIJ,IAAY;QACvB,IAAIF,UAAU,CAACE,KAAK,KAAKC,WAAW;YAClC,MAAM,IAAIC,UAAU,CAAC,OAAO,EAAEF,KAAK,2BAA2B,CAAC;QACjE;QAEAH,OAAO,CAACG,KAAK,GAAGL,YAAYQ,GAAG,KAAKL,UAAU,CAACE,KAAK;QACpD,OAAOH,OAAO,CAACG,KAAK;IACtB;IAEA,OAAO;QAACI;QAAKC,YAAY,IAAMR;QAASE;IAAK;AAC/C"}
|