dynamate-design-to-code
Version:
A powerful tool for converting Figma designs into high-quality, production-ready code with built-in best practices and customizable rulesets
111 lines • 3.68 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.sanitizeFileName = exports.createBackup = exports.isValidFigmaFileId = exports.formatPath = exports.extractDependencies = exports.isValidComponentName = exports.ensureDir = exports.toPascalCase = void 0;
const path_1 = __importDefault(require("path"));
const promises_1 = __importDefault(require("fs/promises"));
/**
* Converts a string to PascalCase
*/
function toPascalCase(str) {
return str
.split(/[-_\s]+/)
.map(word => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
.join('');
}
exports.toPascalCase = toPascalCase;
/**
* Ensures a directory exists, creating it if necessary
*/
async function ensureDir(dir) {
try {
await promises_1.default.access(dir);
}
catch {
await promises_1.default.mkdir(dir, { recursive: true });
}
}
exports.ensureDir = ensureDir;
/**
* Validates a component name
*/
function isValidComponentName(name) {
return /^[A-Z][a-zA-Z0-9]*$/.test(name);
}
exports.isValidComponentName = isValidComponentName;
/**
* Extracts dependencies from code
*/
function extractDependencies(code) {
const importRegex = /import\s+?(?:(?:(?:[\w*\s{},]*)\s+from\s+?)|)(?:(?:".*?")|(?:'.*?'))[\s]*?(?:;|$|)/g;
const matches = code.match(importRegex) || [];
return matches
.map(match => {
const packageMatch = match.match(/from\s+['"]([^'"]+)['"]/);
return packageMatch ? packageMatch[1] : '';
})
.filter(Boolean);
}
exports.extractDependencies = extractDependencies;
/**
* Formats a file path according to the operating system
*/
function formatPath(...parts) {
return path_1.default.join(...parts).replace(/\\/g, '/');
}
exports.formatPath = formatPath;
/**
* Validates a Figma file ID
*/
function isValidFigmaFileId(fileId) {
return /^[a-zA-Z0-9-_]+$/.test(fileId);
}
exports.isValidFigmaFileId = isValidFigmaFileId;
/**
* Creates a backup of an existing file
*/
async function createBackup(filePath) {
try {
const exists = await promises_1.default.access(filePath)
.then(() => true)
.catch(() => false);
if (exists) {
const backupPath = `${filePath}.backup`;
await promises_1.default.copyFile(filePath, backupPath);
}
}
catch (error) {
console.error('Error creating backup:', error);
}
}
exports.createBackup = createBackup;
/**
* Sanitizes a filename
*/
function sanitizeFileName(name) {
return name
.replace(/[^a-zA-Z0-9-_]/g, '-')
.replace(/-+/g, '-')
.toLowerCase();
}
exports.sanitizeFileName = sanitizeFileName;
__exportStar(require("./figma"), exports);
__exportStar(require("./files"), exports);
__exportStar(require("./ruleset-generator"), exports);
//# sourceMappingURL=index.js.map