Skip to content

Commit

Permalink
fix: plugins apply
Browse files Browse the repository at this point in the history
  • Loading branch information
rharkor committed Sep 4, 2024
1 parent aa9ffc1 commit c353b54
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 11 deletions.
1 change: 1 addition & 0 deletions packages/cli/src/app/src/api/configuration/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export const applyConfiguration = async ({}: apiInputFromSchema<typeof undefined
configFileName: "config.json",
pluginsDirectory,
root: env.ROOT_PATH,
noTask: true,
})

const data: z.infer<ReturnType<typeof updateConfigurationResponseSchema>> = { configuration }
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/app/src/lib/configuration/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ const webConfigToApiConfig = (webConfig: TConfiguration): z.infer<typeof optiona
plugins: (webConfig.plugins ?? []).map((plugin) => {
return {
name: plugin.sourcePath,
paths: plugin.paths.map((p) => p.to),
paths: plugin.paths,
}
}),
})
return content
} catch (error) {
logger.error(error)
logger.error("Failed to convert the web configuration", error)
throw new TRPCError({
message: `Failed to convert the web configuration`,
code: "INTERNAL_SERVER_ERROR",
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/functions/apply-config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export const applyConfig = async () => {
configFileName,
pluginsDirectory,
root,
noTask: false,
}).catch(() => {
process.exit(1)
})
Expand Down
5 changes: 3 additions & 2 deletions packages/scripts/src/utils/template-config/apply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const applyConfigurationTask = async ({
throw error
}

//* Apply plugins
//* Verify plugins
if (applyConfigTask) applyConfigTask.log("Applying plugins")
else logger.info("Applying plugins")

Expand Down Expand Up @@ -114,7 +114,8 @@ export const applyConfigurationTask = async ({
const pluginConfigPath = path.join(pluginPath, configFileName)
const pluginConfig = (await fs.readJson(pluginConfigPath)) as TPluginConfig
// Copy the plugin to the destination
for (const { from, to } of pluginConfig.paths) {
for (const { from, to: defaultTo } of pluginConfig.paths) {
const to = typeof plugin === "string" ? defaultTo : (plugin.paths.find((p) => p.from === from)?.to ?? defaultTo)
const sourcePath = path.join(pluginPath, from)
const destinationPath = path.join(root, to)
if (applyConfigTask) applyConfigTask.log(`Copying the plugin ${pluginName} to the destination ${destinationPath}`)
Expand Down
19 changes: 12 additions & 7 deletions packages/scripts/src/utils/template-config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,26 @@ export function isPathInCurrentScope(filePath: string): boolean {
export const fullPluginSchema = z.object({
name: z.string(),
paths: z.array(
z
.string()
.optional()
.refine(
z.object({
from: z.string().refine(
(value) => {
if (value === undefined) {
return true
if (!isPathInCurrentScope(value)) {
return false
}
return true
},
{ message: "The path should be relative and in the current directory" }
),
to: z.string().refine(
(value) => {
if (!isPathInCurrentScope(value)) {
return false
}
return true
},
{ message: "The path should be relative and in the current directory" }
)
),
})
),
})

Expand Down

0 comments on commit c353b54

Please sign in to comment.