@slicemachine/manager 0.15.4-dev-environments.4 → 0.15.4-dev-next-release.2
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/dist/auth/PrismicAuthManager.cjs +1 -1
- package/dist/auth/PrismicAuthManager.cjs.map +1 -1
- package/dist/auth/PrismicAuthManager.js +2 -2
- package/dist/auth/PrismicAuthManager.js.map +1 -1
- package/dist/client/index.d.ts +1 -2
- package/dist/client.cjs +0 -1
- package/dist/client.cjs.map +1 -1
- package/dist/client.js +1 -2
- package/dist/constants/API_ENDPOINTS.cjs +3 -6
- package/dist/constants/API_ENDPOINTS.cjs.map +1 -1
- package/dist/constants/API_ENDPOINTS.d.ts +0 -1
- package/dist/constants/API_ENDPOINTS.js +3 -6
- package/dist/constants/API_ENDPOINTS.js.map +1 -1
- package/dist/errors.cjs +0 -20
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.d.ts +0 -1
- package/dist/errors.js +0 -20
- package/dist/errors.js.map +1 -1
- package/dist/index.cjs +0 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -9
- package/dist/index.js.map +1 -1
- package/dist/managers/customTypes/CustomTypesManager.cjs +4 -4
- package/dist/managers/customTypes/CustomTypesManager.cjs.map +1 -1
- package/dist/managers/customTypes/CustomTypesManager.js +4 -4
- package/dist/managers/customTypes/CustomTypesManager.js.map +1 -1
- package/dist/managers/prismicRepository/PrismicRepositoryManager.cjs +4 -37
- package/dist/managers/prismicRepository/PrismicRepositoryManager.cjs.map +1 -1
- package/dist/managers/prismicRepository/PrismicRepositoryManager.d.ts +1 -2
- package/dist/managers/prismicRepository/PrismicRepositoryManager.js +5 -38
- package/dist/managers/prismicRepository/PrismicRepositoryManager.js.map +1 -1
- package/dist/managers/prismicRepository/types.cjs +0 -9
- package/dist/managers/prismicRepository/types.cjs.map +1 -1
- package/dist/managers/prismicRepository/types.d.ts +0 -9
- package/dist/managers/prismicRepository/types.js +0 -9
- package/dist/managers/prismicRepository/types.js.map +1 -1
- package/dist/managers/project/ProjectManager.cjs +0 -67
- package/dist/managers/project/ProjectManager.cjs.map +1 -1
- package/dist/managers/project/ProjectManager.d.ts +1 -33
- package/dist/managers/project/ProjectManager.js +1 -67
- package/dist/managers/project/ProjectManager.js.map +1 -1
- package/dist/managers/screenshots/ScreenshotsManager.cjs +2 -2
- package/dist/managers/screenshots/ScreenshotsManager.cjs.map +1 -1
- package/dist/managers/screenshots/ScreenshotsManager.js +2 -2
- package/dist/managers/screenshots/ScreenshotsManager.js.map +1 -1
- package/dist/managers/slices/SlicesManager.cjs +4 -4
- package/dist/managers/slices/SlicesManager.cjs.map +1 -1
- package/dist/managers/slices/SlicesManager.js +4 -4
- package/dist/managers/slices/SlicesManager.js.map +1 -1
- package/package.json +3 -3
- package/src/auth/PrismicAuthManager.ts +1 -1
- package/src/client/index.ts +0 -3
- package/src/constants/API_ENDPOINTS.ts +0 -6
- package/src/errors.ts +0 -4
- package/src/index.ts +0 -13
- package/src/managers/customTypes/CustomTypesManager.ts +4 -4
- package/src/managers/prismicRepository/PrismicRepositoryManager.ts +4 -55
- package/src/managers/prismicRepository/types.ts +0 -12
- package/src/managers/project/ProjectManager.ts +3 -131
- package/src/managers/screenshots/ScreenshotsManager.ts +2 -2
- package/src/managers/slices/SlicesManager.ts +4 -4
- package/dist/managers/prismicRepository/sortEnvironments.cjs +0 -36
- package/dist/managers/prismicRepository/sortEnvironments.cjs.map +0 -1
- package/dist/managers/prismicRepository/sortEnvironments.d.ts +0 -17
- package/dist/managers/prismicRepository/sortEnvironments.js +0 -36
- package/dist/managers/prismicRepository/sortEnvironments.js.map +0 -1
- package/src/managers/prismicRepository/sortEnvironments.ts +0 -55
|
@@ -2,7 +2,6 @@ import * as t from "io-ts";
|
|
|
2
2
|
import fetch, { Response } from "../../lib/fetch";
|
|
3
3
|
import { fold } from "fp-ts/Either";
|
|
4
4
|
|
|
5
|
-
import { assertPluginsInitialized } from "../../lib/assertPluginsInitialized";
|
|
6
5
|
import { decode } from "../../lib/decode";
|
|
7
6
|
import { serializeCookies } from "../../lib/serializeCookies";
|
|
8
7
|
|
|
@@ -10,12 +9,6 @@ import { SLICE_MACHINE_USER_AGENT } from "../../constants/SLICE_MACHINE_USER_AGE
|
|
|
10
9
|
import { API_ENDPOINTS } from "../../constants/API_ENDPOINTS";
|
|
11
10
|
import { REPOSITORY_NAME_VALIDATION } from "../../constants/REPOSITORY_NAME_VALIDATION";
|
|
12
11
|
|
|
13
|
-
import {
|
|
14
|
-
UnauthenticatedError,
|
|
15
|
-
UnauthorizedError,
|
|
16
|
-
UnexpectedDataError,
|
|
17
|
-
} from "../../errors";
|
|
18
|
-
|
|
19
12
|
import { BaseManager } from "../BaseManager";
|
|
20
13
|
|
|
21
14
|
import {
|
|
@@ -34,9 +27,9 @@ import {
|
|
|
34
27
|
TransactionalMergeReturnType,
|
|
35
28
|
FrameworkWroomTelemetryID,
|
|
36
29
|
StarterId,
|
|
37
|
-
Environment,
|
|
38
30
|
} from "./types";
|
|
39
|
-
import {
|
|
31
|
+
import { assertPluginsInitialized } from "../../lib/assertPluginsInitialized";
|
|
32
|
+
import { UnauthenticatedError } from "../../errors";
|
|
40
33
|
|
|
41
34
|
const DEFAULT_REPOSITORY_SETTINGS = {
|
|
42
35
|
plan: "personal",
|
|
@@ -390,14 +383,14 @@ export class PrismicRepositoryManager extends BaseManager {
|
|
|
390
383
|
changes: allChanges,
|
|
391
384
|
};
|
|
392
385
|
|
|
393
|
-
const
|
|
386
|
+
const sliceMachineConfig = await this.project.getSliceMachineConfig();
|
|
394
387
|
|
|
395
388
|
// TODO: move to customtypes client
|
|
396
389
|
const response = await this._fetch({
|
|
397
390
|
url: new URL("./bulk", API_ENDPOINTS.PrismicModels),
|
|
398
391
|
method: "POST",
|
|
399
392
|
body: requestBody,
|
|
400
|
-
repository: repositoryName,
|
|
393
|
+
repository: sliceMachineConfig.repositoryName,
|
|
401
394
|
});
|
|
402
395
|
|
|
403
396
|
switch (response.status) {
|
|
@@ -433,50 +426,6 @@ export class PrismicRepositoryManager extends BaseManager {
|
|
|
433
426
|
}
|
|
434
427
|
}
|
|
435
428
|
|
|
436
|
-
async fetchEnvironments(): Promise<Environment[]> {
|
|
437
|
-
const repositoryName = await this.project.getRepositoryName();
|
|
438
|
-
|
|
439
|
-
const url = new URL(`./environments`, API_ENDPOINTS.SliceMachineV1);
|
|
440
|
-
url.searchParams.set("repository", repositoryName);
|
|
441
|
-
const res = await this._fetch({ url });
|
|
442
|
-
|
|
443
|
-
if (res.ok) {
|
|
444
|
-
const json = await res.json();
|
|
445
|
-
|
|
446
|
-
const { value, error } = decode(
|
|
447
|
-
t.union([
|
|
448
|
-
t.type({
|
|
449
|
-
results: t.array(Environment),
|
|
450
|
-
}),
|
|
451
|
-
t.type({
|
|
452
|
-
error: t.literal("invalid_token"),
|
|
453
|
-
}),
|
|
454
|
-
]),
|
|
455
|
-
json,
|
|
456
|
-
);
|
|
457
|
-
|
|
458
|
-
if (error) {
|
|
459
|
-
throw new UnexpectedDataError(
|
|
460
|
-
`Failed to decode environments: ${error.errors.join(", ")}`,
|
|
461
|
-
);
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
if ("results" in value) {
|
|
465
|
-
return sortEnvironments(value.results);
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
switch (res.status) {
|
|
470
|
-
case 400:
|
|
471
|
-
case 401:
|
|
472
|
-
throw new UnauthenticatedError();
|
|
473
|
-
case 403:
|
|
474
|
-
throw new UnauthorizedError();
|
|
475
|
-
default:
|
|
476
|
-
throw new Error("Failed to fetch environments.");
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
|
|
480
429
|
private _decodeLimitOrThrow(
|
|
481
430
|
potentialLimit: unknown,
|
|
482
431
|
statusCode: number,
|
|
@@ -155,15 +155,3 @@ export type StarterId =
|
|
|
155
155
|
| "nuxt_multi_page"
|
|
156
156
|
| "nuxt_blog"
|
|
157
157
|
| "nuxt_multi_lang";
|
|
158
|
-
|
|
159
|
-
export const Environment = t.type({
|
|
160
|
-
kind: t.union([t.literal("prod"), t.literal("stage"), t.literal("dev")]),
|
|
161
|
-
name: t.string,
|
|
162
|
-
domain: t.string,
|
|
163
|
-
users: t.array(
|
|
164
|
-
t.type({
|
|
165
|
-
id: t.string,
|
|
166
|
-
}),
|
|
167
|
-
),
|
|
168
|
-
});
|
|
169
|
-
export type Environment = t.TypeOf<typeof Environment>;
|
|
@@ -4,28 +4,16 @@ import * as path from "node:path";
|
|
|
4
4
|
import { createRequire } from "node:module";
|
|
5
5
|
import { detect as niDetect } from "@antfu/ni";
|
|
6
6
|
import { ExecaChildProcess } from "execa";
|
|
7
|
-
|
|
8
|
-
HookError,
|
|
9
|
-
CallHookReturnType,
|
|
10
|
-
ProjectEnvironmentUpdateHook,
|
|
11
|
-
} from "@slicemachine/plugin-kit";
|
|
12
|
-
import * as t from "io-ts";
|
|
13
|
-
|
|
14
|
-
import { DecodeError } from "../../lib/DecodeError";
|
|
7
|
+
|
|
15
8
|
import { assertPluginsInitialized } from "../../lib/assertPluginsInitialized";
|
|
16
|
-
import { decodeHookResult } from "../../lib/decodeHookResult";
|
|
17
9
|
import { decodeSliceMachineConfig } from "../../lib/decodeSliceMachineConfig";
|
|
18
10
|
import { format } from "../../lib/format";
|
|
19
11
|
import { installDependencies } from "../../lib/installDependencies";
|
|
20
12
|
import { locateFileUpward } from "../../lib/locateFileUpward";
|
|
21
13
|
|
|
22
|
-
import {
|
|
23
|
-
PackageManager,
|
|
24
|
-
SliceMachineConfig,
|
|
25
|
-
OnlyHookErrors,
|
|
26
|
-
} from "../../types";
|
|
14
|
+
import { PackageManager, SliceMachineConfig } from "../../types";
|
|
27
15
|
|
|
28
|
-
import { SliceMachineError, InternalError
|
|
16
|
+
import { SliceMachineError, InternalError } from "../../errors";
|
|
29
17
|
|
|
30
18
|
import { SLICE_MACHINE_CONFIG_FILENAME } from "../../constants/SLICE_MACHINE_CONFIG_FILENAME";
|
|
31
19
|
import { TS_CONFIG_FILENAME } from "../../constants/TS_CONFIG_FILENAME";
|
|
@@ -69,15 +57,6 @@ type ProjectManagerInstallDependenciesReturnType = {
|
|
|
69
57
|
execaProcess: ExecaChildProcess;
|
|
70
58
|
};
|
|
71
59
|
|
|
72
|
-
type ProjectManagerReadEnvironmentReturnType = {
|
|
73
|
-
environment: string | undefined;
|
|
74
|
-
errors: (DecodeError | HookError)[];
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
type ProjectManagerUpdateEnvironmentArgs = {
|
|
78
|
-
environment: string | undefined;
|
|
79
|
-
};
|
|
80
|
-
|
|
81
60
|
export class ProjectManager extends BaseManager {
|
|
82
61
|
private _cachedRoot: string | undefined;
|
|
83
62
|
private _cachedSliceMachineConfigPath: string | undefined;
|
|
@@ -216,43 +195,12 @@ export class ProjectManager extends BaseManager {
|
|
|
216
195
|
return path.dirname(sliceMachinePackageJSONPath);
|
|
217
196
|
}
|
|
218
197
|
|
|
219
|
-
/**
|
|
220
|
-
* Returns the project's repository name (i.e. the production environment). It
|
|
221
|
-
* ignores the currently selected environment.
|
|
222
|
-
*
|
|
223
|
-
* Use this method to retrieve the production environment domain.
|
|
224
|
-
*
|
|
225
|
-
* @returns The project's repository name.
|
|
226
|
-
*/
|
|
227
198
|
async getRepositoryName(): Promise<string> {
|
|
228
199
|
const sliceMachineConfig = await this.getSliceMachineConfig();
|
|
229
200
|
|
|
230
201
|
return sliceMachineConfig.repositoryName;
|
|
231
202
|
}
|
|
232
203
|
|
|
233
|
-
/**
|
|
234
|
-
* Returns the currently selected environment domain if set. If an environment
|
|
235
|
-
* is not set, it returns the project's repository name (the production
|
|
236
|
-
* environment).
|
|
237
|
-
*
|
|
238
|
-
* Use this method to retrieve the repository name to be sent with Prismic API
|
|
239
|
-
* requests.
|
|
240
|
-
*
|
|
241
|
-
* @returns The resolved repository name.
|
|
242
|
-
*/
|
|
243
|
-
async getResolvedRepositoryName(): Promise<string> {
|
|
244
|
-
const repositoryName = await this.getRepositoryName();
|
|
245
|
-
|
|
246
|
-
const supportsEnvironments = this.project.checkSupportsEnvironments();
|
|
247
|
-
if (!supportsEnvironments) {
|
|
248
|
-
return repositoryName;
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
const { environment } = await this.project.readEnvironment();
|
|
252
|
-
|
|
253
|
-
return environment ?? repositoryName;
|
|
254
|
-
}
|
|
255
|
-
|
|
256
204
|
async getAdapterName(): Promise<string> {
|
|
257
205
|
const sliceMachineConfig = await this.getSliceMachineConfig();
|
|
258
206
|
const adapterName =
|
|
@@ -364,80 +312,4 @@ export class ProjectManager extends BaseManager {
|
|
|
364
312
|
throw error;
|
|
365
313
|
}
|
|
366
314
|
}
|
|
367
|
-
|
|
368
|
-
checkSupportsEnvironments(): boolean {
|
|
369
|
-
assertPluginsInitialized(this.sliceMachinePluginRunner);
|
|
370
|
-
|
|
371
|
-
return (
|
|
372
|
-
this.sliceMachinePluginRunner.hooksForType("project:environment:read")
|
|
373
|
-
.length > 0 &&
|
|
374
|
-
this.sliceMachinePluginRunner.hooksForType("project:environment:update")
|
|
375
|
-
.length > 0
|
|
376
|
-
);
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
async readEnvironment(): Promise<ProjectManagerReadEnvironmentReturnType> {
|
|
380
|
-
assertPluginsInitialized(this.sliceMachinePluginRunner);
|
|
381
|
-
|
|
382
|
-
await this._assertAdapterSupportsEnvironments();
|
|
383
|
-
|
|
384
|
-
const hookResult = await this.sliceMachinePluginRunner.callHook(
|
|
385
|
-
"project:environment:read",
|
|
386
|
-
undefined,
|
|
387
|
-
);
|
|
388
|
-
const { data, errors } = decodeHookResult(
|
|
389
|
-
t.type({
|
|
390
|
-
environment: t.union([t.undefined, t.string]),
|
|
391
|
-
}),
|
|
392
|
-
hookResult,
|
|
393
|
-
);
|
|
394
|
-
|
|
395
|
-
// An undefined value is equivalent to the production environment.
|
|
396
|
-
// We cast to undefined.
|
|
397
|
-
const repositoryName = await this.project.getRepositoryName();
|
|
398
|
-
const environmentDomain =
|
|
399
|
-
data[0]?.environment === repositoryName
|
|
400
|
-
? undefined
|
|
401
|
-
: data[0]?.environment;
|
|
402
|
-
|
|
403
|
-
return {
|
|
404
|
-
environment: environmentDomain,
|
|
405
|
-
errors,
|
|
406
|
-
};
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
async updateEnvironment(
|
|
410
|
-
args: ProjectManagerUpdateEnvironmentArgs,
|
|
411
|
-
): Promise<OnlyHookErrors<CallHookReturnType<ProjectEnvironmentUpdateHook>>> {
|
|
412
|
-
assertPluginsInitialized(this.sliceMachinePluginRunner);
|
|
413
|
-
|
|
414
|
-
await this._assertAdapterSupportsEnvironments();
|
|
415
|
-
|
|
416
|
-
const repositoryName = await this.project.getRepositoryName();
|
|
417
|
-
const environment =
|
|
418
|
-
args.environment === repositoryName ? undefined : args.environment;
|
|
419
|
-
|
|
420
|
-
const hookResult = await this.sliceMachinePluginRunner.callHook(
|
|
421
|
-
"project:environment:update",
|
|
422
|
-
{ environment },
|
|
423
|
-
);
|
|
424
|
-
|
|
425
|
-
return {
|
|
426
|
-
errors: hookResult.errors,
|
|
427
|
-
};
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
private async _assertAdapterSupportsEnvironments(): Promise<void> {
|
|
431
|
-
assertPluginsInitialized(this.sliceMachinePluginRunner);
|
|
432
|
-
|
|
433
|
-
const supportsEnvironments = this.checkSupportsEnvironments();
|
|
434
|
-
|
|
435
|
-
if (!supportsEnvironments) {
|
|
436
|
-
const adapterName = await this.project.getAdapterName();
|
|
437
|
-
|
|
438
|
-
throw new PluginError(
|
|
439
|
-
`${adapterName} does not support environments. Use an adapter that implements the \`project:environment:read\` and \`project:environment:update\` hooks to use environments.`,
|
|
440
|
-
);
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
315
|
}
|
|
@@ -183,13 +183,13 @@ export class ScreenshotsManager extends BaseManager {
|
|
|
183
183
|
body?: unknown;
|
|
184
184
|
}): Promise<Response> {
|
|
185
185
|
const authenticationToken = await this.user.getAuthenticationToken();
|
|
186
|
-
const
|
|
186
|
+
const sliceMachineConfig = await this.project.getSliceMachineConfig();
|
|
187
187
|
|
|
188
188
|
return await fetch(args.url, {
|
|
189
189
|
body: args.body ? JSON.stringify(args.body) : undefined,
|
|
190
190
|
headers: {
|
|
191
191
|
Authorization: `Bearer ${authenticationToken}`,
|
|
192
|
-
Repository: repositoryName,
|
|
192
|
+
Repository: sliceMachineConfig.repositoryName,
|
|
193
193
|
"User-Agent": SLICE_MACHINE_USER_AGENT,
|
|
194
194
|
...(args.body ? { "Content-Type": "application/json" } : {}),
|
|
195
195
|
},
|
|
@@ -554,12 +554,12 @@ export class SlicesManager extends BaseManager {
|
|
|
554
554
|
});
|
|
555
555
|
|
|
556
556
|
const authenticationToken = await this.user.getAuthenticationToken();
|
|
557
|
-
const
|
|
557
|
+
const sliceMachineConfig = await this.project.getSliceMachineConfig();
|
|
558
558
|
|
|
559
559
|
// TODO: Create a single shared client.
|
|
560
560
|
const client = prismicCustomTypesClient.createClient({
|
|
561
561
|
endpoint: API_ENDPOINTS.PrismicModels,
|
|
562
|
-
repositoryName,
|
|
562
|
+
repositoryName: sliceMachineConfig.repositoryName,
|
|
563
563
|
token: authenticationToken,
|
|
564
564
|
userAgent: args.userAgent || SLICE_MACHINE_USER_AGENT,
|
|
565
565
|
fetch,
|
|
@@ -752,11 +752,11 @@ export class SlicesManager extends BaseManager {
|
|
|
752
752
|
|
|
753
753
|
async fetchRemoteSlices(): Promise<SharedSlice[]> {
|
|
754
754
|
const authenticationToken = await this.user.getAuthenticationToken();
|
|
755
|
-
const
|
|
755
|
+
const sliceMachineConfig = await this.project.getSliceMachineConfig();
|
|
756
756
|
|
|
757
757
|
const client = prismicCustomTypesClient.createClient({
|
|
758
758
|
endpoint: API_ENDPOINTS.PrismicModels,
|
|
759
|
-
repositoryName,
|
|
759
|
+
repositoryName: sliceMachineConfig.repositoryName,
|
|
760
760
|
token: authenticationToken,
|
|
761
761
|
userAgent: SLICE_MACHINE_USER_AGENT,
|
|
762
762
|
fetch,
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
function sortEnvironments(environments) {
|
|
4
|
-
return [...environments].sort((a, b) => {
|
|
5
|
-
switch (a.kind) {
|
|
6
|
-
case "prod": {
|
|
7
|
-
return -1;
|
|
8
|
-
}
|
|
9
|
-
case "stage": {
|
|
10
|
-
switch (b.kind) {
|
|
11
|
-
case "prod": {
|
|
12
|
-
return 1;
|
|
13
|
-
}
|
|
14
|
-
case "stage": {
|
|
15
|
-
return a.name.localeCompare(b.name);
|
|
16
|
-
}
|
|
17
|
-
case "dev":
|
|
18
|
-
default: {
|
|
19
|
-
return -1;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
case "dev": {
|
|
24
|
-
return 1;
|
|
25
|
-
}
|
|
26
|
-
default: {
|
|
27
|
-
if (b.kind === void 0) {
|
|
28
|
-
return a.name.localeCompare(b.name);
|
|
29
|
-
}
|
|
30
|
-
return 1;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
exports.sortEnvironments = sortEnvironments;
|
|
36
|
-
//# sourceMappingURL=sortEnvironments.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sortEnvironments.cjs","sources":["../../../../src/managers/prismicRepository/sortEnvironments.ts"],"sourcesContent":["import { Environment } from \"./types\";\n\n/**\n * Sorts a list of environments using the following criteria:\n *\n * - The production environment is always first.\n * - Staging environments are always after production, before development\n * environments, and sorted alphabetically by name.\n * - The development environment is always last.\n *\n * It assumes the list of environments contains one production environment and\n * at most one dev environment.\n *\n * @param environments - The environments to sort.\n *\n * @returns The sorted environments.\n */\nexport function sortEnvironments(environments: Environment[]): Environment[] {\n\treturn [...environments].sort((a, b) => {\n\t\tswitch (a.kind) {\n\t\t\tcase \"prod\": {\n\t\t\t\treturn -1;\n\t\t\t}\n\n\t\t\tcase \"stage\": {\n\t\t\t\tswitch (b.kind) {\n\t\t\t\t\tcase \"prod\": {\n\t\t\t\t\t\treturn 1;\n\t\t\t\t\t}\n\n\t\t\t\t\tcase \"stage\": {\n\t\t\t\t\t\treturn a.name.localeCompare(b.name);\n\t\t\t\t\t}\n\n\t\t\t\t\tcase \"dev\":\n\t\t\t\t\tdefault: {\n\t\t\t\t\t\treturn -1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tcase \"dev\": {\n\t\t\t\treturn 1;\n\t\t\t}\n\n\t\t\tdefault: {\n\t\t\t\tif (b.kind === undefined) {\n\t\t\t\t\treturn a.name.localeCompare(b.name);\n\t\t\t\t}\n\n\t\t\t\treturn 1;\n\t\t\t}\n\t\t}\n\t});\n}\n"],"names":[],"mappings":";;AAiBM,SAAU,iBAAiB,cAA2B;AAC3D,SAAO,CAAC,GAAG,YAAY,EAAE,KAAK,CAAC,GAAG,MAAK;AACtC,YAAQ,EAAE,MAAM;AAAA,MACf,KAAK,QAAQ;AACL,eAAA;AAAA,MACP;AAAA,MAED,KAAK,SAAS;AACb,gBAAQ,EAAE,MAAM;AAAA,UACf,KAAK,QAAQ;AACL,mBAAA;AAAA,UACP;AAAA,UAED,KAAK,SAAS;AACb,mBAAO,EAAE,KAAK,cAAc,EAAE,IAAI;AAAA,UAClC;AAAA,UAED,KAAK;AAAA,UACL,SAAS;AACD,mBAAA;AAAA,UACP;AAAA,QACD;AAAA,MACD;AAAA,MAED,KAAK,OAAO;AACJ,eAAA;AAAA,MACP;AAAA,MAED,SAAS;AACJ,YAAA,EAAE,SAAS,QAAW;AACzB,iBAAO,EAAE,KAAK,cAAc,EAAE,IAAI;AAAA,QAClC;AAEM,eAAA;AAAA,MACP;AAAA,IACD;AAAA,EAAA,CACD;AACF;;"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { Environment } from "./types";
|
|
2
|
-
/**
|
|
3
|
-
* Sorts a list of environments using the following criteria:
|
|
4
|
-
*
|
|
5
|
-
* - The production environment is always first.
|
|
6
|
-
* - Staging environments are always after production, before development
|
|
7
|
-
* environments, and sorted alphabetically by name.
|
|
8
|
-
* - The development environment is always last.
|
|
9
|
-
*
|
|
10
|
-
* It assumes the list of environments contains one production environment and
|
|
11
|
-
* at most one dev environment.
|
|
12
|
-
*
|
|
13
|
-
* @param environments - The environments to sort.
|
|
14
|
-
*
|
|
15
|
-
* @returns The sorted environments.
|
|
16
|
-
*/
|
|
17
|
-
export declare function sortEnvironments(environments: Environment[]): Environment[];
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
function sortEnvironments(environments) {
|
|
2
|
-
return [...environments].sort((a, b) => {
|
|
3
|
-
switch (a.kind) {
|
|
4
|
-
case "prod": {
|
|
5
|
-
return -1;
|
|
6
|
-
}
|
|
7
|
-
case "stage": {
|
|
8
|
-
switch (b.kind) {
|
|
9
|
-
case "prod": {
|
|
10
|
-
return 1;
|
|
11
|
-
}
|
|
12
|
-
case "stage": {
|
|
13
|
-
return a.name.localeCompare(b.name);
|
|
14
|
-
}
|
|
15
|
-
case "dev":
|
|
16
|
-
default: {
|
|
17
|
-
return -1;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
case "dev": {
|
|
22
|
-
return 1;
|
|
23
|
-
}
|
|
24
|
-
default: {
|
|
25
|
-
if (b.kind === void 0) {
|
|
26
|
-
return a.name.localeCompare(b.name);
|
|
27
|
-
}
|
|
28
|
-
return 1;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
export {
|
|
34
|
-
sortEnvironments
|
|
35
|
-
};
|
|
36
|
-
//# sourceMappingURL=sortEnvironments.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sortEnvironments.js","sources":["../../../../src/managers/prismicRepository/sortEnvironments.ts"],"sourcesContent":["import { Environment } from \"./types\";\n\n/**\n * Sorts a list of environments using the following criteria:\n *\n * - The production environment is always first.\n * - Staging environments are always after production, before development\n * environments, and sorted alphabetically by name.\n * - The development environment is always last.\n *\n * It assumes the list of environments contains one production environment and\n * at most one dev environment.\n *\n * @param environments - The environments to sort.\n *\n * @returns The sorted environments.\n */\nexport function sortEnvironments(environments: Environment[]): Environment[] {\n\treturn [...environments].sort((a, b) => {\n\t\tswitch (a.kind) {\n\t\t\tcase \"prod\": {\n\t\t\t\treturn -1;\n\t\t\t}\n\n\t\t\tcase \"stage\": {\n\t\t\t\tswitch (b.kind) {\n\t\t\t\t\tcase \"prod\": {\n\t\t\t\t\t\treturn 1;\n\t\t\t\t\t}\n\n\t\t\t\t\tcase \"stage\": {\n\t\t\t\t\t\treturn a.name.localeCompare(b.name);\n\t\t\t\t\t}\n\n\t\t\t\t\tcase \"dev\":\n\t\t\t\t\tdefault: {\n\t\t\t\t\t\treturn -1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tcase \"dev\": {\n\t\t\t\treturn 1;\n\t\t\t}\n\n\t\t\tdefault: {\n\t\t\t\tif (b.kind === undefined) {\n\t\t\t\t\treturn a.name.localeCompare(b.name);\n\t\t\t\t}\n\n\t\t\t\treturn 1;\n\t\t\t}\n\t\t}\n\t});\n}\n"],"names":[],"mappings":"AAiBM,SAAU,iBAAiB,cAA2B;AAC3D,SAAO,CAAC,GAAG,YAAY,EAAE,KAAK,CAAC,GAAG,MAAK;AACtC,YAAQ,EAAE,MAAM;AAAA,MACf,KAAK,QAAQ;AACL,eAAA;AAAA,MACP;AAAA,MAED,KAAK,SAAS;AACb,gBAAQ,EAAE,MAAM;AAAA,UACf,KAAK,QAAQ;AACL,mBAAA;AAAA,UACP;AAAA,UAED,KAAK,SAAS;AACb,mBAAO,EAAE,KAAK,cAAc,EAAE,IAAI;AAAA,UAClC;AAAA,UAED,KAAK;AAAA,UACL,SAAS;AACD,mBAAA;AAAA,UACP;AAAA,QACD;AAAA,MACD;AAAA,MAED,KAAK,OAAO;AACJ,eAAA;AAAA,MACP;AAAA,MAED,SAAS;AACJ,YAAA,EAAE,SAAS,QAAW;AACzB,iBAAO,EAAE,KAAK,cAAc,EAAE,IAAI;AAAA,QAClC;AAEM,eAAA;AAAA,MACP;AAAA,IACD;AAAA,EAAA,CACD;AACF;"}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { Environment } from "./types";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Sorts a list of environments using the following criteria:
|
|
5
|
-
*
|
|
6
|
-
* - The production environment is always first.
|
|
7
|
-
* - Staging environments are always after production, before development
|
|
8
|
-
* environments, and sorted alphabetically by name.
|
|
9
|
-
* - The development environment is always last.
|
|
10
|
-
*
|
|
11
|
-
* It assumes the list of environments contains one production environment and
|
|
12
|
-
* at most one dev environment.
|
|
13
|
-
*
|
|
14
|
-
* @param environments - The environments to sort.
|
|
15
|
-
*
|
|
16
|
-
* @returns The sorted environments.
|
|
17
|
-
*/
|
|
18
|
-
export function sortEnvironments(environments: Environment[]): Environment[] {
|
|
19
|
-
return [...environments].sort((a, b) => {
|
|
20
|
-
switch (a.kind) {
|
|
21
|
-
case "prod": {
|
|
22
|
-
return -1;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
case "stage": {
|
|
26
|
-
switch (b.kind) {
|
|
27
|
-
case "prod": {
|
|
28
|
-
return 1;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
case "stage": {
|
|
32
|
-
return a.name.localeCompare(b.name);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
case "dev":
|
|
36
|
-
default: {
|
|
37
|
-
return -1;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
case "dev": {
|
|
43
|
-
return 1;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
default: {
|
|
47
|
-
if (b.kind === undefined) {
|
|
48
|
-
return a.name.localeCompare(b.name);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return 1;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
}
|