Skip to content

Commit

Permalink
Merge pull request #418 from ieedan/config-files
Browse files Browse the repository at this point in the history
feat: 🎉 Add config files on init 🎉
  • Loading branch information
ieedan authored Feb 7, 2025
2 parents 4840863 + 34198ac commit 21f8cb8
Show file tree
Hide file tree
Showing 21 changed files with 759 additions and 360 deletions.
5 changes: 5 additions & 0 deletions .changeset/few-points-play.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"jsrepo": patch
---

updated: During project init you will now be prompted to initialize registries after being prompted for the formatter.
5 changes: 5 additions & 0 deletions .changeset/lazy-pandas-relate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"jsrepo": patch
---

fix: Fix an issue where the same registry would be duplicated in the config if you ran init multiple times on that registry.
5 changes: 5 additions & 0 deletions .changeset/modern-rats-agree.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"jsrepo": patch
---

fix: Always configure registries provided as args on init.
5 changes: 5 additions & 0 deletions .changeset/rotten-trees-sort.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"jsrepo": minor
---

feat: Use "✨ Update with AI ✨" to update your config files on `init` 🎉
5 changes: 5 additions & 0 deletions .changeset/silver-crabs-arrive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"jsrepo": minor
---

feat: 🎉 Specify config files to add on `init` from `jsrepo-build-config.json` 🎉
2 changes: 1 addition & 1 deletion examples/registry/jsrepo-build-config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "https://unpkg.com/[email protected]/schemas/project-config.json",
"$schema": "https://unpkg.com/[email protected]/schemas/registry-config.json",
"meta": {
"authors": ["Aidan Bleser"],
"description": "An example registry",
Expand Down
Empty file added examples/registry/src/app.css
Empty file.
20 changes: 4 additions & 16 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,7 @@
"bugs": {
"url": "https://github.com/ieedan/jsrepo/issues"
},
"keywords": [
"repo",
"cli",
"svelte",
"vue",
"typescript",
"javascript",
"shadcn",
"registry"
],
"keywords": ["repo", "cli", "svelte", "vue", "typescript", "javascript", "shadcn", "registry"],
"type": "module",
"exports": {
".": {
Expand All @@ -34,10 +25,7 @@
},
"bin": "./dist/index.js",
"main": "./dist/index.js",
"files": [
"./schemas/**/*",
"dist/**/*"
],
"files": ["./schemas/**/*", "dist/**/*"],
"scripts": {
"start": "tsup --silent && node ./dist/index.js",
"build": "tsup",
Expand Down Expand Up @@ -75,15 +63,15 @@
"get-tsconfig": "^4.10.0",
"ignore": "^7.0.3",
"node-fetch": "^3.3.2",
"octokit": "^4.1.0",
"octokit": "^4.1.1",
"ollama": "^0.5.12",
"openai": "^4.83.0",
"package-manager-detector": "^0.2.9",
"parse5": "^7.2.1",
"pathe": "^2.0.2",
"prettier": "^3.4.2",
"semver": "^7.7.1",
"svelte": "^5.19.8",
"svelte": "^5.19.9",
"ts-morph": "^25.0.1",
"valibot": "1.0.0-beta.15",
"validate-npm-package-name": "^6.0.0",
Expand Down
7 changes: 7 additions & 0 deletions packages/cli/schemas/project-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@
"type": "string",
"enum": ["prettier", "biome"]
},
"configFiles": {
"description": "Config file names mapped to their respective path.",
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"paths": {
"description": "Paths used to map categories to a directory.",
"type": "object",
Expand Down
36 changes: 35 additions & 1 deletion packages/cli/schemas/registry-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,33 @@
}
}
},
"configFiles": {
"description": "Any config files that should be included when initializing the registry.",
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"description": "Name of the config file.",
"type": "string"
},
"path": {
"description": "Path where the config file lives.",
"type": "string"
},
"expectedPath": {
"description": "Path to default to searching in the users project.",
"type": "string"
},
"optional": {
"description": "Config file is optional and the user will be prompted accordingly.",
"type": "boolean",
"default": false
}
},
"required": ["name", "path"]
}
},
"dirs": {
"description": "Directories that contain the categories you want to build into the manifest.",
"type": "array",
Expand Down Expand Up @@ -180,6 +207,12 @@
"type": "string",
"enum": ["error", "warn", "off"],
"default": "warn"
},
"require-config-file-exists": {
"description": "Require all of the paths listed in `configFiles` to exist.",
"type": "string",
"enum": ["error", "warn", "off"],
"default": "error"
}
},
"default": {
Expand All @@ -189,7 +222,8 @@
"max-local-dependencies": ["warn", 10],
"no-circular-dependency": "error",
"no-unused-block": "warn",
"no-framework-dependency": "warn"
"no-framework-dependency": "warn",
"require-config-file-exists": "error"
}
}
},
Expand Down
23 changes: 19 additions & 4 deletions packages/cli/src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,8 @@ const _build = async (options: Options) => {

for (const category of builtCategories) {
if (categories.find((cat) => cat.name === category.name) !== undefined) {
const error = 'a category with the same name already exists!';

console.warn(
`${ascii.VERTICAL_LINE} ${ascii.WARN} Skipped adding \`${color.cyan(`${dir}/${category.name}`)}\` because ${error}`
`${ascii.VERTICAL_LINE} ${ascii.WARN} Skipped adding \`${color.cyan(`${dir}/${category.name}`)}\` because a category with the same name already exists!`
);
continue;
}
Expand All @@ -209,7 +207,7 @@ const _build = async (options: Options) => {

loading.start('Checking manifest');

const { warnings, errors } = runRules(manifest, config, config.rules);
const { warnings, errors } = runRules(manifest, config, options.cwd, config.rules);

loading.stop('Completed checking manifest.');

Expand Down Expand Up @@ -259,6 +257,22 @@ const _build = async (options: Options) => {
if (config.outputDir) {
loading.start(`Copying registry files to \`${color.cyan(outDir)}\``);

// copy config files to output directory
if (manifest.configFiles) {
for (const file of manifest.configFiles) {
const originalPath = path.join(options.cwd, file.path);
const destPath = path.join(outDir, file.path);

const containing = path.join(destPath, '../');

if (!fs.existsSync(containing)) {
fs.mkdirSync(containing, { recursive: true });
}

fs.copyFileSync(originalPath, destPath);
}
}

// copy the files for each block in each category
for (const category of manifest.categories) {
for (const block of category.blocks) {
Expand Down Expand Up @@ -292,6 +306,7 @@ const _build = async (options: Options) => {
export const createManifest = (categories: Category[], config: RegistryConfig) => {
const manifest: Manifest = {
meta: config.meta,
configFiles: config.configFiles,
categories,
};

Expand Down
Loading

0 comments on commit 21f8cb8

Please sign in to comment.