@slicemachine/manager 0.16.1-dev-next-release.2 → 0.16.1-dev-environments.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 +2 -1
- package/dist/client.cjs +1 -0
- package/dist/client.cjs.map +1 -1
- package/dist/client.js +2 -1
- package/dist/constants/API_ENDPOINTS.cjs +6 -3
- package/dist/constants/API_ENDPOINTS.cjs.map +1 -1
- package/dist/constants/API_ENDPOINTS.d.ts +1 -0
- package/dist/constants/API_ENDPOINTS.js +6 -3
- package/dist/constants/API_ENDPOINTS.js.map +1 -1
- package/dist/errors.cjs +20 -0
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.d.ts +1 -0
- package/dist/errors.js +20 -0
- package/dist/errors.js.map +1 -1
- package/dist/index.cjs +9 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +9 -0
- 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 +37 -4
- package/dist/managers/prismicRepository/PrismicRepositoryManager.cjs.map +1 -1
- package/dist/managers/prismicRepository/PrismicRepositoryManager.d.ts +2 -1
- package/dist/managers/prismicRepository/PrismicRepositoryManager.js +38 -5
- package/dist/managers/prismicRepository/PrismicRepositoryManager.js.map +1 -1
- package/dist/managers/prismicRepository/sortEnvironments.cjs +36 -0
- package/dist/managers/prismicRepository/sortEnvironments.cjs.map +1 -0
- package/dist/managers/prismicRepository/sortEnvironments.d.ts +17 -0
- package/dist/managers/prismicRepository/sortEnvironments.js +36 -0
- package/dist/managers/prismicRepository/sortEnvironments.js.map +1 -0
- package/dist/managers/prismicRepository/types.cjs +9 -0
- package/dist/managers/prismicRepository/types.cjs.map +1 -1
- package/dist/managers/prismicRepository/types.d.ts +9 -0
- package/dist/managers/prismicRepository/types.js +9 -0
- package/dist/managers/prismicRepository/types.js.map +1 -1
- package/dist/managers/project/ProjectManager.cjs +67 -0
- package/dist/managers/project/ProjectManager.cjs.map +1 -1
- package/dist/managers/project/ProjectManager.d.ts +33 -1
- package/dist/managers/project/ProjectManager.js +67 -1
- 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 +3 -0
- package/src/constants/API_ENDPOINTS.ts +6 -0
- package/src/errors.ts +4 -0
- package/src/index.ts +13 -0
- package/src/managers/customTypes/CustomTypesManager.ts +4 -4
- package/src/managers/prismicRepository/PrismicRepositoryManager.ts +55 -4
- package/src/managers/prismicRepository/sortEnvironments.ts +55 -0
- package/src/managers/prismicRepository/types.ts +12 -0
- package/src/managers/project/ProjectManager.ts +131 -3
- package/src/managers/screenshots/ScreenshotsManager.ts +2 -2
- package/src/managers/slices/SlicesManager.ts +4 -4
|
@@ -0,0 +1,36 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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;"}
|
|
@@ -62,6 +62,15 @@ exports.LimitType = void 0;
|
|
|
62
62
|
LimitType2["SOFT"] = "SOFT";
|
|
63
63
|
LimitType2["HARD"] = "HARD";
|
|
64
64
|
})(exports.LimitType || (exports.LimitType = {}));
|
|
65
|
+
const Environment = t__namespace.type({
|
|
66
|
+
kind: t__namespace.union([t__namespace.literal("prod"), t__namespace.literal("stage"), t__namespace.literal("dev")]),
|
|
67
|
+
name: t__namespace.string,
|
|
68
|
+
domain: t__namespace.string,
|
|
69
|
+
users: t__namespace.array(t__namespace.type({
|
|
70
|
+
id: t__namespace.string
|
|
71
|
+
}))
|
|
72
|
+
});
|
|
73
|
+
exports.Environment = Environment;
|
|
65
74
|
exports.PrismicRepository = PrismicRepository;
|
|
66
75
|
exports.PrismicRepositoryRole = PrismicRepositoryRole;
|
|
67
76
|
exports.PrismicRepositoryUserAgent = PrismicRepositoryUserAgent;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.cjs","sources":["../../../../src/managers/prismicRepository/types.ts"],"sourcesContent":["import {\n\tCustomType,\n\tSharedSlice,\n} from \"@prismicio/types-internal/lib/customtypes\";\nimport * as t from \"io-ts\";\n\nexport const PrismicRepositoryUserAgent = {\n\tSliceMachine: \"prismic-cli/sm\",\n\tLegacyZero: \"prismic-cli/0\",\n} as const;\nexport type PrismicRepositoryUserAgents =\n\t(typeof PrismicRepositoryUserAgent)[keyof typeof PrismicRepositoryUserAgent];\n\nexport const PrismicRepositoryRole = {\n\tSuperUser: \"SuperUser\",\n\tAdministrator: \"Administrator\",\n\tOwner: \"Owner\",\n\tManager: \"Manager\",\n\tPublisher: \"Publisher\",\n\tWriter: \"Writer\",\n\tReadonly: \"Readonly\",\n} as const;\nexport type PrismicRepositoryRoles =\n\t(typeof PrismicRepositoryRole)[keyof typeof PrismicRepositoryRole];\n\nexport const PrismicRepository = t.type({\n\tdomain: t.string,\n\tname: t.string,\n\trole: t.union([\n\t\tt.keyof(PrismicRepositoryRole),\n\t\tt.record(t.string, t.keyof(PrismicRepositoryRole)),\n\t]),\n});\nexport type PrismicRepository = t.TypeOf<typeof PrismicRepository>;\n\nexport enum ChangeTypes {\n\tSLICE_INSERT = \"SLICE_INSERT\",\n\tSLICE_UPDATE = \"SLICE_UPDATE\",\n\tSLICE_DELETE = \"SLICE_DELETE\",\n\tCUSTOM_TYPE_INSERT = \"CUSTOM_TYPE_INSERT\",\n\tCUSTOM_TYPE_UPDATE = \"CUSTOM_TYPE_UPDATE\",\n\tCUSTOM_TYPE_DELETE = \"CUSTOM_TYPE_DELETE\",\n}\ninterface Change {\n\ttype: ChangeTypes;\n\tid: string;\n\tpayload: Record<string, unknown>;\n}\ninterface DeleteChange extends Change {\n\tpayload: {\n\t\tid: Change[\"id\"];\n\t};\n}\nexport interface SliceInsertChange extends Change {\n\ttype: ChangeTypes.SLICE_INSERT;\n\tpayload: SharedSlice;\n}\nexport interface SliceUpdateChange extends Change {\n\ttype: ChangeTypes.SLICE_UPDATE;\n\tpayload: SharedSlice;\n}\nexport interface SliceDeleteChange extends DeleteChange {\n\ttype: ChangeTypes.SLICE_DELETE;\n}\nexport interface CustomTypeInsertChange extends Change {\n\ttype: ChangeTypes.CUSTOM_TYPE_INSERT;\n\tpayload: CustomType;\n}\nexport interface CustomTypeUpdateChange extends Change {\n\ttype: ChangeTypes.CUSTOM_TYPE_UPDATE;\n\tpayload: CustomType;\n}\nexport interface CustomTypeDeleteChange extends DeleteChange {\n\ttype: ChangeTypes.CUSTOM_TYPE_DELETE;\n}\nexport type AllChangeTypes =\n\t| SliceInsertChange\n\t| SliceUpdateChange\n\t| SliceDeleteChange\n\t| CustomTypeInsertChange\n\t| CustomTypeUpdateChange\n\t| CustomTypeDeleteChange;\nexport interface BulkBody extends Record<string, unknown> {\n\tconfirmDeleteDocuments: boolean;\n\tchanges: AllChangeTypes[];\n}\n\nexport const RawLimit = t.type({\n\tdetails: t.type({\n\t\tcustomTypes: t.array(\n\t\t\tt.type({\n\t\t\t\tid: t.string,\n\t\t\t\tnumberOfDocuments: t.number,\n\t\t\t\turl: t.string,\n\t\t\t}),\n\t\t),\n\t}),\n});\nexport type RawLimit = t.TypeOf<typeof RawLimit>;\nexport enum LimitType {\n\tSOFT = \"SOFT\",\n\tHARD = \"HARD\",\n}\nexport type Limit = RawLimit & {\n\ttype: LimitType;\n};\n\nexport interface ClientError {\n\tstatus: number;\n\tmessage: string;\n}\n\ntype ChangeStatus = \"NEW\" | \"MODIFIED\" | \"DELETED\";\n\ntype CustomTypeChange = {\n\tid: string;\n\ttype: \"CustomType\";\n\tstatus: ChangeStatus;\n};\n\ntype SliceChange = {\n\tid: string;\n\ttype: \"Slice\";\n\tstatus: ChangeStatus;\n\tlibraryID: string;\n};\n\nexport type TransactionalMergeArgs = {\n\tconfirmDeleteDocuments: boolean;\n\tchanges: (CustomTypeChange | SliceChange)[];\n};\n\nexport type TransactionalMergeReturnType = Limit | null;\n\n/**\n * Framework id sent to Segment from wroom. Property used for the \"framework\"\n * and \"hasSlicemachine\" properties.\n *\n * Values from:\n * https://github.com/prismicio/wroom/blob/65d4f53fd46df7d366d80e7ba9c965339ac7369d/subprojects/common/app/models/Framework.scala#LL20C6-L20C6\n */\nexport type FrameworkWroomTelemetryID = \"next\" | \"nuxt\" | \"sveltekit\" | \"other\";\n\n/**\n * Starter id sent to Segment from wroom.Property used for the \"starter\"\n * properties.\n *\n * Values from:\n * https://github.com/prismicio/wroom/blob/65d4f53fd46df7d366d80e7ba9c965339ac7369d/conf/application.conf#L938\n */\nexport type StarterId =\n\t| \"next_multi_page\"\n\t| \"next_blog\"\n\t| \"next_multi_lang\"\n\t| \"nuxt_multi_page\"\n\t| \"nuxt_blog\"\n\t| \"nuxt_multi_lang\";\n"],"names":["t","ChangeTypes","LimitType"],"mappings":";;;;;;;;;;;;;;;;;;;;AAMO,MAAM,6BAA6B;AAAA,EACzC,cAAc;AAAA,EACd,YAAY;;AAKN,MAAM,wBAAwB;AAAA,EACpC,WAAW;AAAA,EACX,eAAe;AAAA,EACf,OAAO;AAAA,EACP,SAAS;AAAA,EACT,WAAW;AAAA,EACX,QAAQ;AAAA,EACR,UAAU;;AAKE,MAAA,oBAAoBA,aAAE,KAAK;AAAA,EACvC,QAAQA,aAAE;AAAA,EACV,MAAMA,aAAE;AAAA,EACR,MAAMA,aAAE,MAAM;AAAA,IACbA,aAAE,MAAM,qBAAqB;AAAA,IAC7BA,aAAE,OAAOA,aAAE,QAAQA,aAAE,MAAM,qBAAqB,CAAC;AAAA,EAAA,CACjD;AACD,CAAA;AAGWC,QAAA,cAAA;AAAA,CAAZ,SAAYA,cAAW;AACtBA,eAAA,cAAA,IAAA;AACAA,eAAA,cAAA,IAAA;AACAA,eAAA,cAAA,IAAA;AACAA,eAAA,oBAAA,IAAA;AACAA,eAAA,oBAAA,IAAA;AACAA,eAAA,oBAAA,IAAA;AACD,GAPYA,wBAAAA,QAAAA,cAOX,CAAA,EAAA;AA6CY,MAAA,WAAWD,aAAE,KAAK;AAAA,EAC9B,SAASA,aAAE,KAAK;AAAA,IACf,aAAaA,aAAE,MACdA,aAAE,KAAK;AAAA,MACN,IAAIA,aAAE;AAAA,MACN,mBAAmBA,aAAE;AAAA,MACrB,KAAKA,aAAE;AAAA,IAAA,CACP,CAAC;AAAA,EAAA,CAEH;AACD,CAAA;AAEWE,QAAA,YAAA;AAAA,CAAZ,SAAYA,YAAS;AACpBA,aAAA,MAAA,IAAA;AACAA,aAAA,MAAA,IAAA;AACD,GAHYA,
|
|
1
|
+
{"version":3,"file":"types.cjs","sources":["../../../../src/managers/prismicRepository/types.ts"],"sourcesContent":["import {\n\tCustomType,\n\tSharedSlice,\n} from \"@prismicio/types-internal/lib/customtypes\";\nimport * as t from \"io-ts\";\n\nexport const PrismicRepositoryUserAgent = {\n\tSliceMachine: \"prismic-cli/sm\",\n\tLegacyZero: \"prismic-cli/0\",\n} as const;\nexport type PrismicRepositoryUserAgents =\n\t(typeof PrismicRepositoryUserAgent)[keyof typeof PrismicRepositoryUserAgent];\n\nexport const PrismicRepositoryRole = {\n\tSuperUser: \"SuperUser\",\n\tAdministrator: \"Administrator\",\n\tOwner: \"Owner\",\n\tManager: \"Manager\",\n\tPublisher: \"Publisher\",\n\tWriter: \"Writer\",\n\tReadonly: \"Readonly\",\n} as const;\nexport type PrismicRepositoryRoles =\n\t(typeof PrismicRepositoryRole)[keyof typeof PrismicRepositoryRole];\n\nexport const PrismicRepository = t.type({\n\tdomain: t.string,\n\tname: t.string,\n\trole: t.union([\n\t\tt.keyof(PrismicRepositoryRole),\n\t\tt.record(t.string, t.keyof(PrismicRepositoryRole)),\n\t]),\n});\nexport type PrismicRepository = t.TypeOf<typeof PrismicRepository>;\n\nexport enum ChangeTypes {\n\tSLICE_INSERT = \"SLICE_INSERT\",\n\tSLICE_UPDATE = \"SLICE_UPDATE\",\n\tSLICE_DELETE = \"SLICE_DELETE\",\n\tCUSTOM_TYPE_INSERT = \"CUSTOM_TYPE_INSERT\",\n\tCUSTOM_TYPE_UPDATE = \"CUSTOM_TYPE_UPDATE\",\n\tCUSTOM_TYPE_DELETE = \"CUSTOM_TYPE_DELETE\",\n}\ninterface Change {\n\ttype: ChangeTypes;\n\tid: string;\n\tpayload: Record<string, unknown>;\n}\ninterface DeleteChange extends Change {\n\tpayload: {\n\t\tid: Change[\"id\"];\n\t};\n}\nexport interface SliceInsertChange extends Change {\n\ttype: ChangeTypes.SLICE_INSERT;\n\tpayload: SharedSlice;\n}\nexport interface SliceUpdateChange extends Change {\n\ttype: ChangeTypes.SLICE_UPDATE;\n\tpayload: SharedSlice;\n}\nexport interface SliceDeleteChange extends DeleteChange {\n\ttype: ChangeTypes.SLICE_DELETE;\n}\nexport interface CustomTypeInsertChange extends Change {\n\ttype: ChangeTypes.CUSTOM_TYPE_INSERT;\n\tpayload: CustomType;\n}\nexport interface CustomTypeUpdateChange extends Change {\n\ttype: ChangeTypes.CUSTOM_TYPE_UPDATE;\n\tpayload: CustomType;\n}\nexport interface CustomTypeDeleteChange extends DeleteChange {\n\ttype: ChangeTypes.CUSTOM_TYPE_DELETE;\n}\nexport type AllChangeTypes =\n\t| SliceInsertChange\n\t| SliceUpdateChange\n\t| SliceDeleteChange\n\t| CustomTypeInsertChange\n\t| CustomTypeUpdateChange\n\t| CustomTypeDeleteChange;\nexport interface BulkBody extends Record<string, unknown> {\n\tconfirmDeleteDocuments: boolean;\n\tchanges: AllChangeTypes[];\n}\n\nexport const RawLimit = t.type({\n\tdetails: t.type({\n\t\tcustomTypes: t.array(\n\t\t\tt.type({\n\t\t\t\tid: t.string,\n\t\t\t\tnumberOfDocuments: t.number,\n\t\t\t\turl: t.string,\n\t\t\t}),\n\t\t),\n\t}),\n});\nexport type RawLimit = t.TypeOf<typeof RawLimit>;\nexport enum LimitType {\n\tSOFT = \"SOFT\",\n\tHARD = \"HARD\",\n}\nexport type Limit = RawLimit & {\n\ttype: LimitType;\n};\n\nexport interface ClientError {\n\tstatus: number;\n\tmessage: string;\n}\n\ntype ChangeStatus = \"NEW\" | \"MODIFIED\" | \"DELETED\";\n\ntype CustomTypeChange = {\n\tid: string;\n\ttype: \"CustomType\";\n\tstatus: ChangeStatus;\n};\n\ntype SliceChange = {\n\tid: string;\n\ttype: \"Slice\";\n\tstatus: ChangeStatus;\n\tlibraryID: string;\n};\n\nexport type TransactionalMergeArgs = {\n\tconfirmDeleteDocuments: boolean;\n\tchanges: (CustomTypeChange | SliceChange)[];\n};\n\nexport type TransactionalMergeReturnType = Limit | null;\n\n/**\n * Framework id sent to Segment from wroom. Property used for the \"framework\"\n * and \"hasSlicemachine\" properties.\n *\n * Values from:\n * https://github.com/prismicio/wroom/blob/65d4f53fd46df7d366d80e7ba9c965339ac7369d/subprojects/common/app/models/Framework.scala#LL20C6-L20C6\n */\nexport type FrameworkWroomTelemetryID = \"next\" | \"nuxt\" | \"sveltekit\" | \"other\";\n\n/**\n * Starter id sent to Segment from wroom.Property used for the \"starter\"\n * properties.\n *\n * Values from:\n * https://github.com/prismicio/wroom/blob/65d4f53fd46df7d366d80e7ba9c965339ac7369d/conf/application.conf#L938\n */\nexport type StarterId =\n\t| \"next_multi_page\"\n\t| \"next_blog\"\n\t| \"next_multi_lang\"\n\t| \"nuxt_multi_page\"\n\t| \"nuxt_blog\"\n\t| \"nuxt_multi_lang\";\n\nexport const Environment = t.type({\n\tkind: t.union([t.literal(\"prod\"), t.literal(\"stage\"), t.literal(\"dev\")]),\n\tname: t.string,\n\tdomain: t.string,\n\tusers: t.array(\n\t\tt.type({\n\t\t\t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M,CAACA,aAAE,QAAQ,MAAM,GAAGA,aAAE,QAAQ,OAAO,GAAGA,aAAE,QAAQ,KAAK,CAAC,CAAC;AAAA,EACvE,MAAMA,aAAE;AAAA,EACR,QAAQA,aAAE;AAAA,EACV,OAAOA,aAAE,MACRA,aAAE,KAAK;AAAA,IACN,IAAIA,aAAE;AAAA,EAAA,CACN,CAAC;AAEH,CAAA;;;;;;"}
|
|
@@ -136,4 +136,13 @@ export type FrameworkWroomTelemetryID = "next" | "nuxt" | "sveltekit" | "other";
|
|
|
136
136
|
* https://github.com/prismicio/wroom/blob/65d4f53fd46df7d366d80e7ba9c965339ac7369d/conf/application.conf#L938
|
|
137
137
|
*/
|
|
138
138
|
export type StarterId = "next_multi_page" | "next_blog" | "next_multi_lang" | "nuxt_multi_page" | "nuxt_blog" | "nuxt_multi_lang";
|
|
139
|
+
export declare const Environment: t.TypeC<{
|
|
140
|
+
kind: t.UnionC<[t.LiteralC<"prod">, t.LiteralC<"stage">, t.LiteralC<"dev">]>;
|
|
141
|
+
name: t.StringC;
|
|
142
|
+
domain: t.StringC;
|
|
143
|
+
users: t.ArrayC<t.TypeC<{
|
|
144
|
+
id: t.StringC;
|
|
145
|
+
}>>;
|
|
146
|
+
}>;
|
|
147
|
+
export type Environment = t.TypeOf<typeof Environment>;
|
|
139
148
|
export {};
|
|
@@ -43,8 +43,17 @@ var LimitType;
|
|
|
43
43
|
LimitType2["SOFT"] = "SOFT";
|
|
44
44
|
LimitType2["HARD"] = "HARD";
|
|
45
45
|
})(LimitType || (LimitType = {}));
|
|
46
|
+
const Environment = t.type({
|
|
47
|
+
kind: t.union([t.literal("prod"), t.literal("stage"), t.literal("dev")]),
|
|
48
|
+
name: t.string,
|
|
49
|
+
domain: t.string,
|
|
50
|
+
users: t.array(t.type({
|
|
51
|
+
id: t.string
|
|
52
|
+
}))
|
|
53
|
+
});
|
|
46
54
|
export {
|
|
47
55
|
ChangeTypes,
|
|
56
|
+
Environment,
|
|
48
57
|
LimitType,
|
|
49
58
|
PrismicRepository,
|
|
50
59
|
PrismicRepositoryRole,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sources":["../../../../src/managers/prismicRepository/types.ts"],"sourcesContent":["import {\n\tCustomType,\n\tSharedSlice,\n} from \"@prismicio/types-internal/lib/customtypes\";\nimport * as t from \"io-ts\";\n\nexport const PrismicRepositoryUserAgent = {\n\tSliceMachine: \"prismic-cli/sm\",\n\tLegacyZero: \"prismic-cli/0\",\n} as const;\nexport type PrismicRepositoryUserAgents =\n\t(typeof PrismicRepositoryUserAgent)[keyof typeof PrismicRepositoryUserAgent];\n\nexport const PrismicRepositoryRole = {\n\tSuperUser: \"SuperUser\",\n\tAdministrator: \"Administrator\",\n\tOwner: \"Owner\",\n\tManager: \"Manager\",\n\tPublisher: \"Publisher\",\n\tWriter: \"Writer\",\n\tReadonly: \"Readonly\",\n} as const;\nexport type PrismicRepositoryRoles =\n\t(typeof PrismicRepositoryRole)[keyof typeof PrismicRepositoryRole];\n\nexport const PrismicRepository = t.type({\n\tdomain: t.string,\n\tname: t.string,\n\trole: t.union([\n\t\tt.keyof(PrismicRepositoryRole),\n\t\tt.record(t.string, t.keyof(PrismicRepositoryRole)),\n\t]),\n});\nexport type PrismicRepository = t.TypeOf<typeof PrismicRepository>;\n\nexport enum ChangeTypes {\n\tSLICE_INSERT = \"SLICE_INSERT\",\n\tSLICE_UPDATE = \"SLICE_UPDATE\",\n\tSLICE_DELETE = \"SLICE_DELETE\",\n\tCUSTOM_TYPE_INSERT = \"CUSTOM_TYPE_INSERT\",\n\tCUSTOM_TYPE_UPDATE = \"CUSTOM_TYPE_UPDATE\",\n\tCUSTOM_TYPE_DELETE = \"CUSTOM_TYPE_DELETE\",\n}\ninterface Change {\n\ttype: ChangeTypes;\n\tid: string;\n\tpayload: Record<string, unknown>;\n}\ninterface DeleteChange extends Change {\n\tpayload: {\n\t\tid: Change[\"id\"];\n\t};\n}\nexport interface SliceInsertChange extends Change {\n\ttype: ChangeTypes.SLICE_INSERT;\n\tpayload: SharedSlice;\n}\nexport interface SliceUpdateChange extends Change {\n\ttype: ChangeTypes.SLICE_UPDATE;\n\tpayload: SharedSlice;\n}\nexport interface SliceDeleteChange extends DeleteChange {\n\ttype: ChangeTypes.SLICE_DELETE;\n}\nexport interface CustomTypeInsertChange extends Change {\n\ttype: ChangeTypes.CUSTOM_TYPE_INSERT;\n\tpayload: CustomType;\n}\nexport interface CustomTypeUpdateChange extends Change {\n\ttype: ChangeTypes.CUSTOM_TYPE_UPDATE;\n\tpayload: CustomType;\n}\nexport interface CustomTypeDeleteChange extends DeleteChange {\n\ttype: ChangeTypes.CUSTOM_TYPE_DELETE;\n}\nexport type AllChangeTypes =\n\t| SliceInsertChange\n\t| SliceUpdateChange\n\t| SliceDeleteChange\n\t| CustomTypeInsertChange\n\t| CustomTypeUpdateChange\n\t| CustomTypeDeleteChange;\nexport interface BulkBody extends Record<string, unknown> {\n\tconfirmDeleteDocuments: boolean;\n\tchanges: AllChangeTypes[];\n}\n\nexport const RawLimit = t.type({\n\tdetails: t.type({\n\t\tcustomTypes: t.array(\n\t\t\tt.type({\n\t\t\t\tid: t.string,\n\t\t\t\tnumberOfDocuments: t.number,\n\t\t\t\turl: t.string,\n\t\t\t}),\n\t\t),\n\t}),\n});\nexport type RawLimit = t.TypeOf<typeof RawLimit>;\nexport enum LimitType {\n\tSOFT = \"SOFT\",\n\tHARD = \"HARD\",\n}\nexport type Limit = RawLimit & {\n\ttype: LimitType;\n};\n\nexport interface ClientError {\n\tstatus: number;\n\tmessage: string;\n}\n\ntype ChangeStatus = \"NEW\" | \"MODIFIED\" | \"DELETED\";\n\ntype CustomTypeChange = {\n\tid: string;\n\ttype: \"CustomType\";\n\tstatus: ChangeStatus;\n};\n\ntype SliceChange = {\n\tid: string;\n\ttype: \"Slice\";\n\tstatus: ChangeStatus;\n\tlibraryID: string;\n};\n\nexport type TransactionalMergeArgs = {\n\tconfirmDeleteDocuments: boolean;\n\tchanges: (CustomTypeChange | SliceChange)[];\n};\n\nexport type TransactionalMergeReturnType = Limit | null;\n\n/**\n * Framework id sent to Segment from wroom. Property used for the \"framework\"\n * and \"hasSlicemachine\" properties.\n *\n * Values from:\n * https://github.com/prismicio/wroom/blob/65d4f53fd46df7d366d80e7ba9c965339ac7369d/subprojects/common/app/models/Framework.scala#LL20C6-L20C6\n */\nexport type FrameworkWroomTelemetryID = \"next\" | \"nuxt\" | \"sveltekit\" | \"other\";\n\n/**\n * Starter id sent to Segment from wroom.Property used for the \"starter\"\n * properties.\n *\n * Values from:\n * https://github.com/prismicio/wroom/blob/65d4f53fd46df7d366d80e7ba9c965339ac7369d/conf/application.conf#L938\n */\nexport type StarterId =\n\t| \"next_multi_page\"\n\t| \"next_blog\"\n\t| \"next_multi_lang\"\n\t| \"nuxt_multi_page\"\n\t| \"nuxt_blog\"\n\t| \"nuxt_multi_lang\";\n"],"names":["ChangeTypes","LimitType"],"mappings":";AAMO,MAAM,6BAA6B;AAAA,EACzC,cAAc;AAAA,EACd,YAAY;;AAKN,MAAM,wBAAwB;AAAA,EACpC,WAAW;AAAA,EACX,eAAe;AAAA,EACf,OAAO;AAAA,EACP,SAAS;AAAA,EACT,WAAW;AAAA,EACX,QAAQ;AAAA,EACR,UAAU;;AAKE,MAAA,oBAAoB,EAAE,KAAK;AAAA,EACvC,QAAQ,EAAE;AAAA,EACV,MAAM,EAAE;AAAA,EACR,MAAM,EAAE,MAAM;AAAA,IACb,EAAE,MAAM,qBAAqB;AAAA,IAC7B,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAAA,EAAA,CACjD;AACD,CAAA;AAGW,IAAA;AAAA,CAAZ,SAAYA,cAAW;AACtBA,eAAA,cAAA,IAAA;AACAA,eAAA,cAAA,IAAA;AACAA,eAAA,cAAA,IAAA;AACAA,eAAA,oBAAA,IAAA;AACAA,eAAA,oBAAA,IAAA;AACAA,eAAA,oBAAA,IAAA;AACD,GAPY,gBAAA,cAOX,CAAA,EAAA;AA6CY,MAAA,WAAW,EAAE,KAAK;AAAA,EAC9B,SAAS,EAAE,KAAK;AAAA,IACf,aAAa,EAAE,MACd,EAAE,KAAK;AAAA,MACN,IAAI,EAAE;AAAA,MACN,mBAAmB,EAAE;AAAA,MACrB,KAAK,EAAE;AAAA,IAAA,CACP,CAAC;AAAA,EAAA,CAEH;AACD,CAAA;AAEW,IAAA;AAAA,CAAZ,SAAYC,YAAS;AACpBA,aAAA,MAAA,IAAA;AACAA,aAAA,MAAA,IAAA;AACD,GAHY,cAAA,YAGX,CAAA,EAAA;"}
|
|
1
|
+
{"version":3,"file":"types.js","sources":["../../../../src/managers/prismicRepository/types.ts"],"sourcesContent":["import {\n\tCustomType,\n\tSharedSlice,\n} from \"@prismicio/types-internal/lib/customtypes\";\nimport * as t from \"io-ts\";\n\nexport const PrismicRepositoryUserAgent = {\n\tSliceMachine: \"prismic-cli/sm\",\n\tLegacyZero: \"prismic-cli/0\",\n} as const;\nexport type PrismicRepositoryUserAgents =\n\t(typeof PrismicRepositoryUserAgent)[keyof typeof PrismicRepositoryUserAgent];\n\nexport const PrismicRepositoryRole = {\n\tSuperUser: \"SuperUser\",\n\tAdministrator: \"Administrator\",\n\tOwner: \"Owner\",\n\tManager: \"Manager\",\n\tPublisher: \"Publisher\",\n\tWriter: \"Writer\",\n\tReadonly: \"Readonly\",\n} as const;\nexport type PrismicRepositoryRoles =\n\t(typeof PrismicRepositoryRole)[keyof typeof PrismicRepositoryRole];\n\nexport const PrismicRepository = t.type({\n\tdomain: t.string,\n\tname: t.string,\n\trole: t.union([\n\t\tt.keyof(PrismicRepositoryRole),\n\t\tt.record(t.string, t.keyof(PrismicRepositoryRole)),\n\t]),\n});\nexport type PrismicRepository = t.TypeOf<typeof PrismicRepository>;\n\nexport enum ChangeTypes {\n\tSLICE_INSERT = \"SLICE_INSERT\",\n\tSLICE_UPDATE = \"SLICE_UPDATE\",\n\tSLICE_DELETE = \"SLICE_DELETE\",\n\tCUSTOM_TYPE_INSERT = \"CUSTOM_TYPE_INSERT\",\n\tCUSTOM_TYPE_UPDATE = \"CUSTOM_TYPE_UPDATE\",\n\tCUSTOM_TYPE_DELETE = \"CUSTOM_TYPE_DELETE\",\n}\ninterface Change {\n\ttype: ChangeTypes;\n\tid: string;\n\tpayload: Record<string, unknown>;\n}\ninterface DeleteChange extends Change {\n\tpayload: {\n\t\tid: Change[\"id\"];\n\t};\n}\nexport interface SliceInsertChange extends Change {\n\ttype: ChangeTypes.SLICE_INSERT;\n\tpayload: SharedSlice;\n}\nexport interface SliceUpdateChange extends Change {\n\ttype: ChangeTypes.SLICE_UPDATE;\n\tpayload: SharedSlice;\n}\nexport interface SliceDeleteChange extends DeleteChange {\n\ttype: ChangeTypes.SLICE_DELETE;\n}\nexport interface CustomTypeInsertChange extends Change {\n\ttype: ChangeTypes.CUSTOM_TYPE_INSERT;\n\tpayload: CustomType;\n}\nexport interface CustomTypeUpdateChange extends Change {\n\ttype: ChangeTypes.CUSTOM_TYPE_UPDATE;\n\tpayload: CustomType;\n}\nexport interface CustomTypeDeleteChange extends DeleteChange {\n\ttype: ChangeTypes.CUSTOM_TYPE_DELETE;\n}\nexport type AllChangeTypes =\n\t| SliceInsertChange\n\t| SliceUpdateChange\n\t| SliceDeleteChange\n\t| CustomTypeInsertChange\n\t| CustomTypeUpdateChange\n\t| CustomTypeDeleteChange;\nexport interface BulkBody extends Record<string, unknown> {\n\tconfirmDeleteDocuments: boolean;\n\tchanges: AllChangeTypes[];\n}\n\nexport const RawLimit = t.type({\n\tdetails: t.type({\n\t\tcustomTypes: t.array(\n\t\t\tt.type({\n\t\t\t\tid: t.string,\n\t\t\t\tnumberOfDocuments: t.number,\n\t\t\t\turl: t.string,\n\t\t\t}),\n\t\t),\n\t}),\n});\nexport type RawLimit = t.TypeOf<typeof RawLimit>;\nexport enum LimitType {\n\tSOFT = \"SOFT\",\n\tHARD = \"HARD\",\n}\nexport type Limit = RawLimit & {\n\ttype: LimitType;\n};\n\nexport interface ClientError {\n\tstatus: number;\n\tmessage: string;\n}\n\ntype ChangeStatus = \"NEW\" | \"MODIFIED\" | \"DELETED\";\n\ntype CustomTypeChange = {\n\tid: string;\n\ttype: \"CustomType\";\n\tstatus: ChangeStatus;\n};\n\ntype SliceChange = {\n\tid: string;\n\ttype: \"Slice\";\n\tstatus: ChangeStatus;\n\tlibraryID: string;\n};\n\nexport type TransactionalMergeArgs = {\n\tconfirmDeleteDocuments: boolean;\n\tchanges: (CustomTypeChange | SliceChange)[];\n};\n\nexport type TransactionalMergeReturnType = Limit | null;\n\n/**\n * Framework id sent to Segment from wroom. Property used for the \"framework\"\n * and \"hasSlicemachine\" properties.\n *\n * Values from:\n * https://github.com/prismicio/wroom/blob/65d4f53fd46df7d366d80e7ba9c965339ac7369d/subprojects/common/app/models/Framework.scala#LL20C6-L20C6\n */\nexport type FrameworkWroomTelemetryID = \"next\" | \"nuxt\" | \"sveltekit\" | \"other\";\n\n/**\n * Starter id sent to Segment from wroom.Property used for the \"starter\"\n * properties.\n *\n * Values from:\n * https://github.com/prismicio/wroom/blob/65d4f53fd46df7d366d80e7ba9c965339ac7369d/conf/application.conf#L938\n */\nexport type StarterId =\n\t| \"next_multi_page\"\n\t| \"next_blog\"\n\t| \"next_multi_lang\"\n\t| \"nuxt_multi_page\"\n\t| \"nuxt_blog\"\n\t| \"nuxt_multi_lang\";\n\nexport const Environment = t.type({\n\tkind: t.union([t.literal(\"prod\"), t.literal(\"stage\"), t.literal(\"dev\")]),\n\tname: t.string,\n\tdomain: t.string,\n\tusers: t.array(\n\t\tt.type({\n\t\t\tid: t.string,\n\t\t}),\n\t),\n});\nexport type Environment = t.TypeOf<typeof Environment>;\n"],"names":["ChangeTypes","LimitType"],"mappings":";AAMO,MAAM,6BAA6B;AAAA,EACzC,cAAc;AAAA,EACd,YAAY;;AAKN,MAAM,wBAAwB;AAAA,EACpC,WAAW;AAAA,EACX,eAAe;AAAA,EACf,OAAO;AAAA,EACP,SAAS;AAAA,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const node_module = require("node:module");
|
|
13
13
|
const ni = require("@antfu/ni");
|
|
14
|
+
const t = require("io-ts");
|
|
14
15
|
const assertPluginsInitialized = require("../../lib/assertPluginsInitialized.cjs");
|
|
16
|
+
const decodeHookResult = require("../../lib/decodeHookResult.cjs");
|
|
15
17
|
const decodeSliceMachineConfig = require("../../lib/decodeSliceMachineConfig.cjs");
|
|
16
18
|
const format = require("../../lib/format.cjs");
|
|
17
19
|
const installDependencies = require("../../lib/installDependencies.cjs");
|
|
@@ -39,6 +41,7 @@ function _interopNamespaceDefault(e) {
|
|
|
39
41
|
}
|
|
40
42
|
const fs__namespace = /* @__PURE__ */ _interopNamespaceDefault(fs);
|
|
41
43
|
const path__namespace = /* @__PURE__ */ _interopNamespaceDefault(path);
|
|
44
|
+
const t__namespace = /* @__PURE__ */ _interopNamespaceDefault(t);
|
|
42
45
|
class ProjectManager extends BaseManager.BaseManager {
|
|
43
46
|
constructor() {
|
|
44
47
|
super(...arguments);
|
|
@@ -126,10 +129,37 @@ Error Message: ${error2.message}`);
|
|
|
126
129
|
const sliceMachinePackageJSONPath = require2.resolve(`${SLICE_MACHINE_NPM_PACKAGE_NAME.SLICE_MACHINE_NPM_PACKAGE_NAME}/package.json`);
|
|
127
130
|
return path__namespace.dirname(sliceMachinePackageJSONPath);
|
|
128
131
|
}
|
|
132
|
+
/**
|
|
133
|
+
* Returns the project's repository name (i.e. the production environment). It
|
|
134
|
+
* ignores the currently selected environment.
|
|
135
|
+
*
|
|
136
|
+
* Use this method to retrieve the production environment domain.
|
|
137
|
+
*
|
|
138
|
+
* @returns The project's repository name.
|
|
139
|
+
*/
|
|
129
140
|
async getRepositoryName() {
|
|
130
141
|
const sliceMachineConfig = await this.getSliceMachineConfig();
|
|
131
142
|
return sliceMachineConfig.repositoryName;
|
|
132
143
|
}
|
|
144
|
+
/**
|
|
145
|
+
* Returns the currently selected environment domain if set. If an environment
|
|
146
|
+
* is not set, it returns the project's repository name (the production
|
|
147
|
+
* environment).
|
|
148
|
+
*
|
|
149
|
+
* Use this method to retrieve the repository name to be sent with Prismic API
|
|
150
|
+
* requests.
|
|
151
|
+
*
|
|
152
|
+
* @returns The resolved repository name.
|
|
153
|
+
*/
|
|
154
|
+
async getResolvedRepositoryName() {
|
|
155
|
+
const repositoryName = await this.getRepositoryName();
|
|
156
|
+
const supportsEnvironments = this.project.checkSupportsEnvironments();
|
|
157
|
+
if (!supportsEnvironments) {
|
|
158
|
+
return repositoryName;
|
|
159
|
+
}
|
|
160
|
+
const { environment } = await this.project.readEnvironment();
|
|
161
|
+
return environment ?? repositoryName;
|
|
162
|
+
}
|
|
133
163
|
async getAdapterName() {
|
|
134
164
|
const sliceMachineConfig = await this.getSliceMachineConfig();
|
|
135
165
|
const adapterName = typeof sliceMachineConfig.adapter === "string" ? sliceMachineConfig.adapter : sliceMachineConfig.adapter.resolve;
|
|
@@ -201,6 +231,43 @@ Error Message: ${error2.message}`);
|
|
|
201
231
|
throw error;
|
|
202
232
|
}
|
|
203
233
|
}
|
|
234
|
+
checkSupportsEnvironments() {
|
|
235
|
+
assertPluginsInitialized.assertPluginsInitialized(this.sliceMachinePluginRunner);
|
|
236
|
+
return this.sliceMachinePluginRunner.hooksForType("project:environment:read").length > 0 && this.sliceMachinePluginRunner.hooksForType("project:environment:update").length > 0;
|
|
237
|
+
}
|
|
238
|
+
async readEnvironment() {
|
|
239
|
+
var _a, _b;
|
|
240
|
+
assertPluginsInitialized.assertPluginsInitialized(this.sliceMachinePluginRunner);
|
|
241
|
+
await this._assertAdapterSupportsEnvironments();
|
|
242
|
+
const hookResult = await this.sliceMachinePluginRunner.callHook("project:environment:read", void 0);
|
|
243
|
+
const { data, errors: errors2 } = decodeHookResult.decodeHookResult(t__namespace.type({
|
|
244
|
+
environment: t__namespace.union([t__namespace.undefined, t__namespace.string])
|
|
245
|
+
}), hookResult);
|
|
246
|
+
const repositoryName = await this.project.getRepositoryName();
|
|
247
|
+
const environmentDomain = ((_a = data[0]) == null ? void 0 : _a.environment) === repositoryName ? void 0 : (_b = data[0]) == null ? void 0 : _b.environment;
|
|
248
|
+
return {
|
|
249
|
+
environment: environmentDomain,
|
|
250
|
+
errors: errors2
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
async updateEnvironment(args) {
|
|
254
|
+
assertPluginsInitialized.assertPluginsInitialized(this.sliceMachinePluginRunner);
|
|
255
|
+
await this._assertAdapterSupportsEnvironments();
|
|
256
|
+
const repositoryName = await this.project.getRepositoryName();
|
|
257
|
+
const environment = args.environment === repositoryName ? void 0 : args.environment;
|
|
258
|
+
const hookResult = await this.sliceMachinePluginRunner.callHook("project:environment:update", { environment });
|
|
259
|
+
return {
|
|
260
|
+
errors: hookResult.errors
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
async _assertAdapterSupportsEnvironments() {
|
|
264
|
+
assertPluginsInitialized.assertPluginsInitialized(this.sliceMachinePluginRunner);
|
|
265
|
+
const supportsEnvironments = this.checkSupportsEnvironments();
|
|
266
|
+
if (!supportsEnvironments) {
|
|
267
|
+
const adapterName = await this.project.getAdapterName();
|
|
268
|
+
throw new errors.PluginError(`${adapterName} does not support environments. Use an adapter that implements the \`project:environment:read\` and \`project:environment:update\` hooks to use environments.`);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
204
271
|
}
|
|
205
272
|
exports.ProjectManager = ProjectManager;
|
|
206
273
|
//# sourceMappingURL=ProjectManager.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProjectManager.cjs","sources":["../../../../src/managers/project/ProjectManager.ts"],"sourcesContent":["import * as fs from \"node:fs/promises\";\nimport { existsSync } from \"node:fs\";\nimport * as path from \"node:path\";\nimport { createRequire } from \"node:module\";\nimport { detect as niDetect } from \"@antfu/ni\";\nimport { ExecaChildProcess } from \"execa\";\n\nimport { assertPluginsInitialized } from \"../../lib/assertPluginsInitialized\";\nimport { decodeSliceMachineConfig } from \"../../lib/decodeSliceMachineConfig\";\nimport { format } from \"../../lib/format\";\nimport { installDependencies } from \"../../lib/installDependencies\";\nimport { locateFileUpward } from \"../../lib/locateFileUpward\";\n\nimport { PackageManager, SliceMachineConfig } from \"../../types\";\n\nimport { SliceMachineError, InternalError } from \"../../errors\";\n\nimport { SLICE_MACHINE_CONFIG_FILENAME } from \"../../constants/SLICE_MACHINE_CONFIG_FILENAME\";\nimport { TS_CONFIG_FILENAME } from \"../../constants/TS_CONFIG_FILENAME\";\nimport { SLICE_MACHINE_NPM_PACKAGE_NAME } from \"../../constants/SLICE_MACHINE_NPM_PACKAGE_NAME\";\n\nimport { BaseManager } from \"../BaseManager\";\n\ntype ProjectManagerGetSliceMachineConfigPathArgs = {\n\tignoreCache?: boolean;\n};\n\ntype ProjectManagerGetRootArgs = {\n\tignoreCache?: boolean;\n};\n\ntype ProjectManagerCheckIsTypeScriptArgs = {\n\trootOverride?: string;\n};\n\ntype ProjectManagerWriteSliceMachineConfigArgs = {\n\tconfig: SliceMachineConfig;\n\tpath?: string;\n};\n\ntype ProjectManagerInitProjectArgs = {\n\tlog?: (message: string) => void;\n};\n\ntype ProjectManagerDetectPackageManager = {\n\troot?: string;\n};\n\ntype ProjectManagerInstallDependenciesArgs = {\n\tdependencies: Record<string, string>;\n\tdev?: boolean;\n\tpackageManager?: PackageManager;\n\tlog?: (message: string) => void;\n};\n\ntype ProjectManagerInstallDependenciesReturnType = {\n\texecaProcess: ExecaChildProcess;\n};\n\nexport class ProjectManager extends BaseManager {\n\tprivate _cachedRoot: string | undefined;\n\tprivate _cachedSliceMachineConfigPath: string | undefined;\n\tprivate _cachedSliceMachineConfig: SliceMachineConfig | undefined;\n\n\tasync getSliceMachineConfigPath(\n\t\targs?: ProjectManagerGetSliceMachineConfigPathArgs,\n\t): Promise<string> {\n\t\tif (this._cachedSliceMachineConfigPath && !args?.ignoreCache) {\n\t\t\treturn this._cachedSliceMachineConfigPath;\n\t\t}\n\n\t\ttry {\n\t\t\tthis._cachedSliceMachineConfigPath = await locateFileUpward(\n\t\t\t\tSLICE_MACHINE_CONFIG_FILENAME,\n\t\t\t\t{ startDir: this.cwd },\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tthrow new Error(\n\t\t\t\t`Could not find a ${SLICE_MACHINE_CONFIG_FILENAME} file. Please create a config file at the root of your project.`,\n\t\t\t);\n\t\t}\n\n\t\treturn this._cachedSliceMachineConfigPath;\n\t}\n\n\tasync getRoot(args?: ProjectManagerGetRootArgs): Promise<string> {\n\t\tif (this._cachedRoot && !args?.ignoreCache) {\n\t\t\treturn this._cachedRoot;\n\t\t}\n\n\t\tconst sliceMachineConfigFilePath = await this.getSliceMachineConfigPath({\n\t\t\tignoreCache: args?.ignoreCache,\n\t\t});\n\n\t\tthis._cachedRoot = path.dirname(sliceMachineConfigFilePath);\n\n\t\treturn this._cachedRoot;\n\t}\n\n\tasync suggestRoot(): Promise<string> {\n\t\tconst suggestedRootPackageJSON = await locateFileUpward(\"package.json\", {\n\t\t\tstartDir: this.cwd,\n\t\t});\n\n\t\treturn path.dirname(suggestedRootPackageJSON);\n\t}\n\n\tasync suggestSliceMachineConfigPath(): Promise<string> {\n\t\tconst suggestedRoot = await this.suggestRoot();\n\n\t\treturn path.resolve(suggestedRoot, SLICE_MACHINE_CONFIG_FILENAME);\n\t}\n\n\tasync checkIsTypeScript(\n\t\targs?: ProjectManagerCheckIsTypeScriptArgs,\n\t): Promise<boolean> {\n\t\tconst root = args?.rootOverride || (await this.getRoot());\n\t\tconst rootTSConfigPath = path.resolve(root, TS_CONFIG_FILENAME);\n\n\t\t// We just care if the file exists, we don't need access to it\n\t\treturn existsSync(rootTSConfigPath);\n\t}\n\n\tasync getSliceMachineConfig(): Promise<SliceMachineConfig> {\n\t\tif (this._cachedSliceMachineConfig) {\n\t\t\treturn this._cachedSliceMachineConfig;\n\t\t} else {\n\t\t\treturn await this.loadSliceMachineConfig();\n\t\t}\n\t}\n\n\tasync writeSliceMachineConfig(\n\t\targs: ProjectManagerWriteSliceMachineConfigArgs,\n\t): Promise<void> {\n\t\tconst configFilePath =\n\t\t\targs.path || (await this.getSliceMachineConfigPath());\n\n\t\tconst config = await format(\n\t\t\tJSON.stringify(args.config, null, 2),\n\t\t\tconfigFilePath,\n\t\t);\n\n\t\tawait fs.writeFile(configFilePath, config, \"utf-8\");\n\t\tdelete this._cachedSliceMachineConfig; // Clear config cache\n\t}\n\n\tasync loadSliceMachineConfig(): Promise<SliceMachineConfig> {\n\t\t// TODO: Reload plugins with a fresh plugin runner. Plugins may\n\t\t// have been added or removed.\n\t\tconst configFilePath = await this.getSliceMachineConfigPath();\n\n\t\tlet rawConfig: unknown | undefined;\n\t\ttry {\n\t\t\tconst contents = await fs.readFile(configFilePath, \"utf8\");\n\t\t\trawConfig = JSON.parse(contents);\n\t\t} catch (error) {\n\t\t\tif (error instanceof SyntaxError) {\n\t\t\t\tthrow new SliceMachineError(\n\t\t\t\t\t`Could not parse config file at ${configFilePath}.\\n\\nError Message: ${error.message}`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t// Noop, more specific error is thrown after\n\t\t}\n\n\t\tif (!rawConfig) {\n\t\t\t// TODO: Write a more friendly and useful message.\n\t\t\tthrow new Error(\"No config found.\");\n\t\t}\n\n\t\tconst { value: sliceMachineConfig, error } =\n\t\t\tdecodeSliceMachineConfig(rawConfig);\n\n\t\tif (error) {\n\t\t\t// TODO: Write a more friendly and useful message.\n\t\t\tthrow new Error(`Invalid config. ${error.errors.join(\", \")}`, {\n\t\t\t\tcause: { rawConfig },\n\t\t\t});\n\t\t}\n\n\t\t// Allow cached config reading using `SliceMachineManager.prototype.getProjectConfig()`.\n\t\tthis._cachedSliceMachineConfig = sliceMachineConfig;\n\n\t\treturn sliceMachineConfig;\n\t}\n\n\tasync locateSliceMachineUIDir(): Promise<string> {\n\t\tconst projectRoot = await this.getRoot();\n\n\t\tconst require = createRequire(path.join(projectRoot, \"index.js\"));\n\t\tconst sliceMachinePackageJSONPath = require.resolve(\n\t\t\t`${SLICE_MACHINE_NPM_PACKAGE_NAME}/package.json`,\n\t\t);\n\n\t\treturn path.dirname(sliceMachinePackageJSONPath);\n\t}\n\n\tasync getRepositoryName(): Promise<string> {\n\t\tconst sliceMachineConfig = await this.getSliceMachineConfig();\n\n\t\treturn sliceMachineConfig.repositoryName;\n\t}\n\n\tasync getAdapterName(): Promise<string> {\n\t\tconst sliceMachineConfig = await this.getSliceMachineConfig();\n\t\tconst adapterName =\n\t\t\ttypeof sliceMachineConfig.adapter === \"string\"\n\t\t\t\t? sliceMachineConfig.adapter\n\t\t\t\t: sliceMachineConfig.adapter.resolve;\n\n\t\treturn adapterName;\n\t}\n\n\tasync locateAdapterDir(): Promise<string> {\n\t\tconst projectRoot = await this.getRoot();\n\t\tconst adapterName = await this.getAdapterName();\n\t\tconst require = createRequire(path.join(projectRoot, \"index.js\"));\n\t\tconst adapterPackageJSONPath = require.resolve(\n\t\t\t`${adapterName}/package.json`,\n\t\t);\n\n\t\treturn path.dirname(adapterPackageJSONPath);\n\t}\n\n\tasync initProject(args?: ProjectManagerInitProjectArgs): Promise<void> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\t// eslint-disable-next-line no-console\n\t\tconst log = args?.log || console.log.bind(this);\n\n\t\tconst { errors } = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"project:init\",\n\t\t\t{\n\t\t\t\tlog,\n\t\t\t\tinstallDependencies: async (args) => {\n\t\t\t\t\tconst { execaProcess } = await this.installDependencies({\n\t\t\t\t\t\tdependencies: args.dependencies,\n\t\t\t\t\t\tdev: args.dev,\n\t\t\t\t\t\tlog,\n\t\t\t\t\t});\n\n\t\t\t\t\tawait execaProcess;\n\t\t\t\t},\n\t\t\t},\n\t\t);\n\n\t\tif (errors.length > 0) {\n\t\t\t// TODO: Provide better error message.\n\t\t\tthrow new SliceMachineError(\n\t\t\t\t`Failed to initialize project: ${errors.join(\", \")}`,\n\t\t\t);\n\t\t}\n\t}\n\n\tasync detectPackageManager(\n\t\targs?: ProjectManagerDetectPackageManager,\n\t): Promise<PackageManager> {\n\t\tconst projectRoot = args?.root || (await this.getRoot());\n\n\t\tconst packageManager = await niDetect({\n\t\t\tautoInstall: true,\n\t\t\tcwd: projectRoot,\n\t\t});\n\n\t\treturn packageManager || \"npm\";\n\t}\n\n\tasync installDependencies(\n\t\targs: ProjectManagerInstallDependenciesArgs,\n\t): Promise<ProjectManagerInstallDependenciesReturnType> {\n\t\tconst packageManager =\n\t\t\targs.packageManager || (await this.detectPackageManager());\n\n\t\t// eslint-disable-next-line no-console\n\t\tconst log = args.log || console.log.bind(this);\n\n\t\tconst wrappedLogger = (data: Buffer | string | null) => {\n\t\t\tif (data instanceof Buffer) {\n\t\t\t\tlog(data.toString());\n\t\t\t} else if (typeof data === \"string\") {\n\t\t\t\tlog(data);\n\t\t\t}\n\t\t};\n\n\t\ttry {\n\t\t\tconst { execaProcess } = await installDependencies({\n\t\t\t\tpackageManager,\n\t\t\t\tdependencies: args.dependencies,\n\t\t\t\tdev: args.dev,\n\t\t\t});\n\n\t\t\t// Don't clutter console with logs when process is non TTY (CI, etc.)\n\t\t\tif (process.stdout.isTTY || process.env.NODE_ENV === \"test\") {\n\t\t\t\texecaProcess.stdout?.on(\"data\", wrappedLogger);\n\t\t\t}\n\t\t\texecaProcess.stderr?.on(\"data\", wrappedLogger);\n\n\t\t\treturn {\n\t\t\t\texecaProcess,\n\t\t\t};\n\t\t} catch (error) {\n\t\t\tif (\n\t\t\t\terror instanceof Error &&\n\t\t\t\t\"shortMessage\" in error &&\n\t\t\t\t\"stderr\" in error\n\t\t\t) {\n\t\t\t\tthrow new InternalError(\"Package installation failed\", {\n\t\t\t\t\tcause: error,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tthrow error;\n\t\t}\n\t}\n}\n"],"names":["BaseManager","locateFileUpward","SLICE_MACHINE_CONFIG_FILENAME","path","TS_CONFIG_FILENAME","existsSync","format","fs","error","SliceMachineError","decodeSliceMachineConfig","require","createRequire","SLICE_MACHINE_NPM_PACKAGE_NAME","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AAE3C,UAAM,iBACL,KAAK,kBAAmB,MAAM,KAAK,qBAAoB;AAGxD,UAAM,MAAM,KAAK,OAAO,QAAQ,IAAI,KAAK,IAAI;AAEvC,UAAA,gBAAgB,CAAC,SAAgC;AACtD,UAAI,gBAAgB,QAAQ;AACvB,YAAA,KAAK,UAAU;AAAA,MAAA,WACT,OAAO,SAAS,UAAU;AACpC,YAAI,IAAI;AAAA,MACR;AAAA,IAAA;AAGE,QAAA;AACH,YAAM,EAAE,iBAAiB,MAAMC,wCAAoB;AAAA,QAClD;AAAA,QACA,cAAc,KAAK;AAAA,QACnB,KAAK,KAAK;AAAA,MAAA,CACV;AAGD,UAAI,QAAQ,OAAO,SAAS,QAAQ,IAAI,aAAa,QAAQ;AAC/C,2BAAA,WAAA,mBAAQ,GAAG,QAAQ;AAAA,MAChC;AACY,yBAAA,WAAA,mBAAQ,GAAG,QAAQ;AAEzB,aAAA;AAAA,QACN;AAAA,MAAA;AAAA,aAEO;AACR,UACC,iBAAiB,SACjB,kBAAkB,SAClB,YAAY,OACX;AACK,cAAA,IAAIC,qBAAc,+BAA+B;AAAA,UACtD,OAAO;AAAA,QAAA,CACP;AAAA,MACD;AAEK,YAAA;AAAA,IACN;AAAA,EACF;AACA;;"}
|
|
1
|
+
{"version":3,"file":"ProjectManager.cjs","sources":["../../../../src/managers/project/ProjectManager.ts"],"sourcesContent":["import * as fs from \"node:fs/promises\";\nimport { existsSync } from \"node:fs\";\nimport * as path from \"node:path\";\nimport { createRequire } from \"node:module\";\nimport { detect as niDetect } from \"@antfu/ni\";\nimport { ExecaChildProcess } from \"execa\";\nimport {\n\tHookError,\n\tCallHookReturnType,\n\tProjectEnvironmentUpdateHook,\n} from \"@slicemachine/plugin-kit\";\nimport * as t from \"io-ts\";\n\nimport { DecodeError } from \"../../lib/DecodeError\";\nimport { assertPluginsInitialized } from \"../../lib/assertPluginsInitialized\";\nimport { decodeHookResult } from \"../../lib/decodeHookResult\";\nimport { decodeSliceMachineConfig } from \"../../lib/decodeSliceMachineConfig\";\nimport { format } from \"../../lib/format\";\nimport { installDependencies } from \"../../lib/installDependencies\";\nimport { locateFileUpward } from \"../../lib/locateFileUpward\";\n\nimport {\n\tPackageManager,\n\tSliceMachineConfig,\n\tOnlyHookErrors,\n} from \"../../types\";\n\nimport { SliceMachineError, InternalError, PluginError } from \"../../errors\";\n\nimport { SLICE_MACHINE_CONFIG_FILENAME } from \"../../constants/SLICE_MACHINE_CONFIG_FILENAME\";\nimport { TS_CONFIG_FILENAME } from \"../../constants/TS_CONFIG_FILENAME\";\nimport { SLICE_MACHINE_NPM_PACKAGE_NAME } from \"../../constants/SLICE_MACHINE_NPM_PACKAGE_NAME\";\n\nimport { BaseManager } from \"../BaseManager\";\n\ntype ProjectManagerGetSliceMachineConfigPathArgs = {\n\tignoreCache?: boolean;\n};\n\ntype ProjectManagerGetRootArgs = {\n\tignoreCache?: boolean;\n};\n\ntype ProjectManagerCheckIsTypeScriptArgs = {\n\trootOverride?: string;\n};\n\ntype ProjectManagerWriteSliceMachineConfigArgs = {\n\tconfig: SliceMachineConfig;\n\tpath?: string;\n};\n\ntype ProjectManagerInitProjectArgs = {\n\tlog?: (message: string) => void;\n};\n\ntype ProjectManagerDetectPackageManager = {\n\troot?: string;\n};\n\ntype ProjectManagerInstallDependenciesArgs = {\n\tdependencies: Record<string, string>;\n\tdev?: boolean;\n\tpackageManager?: PackageManager;\n\tlog?: (message: string) => void;\n};\n\ntype ProjectManagerInstallDependenciesReturnType = {\n\texecaProcess: ExecaChildProcess;\n};\n\ntype ProjectManagerReadEnvironmentReturnType = {\n\tenvironment: string | undefined;\n\terrors: (DecodeError | HookError)[];\n};\n\ntype ProjectManagerUpdateEnvironmentArgs = {\n\tenvironment: string | undefined;\n};\n\nexport class ProjectManager extends BaseManager {\n\tprivate _cachedRoot: string | undefined;\n\tprivate _cachedSliceMachineConfigPath: string | undefined;\n\tprivate _cachedSliceMachineConfig: SliceMachineConfig | undefined;\n\n\tasync getSliceMachineConfigPath(\n\t\targs?: ProjectManagerGetSliceMachineConfigPathArgs,\n\t): Promise<string> {\n\t\tif (this._cachedSliceMachineConfigPath && !args?.ignoreCache) {\n\t\t\treturn this._cachedSliceMachineConfigPath;\n\t\t}\n\n\t\ttry {\n\t\t\tthis._cachedSliceMachineConfigPath = await locateFileUpward(\n\t\t\t\tSLICE_MACHINE_CONFIG_FILENAME,\n\t\t\t\t{ startDir: this.cwd },\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tthrow new Error(\n\t\t\t\t`Could not find a ${SLICE_MACHINE_CONFIG_FILENAME} file. Please create a config file at the root of your project.`,\n\t\t\t);\n\t\t}\n\n\t\treturn this._cachedSliceMachineConfigPath;\n\t}\n\n\tasync getRoot(args?: ProjectManagerGetRootArgs): Promise<string> {\n\t\tif (this._cachedRoot && !args?.ignoreCache) {\n\t\t\treturn this._cachedRoot;\n\t\t}\n\n\t\tconst sliceMachineConfigFilePath = await this.getSliceMachineConfigPath({\n\t\t\tignoreCache: args?.ignoreCache,\n\t\t});\n\n\t\tthis._cachedRoot = path.dirname(sliceMachineConfigFilePath);\n\n\t\treturn this._cachedRoot;\n\t}\n\n\tasync suggestRoot(): Promise<string> {\n\t\tconst suggestedRootPackageJSON = await locateFileUpward(\"package.json\", {\n\t\t\tstartDir: this.cwd,\n\t\t});\n\n\t\treturn path.dirname(suggestedRootPackageJSON);\n\t}\n\n\tasync suggestSliceMachineConfigPath(): Promise<string> {\n\t\tconst suggestedRoot = await this.suggestRoot();\n\n\t\treturn path.resolve(suggestedRoot, SLICE_MACHINE_CONFIG_FILENAME);\n\t}\n\n\tasync checkIsTypeScript(\n\t\targs?: ProjectManagerCheckIsTypeScriptArgs,\n\t): Promise<boolean> {\n\t\tconst root = args?.rootOverride || (await this.getRoot());\n\t\tconst rootTSConfigPath = path.resolve(root, TS_CONFIG_FILENAME);\n\n\t\t// We just care if the file exists, we don't need access to it\n\t\treturn existsSync(rootTSConfigPath);\n\t}\n\n\tasync getSliceMachineConfig(): Promise<SliceMachineConfig> {\n\t\tif (this._cachedSliceMachineConfig) {\n\t\t\treturn this._cachedSliceMachineConfig;\n\t\t} else {\n\t\t\treturn await this.loadSliceMachineConfig();\n\t\t}\n\t}\n\n\tasync writeSliceMachineConfig(\n\t\targs: ProjectManagerWriteSliceMachineConfigArgs,\n\t): Promise<void> {\n\t\tconst configFilePath =\n\t\t\targs.path || (await this.getSliceMachineConfigPath());\n\n\t\tconst config = await format(\n\t\t\tJSON.stringify(args.config, null, 2),\n\t\t\tconfigFilePath,\n\t\t);\n\n\t\tawait fs.writeFile(configFilePath, config, \"utf-8\");\n\t\tdelete this._cachedSliceMachineConfig; // Clear config cache\n\t}\n\n\tasync loadSliceMachineConfig(): Promise<SliceMachineConfig> {\n\t\t// TODO: Reload plugins with a fresh plugin runner. Plugins may\n\t\t// have been added or removed.\n\t\tconst configFilePath = await this.getSliceMachineConfigPath();\n\n\t\tlet rawConfig: unknown | undefined;\n\t\ttry {\n\t\t\tconst contents = await fs.readFile(configFilePath, \"utf8\");\n\t\t\trawConfig = JSON.parse(contents);\n\t\t} catch (error) {\n\t\t\tif (error instanceof SyntaxError) {\n\t\t\t\tthrow new SliceMachineError(\n\t\t\t\t\t`Could not parse config file at ${configFilePath}.\\n\\nError Message: ${error.message}`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t// Noop, more specific error is thrown after\n\t\t}\n\n\t\tif (!rawConfig) {\n\t\t\t// TODO: Write a more friendly and useful message.\n\t\t\tthrow new Error(\"No config found.\");\n\t\t}\n\n\t\tconst { value: sliceMachineConfig, error } =\n\t\t\tdecodeSliceMachineConfig(rawConfig);\n\n\t\tif (error) {\n\t\t\t// TODO: Write a more friendly and useful message.\n\t\t\tthrow new Error(`Invalid config. ${error.errors.join(\", \")}`, {\n\t\t\t\tcause: { rawConfig },\n\t\t\t});\n\t\t}\n\n\t\t// Allow cached config reading using `SliceMachineManager.prototype.getProjectConfig()`.\n\t\tthis._cachedSliceMachineConfig = sliceMachineConfig;\n\n\t\treturn sliceMachineConfig;\n\t}\n\n\tasync locateSliceMachineUIDir(): Promise<string> {\n\t\tconst projectRoot = await this.getRoot();\n\n\t\tconst require = createRequire(path.join(projectRoot, \"index.js\"));\n\t\tconst sliceMachinePackageJSONPath = require.resolve(\n\t\t\t`${SLICE_MACHINE_NPM_PACKAGE_NAME}/package.json`,\n\t\t);\n\n\t\treturn path.dirname(sliceMachinePackageJSONPath);\n\t}\n\n\t/**\n\t * Returns the project's repository name (i.e. the production environment). It\n\t * ignores the currently selected environment.\n\t *\n\t * Use this method to retrieve the production environment domain.\n\t *\n\t * @returns The project's repository name.\n\t */\n\tasync getRepositoryName(): Promise<string> {\n\t\tconst sliceMachineConfig = await this.getSliceMachineConfig();\n\n\t\treturn sliceMachineConfig.repositoryName;\n\t}\n\n\t/**\n\t * Returns the currently selected environment domain if set. If an environment\n\t * is not set, it returns the project's repository name (the production\n\t * environment).\n\t *\n\t * Use this method to retrieve the repository name to be sent with Prismic API\n\t * requests.\n\t *\n\t * @returns The resolved repository name.\n\t */\n\tasync getResolvedRepositoryName(): Promise<string> {\n\t\tconst repositoryName = await this.getRepositoryName();\n\n\t\tconst supportsEnvironments = this.project.checkSupportsEnvironments();\n\t\tif (!supportsEnvironments) {\n\t\t\treturn repositoryName;\n\t\t}\n\n\t\tconst { environment } = await this.project.readEnvironment();\n\n\t\treturn environment ?? repositoryName;\n\t}\n\n\tasync getAdapterName(): Promise<string> {\n\t\tconst sliceMachineConfig = await this.getSliceMachineConfig();\n\t\tconst adapterName =\n\t\t\ttypeof sliceMachineConfig.adapter === \"string\"\n\t\t\t\t? sliceMachineConfig.adapter\n\t\t\t\t: sliceMachineConfig.adapter.resolve;\n\n\t\treturn adapterName;\n\t}\n\n\tasync locateAdapterDir(): Promise<string> {\n\t\tconst projectRoot = await this.getRoot();\n\t\tconst adapterName = await this.getAdapterName();\n\t\tconst require = createRequire(path.join(projectRoot, \"index.js\"));\n\t\tconst adapterPackageJSONPath = require.resolve(\n\t\t\t`${adapterName}/package.json`,\n\t\t);\n\n\t\treturn path.dirname(adapterPackageJSONPath);\n\t}\n\n\tasync initProject(args?: ProjectManagerInitProjectArgs): Promise<void> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\t// eslint-disable-next-line no-console\n\t\tconst log = args?.log || console.log.bind(this);\n\n\t\tconst { errors } = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"project:init\",\n\t\t\t{\n\t\t\t\tlog,\n\t\t\t\tinstallDependencies: async (args) => {\n\t\t\t\t\tconst { execaProcess } = await this.installDependencies({\n\t\t\t\t\t\tdependencies: args.dependencies,\n\t\t\t\t\t\tdev: args.dev,\n\t\t\t\t\t\tlog,\n\t\t\t\t\t});\n\n\t\t\t\t\tawait execaProcess;\n\t\t\t\t},\n\t\t\t},\n\t\t);\n\n\t\tif (errors.length > 0) {\n\t\t\t// TODO: Provide better error message.\n\t\t\tthrow new SliceMachineError(\n\t\t\t\t`Failed to initialize project: ${errors.join(\", \")}`,\n\t\t\t);\n\t\t}\n\t}\n\n\tasync detectPackageManager(\n\t\targs?: ProjectManagerDetectPackageManager,\n\t): Promise<PackageManager> {\n\t\tconst projectRoot = args?.root || (await this.getRoot());\n\n\t\tconst packageManager = await niDetect({\n\t\t\tautoInstall: true,\n\t\t\tcwd: projectRoot,\n\t\t});\n\n\t\treturn packageManager || \"npm\";\n\t}\n\n\tasync installDependencies(\n\t\targs: ProjectManagerInstallDependenciesArgs,\n\t): Promise<ProjectManagerInstallDependenciesReturnType> {\n\t\tconst packageManager =\n\t\t\targs.packageManager || (await this.detectPackageManager());\n\n\t\t// eslint-disable-next-line no-console\n\t\tconst log = args.log || console.log.bind(this);\n\n\t\tconst wrappedLogger = (data: Buffer | string | null) => {\n\t\t\tif (data instanceof Buffer) {\n\t\t\t\tlog(data.toString());\n\t\t\t} else if (typeof data === \"string\") {\n\t\t\t\tlog(data);\n\t\t\t}\n\t\t};\n\n\t\ttry {\n\t\t\tconst { execaProcess } = await installDependencies({\n\t\t\t\tpackageManager,\n\t\t\t\tdependencies: args.dependencies,\n\t\t\t\tdev: args.dev,\n\t\t\t});\n\n\t\t\t// Don't clutter console with logs when process is non TTY (CI, etc.)\n\t\t\tif (process.stdout.isTTY || process.env.NODE_ENV === \"test\") {\n\t\t\t\texecaProcess.stdout?.on(\"data\", wrappedLogger);\n\t\t\t}\n\t\t\texecaProcess.stderr?.on(\"data\", wrappedLogger);\n\n\t\t\treturn {\n\t\t\t\texecaProcess,\n\t\t\t};\n\t\t} catch (error) {\n\t\t\tif (\n\t\t\t\terror instanceof Error &&\n\t\t\t\t\"shortMessage\" in error &&\n\t\t\t\t\"stderr\" in error\n\t\t\t) {\n\t\t\t\tthrow new InternalError(\"Package installation failed\", {\n\t\t\t\t\tcause: error,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\tcheckSupportsEnvironments(): boolean {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\treturn (\n\t\t\tthis.sliceMachinePluginRunner.hooksForType(\"project:environment:read\")\n\t\t\t\t.length > 0 &&\n\t\t\tthis.sliceMachinePluginRunner.hooksForType(\"project:environment:update\")\n\t\t\t\t.length > 0\n\t\t);\n\t}\n\n\tasync readEnvironment(): Promise<ProjectManagerReadEnvironmentReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tawait this._assertAdapterSupportsEnvironments();\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"project:environment:read\",\n\t\t\tundefined,\n\t\t);\n\t\tconst { data, errors } = decodeHookResult(\n\t\t\tt.type({\n\t\t\t\tenvironment: t.union([t.undefined, t.string]),\n\t\t\t}),\n\t\t\thookResult,\n\t\t);\n\n\t\t// An undefined value is equivalent to the production environment.\n\t\t// We cast to undefined.\n\t\tconst repositoryName = await this.project.getRepositoryName();\n\t\tconst environmentDomain =\n\t\t\tdata[0]?.environment === repositoryName\n\t\t\t\t? undefined\n\t\t\t\t: data[0]?.environment;\n\n\t\treturn {\n\t\t\tenvironment: environmentDomain,\n\t\t\terrors,\n\t\t};\n\t}\n\n\tasync updateEnvironment(\n\t\targs: ProjectManagerUpdateEnvironmentArgs,\n\t): Promise<OnlyHookErrors<CallHookReturnType<ProjectEnvironmentUpdateHook>>> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tawait this._assertAdapterSupportsEnvironments();\n\n\t\tconst repositoryName = await this.project.getRepositoryName();\n\t\tconst environment =\n\t\t\targs.environment === repositoryName ? undefined : args.environment;\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"project:environment:update\",\n\t\t\t{ environment },\n\t\t);\n\n\t\treturn {\n\t\t\terrors: hookResult.errors,\n\t\t};\n\t}\n\n\tprivate async _assertAdapterSupportsEnvironments(): Promise<void> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst supportsEnvironments = this.checkSupportsEnvironments();\n\n\t\tif (!supportsEnvironments) {\n\t\t\tconst adapterName = await this.project.getAdapterName();\n\n\t\t\tthrow new PluginError(\n\t\t\t\t`${adapterName} does not support environments. Use an adapter that implements the \\`project:environment:read\\` and \\`project:environment:update\\` hooks to use environments.`,\n\t\t\t);\n\t\t}\n\t}\n}\n"],"names":["BaseManager","locateFileUpward","SLICE_MACHINE_CONFIG_FILENAME","path","TS_CONFIG_FILENAME","existsSync","format","fs","error","SliceMachineError","decodeSliceMachineConfig","require","createRequire","SLICE_MACHINE_NPM_PACKAGE_NAME","assertPluginsInitialized","errors","args","niDetect","installDependencies","InternalError","decodeHookResult","t","PluginError"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgFM,MAAO,uBAAuBA,YAAAA,YAAW;AAAA,EAAzC;AAAA;AACG;AACA;AACA;AAAA;AAAA,EAER,MAAM,0BACL,MAAkD;AAElD,QAAI,KAAK,iCAAiC,EAAC,6BAAM,cA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,MACN,aAAaA,aAAE,MAAM,CAACA,aAAE,WAAWA,aAAE,MAAM,CAAC;AAAA,IAAA,CAC5C,GACD,UAAU;AAKX,UAAM,iBAAiB,MAAM,KAAK,QAAQ,kBAAiB;AACrD,UAAA,sBACL,UAAK,CAAC,MAAN,mBAAS,iBAAgB,iBACtB,UACA,UAAK,CAAC,MAAN,mBAAS;AAEN,WAAA;AAAA,MACN,aAAa;AAAA,MACb,QAAAN;AAAA,IAAA;AAAA,EAEF;AAAA,EAEA,MAAM,kBACL,MAAyC;AAEzCD,sDAAyB,KAAK,wBAAwB;AAEtD,UAAM,KAAK;AAEX,UAAM,iBAAiB,MAAM,KAAK,QAAQ,kBAAiB;AAC3D,UAAM,cACL,KAAK,gBAAgB,iBAAiB,SAAY,KAAK;AAElD,UAAA,aAAa,MAAM,KAAK,yBAAyB,SACtD,8BACA,EAAE,aAAa;AAGT,WAAA;AAAA,MACN,QAAQ,WAAW;AAAA,IAAA;AAAA,EAErB;AAAA,EAEQ,MAAM,qCAAkC;AAC/CA,sDAAyB,KAAK,wBAAwB;AAEhD,UAAA,uBAAuB,KAAK;AAElC,QAAI,CAAC,sBAAsB;AAC1B,YAAM,cAAc,MAAM,KAAK,QAAQ,eAAc;AAE/C,YAAA,IAAIQ,OAAAA,YACT,GAAG,0KAA0K;AAAA,IAE9K;AAAA,EACF;AACA;;"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { ExecaChildProcess } from "execa";
|
|
2
|
-
import {
|
|
2
|
+
import { HookError, CallHookReturnType, ProjectEnvironmentUpdateHook } from "@slicemachine/plugin-kit";
|
|
3
|
+
import { DecodeError } from "../../lib/DecodeError";
|
|
4
|
+
import { PackageManager, SliceMachineConfig, OnlyHookErrors } from "../../types";
|
|
3
5
|
import { BaseManager } from "../BaseManager";
|
|
4
6
|
type ProjectManagerGetSliceMachineConfigPathArgs = {
|
|
5
7
|
ignoreCache?: boolean;
|
|
@@ -29,6 +31,13 @@ type ProjectManagerInstallDependenciesArgs = {
|
|
|
29
31
|
type ProjectManagerInstallDependenciesReturnType = {
|
|
30
32
|
execaProcess: ExecaChildProcess;
|
|
31
33
|
};
|
|
34
|
+
type ProjectManagerReadEnvironmentReturnType = {
|
|
35
|
+
environment: string | undefined;
|
|
36
|
+
errors: (DecodeError | HookError)[];
|
|
37
|
+
};
|
|
38
|
+
type ProjectManagerUpdateEnvironmentArgs = {
|
|
39
|
+
environment: string | undefined;
|
|
40
|
+
};
|
|
32
41
|
export declare class ProjectManager extends BaseManager {
|
|
33
42
|
private _cachedRoot;
|
|
34
43
|
private _cachedSliceMachineConfigPath;
|
|
@@ -42,11 +51,34 @@ export declare class ProjectManager extends BaseManager {
|
|
|
42
51
|
writeSliceMachineConfig(args: ProjectManagerWriteSliceMachineConfigArgs): Promise<void>;
|
|
43
52
|
loadSliceMachineConfig(): Promise<SliceMachineConfig>;
|
|
44
53
|
locateSliceMachineUIDir(): Promise<string>;
|
|
54
|
+
/**
|
|
55
|
+
* Returns the project's repository name (i.e. the production environment). It
|
|
56
|
+
* ignores the currently selected environment.
|
|
57
|
+
*
|
|
58
|
+
* Use this method to retrieve the production environment domain.
|
|
59
|
+
*
|
|
60
|
+
* @returns The project's repository name.
|
|
61
|
+
*/
|
|
45
62
|
getRepositoryName(): Promise<string>;
|
|
63
|
+
/**
|
|
64
|
+
* Returns the currently selected environment domain if set. If an environment
|
|
65
|
+
* is not set, it returns the project's repository name (the production
|
|
66
|
+
* environment).
|
|
67
|
+
*
|
|
68
|
+
* Use this method to retrieve the repository name to be sent with Prismic API
|
|
69
|
+
* requests.
|
|
70
|
+
*
|
|
71
|
+
* @returns The resolved repository name.
|
|
72
|
+
*/
|
|
73
|
+
getResolvedRepositoryName(): Promise<string>;
|
|
46
74
|
getAdapterName(): Promise<string>;
|
|
47
75
|
locateAdapterDir(): Promise<string>;
|
|
48
76
|
initProject(args?: ProjectManagerInitProjectArgs): Promise<void>;
|
|
49
77
|
detectPackageManager(args?: ProjectManagerDetectPackageManager): Promise<PackageManager>;
|
|
50
78
|
installDependencies(args: ProjectManagerInstallDependenciesArgs): Promise<ProjectManagerInstallDependenciesReturnType>;
|
|
79
|
+
checkSupportsEnvironments(): boolean;
|
|
80
|
+
readEnvironment(): Promise<ProjectManagerReadEnvironmentReturnType>;
|
|
81
|
+
updateEnvironment(args: ProjectManagerUpdateEnvironmentArgs): Promise<OnlyHookErrors<CallHookReturnType<ProjectEnvironmentUpdateHook>>>;
|
|
82
|
+
private _assertAdapterSupportsEnvironments;
|
|
51
83
|
}
|
|
52
84
|
export {};
|
|
@@ -9,12 +9,14 @@ import { existsSync } from "node:fs";
|
|
|
9
9
|
import * as path from "node:path";
|
|
10
10
|
import { createRequire } from "node:module";
|
|
11
11
|
import { detect } from "@antfu/ni";
|
|
12
|
+
import * as t from "io-ts";
|
|
12
13
|
import { assertPluginsInitialized } from "../../lib/assertPluginsInitialized.js";
|
|
14
|
+
import { decodeHookResult } from "../../lib/decodeHookResult.js";
|
|
13
15
|
import { decodeSliceMachineConfig } from "../../lib/decodeSliceMachineConfig.js";
|
|
14
16
|
import { format } from "../../lib/format.js";
|
|
15
17
|
import { installDependencies } from "../../lib/installDependencies.js";
|
|
16
18
|
import { locateFileUpward } from "../../lib/locateFileUpward.js";
|
|
17
|
-
import { SliceMachineError, InternalError } from "../../errors.js";
|
|
19
|
+
import { SliceMachineError, InternalError, PluginError } from "../../errors.js";
|
|
18
20
|
import { SLICE_MACHINE_CONFIG_FILENAME } from "../../constants/SLICE_MACHINE_CONFIG_FILENAME.js";
|
|
19
21
|
import { TS_CONFIG_FILENAME } from "../../constants/TS_CONFIG_FILENAME.js";
|
|
20
22
|
import { SLICE_MACHINE_NPM_PACKAGE_NAME } from "../../constants/SLICE_MACHINE_NPM_PACKAGE_NAME.js";
|
|
@@ -106,10 +108,37 @@ Error Message: ${error2.message}`);
|
|
|
106
108
|
const sliceMachinePackageJSONPath = require2.resolve(`${SLICE_MACHINE_NPM_PACKAGE_NAME}/package.json`);
|
|
107
109
|
return path.dirname(sliceMachinePackageJSONPath);
|
|
108
110
|
}
|
|
111
|
+
/**
|
|
112
|
+
* Returns the project's repository name (i.e. the production environment). It
|
|
113
|
+
* ignores the currently selected environment.
|
|
114
|
+
*
|
|
115
|
+
* Use this method to retrieve the production environment domain.
|
|
116
|
+
*
|
|
117
|
+
* @returns The project's repository name.
|
|
118
|
+
*/
|
|
109
119
|
async getRepositoryName() {
|
|
110
120
|
const sliceMachineConfig = await this.getSliceMachineConfig();
|
|
111
121
|
return sliceMachineConfig.repositoryName;
|
|
112
122
|
}
|
|
123
|
+
/**
|
|
124
|
+
* Returns the currently selected environment domain if set. If an environment
|
|
125
|
+
* is not set, it returns the project's repository name (the production
|
|
126
|
+
* environment).
|
|
127
|
+
*
|
|
128
|
+
* Use this method to retrieve the repository name to be sent with Prismic API
|
|
129
|
+
* requests.
|
|
130
|
+
*
|
|
131
|
+
* @returns The resolved repository name.
|
|
132
|
+
*/
|
|
133
|
+
async getResolvedRepositoryName() {
|
|
134
|
+
const repositoryName = await this.getRepositoryName();
|
|
135
|
+
const supportsEnvironments = this.project.checkSupportsEnvironments();
|
|
136
|
+
if (!supportsEnvironments) {
|
|
137
|
+
return repositoryName;
|
|
138
|
+
}
|
|
139
|
+
const { environment } = await this.project.readEnvironment();
|
|
140
|
+
return environment ?? repositoryName;
|
|
141
|
+
}
|
|
113
142
|
async getAdapterName() {
|
|
114
143
|
const sliceMachineConfig = await this.getSliceMachineConfig();
|
|
115
144
|
const adapterName = typeof sliceMachineConfig.adapter === "string" ? sliceMachineConfig.adapter : sliceMachineConfig.adapter.resolve;
|
|
@@ -181,6 +210,43 @@ Error Message: ${error2.message}`);
|
|
|
181
210
|
throw error;
|
|
182
211
|
}
|
|
183
212
|
}
|
|
213
|
+
checkSupportsEnvironments() {
|
|
214
|
+
assertPluginsInitialized(this.sliceMachinePluginRunner);
|
|
215
|
+
return this.sliceMachinePluginRunner.hooksForType("project:environment:read").length > 0 && this.sliceMachinePluginRunner.hooksForType("project:environment:update").length > 0;
|
|
216
|
+
}
|
|
217
|
+
async readEnvironment() {
|
|
218
|
+
var _a, _b;
|
|
219
|
+
assertPluginsInitialized(this.sliceMachinePluginRunner);
|
|
220
|
+
await this._assertAdapterSupportsEnvironments();
|
|
221
|
+
const hookResult = await this.sliceMachinePluginRunner.callHook("project:environment:read", void 0);
|
|
222
|
+
const { data, errors } = decodeHookResult(t.type({
|
|
223
|
+
environment: t.union([t.undefined, t.string])
|
|
224
|
+
}), hookResult);
|
|
225
|
+
const repositoryName = await this.project.getRepositoryName();
|
|
226
|
+
const environmentDomain = ((_a = data[0]) == null ? void 0 : _a.environment) === repositoryName ? void 0 : (_b = data[0]) == null ? void 0 : _b.environment;
|
|
227
|
+
return {
|
|
228
|
+
environment: environmentDomain,
|
|
229
|
+
errors
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
async updateEnvironment(args) {
|
|
233
|
+
assertPluginsInitialized(this.sliceMachinePluginRunner);
|
|
234
|
+
await this._assertAdapterSupportsEnvironments();
|
|
235
|
+
const repositoryName = await this.project.getRepositoryName();
|
|
236
|
+
const environment = args.environment === repositoryName ? void 0 : args.environment;
|
|
237
|
+
const hookResult = await this.sliceMachinePluginRunner.callHook("project:environment:update", { environment });
|
|
238
|
+
return {
|
|
239
|
+
errors: hookResult.errors
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
async _assertAdapterSupportsEnvironments() {
|
|
243
|
+
assertPluginsInitialized(this.sliceMachinePluginRunner);
|
|
244
|
+
const supportsEnvironments = this.checkSupportsEnvironments();
|
|
245
|
+
if (!supportsEnvironments) {
|
|
246
|
+
const adapterName = await this.project.getAdapterName();
|
|
247
|
+
throw new PluginError(`${adapterName} does not support environments. Use an adapter that implements the \`project:environment:read\` and \`project:environment:update\` hooks to use environments.`);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
184
250
|
}
|
|
185
251
|
export {
|
|
186
252
|
ProjectManager
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProjectManager.js","sources":["../../../../src/managers/project/ProjectManager.ts"],"sourcesContent":["import * as fs from \"node:fs/promises\";\nimport { existsSync } from \"node:fs\";\nimport * as path from \"node:path\";\nimport { createRequire } from \"node:module\";\nimport { detect as niDetect } from \"@antfu/ni\";\nimport { ExecaChildProcess } from \"execa\";\n\nimport { assertPluginsInitialized } from \"../../lib/assertPluginsInitialized\";\nimport { decodeSliceMachineConfig } from \"../../lib/decodeSliceMachineConfig\";\nimport { format } from \"../../lib/format\";\nimport { installDependencies } from \"../../lib/installDependencies\";\nimport { locateFileUpward } from \"../../lib/locateFileUpward\";\n\nimport { PackageManager, SliceMachineConfig } from \"../../types\";\n\nimport { SliceMachineError, InternalError } from \"../../errors\";\n\nimport { SLICE_MACHINE_CONFIG_FILENAME } from \"../../constants/SLICE_MACHINE_CONFIG_FILENAME\";\nimport { TS_CONFIG_FILENAME } from \"../../constants/TS_CONFIG_FILENAME\";\nimport { SLICE_MACHINE_NPM_PACKAGE_NAME } from \"../../constants/SLICE_MACHINE_NPM_PACKAGE_NAME\";\n\nimport { BaseManager } from \"../BaseManager\";\n\ntype ProjectManagerGetSliceMachineConfigPathArgs = {\n\tignoreCache?: boolean;\n};\n\ntype ProjectManagerGetRootArgs = {\n\tignoreCache?: boolean;\n};\n\ntype ProjectManagerCheckIsTypeScriptArgs = {\n\trootOverride?: string;\n};\n\ntype ProjectManagerWriteSliceMachineConfigArgs = {\n\tconfig: SliceMachineConfig;\n\tpath?: string;\n};\n\ntype ProjectManagerInitProjectArgs = {\n\tlog?: (message: string) => void;\n};\n\ntype ProjectManagerDetectPackageManager = {\n\troot?: string;\n};\n\ntype ProjectManagerInstallDependenciesArgs = {\n\tdependencies: Record<string, string>;\n\tdev?: boolean;\n\tpackageManager?: PackageManager;\n\tlog?: (message: string) => void;\n};\n\ntype ProjectManagerInstallDependenciesReturnType = {\n\texecaProcess: ExecaChildProcess;\n};\n\nexport class ProjectManager extends BaseManager {\n\tprivate _cachedRoot: string | undefined;\n\tprivate _cachedSliceMachineConfigPath: string | undefined;\n\tprivate _cachedSliceMachineConfig: SliceMachineConfig | undefined;\n\n\tasync getSliceMachineConfigPath(\n\t\targs?: ProjectManagerGetSliceMachineConfigPathArgs,\n\t): Promise<string> {\n\t\tif (this._cachedSliceMachineConfigPath && !args?.ignoreCache) {\n\t\t\treturn this._cachedSliceMachineConfigPath;\n\t\t}\n\n\t\ttry {\n\t\t\tthis._cachedSliceMachineConfigPath = await locateFileUpward(\n\t\t\t\tSLICE_MACHINE_CONFIG_FILENAME,\n\t\t\t\t{ startDir: this.cwd },\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tthrow new Error(\n\t\t\t\t`Could not find a ${SLICE_MACHINE_CONFIG_FILENAME} file. Please create a config file at the root of your project.`,\n\t\t\t);\n\t\t}\n\n\t\treturn this._cachedSliceMachineConfigPath;\n\t}\n\n\tasync getRoot(args?: ProjectManagerGetRootArgs): Promise<string> {\n\t\tif (this._cachedRoot && !args?.ignoreCache) {\n\t\t\treturn this._cachedRoot;\n\t\t}\n\n\t\tconst sliceMachineConfigFilePath = await this.getSliceMachineConfigPath({\n\t\t\tignoreCache: args?.ignoreCache,\n\t\t});\n\n\t\tthis._cachedRoot = path.dirname(sliceMachineConfigFilePath);\n\n\t\treturn this._cachedRoot;\n\t}\n\n\tasync suggestRoot(): Promise<string> {\n\t\tconst suggestedRootPackageJSON = await locateFileUpward(\"package.json\", {\n\t\t\tstartDir: this.cwd,\n\t\t});\n\n\t\treturn path.dirname(suggestedRootPackageJSON);\n\t}\n\n\tasync suggestSliceMachineConfigPath(): Promise<string> {\n\t\tconst suggestedRoot = await this.suggestRoot();\n\n\t\treturn path.resolve(suggestedRoot, SLICE_MACHINE_CONFIG_FILENAME);\n\t}\n\n\tasync checkIsTypeScript(\n\t\targs?: ProjectManagerCheckIsTypeScriptArgs,\n\t): Promise<boolean> {\n\t\tconst root = args?.rootOverride || (await this.getRoot());\n\t\tconst rootTSConfigPath = path.resolve(root, TS_CONFIG_FILENAME);\n\n\t\t// We just care if the file exists, we don't need access to it\n\t\treturn existsSync(rootTSConfigPath);\n\t}\n\n\tasync getSliceMachineConfig(): Promise<SliceMachineConfig> {\n\t\tif (this._cachedSliceMachineConfig) {\n\t\t\treturn this._cachedSliceMachineConfig;\n\t\t} else {\n\t\t\treturn await this.loadSliceMachineConfig();\n\t\t}\n\t}\n\n\tasync writeSliceMachineConfig(\n\t\targs: ProjectManagerWriteSliceMachineConfigArgs,\n\t): Promise<void> {\n\t\tconst configFilePath =\n\t\t\targs.path || (await this.getSliceMachineConfigPath());\n\n\t\tconst config = await format(\n\t\t\tJSON.stringify(args.config, null, 2),\n\t\t\tconfigFilePath,\n\t\t);\n\n\t\tawait fs.writeFile(configFilePath, config, \"utf-8\");\n\t\tdelete this._cachedSliceMachineConfig; // Clear config cache\n\t}\n\n\tasync loadSliceMachineConfig(): Promise<SliceMachineConfig> {\n\t\t// TODO: Reload plugins with a fresh plugin runner. Plugins may\n\t\t// have been added or removed.\n\t\tconst configFilePath = await this.getSliceMachineConfigPath();\n\n\t\tlet rawConfig: unknown | undefined;\n\t\ttry {\n\t\t\tconst contents = await fs.readFile(configFilePath, \"utf8\");\n\t\t\trawConfig = JSON.parse(contents);\n\t\t} catch (error) {\n\t\t\tif (error instanceof SyntaxError) {\n\t\t\t\tthrow new SliceMachineError(\n\t\t\t\t\t`Could not parse config file at ${configFilePath}.\\n\\nError Message: ${error.message}`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t// Noop, more specific error is thrown after\n\t\t}\n\n\t\tif (!rawConfig) {\n\t\t\t// TODO: Write a more friendly and useful message.\n\t\t\tthrow new Error(\"No config found.\");\n\t\t}\n\n\t\tconst { value: sliceMachineConfig, error } =\n\t\t\tdecodeSliceMachineConfig(rawConfig);\n\n\t\tif (error) {\n\t\t\t// TODO: Write a more friendly and useful message.\n\t\t\tthrow new Error(`Invalid config. ${error.errors.join(\", \")}`, {\n\t\t\t\tcause: { rawConfig },\n\t\t\t});\n\t\t}\n\n\t\t// Allow cached config reading using `SliceMachineManager.prototype.getProjectConfig()`.\n\t\tthis._cachedSliceMachineConfig = sliceMachineConfig;\n\n\t\treturn sliceMachineConfig;\n\t}\n\n\tasync locateSliceMachineUIDir(): Promise<string> {\n\t\tconst projectRoot = await this.getRoot();\n\n\t\tconst require = createRequire(path.join(projectRoot, \"index.js\"));\n\t\tconst sliceMachinePackageJSONPath = require.resolve(\n\t\t\t`${SLICE_MACHINE_NPM_PACKAGE_NAME}/package.json`,\n\t\t);\n\n\t\treturn path.dirname(sliceMachinePackageJSONPath);\n\t}\n\n\tasync getRepositoryName(): Promise<string> {\n\t\tconst sliceMachineConfig = await this.getSliceMachineConfig();\n\n\t\treturn sliceMachineConfig.repositoryName;\n\t}\n\n\tasync getAdapterName(): Promise<string> {\n\t\tconst sliceMachineConfig = await this.getSliceMachineConfig();\n\t\tconst adapterName =\n\t\t\ttypeof sliceMachineConfig.adapter === \"string\"\n\t\t\t\t? sliceMachineConfig.adapter\n\t\t\t\t: sliceMachineConfig.adapter.resolve;\n\n\t\treturn adapterName;\n\t}\n\n\tasync locateAdapterDir(): Promise<string> {\n\t\tconst projectRoot = await this.getRoot();\n\t\tconst adapterName = await this.getAdapterName();\n\t\tconst require = createRequire(path.join(projectRoot, \"index.js\"));\n\t\tconst adapterPackageJSONPath = require.resolve(\n\t\t\t`${adapterName}/package.json`,\n\t\t);\n\n\t\treturn path.dirname(adapterPackageJSONPath);\n\t}\n\n\tasync initProject(args?: ProjectManagerInitProjectArgs): Promise<void> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\t// eslint-disable-next-line no-console\n\t\tconst log = args?.log || console.log.bind(this);\n\n\t\tconst { errors } = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"project:init\",\n\t\t\t{\n\t\t\t\tlog,\n\t\t\t\tinstallDependencies: async (args) => {\n\t\t\t\t\tconst { execaProcess } = await this.installDependencies({\n\t\t\t\t\t\tdependencies: args.dependencies,\n\t\t\t\t\t\tdev: args.dev,\n\t\t\t\t\t\tlog,\n\t\t\t\t\t});\n\n\t\t\t\t\tawait execaProcess;\n\t\t\t\t},\n\t\t\t},\n\t\t);\n\n\t\tif (errors.length > 0) {\n\t\t\t// TODO: Provide better error message.\n\t\t\tthrow new SliceMachineError(\n\t\t\t\t`Failed to initialize project: ${errors.join(\", \")}`,\n\t\t\t);\n\t\t}\n\t}\n\n\tasync detectPackageManager(\n\t\targs?: ProjectManagerDetectPackageManager,\n\t): Promise<PackageManager> {\n\t\tconst projectRoot = args?.root || (await this.getRoot());\n\n\t\tconst packageManager = await niDetect({\n\t\t\tautoInstall: true,\n\t\t\tcwd: projectRoot,\n\t\t});\n\n\t\treturn packageManager || \"npm\";\n\t}\n\n\tasync installDependencies(\n\t\targs: ProjectManagerInstallDependenciesArgs,\n\t): Promise<ProjectManagerInstallDependenciesReturnType> {\n\t\tconst packageManager =\n\t\t\targs.packageManager || (await this.detectPackageManager());\n\n\t\t// eslint-disable-next-line no-console\n\t\tconst log = args.log || console.log.bind(this);\n\n\t\tconst wrappedLogger = (data: Buffer | string | null) => {\n\t\t\tif (data instanceof Buffer) {\n\t\t\t\tlog(data.toString());\n\t\t\t} else if (typeof data === \"string\") {\n\t\t\t\tlog(data);\n\t\t\t}\n\t\t};\n\n\t\ttry {\n\t\t\tconst { execaProcess } = await installDependencies({\n\t\t\t\tpackageManager,\n\t\t\t\tdependencies: args.dependencies,\n\t\t\t\tdev: args.dev,\n\t\t\t});\n\n\t\t\t// Don't clutter console with logs when process is non TTY (CI, etc.)\n\t\t\tif (process.stdout.isTTY || process.env.NODE_ENV === \"test\") {\n\t\t\t\texecaProcess.stdout?.on(\"data\", wrappedLogger);\n\t\t\t}\n\t\t\texecaProcess.stderr?.on(\"data\", wrappedLogger);\n\n\t\t\treturn {\n\t\t\t\texecaProcess,\n\t\t\t};\n\t\t} catch (error) {\n\t\t\tif (\n\t\t\t\terror instanceof Error &&\n\t\t\t\t\"shortMessage\" in error &&\n\t\t\t\t\"stderr\" in error\n\t\t\t) {\n\t\t\t\tthrow new InternalError(\"Package installation failed\", {\n\t\t\t\t\tcause: error,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tthrow error;\n\t\t}\n\t}\n}\n"],"names":["error","require","args","niDetect"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA2DM,MAAO,uBAAuB,YAAW;AAAA,EAAzC;AAAA;AACG;AACA;AACA;AAAA;AAAA,EAER,MAAM,0BACL,MAAkD;AAElD,QAAI,KAAK,iCAAiC,EAAC,6BAAM,cAAa;AAC7D,aAAO,KAAK;AAAA,IACZ;AAEG,QAAA;AACE,WAAA,gCAAgC,MAAM,iBAC1C,+BACA,EAAE,UAAU,KAAK,KAAK;AAAA,aAEf;AACF,YAAA,IAAI,MACT,oBAAoB,8FAA8F;AAAA,IAEnH;AAED,WAAO,KAAK;AAAA,EACb;AAAA,EAEA,MAAM,QAAQ,MAAgC;AAC7C,QAAI,KAAK,eAAe,EAAC,6BAAM,cAAa;AAC3C,aAAO,KAAK;AAAA,IACZ;AAEK,UAAA,6BAA6B,MAAM,KAAK,0BAA0B;AAAA,MACvE,aAAa,6BAAM;AAAA,IAAA,CACnB;AAEI,SAAA,cAAc,KAAK,QAAQ,0BAA0B;AAE1D,WAAO,KAAK;AAAA,EACb;AAAA,EAEA,MAAM,cAAW;AACV,UAAA,2BAA2B,MAAM,iBAAiB,gBAAgB;AAAA,MACvE,UAAU,KAAK;AAAA,IAAA,CACf;AAEM,WAAA,KAAK,QAAQ,wBAAwB;AAAA,EAC7C;AAAA,EAEA,MAAM,gCAA6B;AAC5B,UAAA,gBAAgB,MAAM,KAAK;AAE1B,WAAA,KAAK,QAAQ,eAAe,6BAA6B;AAAA,EACjE;AAAA,EAEA,MAAM,kBACL,MAA0C;AAE1C,UAAM,QAAO,6BAAM,iBAAiB,MAAM,KAAK,QAAO;AACtD,UAAM,mBAAmB,KAAK,QAAQ,MAAM,kBAAkB;A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M,iBACL,KAAK,kBAAmB,MAAM,KAAK,qBAAoB;AAGxD,UAAM,MAAM,KAAK,OAAO,QAAQ,IAAI,KAAK,IAAI;AAEvC,UAAA,gBAAgB,CAAC,SAAgC;AACtD,UAAI,gBAAgB,QAAQ;AACvB,YAAA,KAAK,UAAU;AAAA,MAAA,WACT,OAAO,SAAS,UAAU;AACpC,YAAI,IAAI;AAAA,MACR;AAAA,IAAA;AAGE,QAAA;AACH,YAAM,EAAE,iBAAiB,MAAM,oBAAoB;AAAA,QAClD;AAAA,QACA,cAAc,KAAK;AAAA,QACnB,KAAK,KAAK;AAAA,MAAA,CACV;AAGD,UAAI,QAAQ,OAAO,SAAS,QAAQ,IAAI,aAAa,QAAQ;AAC/C,2BAAA,WAAA,mBAAQ,GAAG,QAAQ;AAAA,MAChC;AACY,yBAAA,WAAA,mBAAQ,GAAG,QAAQ;AAEzB,aAAA;AAAA,QACN;AAAA,MAAA;AAAA,aAEO;AACR,UACC,iBAAiB,SACjB,kBAAkB,SAClB,YAAY,OACX;AACK,cAAA,IAAI,cAAc,+BAA+B;AAAA,UACtD,OAAO;AAAA,QAAA,CACP;AAAA,MACD;AAEK,YAAA;AAAA,IACN;AAAA,EACF;AACA;"}
|
|
1
|
+
{"version":3,"file":"ProjectManager.js","sources":["../../../../src/managers/project/ProjectManager.ts"],"sourcesContent":["import * as fs from \"node:fs/promises\";\nimport { existsSync } from \"node:fs\";\nimport * as path from \"node:path\";\nimport { createRequire } from \"node:module\";\nimport { detect as niDetect } from \"@antfu/ni\";\nimport { ExecaChildProcess } from \"execa\";\nimport {\n\tHookError,\n\tCallHookReturnType,\n\tProjectEnvironmentUpdateHook,\n} from \"@slicemachine/plugin-kit\";\nimport * as t from \"io-ts\";\n\nimport { DecodeError } from \"../../lib/DecodeError\";\nimport { assertPluginsInitialized } from \"../../lib/assertPluginsInitialized\";\nimport { decodeHookResult } from \"../../lib/decodeHookResult\";\nimport { decodeSliceMachineConfig } from \"../../lib/decodeSliceMachineConfig\";\nimport { format } from \"../../lib/format\";\nimport { installDependencies } from \"../../lib/installDependencies\";\nimport { locateFileUpward } from \"../../lib/locateFileUpward\";\n\nimport {\n\tPackageManager,\n\tSliceMachineConfig,\n\tOnlyHookErrors,\n} from \"../../types\";\n\nimport { SliceMachineError, InternalError, PluginError } from \"../../errors\";\n\nimport { SLICE_MACHINE_CONFIG_FILENAME } from \"../../constants/SLICE_MACHINE_CONFIG_FILENAME\";\nimport { TS_CONFIG_FILENAME } from \"../../constants/TS_CONFIG_FILENAME\";\nimport { SLICE_MACHINE_NPM_PACKAGE_NAME } from \"../../constants/SLICE_MACHINE_NPM_PACKAGE_NAME\";\n\nimport { BaseManager } from \"../BaseManager\";\n\ntype ProjectManagerGetSliceMachineConfigPathArgs = {\n\tignoreCache?: boolean;\n};\n\ntype ProjectManagerGetRootArgs = {\n\tignoreCache?: boolean;\n};\n\ntype ProjectManagerCheckIsTypeScriptArgs = {\n\trootOverride?: string;\n};\n\ntype ProjectManagerWriteSliceMachineConfigArgs = {\n\tconfig: SliceMachineConfig;\n\tpath?: string;\n};\n\ntype ProjectManagerInitProjectArgs = {\n\tlog?: (message: string) => void;\n};\n\ntype ProjectManagerDetectPackageManager = {\n\troot?: string;\n};\n\ntype ProjectManagerInstallDependenciesArgs = {\n\tdependencies: Record<string, string>;\n\tdev?: boolean;\n\tpackageManager?: PackageManager;\n\tlog?: (message: string) => void;\n};\n\ntype ProjectManagerInstallDependenciesReturnType = {\n\texecaProcess: ExecaChildProcess;\n};\n\ntype ProjectManagerReadEnvironmentReturnType = {\n\tenvironment: string | undefined;\n\terrors: (DecodeError | HookError)[];\n};\n\ntype ProjectManagerUpdateEnvironmentArgs = {\n\tenvironment: string | undefined;\n};\n\nexport class ProjectManager extends BaseManager {\n\tprivate _cachedRoot: string | undefined;\n\tprivate _cachedSliceMachineConfigPath: string | undefined;\n\tprivate _cachedSliceMachineConfig: SliceMachineConfig | undefined;\n\n\tasync getSliceMachineConfigPath(\n\t\targs?: ProjectManagerGetSliceMachineConfigPathArgs,\n\t): Promise<string> {\n\t\tif (this._cachedSliceMachineConfigPath && !args?.ignoreCache) {\n\t\t\treturn this._cachedSliceMachineConfigPath;\n\t\t}\n\n\t\ttry {\n\t\t\tthis._cachedSliceMachineConfigPath = await locateFileUpward(\n\t\t\t\tSLICE_MACHINE_CONFIG_FILENAME,\n\t\t\t\t{ startDir: this.cwd },\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tthrow new Error(\n\t\t\t\t`Could not find a ${SLICE_MACHINE_CONFIG_FILENAME} file. Please create a config file at the root of your project.`,\n\t\t\t);\n\t\t}\n\n\t\treturn this._cachedSliceMachineConfigPath;\n\t}\n\n\tasync getRoot(args?: ProjectManagerGetRootArgs): Promise<string> {\n\t\tif (this._cachedRoot && !args?.ignoreCache) {\n\t\t\treturn this._cachedRoot;\n\t\t}\n\n\t\tconst sliceMachineConfigFilePath = await this.getSliceMachineConfigPath({\n\t\t\tignoreCache: args?.ignoreCache,\n\t\t});\n\n\t\tthis._cachedRoot = path.dirname(sliceMachineConfigFilePath);\n\n\t\treturn this._cachedRoot;\n\t}\n\n\tasync suggestRoot(): Promise<string> {\n\t\tconst suggestedRootPackageJSON = await locateFileUpward(\"package.json\", {\n\t\t\tstartDir: this.cwd,\n\t\t});\n\n\t\treturn path.dirname(suggestedRootPackageJSON);\n\t}\n\n\tasync suggestSliceMachineConfigPath(): Promise<string> {\n\t\tconst suggestedRoot = await this.suggestRoot();\n\n\t\treturn path.resolve(suggestedRoot, SLICE_MACHINE_CONFIG_FILENAME);\n\t}\n\n\tasync checkIsTypeScript(\n\t\targs?: ProjectManagerCheckIsTypeScriptArgs,\n\t): Promise<boolean> {\n\t\tconst root = args?.rootOverride || (await this.getRoot());\n\t\tconst rootTSConfigPath = path.resolve(root, TS_CONFIG_FILENAME);\n\n\t\t// We just care if the file exists, we don't need access to it\n\t\treturn existsSync(rootTSConfigPath);\n\t}\n\n\tasync getSliceMachineConfig(): Promise<SliceMachineConfig> {\n\t\tif (this._cachedSliceMachineConfig) {\n\t\t\treturn this._cachedSliceMachineConfig;\n\t\t} else {\n\t\t\treturn await this.loadSliceMachineConfig();\n\t\t}\n\t}\n\n\tasync writeSliceMachineConfig(\n\t\targs: ProjectManagerWriteSliceMachineConfigArgs,\n\t): Promise<void> {\n\t\tconst configFilePath =\n\t\t\targs.path || (await this.getSliceMachineConfigPath());\n\n\t\tconst config = await format(\n\t\t\tJSON.stringify(args.config, null, 2),\n\t\t\tconfigFilePath,\n\t\t);\n\n\t\tawait fs.writeFile(configFilePath, config, \"utf-8\");\n\t\tdelete this._cachedSliceMachineConfig; // Clear config cache\n\t}\n\n\tasync loadSliceMachineConfig(): Promise<SliceMachineConfig> {\n\t\t// TODO: Reload plugins with a fresh plugin runner. Plugins may\n\t\t// have been added or removed.\n\t\tconst configFilePath = await this.getSliceMachineConfigPath();\n\n\t\tlet rawConfig: unknown | undefined;\n\t\ttry {\n\t\t\tconst contents = await fs.readFile(configFilePath, \"utf8\");\n\t\t\trawConfig = JSON.parse(contents);\n\t\t} catch (error) {\n\t\t\tif (error instanceof SyntaxError) {\n\t\t\t\tthrow new SliceMachineError(\n\t\t\t\t\t`Could not parse config file at ${configFilePath}.\\n\\nError Message: ${error.message}`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t// Noop, more specific error is thrown after\n\t\t}\n\n\t\tif (!rawConfig) {\n\t\t\t// TODO: Write a more friendly and useful message.\n\t\t\tthrow new Error(\"No config found.\");\n\t\t}\n\n\t\tconst { value: sliceMachineConfig, error } =\n\t\t\tdecodeSliceMachineConfig(rawConfig);\n\n\t\tif (error) {\n\t\t\t// TODO: Write a more friendly and useful message.\n\t\t\tthrow new Error(`Invalid config. ${error.errors.join(\", \")}`, {\n\t\t\t\tcause: { rawConfig },\n\t\t\t});\n\t\t}\n\n\t\t// Allow cached config reading using `SliceMachineManager.prototype.getProjectConfig()`.\n\t\tthis._cachedSliceMachineConfig = sliceMachineConfig;\n\n\t\treturn sliceMachineConfig;\n\t}\n\n\tasync locateSliceMachineUIDir(): Promise<string> {\n\t\tconst projectRoot = await this.getRoot();\n\n\t\tconst require = createRequire(path.join(projectRoot, \"index.js\"));\n\t\tconst sliceMachinePackageJSONPath = require.resolve(\n\t\t\t`${SLICE_MACHINE_NPM_PACKAGE_NAME}/package.json`,\n\t\t);\n\n\t\treturn path.dirname(sliceMachinePackageJSONPath);\n\t}\n\n\t/**\n\t * Returns the project's repository name (i.e. the production environment). It\n\t * ignores the currently selected environment.\n\t *\n\t * Use this method to retrieve the production environment domain.\n\t *\n\t * @returns The project's repository name.\n\t */\n\tasync getRepositoryName(): Promise<string> {\n\t\tconst sliceMachineConfig = await this.getSliceMachineConfig();\n\n\t\treturn sliceMachineConfig.repositoryName;\n\t}\n\n\t/**\n\t * Returns the currently selected environment domain if set. If an environment\n\t * is not set, it returns the project's repository name (the production\n\t * environment).\n\t *\n\t * Use this method to retrieve the repository name to be sent with Prismic API\n\t * requests.\n\t *\n\t * @returns The resolved repository name.\n\t */\n\tasync getResolvedRepositoryName(): Promise<string> {\n\t\tconst repositoryName = await this.getRepositoryName();\n\n\t\tconst supportsEnvironments = this.project.checkSupportsEnvironments();\n\t\tif (!supportsEnvironments) {\n\t\t\treturn repositoryName;\n\t\t}\n\n\t\tconst { environment } = await this.project.readEnvironment();\n\n\t\treturn environment ?? repositoryName;\n\t}\n\n\tasync getAdapterName(): Promise<string> {\n\t\tconst sliceMachineConfig = await this.getSliceMachineConfig();\n\t\tconst adapterName =\n\t\t\ttypeof sliceMachineConfig.adapter === \"string\"\n\t\t\t\t? sliceMachineConfig.adapter\n\t\t\t\t: sliceMachineConfig.adapter.resolve;\n\n\t\treturn adapterName;\n\t}\n\n\tasync locateAdapterDir(): Promise<string> {\n\t\tconst projectRoot = await this.getRoot();\n\t\tconst adapterName = await this.getAdapterName();\n\t\tconst require = createRequire(path.join(projectRoot, \"index.js\"));\n\t\tconst adapterPackageJSONPath = require.resolve(\n\t\t\t`${adapterName}/package.json`,\n\t\t);\n\n\t\treturn path.dirname(adapterPackageJSONPath);\n\t}\n\n\tasync initProject(args?: ProjectManagerInitProjectArgs): Promise<void> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\t// eslint-disable-next-line no-console\n\t\tconst log = args?.log || console.log.bind(this);\n\n\t\tconst { errors } = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"project:init\",\n\t\t\t{\n\t\t\t\tlog,\n\t\t\t\tinstallDependencies: async (args) => {\n\t\t\t\t\tconst { execaProcess } = await this.installDependencies({\n\t\t\t\t\t\tdependencies: args.dependencies,\n\t\t\t\t\t\tdev: args.dev,\n\t\t\t\t\t\tlog,\n\t\t\t\t\t});\n\n\t\t\t\t\tawait execaProcess;\n\t\t\t\t},\n\t\t\t},\n\t\t);\n\n\t\tif (errors.length > 0) {\n\t\t\t// TODO: Provide better error message.\n\t\t\tthrow new SliceMachineError(\n\t\t\t\t`Failed to initialize project: ${errors.join(\", \")}`,\n\t\t\t);\n\t\t}\n\t}\n\n\tasync detectPackageManager(\n\t\targs?: ProjectManagerDetectPackageManager,\n\t): Promise<PackageManager> {\n\t\tconst projectRoot = args?.root || (await this.getRoot());\n\n\t\tconst packageManager = await niDetect({\n\t\t\tautoInstall: true,\n\t\t\tcwd: projectRoot,\n\t\t});\n\n\t\treturn packageManager || \"npm\";\n\t}\n\n\tasync installDependencies(\n\t\targs: ProjectManagerInstallDependenciesArgs,\n\t): Promise<ProjectManagerInstallDependenciesReturnType> {\n\t\tconst packageManager =\n\t\t\targs.packageManager || (await this.detectPackageManager());\n\n\t\t// eslint-disable-next-line no-console\n\t\tconst log = args.log || console.log.bind(this);\n\n\t\tconst wrappedLogger = (data: Buffer | string | null) => {\n\t\t\tif (data instanceof Buffer) {\n\t\t\t\tlog(data.toString());\n\t\t\t} else if (typeof data === \"string\") {\n\t\t\t\tlog(data);\n\t\t\t}\n\t\t};\n\n\t\ttry {\n\t\t\tconst { execaProcess } = await installDependencies({\n\t\t\t\tpackageManager,\n\t\t\t\tdependencies: args.dependencies,\n\t\t\t\tdev: args.dev,\n\t\t\t});\n\n\t\t\t// Don't clutter console with logs when process is non TTY (CI, etc.)\n\t\t\tif (process.stdout.isTTY || process.env.NODE_ENV === \"test\") {\n\t\t\t\texecaProcess.stdout?.on(\"data\", wrappedLogger);\n\t\t\t}\n\t\t\texecaProcess.stderr?.on(\"data\", wrappedLogger);\n\n\t\t\treturn {\n\t\t\t\texecaProcess,\n\t\t\t};\n\t\t} catch (error) {\n\t\t\tif (\n\t\t\t\terror instanceof Error &&\n\t\t\t\t\"shortMessage\" in error &&\n\t\t\t\t\"stderr\" in error\n\t\t\t) {\n\t\t\t\tthrow new InternalError(\"Package installation failed\", {\n\t\t\t\t\tcause: error,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\tcheckSupportsEnvironments(): boolean {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\treturn (\n\t\t\tthis.sliceMachinePluginRunner.hooksForType(\"project:environment:read\")\n\t\t\t\t.length > 0 &&\n\t\t\tthis.sliceMachinePluginRunner.hooksForType(\"project:environment:update\")\n\t\t\t\t.length > 0\n\t\t);\n\t}\n\n\tasync readEnvironment(): Promise<ProjectManagerReadEnvironmentReturnType> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tawait this._assertAdapterSupportsEnvironments();\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"project:environment:read\",\n\t\t\tundefined,\n\t\t);\n\t\tconst { data, errors } = decodeHookResult(\n\t\t\tt.type({\n\t\t\t\tenvironment: t.union([t.undefined, t.string]),\n\t\t\t}),\n\t\t\thookResult,\n\t\t);\n\n\t\t// An undefined value is equivalent to the production environment.\n\t\t// We cast to undefined.\n\t\tconst repositoryName = await this.project.getRepositoryName();\n\t\tconst environmentDomain =\n\t\t\tdata[0]?.environment === repositoryName\n\t\t\t\t? undefined\n\t\t\t\t: data[0]?.environment;\n\n\t\treturn {\n\t\t\tenvironment: environmentDomain,\n\t\t\terrors,\n\t\t};\n\t}\n\n\tasync updateEnvironment(\n\t\targs: ProjectManagerUpdateEnvironmentArgs,\n\t): Promise<OnlyHookErrors<CallHookReturnType<ProjectEnvironmentUpdateHook>>> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tawait this._assertAdapterSupportsEnvironments();\n\n\t\tconst repositoryName = await this.project.getRepositoryName();\n\t\tconst environment =\n\t\t\targs.environment === repositoryName ? undefined : args.environment;\n\n\t\tconst hookResult = await this.sliceMachinePluginRunner.callHook(\n\t\t\t\"project:environment:update\",\n\t\t\t{ environment },\n\t\t);\n\n\t\treturn {\n\t\t\terrors: hookResult.errors,\n\t\t};\n\t}\n\n\tprivate async _assertAdapterSupportsEnvironments(): Promise<void> {\n\t\tassertPluginsInitialized(this.sliceMachinePluginRunner);\n\n\t\tconst supportsEnvironments = this.checkSupportsEnvironments();\n\n\t\tif (!supportsEnvironments) {\n\t\t\tconst adapterName = await this.project.getAdapterName();\n\n\t\t\tthrow new PluginError(\n\t\t\t\t`${adapterName} does not support environments. Use an adapter that implements the \\`project:environment:read\\` and \\`project:environment:update\\` hooks to use environments.`,\n\t\t\t);\n\t\t}\n\t}\n}\n"],"names":["error","require","args","niDetect"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAgFM,MAAO,uBAAuB,YAAW;AAAA,EAAzC;AAAA;AACG;AACA;AACA;AAAA;AAAA,EAER,MAAM,0BACL,MAAkD;AAElD,QAAI,KAAK,iCAAiC,EAAC,6BAAM,cAAa;AAC7D,aAAO,KAAK;AAAA,IACZ;AAEG,QAAA;AACE,WAAA,gCAAgC,MAAM,iBAC1C,+BACA,EAAE,UAAU,KAAK,KAAK;AAAA,aAEf;AACF,YAAA,IAAI,MACT,oBAAoB,8FAA8F;AAAA,IAEnH;AAED,WAAO,KAAK;AAAA,EACb;AAAA,EAEA,MAAM,QAAQ,MAAgC;AAC7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KAAK,QAAQ,kBAAiB;AAC3D,UAAM,cACL,KAAK,gBAAgB,iBAAiB,SAAY,KAAK;AAElD,UAAA,aAAa,MAAM,KAAK,yBAAyB,SACtD,8BACA,EAAE,aAAa;AAGT,WAAA;AAAA,MACN,QAAQ,WAAW;AAAA,IAAA;AAAA,EAErB;AAAA,EAEQ,MAAM,qCAAkC;AAC/C,6BAAyB,KAAK,wBAAwB;AAEhD,UAAA,uBAAuB,KAAK;AAElC,QAAI,CAAC,sBAAsB;AAC1B,YAAM,cAAc,MAAM,KAAK,QAAQ,eAAc;AAE/C,YAAA,IAAI,YACT,GAAG,0KAA0K;AAAA,IAE9K;AAAA,EACF;AACA;"}
|
|
@@ -147,12 +147,12 @@ class ScreenshotsManager extends BaseManager.BaseManager {
|
|
|
147
147
|
}
|
|
148
148
|
async _fetch(args) {
|
|
149
149
|
const authenticationToken = await this.user.getAuthenticationToken();
|
|
150
|
-
const
|
|
150
|
+
const repositoryName = await this.project.getRepositoryName();
|
|
151
151
|
return await fetch.default(args.url, {
|
|
152
152
|
body: args.body ? JSON.stringify(args.body) : void 0,
|
|
153
153
|
headers: {
|
|
154
154
|
Authorization: `Bearer ${authenticationToken}`,
|
|
155
|
-
Repository:
|
|
155
|
+
Repository: repositoryName,
|
|
156
156
|
"User-Agent": SLICE_MACHINE_USER_AGENT.SLICE_MACHINE_USER_AGENT,
|
|
157
157
|
...args.body ? { "Content-Type": "application/json" } : {}
|
|
158
158
|
},
|