-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Description
I'm currently working with tikui on a project and I regularly have components that change depending on an element.
Example:
mixin test-button(options)
-const opt = options || {}
-const classList = [];
-if (opt.isRed) classList.push('-red');
-if (opt.isBlue) { classList.push('-blue') };
-const classes = classList.length > 0 ? classList.join(' ') : null;
button.test-button(disabled=opt.isDisabled, class=classes)I would like to propose that we add to CLI the possibility to add options to mixin:
program
.command('create <component> [destination]')
.option('-p, --prefix <name>', 'prefix')
.option('-mo, --mixin-options', 'add options parameter to mixin')
.description('create a component.')
.addHelpText('after', '\nExample:\n $ tikui create -p tikui component src/atom')
.action((component, destination, options) => {
createComponent(destination, component, options.prefix, options.mixinOptions);
console.log(`Creating component ${component} to ${path.resolve(destination)}`); // eslint-disable-line no-console
});To get this result :
mixin test-component(options)
-const opt = options || {};
-const classList = [];
-const classes = classList.length > 0 ? classList.join(' ') : null;
.test-component(class=classes) test-componentThe createMixin function will be like this:
const createMixin = (componentDirectory: string, component: string, prefix?: string, mixinOptions?: boolean): void => {
let content = `mixin ${dashPrefix(prefix)}${component}\n .${dashPrefix(prefix)}${component} ${component}\n`;
if(mixinOptions){
content = `mixin ${dashPrefix(prefix)}${component}(options)
-const opt = options || {};
-const classList = [];
-const classes = classList.length > 0 ? classList.join(' ') : null;
.${dashPrefix(prefix)}${component}(class=classes) ${component}\n`;
}
const file = `${component}.mixin.pug`;
createFile(componentDirectory, file);
fs.writeFileSync(path.resolve(componentDirectory, file), content);
};What do you think ?
Metadata
Metadata
Assignees
Labels
No labels