import chalk from 'chalk'; import fs from 'fs'; import mkdirp from 'mkdirp'; import path from 'path'; import process from 'process'; const args = process.argv.slice(2); const tagName = (args[0] + '').toLowerCase().trim(); const tagNameWithoutPrefix = tagName.replace(/^sl-/, ''); const className = tagName.replace(/(^\w|-\w)/g, string => string.replace(/-/, '').toUpperCase()); const readableName = tagNameWithoutPrefix .replace(/-/g, ' ') .replace(/\w\S*/g, string => string.charAt(0).toUpperCase() + string.substr(1).toLowerCase()); const packageData = JSON.parse(fs.readFileSync('./package.json', 'utf8')); const minorVersion = packageData.version.split('.').slice(0, 2).join('.'); // Check for tag name if (!tagName) { console.error('Please provide a tag name for the new component.\n'); process.exit(); } // Verify tag name prefix if (!/^sl-/.test(tagName)) { console.error('Tag names must start with the sl- prefix.\n'); process.exit(); } // Generate a source file const componentFile = `src/components/${tagNameWithoutPrefix}/${tagNameWithoutPrefix}.ts`; if (fs.existsSync(componentFile)) { console.error(`There is already a component using the <${tagName}> tag!\n`); process.exit(); } const componentSource = ` import { LitElement, html, unsafeCSS } from 'lit'; import { customElement } from 'lit/decorators.js'; import styles from 'sass:./${tagNameWithoutPrefix}.scss'; /** * @since ${minorVersion} * @status experimental * * @dependency sl-tag-here * @dependency sl-tag-here * * @slot - The default slot. * @slot example - A named slot called example. * * @part base - The component's base wrapper. * * @customProperty example - An example custom property * * @animation example.show - An example animation. * @animation example.hide - An example animation. */ @customElement('${tagName}') export default class ${className} extends LitElement { static styles = unsafeCSS(styles); render() { return html\`