Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/rec' into rec-release
Browse files Browse the repository at this point in the history
  • Loading branch information
GitHub Actions committed Nov 12, 2024
2 parents 678b32f + 72bbe37 commit 4f28bcd
Show file tree
Hide file tree
Showing 9 changed files with 768 additions and 696 deletions.
2 changes: 1 addition & 1 deletion _old/apps/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"react-dom": "^18.2.0"
},
"devDependencies": {
"@types/node": "20.14.10",
"@types/node": "20.16.6",
"typescript": "^5.4.3"
}
}
1,320 changes: 645 additions & 675 deletions _old/package-lock.json

Large diffs are not rendered by default.

16 changes: 0 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"test": "turbo run test",
"ci-check": "turbo run ci-check",
"init": "npm run init -s -w packages/scripts",
"build-deps": "turbo run build --filter='@next-boilerplate/*'^...",
"depcheck": "npm run depcheck -s -w packages/scripts"
},
"homepage": "https://github.com/rharkor/next-boilerplate",
Expand Down
1 change: 1 addition & 0 deletions packages/cli-app/src/lib/configuration/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ const apiConfigToWebConfig = async (apiConfig: z.infer<typeof optionalConfigSche
overridedTo,
}
}),
scripts: foundPlugin.scripts,
}
}),
stores: apiConfig.stores,
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-app/tsconfig.tsbuildinfo

Large diffs are not rendered by default.

44 changes: 41 additions & 3 deletions packages/cli-helpers/schemas/plugin.d.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
"description": {
"type": "string"
},
"source": {
"type": "string"
},
"paths": {
"type": "array",
"items": {
Expand All @@ -29,6 +26,47 @@
}
}
}
},
"scripts": {
"type": "object",
"additionalProperties": false,
"properties": {
"replaceByProjectName": {
"type": "object",
"additionalProperties": false,
"properties": {
"search": {
"type": "string",
"description": "The string to search for and replace"
},
"root": {
"type": "string",
"description": "Root path to search in"
},
"paths": {
"type": "array",
"items": {
"type": "string"
},
"description": "Specific file or folder paths to search in"
}
},
"oneOf": [
{
"required": [
"search",
"root"
]
},
{
"required": [
"search",
"paths"
]
}
]
}
}
}
},
"required": [
Expand Down
50 changes: 50 additions & 0 deletions packages/cli-helpers/src/apply.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import fs from "fs-extra"
import { globby } from "globby"
import path from "path"

import { logger } from "@rharkor/logger"
Expand Down Expand Up @@ -126,6 +127,55 @@ export const applyConfigurationTask = async ({
}
}

//*** Apply scripts ***
for (const plugin of config.plugins) {
const pluginPath = getPluginPath({ assetsDirectory, plugin })
const pluginConfigPath = path.join(pluginPath, pluginConfigFileName)
const pluginConfig = (await fs.readJson(pluginConfigPath)) as TPluginConfig
const { scripts } = pluginConfig
//* Replace by project name
if (scripts?.replaceByProjectName) {
const { search } = scripts.replaceByProjectName

// Handle either root-based or paths-based replacement
if ("root" in scripts.replaceByProjectName) {
const { root: searchRoot } = scripts.replaceByProjectName
const fullSearchPath = path.join(root, searchRoot)

// Find all files under root path using globby
const files = await globby("**/*", {
cwd: fullSearchPath,
absolute: true,
})

// Replace in each file
for (const filePath of files) {
applyConfigTask.log(`Replacing "${search}" with project name in ${filePath}`)
const content = await fs.readFile(filePath, "utf-8")
const updatedContent = content.replaceAll(search, config.name)
await fs.writeFile(filePath, updatedContent)
}
} else {
const { paths: searchPaths } = scripts.replaceByProjectName
// Replace in specific paths using globby
for (const searchPath of searchPaths) {
const fullPath = path.join(root, searchPath)

const files = await globby(fullPath, {
absolute: true,
})

for (const filePath of files) {
applyConfigTask.log(`Replacing "${search}" with project name in ${filePath}`)
const content = await fs.readFile(filePath, "utf-8")
const updatedContent = content.replaceAll(search, config.name)
await fs.writeFile(filePath, updatedContent)
}
}
}
}
}

//* Delete config.json
// applyConfigTask.log("Deleting the config file")
// await fs.remove(configPath)
Expand Down
28 changes: 28 additions & 0 deletions packages/cli-helpers/src/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,34 @@ export const pluginConfigSchema = z.object({
),
})
),
scripts: z.object({
replaceByProjectName: z
.object({
search: z.string(),
root: z.string().refine(
(value) => {
if (!isPathInCurrentScope(value)) {
return false
}
return true
},
{ message: "The path should be relative and in the current directory" }
),
})
.or(
z.object({
search: z.string(),
paths: z.array(
z.string().refine((value) => {
if (!isPathInCurrentScope(value)) {
return false
}
return true
})
),
})
),
}),
})

export type TPluginConfig = z.infer<typeof pluginConfigSchema>

0 comments on commit 4f28bcd

Please sign in to comment.