@slicemachine/manager 0.25.2-beta.9 → 0.25.3-alpha.dani-mcp.1
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/_node_modules/@amplitude/experiment-node-server/dist/src/local/client.cjs +1 -1
- package/dist/_node_modules/@amplitude/experiment-node-server/dist/src/local/client.js +1 -1
- package/dist/_node_modules/cross-spawn/index.cjs +1 -1
- package/dist/_node_modules/cross-spawn/index.js +1 -1
- package/dist/_node_modules/execa/index.cjs +8 -70
- package/dist/_node_modules/execa/index.cjs.map +1 -1
- package/dist/_node_modules/execa/index.js +2 -64
- package/dist/_node_modules/execa/index.js.map +1 -1
- package/dist/_node_modules/execa/lib/stream.cjs +0 -15
- package/dist/_node_modules/execa/lib/stream.cjs.map +1 -1
- package/dist/_node_modules/execa/lib/stream.js +1 -16
- package/dist/_node_modules/execa/lib/stream.js.map +1 -1
- package/dist/_virtual/index2.cjs +4 -3
- package/dist/_virtual/index2.cjs.map +1 -1
- package/dist/_virtual/index2.js +4 -2
- package/dist/_virtual/index2.js.map +1 -1
- package/dist/_virtual/index3.cjs +3 -4
- package/dist/_virtual/index3.cjs.map +1 -1
- package/dist/_virtual/index3.js +2 -4
- package/dist/_virtual/index3.js.map +1 -1
- package/dist/client/index.d.ts +0 -1
- package/dist/client.cjs +0 -2
- package/dist/client.cjs.map +1 -1
- package/dist/client.js +0 -2
- package/dist/client.js.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/managers/SliceMachineManager.cjs +0 -3
- package/dist/managers/SliceMachineManager.cjs.map +1 -1
- package/dist/managers/SliceMachineManager.d.ts +0 -2
- package/dist/managers/SliceMachineManager.js +0 -3
- package/dist/managers/SliceMachineManager.js.map +1 -1
- package/dist/managers/prismicRepository/PrismicRepositoryManager.cjs +2 -0
- package/dist/managers/prismicRepository/PrismicRepositoryManager.cjs.map +1 -1
- package/dist/managers/prismicRepository/PrismicRepositoryManager.js +2 -0
- package/dist/managers/prismicRepository/PrismicRepositoryManager.js.map +1 -1
- package/dist/managers/prismicRepository/types.cjs.map +1 -1
- package/dist/managers/prismicRepository/types.d.ts +7 -0
- package/dist/managers/prismicRepository/types.js.map +1 -1
- package/dist/managers/project/ProjectManager.cjs +6 -3
- package/dist/managers/project/ProjectManager.cjs.map +1 -1
- package/dist/managers/project/ProjectManager.d.ts +5 -0
- package/dist/managers/project/ProjectManager.js +6 -3
- package/dist/managers/project/ProjectManager.js.map +1 -1
- package/dist/managers/slices/SlicesManager.cjs +11 -3
- package/dist/managers/slices/SlicesManager.cjs.map +1 -1
- package/dist/managers/slices/SlicesManager.d.ts +9 -2
- package/dist/managers/slices/SlicesManager.js +11 -3
- package/dist/managers/slices/SlicesManager.js.map +1 -1
- package/dist/managers/telemetry/TelemetryManager.cjs +6 -2
- package/dist/managers/telemetry/TelemetryManager.cjs.map +1 -1
- package/dist/managers/telemetry/TelemetryManager.js +6 -2
- package/dist/managers/telemetry/TelemetryManager.js.map +1 -1
- package/dist/managers/telemetry/types.cjs +4 -2
- package/dist/managers/telemetry/types.cjs.map +1 -1
- package/dist/managers/telemetry/types.d.ts +7 -2
- package/dist/managers/telemetry/types.js +4 -2
- package/dist/managers/telemetry/types.js.map +1 -1
- package/package.json +3 -3
- package/src/client/index.ts +0 -2
- package/src/index.ts +0 -2
- package/src/managers/SliceMachineManager.ts +0 -4
- package/src/managers/prismicRepository/PrismicRepositoryManager.ts +2 -0
- package/src/managers/prismicRepository/types.ts +7 -0
- package/src/managers/project/ProjectManager.ts +9 -6
- package/src/managers/slices/SlicesManager.ts +22 -6
- package/src/managers/telemetry/TelemetryManager.ts +7 -2
- package/src/managers/telemetry/types.ts +12 -2
- package/dist/constants/GIT_PROVIDER.cjs +0 -7
- package/dist/constants/GIT_PROVIDER.cjs.map +0 -1
- package/dist/constants/GIT_PROVIDER.d.ts +0 -4
- package/dist/constants/GIT_PROVIDER.js +0 -7
- package/dist/constants/GIT_PROVIDER.js.map +0 -1
- package/dist/constants/GIT_PROVIDER_APP_SLUGS.cjs +0 -26
- package/dist/constants/GIT_PROVIDER_APP_SLUGS.cjs.map +0 -1
- package/dist/constants/GIT_PROVIDER_APP_SLUGS.d.ts +0 -3
- package/dist/constants/GIT_PROVIDER_APP_SLUGS.js +0 -26
- package/dist/constants/GIT_PROVIDER_APP_SLUGS.js.map +0 -1
- package/dist/managers/git/GitManager.cjs +0 -334
- package/dist/managers/git/GitManager.cjs.map +0 -1
- package/dist/managers/git/GitManager.d.ts +0 -89
- package/dist/managers/git/GitManager.js +0 -316
- package/dist/managers/git/GitManager.js.map +0 -1
- package/dist/managers/git/buildGitRepoSpecifier.cjs +0 -7
- package/dist/managers/git/buildGitRepoSpecifier.cjs.map +0 -1
- package/dist/managers/git/buildGitRepoSpecifier.d.ts +0 -19
- package/dist/managers/git/buildGitRepoSpecifier.js +0 -7
- package/dist/managers/git/buildGitRepoSpecifier.js.map +0 -1
- package/dist/managers/git/types.d.ts +0 -20
- package/src/constants/GIT_PROVIDER.ts +0 -5
- package/src/constants/GIT_PROVIDER_APP_SLUGS.ts +0 -28
- package/src/managers/git/GitManager.ts +0 -502
- package/src/managers/git/buildGitRepoSpecifier.ts +0 -24
- package/src/managers/git/types.ts +0 -26
|
@@ -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\";\nimport { z } from \"zod\";\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 PushBody {\n\tconfirmDeleteDocuments: boolean;\n\tchanges: AllChangeTypes[];\n}\n\nexport const PushChangesRawLimit = 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 PushChangesRawLimit = t.TypeOf<typeof PushChangesRawLimit>;\nexport enum PushChangesLimitType {\n\tSOFT = \"SOFT\",\n\tHARD = \"HARD\",\n}\nexport type PushChangesLimit = PushChangesRawLimit & {\n\ttype: PushChangesLimitType;\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 = PushChangesLimit | 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\nexport const supportedSliceMachineFrameworks = [\n\t\"next\",\n\t\"nuxt\",\n\t\"sveltekit\",\n] as const;\n\ntype SupportedFramework = (typeof supportedSliceMachineFrameworks)[number];\n\nfunction isSupportedFramework(value: string): value is SupportedFramework {\n\treturn supportedSliceMachineFrameworks.includes(value as SupportedFramework);\n}\n\nexport const repositoryFramework = z.preprocess(\n\t(value) => {\n\t\t// NOTE: we persist a lot of different frameworks in the DB, but only the SM supported are relevant to us\n\t\t// Any other framework is treated like \"other\"\n\t\tif (typeof value === \"string\" && isSupportedFramework(value)) {\n\t\t\treturn value;\n\t\t}\n\n\t\treturn \"other\";\n\t},\n\tz.enum([...supportedSliceMachineFrameworks, \"other\"]),\n);\n\nexport type RepositoryFramework = z.TypeOf<typeof repositoryFramework>;\n\nexport const OnboardingState = z.object({\n\tcompletedSteps: z.array(z.string()),\n\tisDismissed: z.boolean(),\n\tcontext: z.object({\n\t\tframework: repositoryFramework,\n\t\tstarterId: z.string().nullable(),\n\t}),\n});\nexport type OnboardingState = z.infer<typeof OnboardingState>;\n"],"names":["t","ChangeTypes","PushChangesLimitType","z"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAOO,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,sBAAsBD,aAAE,KAAK;AAAA,EACzC,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,uBAAA;AAAA,CAAZ,SAAYA,uBAAoB;AAC/BA,wBAAA,MAAA,IAAA;AACAA,wBAAA,MAAA,IAAA;AACD,GAHYA,iCAAAA,QAAAA,uBAGX,CAAA,EAAA;
|
|
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\";\nimport { z } from \"zod\";\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 PushBody {\n\tconfirmDeleteDocuments: boolean;\n\tchanges: AllChangeTypes[];\n}\n\nexport const PushChangesRawLimit = 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 PushChangesRawLimit = t.TypeOf<typeof PushChangesRawLimit>;\nexport enum PushChangesLimitType {\n\tSOFT = \"SOFT\",\n\tHARD = \"HARD\",\n}\nexport type PushChangesLimit = PushChangesRawLimit & {\n\ttype: PushChangesLimitType;\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\t/**\n\t * A map of variation IDs to remote screenshot URLs. These URLs are used to\n\t * detect if a screenshot has changed when comparing with local ones and to\n\t * push slices with the current screenshot. If a matching screenshot is not\n\t * found in this map, the current local screenshot is uploaded again.\n\t */\n\tvariationImageUrlMap: Record<string, string>;\n};\n\nexport type TransactionalMergeArgs = {\n\tconfirmDeleteDocuments: boolean;\n\tchanges: (CustomTypeChange | SliceChange)[];\n};\n\nexport type TransactionalMergeReturnType = PushChangesLimit | 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\nexport const supportedSliceMachineFrameworks = [\n\t\"next\",\n\t\"nuxt\",\n\t\"sveltekit\",\n] as const;\n\ntype SupportedFramework = (typeof supportedSliceMachineFrameworks)[number];\n\nfunction isSupportedFramework(value: string): value is SupportedFramework {\n\treturn supportedSliceMachineFrameworks.includes(value as SupportedFramework);\n}\n\nexport const repositoryFramework = z.preprocess(\n\t(value) => {\n\t\t// NOTE: we persist a lot of different frameworks in the DB, but only the SM supported are relevant to us\n\t\t// Any other framework is treated like \"other\"\n\t\tif (typeof value === \"string\" && isSupportedFramework(value)) {\n\t\t\treturn value;\n\t\t}\n\n\t\treturn \"other\";\n\t},\n\tz.enum([...supportedSliceMachineFrameworks, \"other\"]),\n);\n\nexport type RepositoryFramework = z.TypeOf<typeof repositoryFramework>;\n\nexport const OnboardingState = z.object({\n\tcompletedSteps: z.array(z.string()),\n\tisDismissed: z.boolean(),\n\tcontext: z.object({\n\t\tframework: repositoryFramework,\n\t\tstarterId: z.string().nullable(),\n\t}),\n});\nexport type OnboardingState = z.infer<typeof OnboardingState>;\n"],"names":["t","ChangeTypes","PushChangesLimitType","z"],"mappings":";;;;;;;;;;;;;;;;;;;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,MAAMA,aAAE;AAAA,EACR,QAAQA,aAAE;AAAA,EACV,OAAOA,aAAE,MACRA,aAAE,KAAK;AAAA,IACN,IAAIA,aAAE;AAAA,EAAA,CACN,CAAC;AAEH,CAAA;AAGM,MAAM,kCAAkC;AAAA,EAC9C;AAAA,EACA;AAAA,EACA;;AAKD,SAAS,qBAAqB,OAAa;AACnC,SAAA,gCAAgC,SAAS,KAA2B;AAC5E;AAEO,MAAM,sBAAsBG,MAAA,QAAE,WACpC,CAAC,UAAS;AAGT,MAAI,OAAO,UAAU,YAAY,qBAAqB,KAAK,GAAG;AACtD,WAAA;AAAA,EACR;AAEO,SAAA;AACR,GACAA,MAAAA,QAAE,KAAK,CAAC,GAAG,iCAAiC,OAAO,CAAC,CAAC;AAKzC,MAAA,kBAAkBA,cAAE,OAAO;AAAA,EACvC,gBAAgBA,MAAAA,QAAE,MAAMA,MAAA,QAAE,QAAQ;AAAA,EAClC,aAAaA,cAAE,QAAS;AAAA,EACxB,SAASA,cAAE,OAAO;AAAA,IACjB,WAAW;AAAA,IACX,WAAWA,MAAA,QAAE,OAAQ,EAAC,SAAU;AAAA,EAAA,CAChC;AACD,CAAA;;;;;;;;;"}
|
|
@@ -115,6 +115,13 @@ type SliceChange = {
|
|
|
115
115
|
type: "Slice";
|
|
116
116
|
status: ChangeStatus;
|
|
117
117
|
libraryID: string;
|
|
118
|
+
/**
|
|
119
|
+
* A map of variation IDs to remote screenshot URLs. These URLs are used to
|
|
120
|
+
* detect if a screenshot has changed when comparing with local ones and to
|
|
121
|
+
* push slices with the current screenshot. If a matching screenshot is not
|
|
122
|
+
* found in this map, the current local screenshot is uploaded again.
|
|
123
|
+
*/
|
|
124
|
+
variationImageUrlMap: Record<string, string>;
|
|
118
125
|
};
|
|
119
126
|
export type TransactionalMergeArgs = {
|
|
120
127
|
confirmDeleteDocuments: boolean;
|
|
@@ -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\";\nimport { z } from \"zod\";\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 PushBody {\n\tconfirmDeleteDocuments: boolean;\n\tchanges: AllChangeTypes[];\n}\n\nexport const PushChangesRawLimit = 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 PushChangesRawLimit = t.TypeOf<typeof PushChangesRawLimit>;\nexport enum PushChangesLimitType {\n\tSOFT = \"SOFT\",\n\tHARD = \"HARD\",\n}\nexport type PushChangesLimit = PushChangesRawLimit & {\n\ttype: PushChangesLimitType;\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 = PushChangesLimit | 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\nexport const supportedSliceMachineFrameworks = [\n\t\"next\",\n\t\"nuxt\",\n\t\"sveltekit\",\n] as const;\n\ntype SupportedFramework = (typeof supportedSliceMachineFrameworks)[number];\n\nfunction isSupportedFramework(value: string): value is SupportedFramework {\n\treturn supportedSliceMachineFrameworks.includes(value as SupportedFramework);\n}\n\nexport const repositoryFramework = z.preprocess(\n\t(value) => {\n\t\t// NOTE: we persist a lot of different frameworks in the DB, but only the SM supported are relevant to us\n\t\t// Any other framework is treated like \"other\"\n\t\tif (typeof value === \"string\" && isSupportedFramework(value)) {\n\t\t\treturn value;\n\t\t}\n\n\t\treturn \"other\";\n\t},\n\tz.enum([...supportedSliceMachineFrameworks, \"other\"]),\n);\n\nexport type RepositoryFramework = z.TypeOf<typeof repositoryFramework>;\n\nexport const OnboardingState = z.object({\n\tcompletedSteps: z.array(z.string()),\n\tisDismissed: z.boolean(),\n\tcontext: z.object({\n\t\tframework: repositoryFramework,\n\t\tstarterId: z.string().nullable(),\n\t}),\n});\nexport type OnboardingState = z.infer<typeof OnboardingState>;\n"],"names":["ChangeTypes","PushChangesLimitType"],"mappings":";;AAOO,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,sBAAsB,EAAE,KAAK;AAAA,EACzC,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,uBAAoB;AAC/BA,wBAAA,MAAA,IAAA;AACAA,wBAAA,MAAA,IAAA;AACD,GAHY,yBAAA,uBAGX,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\";\nimport { z } from \"zod\";\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 PushBody {\n\tconfirmDeleteDocuments: boolean;\n\tchanges: AllChangeTypes[];\n}\n\nexport const PushChangesRawLimit = 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 PushChangesRawLimit = t.TypeOf<typeof PushChangesRawLimit>;\nexport enum PushChangesLimitType {\n\tSOFT = \"SOFT\",\n\tHARD = \"HARD\",\n}\nexport type PushChangesLimit = PushChangesRawLimit & {\n\ttype: PushChangesLimitType;\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\t/**\n\t * A map of variation IDs to remote screenshot URLs. These URLs are used to\n\t * detect if a screenshot has changed when comparing with local ones and to\n\t * push slices with the current screenshot. If a matching screenshot is not\n\t * found in this map, the current local screenshot is uploaded again.\n\t */\n\tvariationImageUrlMap: Record<string, string>;\n};\n\nexport type TransactionalMergeArgs = {\n\tconfirmDeleteDocuments: boolean;\n\tchanges: (CustomTypeChange | SliceChange)[];\n};\n\nexport type TransactionalMergeReturnType = PushChangesLimit | 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\nexport const supportedSliceMachineFrameworks = [\n\t\"next\",\n\t\"nuxt\",\n\t\"sveltekit\",\n] as const;\n\ntype SupportedFramework = (typeof supportedSliceMachineFrameworks)[number];\n\nfunction isSupportedFramework(value: string): value is SupportedFramework {\n\treturn supportedSliceMachineFrameworks.includes(value as SupportedFramework);\n}\n\nexport const repositoryFramework = z.preprocess(\n\t(value) => {\n\t\t// NOTE: we persist a lot of different frameworks in the DB, but only the SM supported are relevant to us\n\t\t// Any other framework is treated like \"other\"\n\t\tif (typeof value === \"string\" && isSupportedFramework(value)) {\n\t\t\treturn value;\n\t\t}\n\n\t\treturn \"other\";\n\t},\n\tz.enum([...supportedSliceMachineFrameworks, \"other\"]),\n);\n\nexport type RepositoryFramework = z.TypeOf<typeof repositoryFramework>;\n\nexport const OnboardingState = z.object({\n\tcompletedSteps: z.array(z.string()),\n\tisDismissed: z.boolean(),\n\tcontext: z.object({\n\t\tframework: repositoryFramework,\n\t\tstarterId: z.string().nullable(),\n\t}),\n});\nexport type OnboardingState = z.infer<typeof OnboardingState>;\n"],"names":["ChangeTypes","PushChangesLimitType"],"mappings":";;AAOO,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,sBAAsB,EAAE,KAAK;AAAA,EACzC,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,uBAAoB;AAC/BA,wBAAA,MAAA,IAAA;AACAA,wBAAA,MAAA,IAAA;AACD,GAHY,yBAAA,uBAGX,CAAA,EAAA;AA+DY,MAAA,cAAc,EAAE,KAAK;AAAA,EACjC,MAAM,EAAE,MAAM,CAAC,EAAE,QAAQ,MAAM,GAAG,EAAE,QAAQ,OAAO,GAAG,EAAE,QAAQ,KAAK,CAAC,CAAC;AAAA,EACvE,MAAM,EAAE;AAAA,EACR,QAAQ,EAAE;AAAA,EACV,OAAO,EAAE,MACR,EAAE,KAAK;AAAA,IACN,IAAI,EAAE;AAAA,EAAA,CACN,CAAC;AAEH,CAAA;AAGM,MAAM,kCAAkC;AAAA,EAC9C;AAAA,EACA;AAAA,EACA;;AAKD,SAAS,qBAAqB,OAAa;AACnC,SAAA,gCAAgC,SAAS,KAA2B;AAC5E;AAEO,MAAM,sBAAsB,EAAE,WACpC,CAAC,UAAS;AAGT,MAAI,OAAO,UAAU,YAAY,qBAAqB,KAAK,GAAG;AACtD,WAAA;AAAA,EACR;AAEO,SAAA;AACR,GACA,EAAE,KAAK,CAAC,GAAG,iCAAiC,OAAO,CAAC,CAAC;AAKzC,MAAA,kBAAkB,EAAE,OAAO;AAAA,EACvC,gBAAgB,EAAE,MAAM,EAAE,QAAQ;AAAA,EAClC,aAAa,EAAE,QAAS;AAAA,EACxB,SAAS,EAAE,OAAO;AAAA,IACjB,WAAW;AAAA,IACX,WAAW,EAAE,OAAQ,EAAC,SAAU;AAAA,EAAA,CAChC;AACD,CAAA;"}
|
|
@@ -264,7 +264,7 @@ Error Message: ${error2.message}`);
|
|
|
264
264
|
const { environment: activeEnvironmentDomain } = await this.readEnvironment();
|
|
265
265
|
const cachedActiveEnvironment = findEnvironment.findEnvironment(activeEnvironmentDomain, this._cachedEnvironments || []);
|
|
266
266
|
if (cachedActiveEnvironment) {
|
|
267
|
-
return { activeEnvironment: cachedActiveEnvironment };
|
|
267
|
+
return { type: "ok", activeEnvironment: cachedActiveEnvironment };
|
|
268
268
|
}
|
|
269
269
|
const { environments } = await this.prismicRepository.fetchEnvironments();
|
|
270
270
|
if (environments) {
|
|
@@ -272,9 +272,12 @@ Error Message: ${error2.message}`);
|
|
|
272
272
|
}
|
|
273
273
|
const activeEnvironment = findEnvironment.findEnvironment(activeEnvironmentDomain, this._cachedEnvironments || []);
|
|
274
274
|
if (!activeEnvironment) {
|
|
275
|
-
|
|
275
|
+
return {
|
|
276
|
+
type: "error",
|
|
277
|
+
error: new errors.InvalidActiveEnvironmentError()
|
|
278
|
+
};
|
|
276
279
|
}
|
|
277
|
-
return { activeEnvironment };
|
|
280
|
+
return { type: "ok", activeEnvironment };
|
|
278
281
|
}
|
|
279
282
|
async detectVersionControlSystem() {
|
|
280
283
|
try {
|
|
@@ -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 { 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 { findEnvironment } from \"../../lib/findEnvironment\";\nimport { format } from \"../../lib/format\";\nimport { installDependencies } from \"../../lib/installDependencies\";\nimport { locateFileUpward } from \"../../lib/locateFileUpward\";\nimport { requireResolve } from \"../../lib/requireResolve\";\n\nimport {\n\tPackageManager,\n\tSliceMachineConfig,\n\tOnlyHookErrors,\n} from \"../../types\";\n\nimport {\n\tSliceMachineError,\n\tInternalError,\n\tPluginError,\n\tInvalidActiveEnvironmentError,\n} 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\";\nimport { Environment } from \"../prismicRepository/types\";\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\ntype ProjectManagerFetchActiveEnvironmentReturnType = {\n\tactiveEnvironment: Environment;\n};\n\nexport class ProjectManager extends BaseManager {\n\tprivate _cachedRoot: string | undefined;\n\tprivate _cachedSliceMachineConfigPath: string | undefined;\n\tprivate _cachedSliceMachineConfig: SliceMachineConfig | undefined;\n\tprivate _cachedEnvironments: Environment[] | 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 sliceMachinePackageJSONPath = requireResolve(\n\t\t\t`${SLICE_MACHINE_NPM_PACKAGE_NAME}/package.json`,\n\t\t\tpath.join(projectRoot, \"index.js\"),\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 adapterPackageJSONPath = requireResolve(\n\t\t\t`${adapterName}/package.json`,\n\t\t\tpath.join(projectRoot, \"index.js\"),\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\tasync fetchActiveEnvironment(): Promise<ProjectManagerFetchActiveEnvironmentReturnType> {\n\t\tconst { environment: activeEnvironmentDomain } =\n\t\t\tawait this.readEnvironment();\n\n\t\t// We can assume an environment cannot change its kind. If the\n\t\t// environment exists in the cached list, we are confident it\n\t\t// will not change.\n\t\tconst cachedActiveEnvironment = findEnvironment(\n\t\t\tactiveEnvironmentDomain,\n\t\t\tthis._cachedEnvironments || [],\n\t\t);\n\t\tif (cachedActiveEnvironment) {\n\t\t\treturn { activeEnvironment: cachedActiveEnvironment };\n\t\t}\n\n\t\t// If the environment is not in the cached environments list, we\n\t\t// must fetch a fresh list and set the cache.\n\t\tconst { environments } = await this.prismicRepository.fetchEnvironments();\n\t\t// TODO: Remove the wrapping if statement when\n\t\t// `this.prismicRepository.fetchEnvironments()` is able to throw\n\t\t// normally. The method returns an object with an `error`\n\t\t// property at the time of this writing, which means we need to\n\t\t// check if the `environments` property exists.\n\t\tif (environments) {\n\t\t\tthis._cachedEnvironments = environments;\n\t\t}\n\n\t\tconst activeEnvironment = findEnvironment(\n\t\t\tactiveEnvironmentDomain,\n\t\t\tthis._cachedEnvironments || [],\n\t\t);\n\n\t\tif (!activeEnvironment) {\n\t\t\tthrow new InvalidActiveEnvironmentError();\n\t\t}\n\n\t\treturn { activeEnvironment };\n\t}\n\n\tasync detectVersionControlSystem(): Promise<string | \"_unknown\"> {\n\t\ttry {\n\t\t\tconst projectRoot = await this.getRoot();\n\n\t\t\tif (existsSync(path.join(projectRoot, \".git\"))) {\n\t\t\t\treturn \"Git\";\n\t\t\t}\n\n\t\t\tif (existsSync(path.join(projectRoot, \".svn\"))) {\n\t\t\t\treturn \"SVN\";\n\t\t\t}\n\n\t\t\tif (existsSync(path.join(projectRoot, \".hg\"))) {\n\t\t\t\treturn \"Mercurial\";\n\t\t\t}\n\n\t\t\tif (existsSync(path.join(projectRoot, \"CVS\"))) {\n\t\t\t\treturn \"CVS\";\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tif (import.meta.env.DEV) {\n\t\t\t\tconsole.error(\"Failed to detect Version Control System:\", error);\n\t\t\t}\n\t\t}\n\n\t\treturn \"_unknown\";\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","requireResolve","SLICE_MACHINE_NPM_PACKAGE_NAME","assertPluginsInitialized","errors","args","niDetect","installDependencies","InternalError","decodeHookResult","t","findEnvironment","InvalidActiveEnvironmentError","PluginError"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2FM,MAAO,uBAAuBA,YAAAA,YAAW;AAAA,EAAzC;AAAA;AACG;AACA;AACA;AACA;AAAA;AAAA,EAER,MAAM,0BACL,MAAkD;AAElD,QAAI,KAAK,iCAAiC,EAAC,6BAAM,cAAa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C,GAAG;AACxC,eAAA;AAAA,MACR;AAEA,UAAIE,QAAAA,WAAWF,gBAAK,KAAK,aAAa,MAAM,CAAC,GAAG;AACxC,eAAA;AAAA,MACR;AAEA,UAAIE,QAAAA,WAAWF,gBAAK,KAAK,aAAa,KAAK,CAAC,GAAG;AACvC,eAAA;AAAA,MACR;AAEA,UAAIE,QAAAA,WAAWF,gBAAK,KAAK,aAAa,KAAK,CAAC,GAAG;AACvC,eAAA;AAAA,MACR;AAAA,aACQ,OAAO;AAAA,IAIhB;AAEO,WAAA;AAAA,EACR;AAAA,EAEQ,MAAM,qCAAkC;AAC/CU,sDAAyB,KAAK,wBAAwB;AAEhD,UAAA,uBAAuB,KAAK;AAElC,QAAI,CAAC,sBAAsB;AAC1B,YAAM,cAAc,MAAM,KAAK,QAAQ,eAAc;AAErD,YAAM,IAAIU,OAAAA,YACT,GAAG,WAAW,+JAA+J;AAAA,IAE/K;AAAA,EACD;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 { 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 { findEnvironment } from \"../../lib/findEnvironment\";\nimport { format } from \"../../lib/format\";\nimport { installDependencies } from \"../../lib/installDependencies\";\nimport { locateFileUpward } from \"../../lib/locateFileUpward\";\nimport { requireResolve } from \"../../lib/requireResolve\";\n\nimport {\n\tPackageManager,\n\tSliceMachineConfig,\n\tOnlyHookErrors,\n} from \"../../types\";\n\nimport {\n\tSliceMachineError,\n\tInternalError,\n\tPluginError,\n\tInvalidActiveEnvironmentError,\n} 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\";\nimport { Environment } from \"../prismicRepository/types\";\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\ntype ProjectManagerFetchActiveEnvironmentReturnType =\n\t| { type: \"ok\"; activeEnvironment: Environment }\n\t| { type: \"error\"; error: InvalidActiveEnvironmentError };\n\nexport class ProjectManager extends BaseManager {\n\tprivate _cachedRoot: string | undefined;\n\tprivate _cachedSliceMachineConfigPath: string | undefined;\n\tprivate _cachedSliceMachineConfig: SliceMachineConfig | undefined;\n\tprivate _cachedEnvironments: Environment[] | 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 sliceMachinePackageJSONPath = requireResolve(\n\t\t\t`${SLICE_MACHINE_NPM_PACKAGE_NAME}/package.json`,\n\t\t\tpath.join(projectRoot, \"index.js\"),\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 adapterPackageJSONPath = requireResolve(\n\t\t\t`${adapterName}/package.json`,\n\t\t\tpath.join(projectRoot, \"index.js\"),\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\tasync fetchActiveEnvironment(): Promise<ProjectManagerFetchActiveEnvironmentReturnType> {\n\t\tconst { environment: activeEnvironmentDomain } =\n\t\t\tawait this.readEnvironment();\n\n\t\t// We can assume an environment cannot change its kind. If the\n\t\t// environment exists in the cached list, we are confident it\n\t\t// will not change.\n\t\tconst cachedActiveEnvironment = findEnvironment(\n\t\t\tactiveEnvironmentDomain,\n\t\t\tthis._cachedEnvironments || [],\n\t\t);\n\t\tif (cachedActiveEnvironment) {\n\t\t\treturn { type: \"ok\", activeEnvironment: cachedActiveEnvironment };\n\t\t}\n\n\t\t// If the environment is not in the cached environments list, we\n\t\t// must fetch a fresh list and set the cache.\n\t\tconst { environments } = await this.prismicRepository.fetchEnvironments();\n\t\t// TODO: Remove the wrapping if statement when\n\t\t// `this.prismicRepository.fetchEnvironments()` is able to throw\n\t\t// normally. The method returns an object with an `error`\n\t\t// property at the time of this writing, which means we need to\n\t\t// check if the `environments` property exists.\n\t\tif (environments) {\n\t\t\tthis._cachedEnvironments = environments;\n\t\t}\n\n\t\tconst activeEnvironment = findEnvironment(\n\t\t\tactiveEnvironmentDomain,\n\t\t\tthis._cachedEnvironments || [],\n\t\t);\n\n\t\tif (!activeEnvironment) {\n\t\t\treturn {\n\t\t\t\ttype: \"error\",\n\t\t\t\terror: new InvalidActiveEnvironmentError(),\n\t\t\t};\n\t\t}\n\n\t\treturn { type: \"ok\", activeEnvironment: activeEnvironment };\n\t}\n\n\tasync detectVersionControlSystem(): Promise<string | \"_unknown\"> {\n\t\ttry {\n\t\t\tconst projectRoot = await this.getRoot();\n\n\t\t\tif (existsSync(path.join(projectRoot, \".git\"))) {\n\t\t\t\treturn \"Git\";\n\t\t\t}\n\n\t\t\tif (existsSync(path.join(projectRoot, \".svn\"))) {\n\t\t\t\treturn \"SVN\";\n\t\t\t}\n\n\t\t\tif (existsSync(path.join(projectRoot, \".hg\"))) {\n\t\t\t\treturn \"Mercurial\";\n\t\t\t}\n\n\t\t\tif (existsSync(path.join(projectRoot, \"CVS\"))) {\n\t\t\t\treturn \"CVS\";\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tif (import.meta.env.DEV) {\n\t\t\t\tconsole.error(\"Failed to detect Version Control System:\", error);\n\t\t\t}\n\t\t}\n\n\t\treturn \"_unknown\";\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","requireResolve","SLICE_MACHINE_NPM_PACKAGE_NAME","assertPluginsInitialized","errors","args","niDetect","installDependenc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AAoBA,gBAAAA,gBACzB,yBACA,KAAK,uBAAuB,CAAA,CAAE;AAG/B,QAAI,CAAC,mBAAmB;AAChB,aAAA;AAAA,QACN,MAAM;AAAA,QACN,OAAO,IAAIC,OAAAA,8BAA+B;AAAA,MAAA;AAAA,IAE5C;AAEO,WAAA,EAAE,MAAM,MAAM;EACtB;AAAA,EAEA,MAAM,6BAA0B;AAC3B,QAAA;AACG,YAAA,cAAc,MAAM,KAAK;AAE/B,UAAIjB,QAAAA,WAAWF,gBAAK,KAAK,aAAa,MAAM,CAAC,GAAG;AACxC,eAAA;AAAA,MACR;AAEA,UAAIE,QAAAA,WAAWF,gBAAK,KAAK,aAAa,MAAM,CAAC,GAAG;AACxC,eAAA;AAAA,MACR;AAEA,UAAIE,QAAAA,WAAWF,gBAAK,KAAK,aAAa,KAAK,CAAC,GAAG;AACvC,eAAA;AAAA,MACR;AAEA,UAAIE,QAAAA,WAAWF,gBAAK,KAAK,aAAa,KAAK,CAAC,GAAG;AACvC,eAAA;AAAA,MACR;AAAA,aACQ,OAAO;AAAA,IAIhB;AAEO,WAAA;AAAA,EACR;AAAA,EAEQ,MAAM,qCAAkC;AAC/CU,sDAAyB,KAAK,wBAAwB;AAEhD,UAAA,uBAAuB,KAAK;AAElC,QAAI,CAAC,sBAAsB;AAC1B,YAAM,cAAc,MAAM,KAAK,QAAQ,eAAc;AAErD,YAAM,IAAIU,OAAAA,YACT,GAAG,WAAW,+JAA+J;AAAA,IAE/K;AAAA,EACD;AACA;;"}
|
|
@@ -2,6 +2,7 @@ import { ExecaChildProcess } from "execa";
|
|
|
2
2
|
import { HookError, CallHookReturnType, ProjectEnvironmentUpdateHook } from "@slicemachine/plugin-kit";
|
|
3
3
|
import { DecodeError } from "../../lib/DecodeError";
|
|
4
4
|
import { PackageManager, SliceMachineConfig, OnlyHookErrors } from "../../types";
|
|
5
|
+
import { InvalidActiveEnvironmentError } from "../../errors";
|
|
5
6
|
import { BaseManager } from "../BaseManager";
|
|
6
7
|
import { Environment } from "../prismicRepository/types";
|
|
7
8
|
type ProjectManagerGetSliceMachineConfigPathArgs = {
|
|
@@ -40,7 +41,11 @@ type ProjectManagerUpdateEnvironmentArgs = {
|
|
|
40
41
|
environment: string | undefined;
|
|
41
42
|
};
|
|
42
43
|
type ProjectManagerFetchActiveEnvironmentReturnType = {
|
|
44
|
+
type: "ok";
|
|
43
45
|
activeEnvironment: Environment;
|
|
46
|
+
} | {
|
|
47
|
+
type: "error";
|
|
48
|
+
error: InvalidActiveEnvironmentError;
|
|
44
49
|
};
|
|
45
50
|
export declare class ProjectManager extends BaseManager {
|
|
46
51
|
private _cachedRoot;
|
|
@@ -243,7 +243,7 @@ Error Message: ${error2.message}`);
|
|
|
243
243
|
const { environment: activeEnvironmentDomain } = await this.readEnvironment();
|
|
244
244
|
const cachedActiveEnvironment = findEnvironment(activeEnvironmentDomain, this._cachedEnvironments || []);
|
|
245
245
|
if (cachedActiveEnvironment) {
|
|
246
|
-
return { activeEnvironment: cachedActiveEnvironment };
|
|
246
|
+
return { type: "ok", activeEnvironment: cachedActiveEnvironment };
|
|
247
247
|
}
|
|
248
248
|
const { environments } = await this.prismicRepository.fetchEnvironments();
|
|
249
249
|
if (environments) {
|
|
@@ -251,9 +251,12 @@ Error Message: ${error2.message}`);
|
|
|
251
251
|
}
|
|
252
252
|
const activeEnvironment = findEnvironment(activeEnvironmentDomain, this._cachedEnvironments || []);
|
|
253
253
|
if (!activeEnvironment) {
|
|
254
|
-
|
|
254
|
+
return {
|
|
255
|
+
type: "error",
|
|
256
|
+
error: new InvalidActiveEnvironmentError()
|
|
257
|
+
};
|
|
255
258
|
}
|
|
256
|
-
return { activeEnvironment };
|
|
259
|
+
return { type: "ok", activeEnvironment };
|
|
257
260
|
}
|
|
258
261
|
async detectVersionControlSystem() {
|
|
259
262
|
try {
|
|
@@ -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 { 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 { findEnvironment } from \"../../lib/findEnvironment\";\nimport { format } from \"../../lib/format\";\nimport { installDependencies } from \"../../lib/installDependencies\";\nimport { locateFileUpward } from \"../../lib/locateFileUpward\";\nimport { requireResolve } from \"../../lib/requireResolve\";\n\nimport {\n\tPackageManager,\n\tSliceMachineConfig,\n\tOnlyHookErrors,\n} from \"../../types\";\n\nimport {\n\tSliceMachineError,\n\tInternalError,\n\tPluginError,\n\tInvalidActiveEnvironmentError,\n} 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\";\nimport { Environment } from \"../prismicRepository/types\";\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\ntype ProjectManagerFetchActiveEnvironmentReturnType = {\n\tactiveEnvironment: Environment;\n};\n\nexport class ProjectManager extends BaseManager {\n\tprivate _cachedRoot: string | undefined;\n\tprivate _cachedSliceMachineConfigPath: string | undefined;\n\tprivate _cachedSliceMachineConfig: SliceMachineConfig | undefined;\n\tprivate _cachedEnvironments: Environment[] | 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 sliceMachinePackageJSONPath = requireResolve(\n\t\t\t`${SLICE_MACHINE_NPM_PACKAGE_NAME}/package.json`,\n\t\t\tpath.join(projectRoot, \"index.js\"),\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 adapterPackageJSONPath = requireResolve(\n\t\t\t`${adapterName}/package.json`,\n\t\t\tpath.join(projectRoot, \"index.js\"),\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\tasync fetchActiveEnvironment(): Promise<ProjectManagerFetchActiveEnvironmentReturnType> {\n\t\tconst { environment: activeEnvironmentDomain } =\n\t\t\tawait this.readEnvironment();\n\n\t\t// We can assume an environment cannot change its kind. If the\n\t\t// environment exists in the cached list, we are confident it\n\t\t// will not change.\n\t\tconst cachedActiveEnvironment = findEnvironment(\n\t\t\tactiveEnvironmentDomain,\n\t\t\tthis._cachedEnvironments || [],\n\t\t);\n\t\tif (cachedActiveEnvironment) {\n\t\t\treturn { activeEnvironment: cachedActiveEnvironment };\n\t\t}\n\n\t\t// If the environment is not in the cached environments list, we\n\t\t// must fetch a fresh list and set the cache.\n\t\tconst { environments } = await this.prismicRepository.fetchEnvironments();\n\t\t// TODO: Remove the wrapping if statement when\n\t\t// `this.prismicRepository.fetchEnvironments()` is able to throw\n\t\t// normally. The method returns an object with an `error`\n\t\t// property at the time of this writing, which means we need to\n\t\t// check if the `environments` property exists.\n\t\tif (environments) {\n\t\t\tthis._cachedEnvironments = environments;\n\t\t}\n\n\t\tconst activeEnvironment = findEnvironment(\n\t\t\tactiveEnvironmentDomain,\n\t\t\tthis._cachedEnvironments || [],\n\t\t);\n\n\t\tif (!activeEnvironment) {\n\t\t\tthrow new InvalidActiveEnvironmentError();\n\t\t}\n\n\t\treturn { activeEnvironment };\n\t}\n\n\tasync detectVersionControlSystem(): Promise<string | \"_unknown\"> {\n\t\ttry {\n\t\t\tconst projectRoot = await this.getRoot();\n\n\t\t\tif (existsSync(path.join(projectRoot, \".git\"))) {\n\t\t\t\treturn \"Git\";\n\t\t\t}\n\n\t\t\tif (existsSync(path.join(projectRoot, \".svn\"))) {\n\t\t\t\treturn \"SVN\";\n\t\t\t}\n\n\t\t\tif (existsSync(path.join(projectRoot, \".hg\"))) {\n\t\t\t\treturn \"Mercurial\";\n\t\t\t}\n\n\t\t\tif (existsSync(path.join(projectRoot, \"CVS\"))) {\n\t\t\t\treturn \"CVS\";\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tif (import.meta.env.DEV) {\n\t\t\t\tconsole.error(\"Failed to detect Version Control System:\", error);\n\t\t\t}\n\t\t}\n\n\t\treturn \"_unknown\";\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","args","niDetect"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA2FM,MAAO,uBAAuB,YAAW;AAAA,EAAzC;AAAA;AACG;AACA;AACA;AACA;AAAA;AAAA,EAER,MAAM,0BACL,MAAkD;AAElD,QAAI,KAAK,iCAAiC,EAAC,6BAAM,cAAa;AAC7D,aAAO,KAAK;AAAA,IACb;AAEI,QAAA;AACE,WAAA,gCAAgC,MAAM,iBAC1C,+BACA,EAAE,UAAU,KAAK,KAAK;AAAA,aAEf,OAAO;AACf,YAAM,IAAI,MACT,oBAAoB,6BAA6B,iEAAiE;AAAA,IAEpH;AAEA,WAAO,KAAK;AAAA,EACb;AAAA,EAEA,MAAM,QAAQ,MAAgC;AAC7C,QAAI,KAAK,eAAe,EAAC,6BAAM,cAAa;AAC3C,aAAO,KAAK;AAAA,IACb;AAEM,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;AAE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,KAAK,uBAAuB,CAAA,CAAE;AAG/B,QAAI,CAAC,mBAAmB;AACvB,YAAM,IAAI,8BAA6B;AAAA,IACxC;AAEA,WAAO,EAAE,kBAAiB;AAAA,EAC3B;AAAA,EAEA,MAAM,6BAA0B;AAC3B,QAAA;AACG,YAAA,cAAc,MAAM,KAAK;AAE/B,UAAI,WAAW,KAAK,KAAK,aAAa,MAAM,CAAC,GAAG;AACxC,eAAA;AAAA,MACR;AAEA,UAAI,WAAW,KAAK,KAAK,aAAa,MAAM,CAAC,GAAG;AACxC,eAAA;AAAA,MACR;AAEA,UAAI,WAAW,KAAK,KAAK,aAAa,KAAK,CAAC,GAAG;AACvC,eAAA;AAAA,MACR;AAEA,UAAI,WAAW,KAAK,KAAK,aAAa,KAAK,CAAC,GAAG;AACvC,eAAA;AAAA,MACR;AAAA,aACQ,OAAO;AAAA,IAIhB;AAEO,WAAA;AAAA,EACR;AAAA,EAEQ,MAAM,qCAAkC;AAC/C,6BAAyB,KAAK,wBAAwB;AAEhD,UAAA,uBAAuB,KAAK;AAElC,QAAI,CAAC,sBAAsB;AAC1B,YAAM,cAAc,MAAM,KAAK,QAAQ,eAAc;AAErD,YAAM,IAAI,YACT,GAAG,WAAW,+JAA+J;AAAA,IAE/K;AAAA,EACD;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 { 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 { findEnvironment } from \"../../lib/findEnvironment\";\nimport { format } from \"../../lib/format\";\nimport { installDependencies } from \"../../lib/installDependencies\";\nimport { locateFileUpward } from \"../../lib/locateFileUpward\";\nimport { requireResolve } from \"../../lib/requireResolve\";\n\nimport {\n\tPackageManager,\n\tSliceMachineConfig,\n\tOnlyHookErrors,\n} from \"../../types\";\n\nimport {\n\tSliceMachineError,\n\tInternalError,\n\tPluginError,\n\tInvalidActiveEnvironmentError,\n} 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\";\nimport { Environment } from \"../prismicRepository/types\";\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\ntype ProjectManagerFetchActiveEnvironmentReturnType =\n\t| { type: \"ok\"; activeEnvironment: Environment }\n\t| { type: \"error\"; error: InvalidActiveEnvironmentError };\n\nexport class ProjectManager extends BaseManager {\n\tprivate _cachedRoot: string | undefined;\n\tprivate _cachedSliceMachineConfigPath: string | undefined;\n\tprivate _cachedSliceMachineConfig: SliceMachineConfig | undefined;\n\tprivate _cachedEnvironments: Environment[] | 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 sliceMachinePackageJSONPath = requireResolve(\n\t\t\t`${SLICE_MACHINE_NPM_PACKAGE_NAME}/package.json`,\n\t\t\tpath.join(projectRoot, \"index.js\"),\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 adapterPackageJSONPath = requireResolve(\n\t\t\t`${adapterName}/package.json`,\n\t\t\tpath.join(projectRoot, \"index.js\"),\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\tasync fetchActiveEnvironment(): Promise<ProjectManagerFetchActiveEnvironmentReturnType> {\n\t\tconst { environment: activeEnvironmentDomain } =\n\t\t\tawait this.readEnvironment();\n\n\t\t// We can assume an environment cannot change its kind. If the\n\t\t// environment exists in the cached list, we are confident it\n\t\t// will not change.\n\t\tconst cachedActiveEnvironment = findEnvironment(\n\t\t\tactiveEnvironmentDomain,\n\t\t\tthis._cachedEnvironments || [],\n\t\t);\n\t\tif (cachedActiveEnvironment) {\n\t\t\treturn { type: \"ok\", activeEnvironment: cachedActiveEnvironment };\n\t\t}\n\n\t\t// If the environment is not in the cached environments list, we\n\t\t// must fetch a fresh list and set the cache.\n\t\tconst { environments } = await this.prismicRepository.fetchEnvironments();\n\t\t// TODO: Remove the wrapping if statement when\n\t\t// `this.prismicRepository.fetchEnvironments()` is able to throw\n\t\t// normally. The method returns an object with an `error`\n\t\t// property at the time of this writing, which means we need to\n\t\t// check if the `environments` property exists.\n\t\tif (environments) {\n\t\t\tthis._cachedEnvironments = environments;\n\t\t}\n\n\t\tconst activeEnvironment = findEnvironment(\n\t\t\tactiveEnvironmentDomain,\n\t\t\tthis._cachedEnvironments || [],\n\t\t);\n\n\t\tif (!activeEnvironment) {\n\t\t\treturn {\n\t\t\t\ttype: \"error\",\n\t\t\t\terror: new InvalidActiveEnvironmentError(),\n\t\t\t};\n\t\t}\n\n\t\treturn { type: \"ok\", activeEnvironment: activeEnvironment };\n\t}\n\n\tasync detectVersionControlSystem(): Promise<string | \"_unknown\"> {\n\t\ttry {\n\t\t\tconst projectRoot = await this.getRoot();\n\n\t\t\tif (existsSync(path.join(projectRoot, \".git\"))) {\n\t\t\t\treturn \"Git\";\n\t\t\t}\n\n\t\t\tif (existsSync(path.join(projectRoot, \".svn\"))) {\n\t\t\t\treturn \"SVN\";\n\t\t\t}\n\n\t\t\tif (existsSync(path.join(projectRoot, \".hg\"))) {\n\t\t\t\treturn \"Mercurial\";\n\t\t\t}\n\n\t\t\tif (existsSync(path.join(projectRoot, \"CVS\"))) {\n\t\t\t\treturn \"CVS\";\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tif (import.meta.env.DEV) {\n\t\t\t\tconsole.error(\"Failed to detect Version Control System:\", error);\n\t\t\t}\n\t\t}\n\n\t\treturn \"_unknown\";\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\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AC3B,QAAA;AACG,YAAA,cAAc,MAAM,KAAK;AAE/B,UAAI,WAAW,KAAK,KAAK,aAAa,MAAM,CAAC,GAAG;AACxC,eAAA;AAAA,MACR;AAEA,UAAI,WAAW,KAAK,KAAK,aAAa,MAAM,CAAC,GAAG;AACxC,eAAA;AAAA,MACR;AAEA,UAAI,WAAW,KAAK,KAAK,aAAa,KAAK,CAAC,GAAG;AACvC,eAAA;AAAA,MACR;AAEA,UAAI,WAAW,KAAK,KAAK,aAAa,KAAK,CAAC,GAAG;AACvC,eAAA;AAAA,MACR;AAAA,aACQ,OAAO;AAAA,IAIhB;AAEO,WAAA;AAAA,EACR;AAAA,EAEQ,MAAM,qCAAkC;AAC/C,6BAAyB,KAAK,wBAAwB;AAEhD,UAAA,uBAAuB,KAAK;AAElC,QAAI,CAAC,sBAAsB;AAC1B,YAAM,cAAc,MAAM,KAAK,QAAQ,eAAc;AAErD,YAAM,IAAI,YACT,GAAG,WAAW,+JAA+J;AAAA,IAE/K;AAAA,EACD;AACA;"}
|
|
@@ -413,8 +413,11 @@ class SlicesManager extends BaseManager.BaseManager {
|
|
|
413
413
|
});
|
|
414
414
|
if (model) {
|
|
415
415
|
const modelWithScreenshots = await this.updateSliceModelScreenshotsInPlace({
|
|
416
|
+
model,
|
|
416
417
|
libraryID: args.libraryID,
|
|
417
|
-
|
|
418
|
+
// We are pushing it for the first time here, no remote image URLs to
|
|
419
|
+
// use during the update.
|
|
420
|
+
variationImageUrlMap: {}
|
|
418
421
|
});
|
|
419
422
|
const authenticationToken = await this.user.getAuthenticationToken();
|
|
420
423
|
const repositoryName = await this.project.getResolvedRepositoryName();
|
|
@@ -601,9 +604,14 @@ class SlicesManager extends BaseManager.BaseManager {
|
|
|
601
604
|
imageUrl: DEFAULT_SLICE_SCREENSHOT_URL.DEFAULT_SLICE_SCREENSHOT_URL
|
|
602
605
|
};
|
|
603
606
|
}
|
|
604
|
-
const
|
|
607
|
+
const remoteImageUrl = (_a = args.variationImageUrlMap) == null ? void 0 : _a[variation.id];
|
|
608
|
+
const hasScreenshotChanged = !(remoteImageUrl == null ? void 0 : remoteImageUrl.includes(createContentDigest.createContentDigest(screenshot.data)));
|
|
605
609
|
if (!hasScreenshotChanged) {
|
|
606
|
-
return
|
|
610
|
+
return {
|
|
611
|
+
...variation,
|
|
612
|
+
// Keep the existing remote screenshot URL if it exists.
|
|
613
|
+
imageUrl: remoteImageUrl ?? variation.imageUrl
|
|
614
|
+
};
|
|
607
615
|
}
|
|
608
616
|
const keyPrefix = [
|
|
609
617
|
repositoryName,
|