regify 1.0.0
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/LICENSE +15 -0
- package/README.md +53 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +50 -0
- package/dist/index.js.map +1 -0
- package/dist/scripts/index.d.ts +21 -0
- package/dist/scripts/index.d.ts.map +1 -0
- package/dist/scripts/index.js +18 -0
- package/dist/scripts/index.js.map +1 -0
- package/dist/src/commands/generate.d.ts +14 -0
- package/dist/src/commands/generate.d.ts.map +1 -0
- package/dist/src/commands/generate.js +152 -0
- package/dist/src/commands/generate.js.map +1 -0
- package/dist/src/commands/init.d.ts +2 -0
- package/dist/src/commands/init.d.ts.map +1 -0
- package/dist/src/commands/init.js +29 -0
- package/dist/src/commands/init.js.map +1 -0
- package/dist/src/constant/current-version.d.ts +2 -0
- package/dist/src/constant/current-version.d.ts.map +1 -0
- package/dist/src/constant/current-version.js +2 -0
- package/dist/src/constant/current-version.js.map +1 -0
- package/dist/src/constant/registry-structure.d.ts +3 -0
- package/dist/src/constant/registry-structure.d.ts.map +1 -0
- package/dist/src/constant/registry-structure.js +9 -0
- package/dist/src/constant/registry-structure.js.map +1 -0
- package/dist/src/schema/generate.d.ts +19 -0
- package/dist/src/schema/generate.d.ts.map +1 -0
- package/dist/src/schema/generate.js +42 -0
- package/dist/src/schema/generate.js.map +1 -0
- package/dist/src/types/index.d.ts +79 -0
- package/dist/src/types/index.d.ts.map +1 -0
- package/dist/src/types/index.js +2 -0
- package/dist/src/types/index.js.map +1 -0
- package/dist/src/utils/detect-registry-type.d.ts +28 -0
- package/dist/src/utils/detect-registry-type.d.ts.map +1 -0
- package/dist/src/utils/detect-registry-type.js +134 -0
- package/dist/src/utils/detect-registry-type.js.map +1 -0
- package/dist/src/utils/generate-registry.d.ts +9 -0
- package/dist/src/utils/generate-registry.d.ts.map +1 -0
- package/dist/src/utils/generate-registry.js +215 -0
- package/dist/src/utils/generate-registry.js.map +1 -0
- package/dist/src/utils/logger.d.ts +4 -0
- package/dist/src/utils/logger.d.ts.map +1 -0
- package/dist/src/utils/logger.js +9 -0
- package/dist/src/utils/logger.js.map +1 -0
- package/dist/src/utils/read-config.d.ts +3 -0
- package/dist/src/utils/read-config.d.ts.map +1 -0
- package/dist/src/utils/read-config.js +10 -0
- package/dist/src/utils/read-config.js.map +1 -0
- package/dist/src/utils/save-file.d.ts +3 -0
- package/dist/src/utils/save-file.d.ts.map +1 -0
- package/dist/src/utils/save-file.js +18 -0
- package/dist/src/utils/save-file.js.map +1 -0
- package/dist/src/utils/validate-options.d.ts +3 -0
- package/dist/src/utils/validate-options.d.ts.map +1 -0
- package/dist/src/utils/validate-options.js +23 -0
- package/dist/src/utils/validate-options.js.map +1 -0
- package/package.json +68 -0
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
/**
|
|
3
|
+
* Registry type constants
|
|
4
|
+
*/
|
|
5
|
+
export const REGISTRY_TYPES = {
|
|
6
|
+
UI: "registry:ui",
|
|
7
|
+
HOOK: "registry:hook",
|
|
8
|
+
LIB: "registry:lib",
|
|
9
|
+
STYLE: "registry:style",
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* File extensions for different types
|
|
13
|
+
*/
|
|
14
|
+
const STYLE_EXTENSIONS = [".css", ".scss", ".sass", ".less"];
|
|
15
|
+
const CODE_EXTENSIONS = [".ts", ".tsx", ".js", ".jsx"];
|
|
16
|
+
/**
|
|
17
|
+
* Path patterns for type detection
|
|
18
|
+
*/
|
|
19
|
+
const PATH_PATTERNS = {
|
|
20
|
+
UI: ["/ui/", "\\ui\\", "/components/ui/", "\\components\\ui\\"],
|
|
21
|
+
HOOK: ["/hooks/", "\\hooks\\"],
|
|
22
|
+
LIB: ["/lib/", "\\lib\\", "/utils/", "\\utils\\"],
|
|
23
|
+
STYLE: ["/styles/", "\\styles\\", "/css/", "\\css\\"],
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Detects if a file is a style file based on its extension
|
|
27
|
+
*/
|
|
28
|
+
function isStyleFile(fileExt) {
|
|
29
|
+
return STYLE_EXTENSIONS.includes(fileExt);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Detects type based on file path patterns
|
|
33
|
+
*/
|
|
34
|
+
function detectTypeByPath(relativePath) {
|
|
35
|
+
for (const [type, patterns] of Object.entries(PATH_PATTERNS)) {
|
|
36
|
+
if (patterns.some((pattern) => relativePath.includes(pattern))) {
|
|
37
|
+
return REGISTRY_TYPES[type];
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Detects if a file is a hook based on naming convention
|
|
44
|
+
*/
|
|
45
|
+
function isHookByNaming(fileName, fileExt) {
|
|
46
|
+
return fileName.startsWith("use") && CODE_EXTENSIONS.includes(fileExt);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Analyzes the source file content to detect if it's a React hook
|
|
50
|
+
*/
|
|
51
|
+
function isHookByContent(sourceFile) {
|
|
52
|
+
try {
|
|
53
|
+
// Check for exported functions starting with "use"
|
|
54
|
+
const exportedFunctions = sourceFile
|
|
55
|
+
.getFunctions()
|
|
56
|
+
.filter((fn) => fn.isExported());
|
|
57
|
+
return exportedFunctions.some((fn) => {
|
|
58
|
+
const name = fn.getName();
|
|
59
|
+
return name && name.startsWith("use");
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Analyzes the source file content to detect if it's a React UI component
|
|
68
|
+
*/
|
|
69
|
+
function isUIComponent(sourceFile, fileExt) {
|
|
70
|
+
if (![".tsx", ".jsx"].includes(fileExt))
|
|
71
|
+
return false;
|
|
72
|
+
try {
|
|
73
|
+
const content = sourceFile.getFullText();
|
|
74
|
+
// Check for JSX syntax (common indicators)
|
|
75
|
+
const hasJSXReturn = content.includes("return (") || content.includes("return<");
|
|
76
|
+
const hasJSXElements = /\<[A-Z]/.test(content) || /\<[a-z]+\s/.test(content);
|
|
77
|
+
return hasJSXReturn && hasJSXElements;
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Main function to detect registry type based on file path, name, and content
|
|
85
|
+
*
|
|
86
|
+
* Detection priority:
|
|
87
|
+
* 1. File extension (style files)
|
|
88
|
+
* 2. Naming convention (e.g., use-* for hooks)
|
|
89
|
+
* 3. Path-based detection (most reliable for organized projects)
|
|
90
|
+
* 4. Content analysis (for ambiguous cases)
|
|
91
|
+
* 5. Default fallback (lib)
|
|
92
|
+
*
|
|
93
|
+
* @param filePath - Absolute path to the file
|
|
94
|
+
* @param rootDir - Root directory of the project
|
|
95
|
+
* @param sourceFile - ts-morph SourceFile object (optional)
|
|
96
|
+
* @returns Registry type (e.g., "registry:ui")
|
|
97
|
+
*/
|
|
98
|
+
export function detectRegistryType(filePath, rootDir, sourceFile = null) {
|
|
99
|
+
try {
|
|
100
|
+
const fileName = path.basename(filePath);
|
|
101
|
+
const fileExt = path.extname(filePath);
|
|
102
|
+
const relativePath = path.relative(rootDir, filePath).replace(/\\/g, "/");
|
|
103
|
+
// 1. Check if it's a style file
|
|
104
|
+
if (isStyleFile(fileExt)) {
|
|
105
|
+
return REGISTRY_TYPES.STYLE;
|
|
106
|
+
}
|
|
107
|
+
// 2. Naming convention detection
|
|
108
|
+
if (isHookByNaming(fileName, fileExt)) {
|
|
109
|
+
return REGISTRY_TYPES.HOOK;
|
|
110
|
+
}
|
|
111
|
+
// 3. Path-based detection (highest priority for code files)
|
|
112
|
+
const pathBasedType = detectTypeByPath(relativePath);
|
|
113
|
+
if (pathBasedType) {
|
|
114
|
+
return pathBasedType;
|
|
115
|
+
}
|
|
116
|
+
// 4. Content analysis (only for JS/TS files)
|
|
117
|
+
if (sourceFile && CODE_EXTENSIONS.includes(fileExt)) {
|
|
118
|
+
// Check for hooks first
|
|
119
|
+
if (isHookByContent(sourceFile)) {
|
|
120
|
+
return REGISTRY_TYPES.HOOK;
|
|
121
|
+
}
|
|
122
|
+
// Check for UI components
|
|
123
|
+
if (isUIComponent(sourceFile, fileExt)) {
|
|
124
|
+
return REGISTRY_TYPES.UI;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
// 5. Default fallback - assume it's a utility/library file
|
|
128
|
+
return REGISTRY_TYPES.LIB;
|
|
129
|
+
}
|
|
130
|
+
catch (err) {
|
|
131
|
+
throw new Error(`Failed to detect registry type for ${filePath}: ${err.message}`);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
//# sourceMappingURL=detect-registry-type.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detect-registry-type.js","sourceRoot":"","sources":["../../../src/utils/detect-registry-type.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAIxB;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,EAAE,EAAE,aAAa;IACjB,IAAI,EAAE,eAAe;IACrB,GAAG,EAAE,cAAc;IACnB,KAAK,EAAE,gBAAgB;CACf,CAAC;AAEX;;GAEG;AACH,MAAM,gBAAgB,GAAa,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;AACvE,MAAM,eAAe,GAAa,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;AAEjE;;GAEG;AACH,MAAM,aAAa,GAAkD;IACnE,EAAE,EAAE,CAAC,MAAM,EAAE,QAAQ,EAAE,iBAAiB,EAAE,oBAAoB,CAAC;IAC/D,IAAI,EAAE,CAAC,SAAS,EAAE,WAAW,CAAC;IAC9B,GAAG,EAAE,CAAC,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE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AG,gBAAgB,CAAC,YAAY,CAAC,CAAC;QACrD,IAAI,aAAa,EAAE,CAAC;YAClB,OAAO,aAAa,CAAC;QACvB,CAAC;QAED,6CAA6C;QAC7C,IAAI,UAAU,IAAI,eAAe,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;YACpD,wBAAwB;YACxB,IAAI,eAAe,CAAC,UAAU,CAAC,EAAE,CAAC;gBAChC,OAAO,cAAc,CAAC,IAAI,CAAC;YAC7B,CAAC;YAED,0BAA0B;YAC1B,IAAI,aAAa,CAAC,UAAU,EAAE,OAAO,CAAC,EAAE,CAAC;gBACvC,OAAO,cAAc,CAAC,EAAE,CAAC;YAC3B,CAAC;QACH,CAAC;QAED,2DAA2D;QAC3D,OAAO,cAAc,CAAC,GAAG,CAAC;IAC5B,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CACb,sCAAsC,QAAQ,KAAM,GAAa,CAAC,OAAO,EAAE,CAC5E,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { RegifyConfig, RegistryJson } from "../types/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Generates a registry JSON file for the given component or directory of components.
|
|
4
|
+
* @param entryFilePath - Path to the component file or directory.
|
|
5
|
+
* @param REGIFY_CONFIG - Configuration object for the registry.
|
|
6
|
+
* @returns The generated registry JSON object.
|
|
7
|
+
*/
|
|
8
|
+
export declare function generateRegistry(entryFilePath: string, REGIFY_CONFIG: RegifyConfig): RegistryJson;
|
|
9
|
+
//# sourceMappingURL=generate-registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-registry.d.ts","sourceRoot":"","sources":["../../../src/utils/generate-registry.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,YAAY,EACZ,YAAY,EAGb,MAAM,mBAAmB,CAAC;AAqE3B;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,aAAa,EAAE,MAAM,EACrB,aAAa,EAAE,YAAY,GAC1B,YAAY,CAoLd"}
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { Project } from "ts-morph";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import fs from "fs";
|
|
4
|
+
import { detectRegistryType } from "./detect-registry-type.js";
|
|
5
|
+
/**
|
|
6
|
+
* Robustly finds a configuration file by walking up the directory tree.
|
|
7
|
+
*/
|
|
8
|
+
function findConfigFile(startDir, filenames) {
|
|
9
|
+
let currentDir = path.resolve(startDir);
|
|
10
|
+
while (true) {
|
|
11
|
+
for (const filename of filenames) {
|
|
12
|
+
const filePath = path.join(currentDir, filename);
|
|
13
|
+
if (fs.existsSync(filePath))
|
|
14
|
+
return filePath;
|
|
15
|
+
}
|
|
16
|
+
const parentDir = path.dirname(currentDir);
|
|
17
|
+
if (parentDir === currentDir)
|
|
18
|
+
break;
|
|
19
|
+
currentDir = parentDir;
|
|
20
|
+
}
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Detects if the current project is a monorepo and returns workspace info.
|
|
25
|
+
*/
|
|
26
|
+
function getWorkspaceInfo(rootPath) {
|
|
27
|
+
const pkgJsonPath = path.join(rootPath, "package.json");
|
|
28
|
+
if (!fs.existsSync(pkgJsonPath))
|
|
29
|
+
return null;
|
|
30
|
+
try {
|
|
31
|
+
const pkg = JSON.parse(fs.readFileSync(pkgJsonPath, "utf-8"));
|
|
32
|
+
// check workspace keyword in the dependency to identify, if it is a monorepo and help to detect the workspace components or code
|
|
33
|
+
const dependencies = pkg.dependencies || {};
|
|
34
|
+
const dependenciesKeys = Object.keys(dependencies);
|
|
35
|
+
const workspaceDependencies = dependenciesKeys.filter((dependency) => dependencies[dependency].includes("workspace"));
|
|
36
|
+
const isMonorepo = !!(workspaceDependencies.length > 0 ||
|
|
37
|
+
pkg.workspaces ||
|
|
38
|
+
fs.existsSync(path.join(rootPath, "pnpm-workspace.yaml")) ||
|
|
39
|
+
fs.existsSync(path.join(rootPath, "lerna.json")));
|
|
40
|
+
const dependenciesList = [
|
|
41
|
+
...Object.keys(pkg.dependencies || {}),
|
|
42
|
+
...Object.keys(pkg.devDependencies || {}),
|
|
43
|
+
...Object.keys(pkg.peerDependencies || {}),
|
|
44
|
+
].filter((dep) => {
|
|
45
|
+
return !workspaceDependencies.includes(dep);
|
|
46
|
+
});
|
|
47
|
+
return {
|
|
48
|
+
isMonorepo,
|
|
49
|
+
workspaces: Array.isArray(pkg.workspaces)
|
|
50
|
+
? pkg.workspaces
|
|
51
|
+
: pkg.workspaces?.packages || [],
|
|
52
|
+
dependencies: new Set([...dependenciesList]),
|
|
53
|
+
workspaceDependencies: new Set([...workspaceDependencies]),
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Generates a registry JSON file for the given component or directory of components.
|
|
62
|
+
* @param entryFilePath - Path to the component file or directory.
|
|
63
|
+
* @param REGIFY_CONFIG - Configuration object for the registry.
|
|
64
|
+
* @returns The generated registry JSON object.
|
|
65
|
+
*/
|
|
66
|
+
export function generateRegistry(entryFilePath, REGIFY_CONFIG) {
|
|
67
|
+
const absoluteEntryPath = path.resolve(entryFilePath);
|
|
68
|
+
const configRegistryDependencies = REGIFY_CONFIG.registryDependencies || {};
|
|
69
|
+
const basePath = (REGIFY_CONFIG.basePath || "");
|
|
70
|
+
if (!fs.existsSync(absoluteEntryPath)) {
|
|
71
|
+
throw new Error(`Entry file not found: ${absoluteEntryPath}`);
|
|
72
|
+
}
|
|
73
|
+
const projectDir = path.dirname(absoluteEntryPath);
|
|
74
|
+
const tsConfigPath = findConfigFile(projectDir, [
|
|
75
|
+
"tsconfig.json",
|
|
76
|
+
"jsconfig.json",
|
|
77
|
+
]);
|
|
78
|
+
// Initialize ts-morph project
|
|
79
|
+
const project = new Project({
|
|
80
|
+
tsConfigFilePath: tsConfigPath || undefined,
|
|
81
|
+
compilerOptions: !tsConfigPath
|
|
82
|
+
? {
|
|
83
|
+
allowJs: true,
|
|
84
|
+
moduleResolution: 2, // Node
|
|
85
|
+
resolveJsonModule: true,
|
|
86
|
+
jsx: 1, // Preserve
|
|
87
|
+
}
|
|
88
|
+
: undefined,
|
|
89
|
+
skipAddingFilesFromTsConfig: true,
|
|
90
|
+
});
|
|
91
|
+
const rootPkgPath = findConfigFile(projectDir, ["package.json"]);
|
|
92
|
+
const rootDir = rootPkgPath ? path.dirname(rootPkgPath) : process.cwd();
|
|
93
|
+
const workspaceInfo = getWorkspaceInfo(rootDir);
|
|
94
|
+
const visitedFiles = new Set();
|
|
95
|
+
const dependencyStack = [];
|
|
96
|
+
// Initialize registry for each generation to avoid shared state mutations
|
|
97
|
+
const registry = {
|
|
98
|
+
name: path.basename(entryFilePath, path.extname(entryFilePath)),
|
|
99
|
+
type: null,
|
|
100
|
+
dependencies: new Set(),
|
|
101
|
+
devDependencies: new Set(),
|
|
102
|
+
registryDependencies: new Set(),
|
|
103
|
+
files: [],
|
|
104
|
+
};
|
|
105
|
+
// Add a validator for duplicate file processing
|
|
106
|
+
const processedFiles = new Set();
|
|
107
|
+
function processFile(filePath) {
|
|
108
|
+
if (processedFiles.has(filePath))
|
|
109
|
+
return;
|
|
110
|
+
processedFiles.add(filePath);
|
|
111
|
+
const absolutePath = path.resolve(filePath);
|
|
112
|
+
// Circular dependency check
|
|
113
|
+
if (dependencyStack.includes(absolutePath)) {
|
|
114
|
+
const chain = [...dependencyStack, absolutePath]
|
|
115
|
+
.map((p) => path.relative(rootDir, p))
|
|
116
|
+
.join(" -> ");
|
|
117
|
+
throw new Error(`Circular dependency detected: ${chain}`);
|
|
118
|
+
}
|
|
119
|
+
if (visitedFiles.has(absolutePath))
|
|
120
|
+
return;
|
|
121
|
+
visitedFiles.add(absolutePath);
|
|
122
|
+
dependencyStack.push(absolutePath);
|
|
123
|
+
const sourceFile = project.addSourceFileAtPath(absolutePath);
|
|
124
|
+
const content = sourceFile.getFullText();
|
|
125
|
+
// Detect the registry type for this file
|
|
126
|
+
const fileType = detectRegistryType(absolutePath, rootDir, sourceFile);
|
|
127
|
+
// Set the main registry type based on the entry file (first file processed)
|
|
128
|
+
if (registry.type === null) {
|
|
129
|
+
registry.type = fileType;
|
|
130
|
+
}
|
|
131
|
+
// Add file to registry
|
|
132
|
+
registry.files.push({
|
|
133
|
+
path: basePath
|
|
134
|
+
? path.join(basePath, path.basename(absolutePath)).replace(/\\/g, "/")
|
|
135
|
+
: path.relative(rootDir, absolutePath).replace(/\\/g, "/"),
|
|
136
|
+
content: content,
|
|
137
|
+
type: fileType,
|
|
138
|
+
});
|
|
139
|
+
// Analyze imports
|
|
140
|
+
const imports = sourceFile.getImportDeclarations();
|
|
141
|
+
for (const importDecl of imports) {
|
|
142
|
+
const moduleSpecifier = importDecl.getModuleSpecifierValue();
|
|
143
|
+
// Try to resolve the module to a source file
|
|
144
|
+
const resolvedSourceFile = importDecl.getModuleSpecifierSourceFile();
|
|
145
|
+
if (resolvedSourceFile) {
|
|
146
|
+
// It's a local file or a workspace package resolved by ts-morph
|
|
147
|
+
const resolvedPath = resolvedSourceFile.getFilePath();
|
|
148
|
+
const normalizedRootDir = rootDir.toLowerCase().replace(/\\/g, "/");
|
|
149
|
+
const normalizedResolvedPath = resolvedPath
|
|
150
|
+
.toLowerCase()
|
|
151
|
+
.replace(/\\/g, "/");
|
|
152
|
+
// If the resolved path is inside our project, it's a registry dependency (local file)
|
|
153
|
+
if (normalizedResolvedPath.startsWith(normalizedRootDir) &&
|
|
154
|
+
!normalizedResolvedPath.includes("node_modules")) {
|
|
155
|
+
const filename = path.basename(resolvedPath).split(".")[0];
|
|
156
|
+
const registryDependencies = Object.keys(configRegistryDependencies);
|
|
157
|
+
if (registryDependencies.includes(filename)) {
|
|
158
|
+
registry.registryDependencies.add(configRegistryDependencies[filename]);
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
processFile(resolvedPath);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
else if (workspaceInfo?.isMonorepo &&
|
|
165
|
+
!normalizedResolvedPath.includes("node_modules")) {
|
|
166
|
+
// It's outside project root so, its code will be added
|
|
167
|
+
const isWorkspaceDependency = [
|
|
168
|
+
...workspaceInfo.workspaceDependencies,
|
|
169
|
+
].find((dep) => moduleSpecifier.includes(dep));
|
|
170
|
+
if (!isWorkspaceDependency) {
|
|
171
|
+
registry.dependencies.add(moduleSpecifier);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
// It's in node_modules, treat as NPM dependency
|
|
176
|
+
registry.dependencies.add(moduleSpecifier);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
// Fallback resolution for common aliases if tsconfig didn't catch them
|
|
181
|
+
if (moduleSpecifier.startsWith(".") ||
|
|
182
|
+
moduleSpecifier.startsWith("@/")) {
|
|
183
|
+
throw new Error(`Could not resolve local import: "${moduleSpecifier}" in ${path.relative(rootDir, absolutePath)}. Ensure your tsconfig.json/jsconfig.json paths are correct.`);
|
|
184
|
+
}
|
|
185
|
+
// Check if it's a known dependency in package.json
|
|
186
|
+
if (workspaceInfo && workspaceInfo.dependencies.has(moduleSpecifier)) {
|
|
187
|
+
registry.dependencies.add(moduleSpecifier);
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
// Probably an NPM package that isn't explicitly in the nearest package.json
|
|
191
|
+
// or a scoped package, etc.
|
|
192
|
+
registry.dependencies.add(moduleSpecifier);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
dependencyStack.pop();
|
|
197
|
+
}
|
|
198
|
+
try {
|
|
199
|
+
processFile(absoluteEntryPath);
|
|
200
|
+
}
|
|
201
|
+
catch (error) {
|
|
202
|
+
throw new Error(`Failed to generate registry for ${entryFilePath}: ${error.message}`);
|
|
203
|
+
}
|
|
204
|
+
// Convert Sets to Arrays for final output - mapping explicitly to avoid spread iterator errors
|
|
205
|
+
const registryJson = {
|
|
206
|
+
name: registry.name,
|
|
207
|
+
type: registry.type,
|
|
208
|
+
dependencies: Array.from(registry.dependencies),
|
|
209
|
+
devDependencies: Array.from(registry.devDependencies),
|
|
210
|
+
registryDependencies: Array.from(registry.registryDependencies),
|
|
211
|
+
files: registry.files,
|
|
212
|
+
};
|
|
213
|
+
return registryJson;
|
|
214
|
+
}
|
|
215
|
+
//# sourceMappingURL=generate-registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-registry.js","sourceRoot":"","sources":["../../../src/utils/generate-registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AACnC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAQ/D;;GAEG;AACH,SAAS,cAAc,CAAC,QAAgB,EAAE,SAAmB;IAC3D,IAAI,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IACxC,OAAO,IAAI,EAAE,CAAC;QACZ,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;YACjC,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;YACjD,IAAI,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC;gBAAE,OAAO,QAAQ,CAAC;QAC/C,CAAC;QACD,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QAC3C,IAAI,SAAS,KAAK,UAAU;YAAE,MAAM;QACpC,UAAU,GAAG,SAAS,CAAC;IACzB,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;GAEG;AACH,SAAS,gBAAgB,CAAC,QAAgB;IACxC,MAAM,WAAW,GAAG,IAAI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K,CAAC,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC;QAC/C,eAAe,EAAE,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC;QACrD,oBAAoB,EAAE,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,oBAAoB,CAAC;QAC/D,KAAK,EAAE,QAAQ,CAAC,KAAK;KACtB,CAAC;IAEF,OAAO,YAAY,CAAC;AACtB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../../src/utils/logger.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEhD,QAAA,MAAM,MAAM,EAAE,MASb,CAAC;AAEF,eAAe,MAAM,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
const logger = {
|
|
3
|
+
error: (msg) => console.log(`${chalk.red.bold("Error:")} ${chalk.red(msg)}`),
|
|
4
|
+
success: (msg) => console.log(`${chalk.green.bold("Success:")} ${chalk.green(msg)}`),
|
|
5
|
+
info: (msg) => console.log(`${chalk.blue.bold("Info:")} ${chalk.blue(msg)}`),
|
|
6
|
+
warn: (msg) => console.log(`${chalk.yellow.bold("Warning:")} ${chalk.yellow(msg)}`),
|
|
7
|
+
};
|
|
8
|
+
export default logger;
|
|
9
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../../src/utils/logger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,MAAM,MAAM,GAAW;IACrB,KAAK,EAAE,CAAC,GAAW,EAAQ,EAAE,CAC3B,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;IAC9D,OAAO,EAAE,CAAC,GAAW,EAAQ,EAAE,CAC7B,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;IACpE,IAAI,EAAE,CAAC,GAAW,EAAQ,EAAE,CAC1B,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;IAC/D,IAAI,EAAE,CAAC,GAAW,EAAQ,EAAE,CAC1B,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;CACvE,CAAC;AAEF,eAAe,MAAM,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-config.d.ts","sourceRoot":"","sources":["../../../src/utils/read-config.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,wBAAsB,UAAU,IAAI,OAAO,CAAC,YAAY,CAAC,CAQxD"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
export async function readConfig() {
|
|
4
|
+
const regifyConfigPath = path.resolve(process.cwd(), "regify.json");
|
|
5
|
+
if (fs.existsSync(regifyConfigPath)) {
|
|
6
|
+
return JSON.parse(fs.readFileSync(regifyConfigPath, "utf-8"));
|
|
7
|
+
}
|
|
8
|
+
return {};
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=read-config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-config.js","sourceRoot":"","sources":["../../../src/utils/read-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AAGxB,MAAM,CAAC,KAAK,UAAU,UAAU;IAC9B,MAAM,gBAAgB,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,aAAa,CAAC,CAAC;IACpE,IAAI,EAAE,CAAC,UAAU,CAAC,gBAAgB,CAAC,EAAE,CAAC;QACpC,OAAO,IAAI,CAAC,KAAK,CACf,EAAE,CAAC,YAAY,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAC3B,CAAC;IACpB,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"save-file.d.ts","sourceRoot":"","sources":["../../../src/utils/save-file.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEtD,wBAAgB,QAAQ,CACtB,IAAI,EAAE,YAAY,EAClB,aAAa,EAAE,MAAM,EACrB,QAAQ,EAAE,MAAM,GACf,MAAM,CAoBR"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
export function saveFile(data, directoryPath, fileName) {
|
|
4
|
+
const componentName = fileName.split(".").shift() ?? "component";
|
|
5
|
+
const resolvedDirPath = path.resolve(directoryPath);
|
|
6
|
+
try {
|
|
7
|
+
if (!fs.existsSync(resolvedDirPath)) {
|
|
8
|
+
fs.mkdirSync(resolvedDirPath, { recursive: true });
|
|
9
|
+
}
|
|
10
|
+
const filePath = path.join(resolvedDirPath, fileName);
|
|
11
|
+
fs.writeFileSync(filePath, JSON.stringify(data, null, 2));
|
|
12
|
+
return path.relative(process.cwd(), filePath);
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
throw new Error(`Failed to save registry for ${componentName}: ${error.message || error}`);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=save-file.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"save-file.js","sourceRoot":"","sources":["../../../src/utils/save-file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AAGxB,MAAM,UAAU,QAAQ,CACtB,IAAkB,EAClB,aAAqB,EACrB,QAAgB;IAEhB,MAAM,aAAa,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,IAAI,WAAW,CAAC;IACjE,MAAM,eAAe,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;IAEpD,IAAI,CAAC;QACH,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,eAAe,CAAC,EAAE,CAAC;YACpC,EAAE,CAAC,SAAS,CAAC,eAAe,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QACrD,CAAC;QAED,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,QAAQ,CAAC,CAAC;QACtD,EAAE,CAAC,aAAa,CAAC,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;QAE1D,OAAO,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,QAAQ,CAAC,CAAC;IAChD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CACb,+BAA+B,aAAa,KACzC,KAAe,CAAC,OAAO,IAAI,KAC9B,EAAE,CACH,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate-options.d.ts","sourceRoot":"","sources":["../../../src/utils/validate-options.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAGxE,eAAO,MAAM,eAAe,GAC1B,SAAS,kBAAkB,KAC1B,eAgBF,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import z from "zod";
|
|
2
|
+
import generateSchema from "../schema/generate.js";
|
|
3
|
+
import logger from "./logger.js";
|
|
4
|
+
export const validateOptions = (options) => {
|
|
5
|
+
try {
|
|
6
|
+
const parsedOptions = generateSchema.parse(options);
|
|
7
|
+
return parsedOptions;
|
|
8
|
+
}
|
|
9
|
+
catch (error) {
|
|
10
|
+
if (error instanceof z.ZodError) {
|
|
11
|
+
logger.error("Invalid options provided:");
|
|
12
|
+
error.errors.forEach((err) => {
|
|
13
|
+
logger.error(`- ${err.message}`);
|
|
14
|
+
});
|
|
15
|
+
process.exit(1);
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
logger.error("An unexpected error occurred:");
|
|
19
|
+
process.exit(1);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=validate-options.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate-options.js","sourceRoot":"","sources":["../../../src/utils/validate-options.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,KAAK,CAAC;AACpB,OAAO,cAAc,MAAM,uBAAuB,CAAC;AAEnD,OAAO,MAAM,MAAM,aAAa,CAAC;AAEjC,MAAM,CAAC,MAAM,eAAe,GAAG,CAC7B,OAA2B,EACV,EAAE;IACnB,IAAI,CAAC;QACH,MAAM,aAAa,GAAG,cAAc,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACpD,OAAO,aAAa,CAAC;IACvB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,CAAC,CAAC,QAAQ,EAAE,CAAC;YAChC,MAAM,CAAC,KAAK,CAAC,2BAA2B,CAAC,CAAC;YAC1C,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;gBAC3B,MAAM,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;YACnC,CAAC,CAAC,CAAC;YACH,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,KAAK,CAAC,+BAA+B,CAAC,CAAC;YAC9C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;IACH,CAAC;AACH,CAAC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "regify",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Turn components into shareable registries - The Universal Component Registry CLI.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/scripts/index.js",
|
|
7
|
+
"types": "dist/scripts/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/scripts/index.d.ts",
|
|
11
|
+
"import": "./dist/scripts/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./scripts": {
|
|
14
|
+
"types": "./dist/scripts/index.d.ts",
|
|
15
|
+
"import": "./dist/scripts/index.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"bin": {
|
|
19
|
+
"regify": "dist/index.js"
|
|
20
|
+
},
|
|
21
|
+
"keywords": [
|
|
22
|
+
"regify",
|
|
23
|
+
"component-registry",
|
|
24
|
+
"cli",
|
|
25
|
+
"registry",
|
|
26
|
+
"component",
|
|
27
|
+
"react",
|
|
28
|
+
"metadata",
|
|
29
|
+
"generator",
|
|
30
|
+
"typescript"
|
|
31
|
+
],
|
|
32
|
+
"author": "Yashraj",
|
|
33
|
+
"license": "ISC",
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"chalk": "^5.3.0",
|
|
36
|
+
"commander": "^12.0.0",
|
|
37
|
+
"glob": "^13.0.1",
|
|
38
|
+
"ora": "^8.0.1",
|
|
39
|
+
"ts-morph": "^27.0.2",
|
|
40
|
+
"zod": "^3.22.4"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@types/node": "^22.0.0",
|
|
44
|
+
"tsx": "^4.7.0",
|
|
45
|
+
"typescript": "^5.3.3"
|
|
46
|
+
},
|
|
47
|
+
"homepage": "https://github.com/ameghcoder/regify#readme",
|
|
48
|
+
"repository": {
|
|
49
|
+
"type": "git",
|
|
50
|
+
"url": "git+https://github.com/ameghcoder/regify.git",
|
|
51
|
+
"directory": "packages/regify"
|
|
52
|
+
},
|
|
53
|
+
"bugs": {
|
|
54
|
+
"url": "https://github.com/ameghcoder/regify/issues"
|
|
55
|
+
},
|
|
56
|
+
"files": [
|
|
57
|
+
"dist",
|
|
58
|
+
"README.md",
|
|
59
|
+
"LICENSE"
|
|
60
|
+
],
|
|
61
|
+
"scripts": {
|
|
62
|
+
"dev": "tsx index.ts",
|
|
63
|
+
"build": "tsc",
|
|
64
|
+
"build:watch": "tsc --watch",
|
|
65
|
+
"typecheck": "tsc --noEmit",
|
|
66
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
67
|
+
}
|
|
68
|
+
}
|