nucleus-ui-builder
Version:
149 lines (143 loc) • 4.85 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "default", {
enumerable: true,
get: function() {
return BootstrapConfig;
}
});
const _fs = /*#__PURE__*/ _interop_require_wildcard(require("fs"));
const _jsyaml = /*#__PURE__*/ _interop_require_wildcard(require("js-yaml"));
const _path = /*#__PURE__*/ _interop_require_wildcard(require("path"));
function _define_property(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function _getRequireWildcardCache(nodeInterop) {
if (typeof WeakMap !== "function") return null;
var cacheBabelInterop = new WeakMap();
var cacheNodeInterop = new WeakMap();
return (_getRequireWildcardCache = function(nodeInterop) {
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
})(nodeInterop);
}
function _interop_require_wildcard(obj, nodeInterop) {
if (!nodeInterop && obj && obj.__esModule) {
return obj;
}
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
return {
default: obj
};
}
var cache = _getRequireWildcardCache(nodeInterop);
if (cache && cache.has(obj)) {
return cache.get(obj);
}
var newObj = {
__proto__: null
};
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
for(var key in obj){
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
if (desc && (desc.get || desc.set)) {
Object.defineProperty(newObj, key, desc);
} else {
newObj[key] = obj[key];
}
}
}
newObj.default = obj;
if (cache) {
cache.set(obj, newObj);
}
return newObj;
}
class BootstrapConfig {
static run(filePath = `.nucleus.yml`) {
const targetPath = _path.resolve(process.cwd(), filePath);
if (_fs.existsSync(targetPath)) {
console.log(`✅ Configuration file "${filePath}" already exists.`);
return;
}
const yamlContent = _jsyaml.dump(this.defaultConfig);
_fs.writeFileSync(targetPath, yamlContent, `utf8`);
console.log(`🚀 Created default configuration at "${filePath}"`);
}
}
_define_property(BootstrapConfig, "defaultConfig", {
settings: {
rootDirectory: `./src`
},
categories: [
{
name: `Atom`,
path: `/atom`
}
],
templates: {
component: {
extensions: [],
files: [
{
name: `{{componentName}}.tsx`,
content: `
import React from 'react';
import { I{{componentName}}Props } from './interface';
const {{componentName}}: React.FC<I{{componentName}}Props> = ({}) => {
return <div>{{componentName}}</div>;
};
export default {{componentName}};
`
},
{
name: `interface.ts`,
content: `export interface I{{componentName}}Props {};`
},
{
name: `index.ts`,
content: `
export { default } from './{{componentName}}';
export * from './interface';
`
},
{
name: `{{componentName}}.test.tsx`,
condition: `storybook`,
content: `
import React from 'react';
import { ComponentMeta, ComponentStory } from '@storybook/react';
import {{componentName}} from './{{componentName}}';
export default {
title: '{{category}}/{{subcategory}}/{{componentName}}',
component: {{componentName}},
argTypes: {
// Add controls for props if needed
},
} as ComponentMeta<typeof {{componentName}}>;
const Template: ComponentStory<typeof {{componentName}}> = (args) => <{{componentName}} {...args} />;
export const Default = Template.bind({});
Default.args = {
// Define default props here
};
`
}
]
}
}
});
if (require("url").pathToFileURL(__filename).toString() === `file://${process.argv[1]}`) BootstrapConfig.run();
//# sourceMappingURL=bootstrap.config.js.map