You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

151 lines
3.9 KiB

import path from 'path';
import Generator from "yeoman-generator";
import mkdirp from "mkdirp";
import {fileURLToPath} from 'url';
import {capitalize} from "../../helpers.js";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const baseDir = path.join(__dirname, '../../');
export default class extends Generator {
async prompting() {
this.data = await this.prompt([
{
type: "input",
name: "name",
message: "Block Name",
validate: (str) => {
const matches = str.match(/\d+/g);
if (matches != null) {
return false;
}
return !!str;
}
},
{
type: "input",
name: "group",
message: "Company/Organization Name",
validate: (str) => {
const matches = str.match(/\d+/g);
if (matches != null) {
return false;
}
return !!str;
}
},
{
type: "list",
name: "baseView",
message: "View Template",
default: 'container',
choices: ['container', 'alignfull'],
},
{
type: "number",
name: "remToPx",
message: "Provide declaration of 1rem:",
default: 16
},
{
type: 'input',
name: 'devToolSource',
message: 'DevTool Version/Source (master)',
default: 'git+https://roman-axe-web@bitbucket.org/axeweb/create-block-dev-tool.git#master'
}
]);
}
writing() {
const title = capitalize(this.data.name);
const group = capitalize(this.data.group);
const data = Object.assign(this.data, {
title,
blockFilename: title.toLowerCase().replace(/ /ig, '-'),
blockGroupName: group.toLowerCase().replace(/ /ig, '-'),
blockClassName: title.toLowerCase().replace(/ /ig, '_'),
});
const pathDist = path.join(baseDir, 'blocks', data.blockFilename);
this.fs.copyTpl(
this.templatePath('src/template.template.hbs'),
this.destinationPath(path.join(pathDist, 'src', data.blockFilename + '.template.hbs')),
data
);
this.fs.copyTpl(
this.templatePath('src/styles/template.scss'),
this.destinationPath(path.join(pathDist, 'src', 'styles', data.blockFilename + '.scss')),
data
);
this.fs.copyTpl(
this.templatePath('src/scripts/template.js'),
this.destinationPath(path.join(pathDist, 'src', 'scripts', data.blockFilename + '.js')),
data
);
this.fs.copyTpl(
this.templatePath('src/images/demo.jpeg'),
this.destinationPath(path.join(pathDist, 'src', 'images', 'demo.jpeg')),
data
);
mkdirp.sync(path.join(pathDist, 'design'));
this.fs.copyTpl(
this.templatePath('config/default.cjs'),
this.destinationPath(path.join(pathDist, 'config', 'default.cjs')),
data
);
this.fs.copyTpl(
this.templatePath('block.json'),
this.destinationPath(path.join(pathDist, 'block.json')),
data
);
this.fs.copyTpl(
this.templatePath('package.json'),
this.destinationPath(path.join(pathDist, 'package.json')),
data
);
this.fs.copyTpl(
this.templatePath('data/default.json'),
this.destinationPath(path.join(pathDist, 'data', 'default.json')),
data
);
this.fs.copyTpl(
this.templatePath('data/advanced.json'),
this.destinationPath(path.join(pathDist, 'data', 'advanced.json')),
data
);
this.fs.copyTpl(
this.templatePath('README.md'),
this.destinationPath(path.join(pathDist, 'README.md')),
data
);
this.fs.copyTpl(
this.templatePath('.editorconfig'),
this.destinationPath(path.join(pathDist, '.editorconfig')),
data
);
this.fs.copyTpl(
this.templatePath('.gitignore'),
this.destinationPath(path.join(pathDist, '.gitignore')),
data
);
}
}