- Generate technical repo files.
#Create Block from registry.
This commit is contained in:
+63
-32
@@ -3,12 +3,16 @@ import Generator from "yeoman-generator";
|
||||
import mkdirp from "mkdirp";
|
||||
import {fileURLToPath} from 'url';
|
||||
import {capitalize} from "../../helpers.js";
|
||||
import memFs from 'mem-fs';
|
||||
import editor from 'mem-fs-editor';
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
|
||||
const baseDir = path.join(__dirname, '../../');
|
||||
|
||||
export const defaultGitRepo = 'git+https://roman-axe-web@bitbucket.org/axeweb/create-block-dev-tool.git#master';
|
||||
|
||||
export default class extends Generator {
|
||||
async prompting() {
|
||||
this.data = await this.prompt([
|
||||
@@ -57,7 +61,7 @@ export default class extends Generator {
|
||||
type: 'input',
|
||||
name: 'devToolSource',
|
||||
message: 'DevTool Version/Source (master)',
|
||||
default: 'git+https://roman-axe-web@bitbucket.org/axeweb/create-block-dev-tool.git#master'
|
||||
default: defaultGitRepo
|
||||
}
|
||||
]);
|
||||
}
|
||||
@@ -74,6 +78,20 @@ export default class extends Generator {
|
||||
|
||||
const pathDist = path.join(baseDir, 'blocks', data.blockFilename);
|
||||
|
||||
this.fs.copyTpl(
|
||||
this.templatePath('block.json'),
|
||||
this.destinationPath(path.join(pathDist, 'block.json')),
|
||||
data
|
||||
);
|
||||
|
||||
this.fs.copyTpl(
|
||||
this.templatePath('config/default.cjs'),
|
||||
this.destinationPath(path.join(pathDist, 'config', 'default.cjs')),
|
||||
data
|
||||
);
|
||||
|
||||
|
||||
// SRC Template files
|
||||
this.fs.copyTpl(
|
||||
this.templatePath('src/template.template.hbs'),
|
||||
this.destinationPath(path.join(pathDist, 'src', data.blockFilename + '.template.hbs')),
|
||||
@@ -98,26 +116,10 @@ export default class extends Generator {
|
||||
data
|
||||
);
|
||||
|
||||
// Design Directory
|
||||
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
|
||||
);
|
||||
|
||||
// Data Files
|
||||
this.fs.copyTpl(
|
||||
this.templatePath('data/default.json'),
|
||||
this.destinationPath(path.join(pathDist, 'data', 'default.json')),
|
||||
@@ -130,22 +132,51 @@ export default class extends Generator {
|
||||
data
|
||||
);
|
||||
|
||||
this.fs.copyTpl(
|
||||
this.templatePath('README.md'),
|
||||
this.destinationPath(path.join(pathDist, 'README.md')),
|
||||
data
|
||||
);
|
||||
// Technical Project files.
|
||||
createTechnicalFiles(data, baseDir).then();
|
||||
|
||||
this.fs.copyTpl(
|
||||
this.templatePath('.editorconfig'),
|
||||
this.destinationPath(path.join(pathDist, '.editorconfig')),
|
||||
data
|
||||
);
|
||||
// this.fs.copyTpl(
|
||||
// this.templatePath('package.json'),
|
||||
// this.destinationPath(path.join(pathDist, 'package.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
|
||||
// );
|
||||
}
|
||||
}
|
||||
|
||||
this.fs.copyTpl(
|
||||
this.templatePath('.gitignore'),
|
||||
this.destinationPath(path.join(pathDist, '.gitignore')),
|
||||
export async function createTechnicalFiles(data, baseDir) {
|
||||
const pathDist = path.join(baseDir, `blocks/${data.name}`);
|
||||
const generatorsPath = path.join(baseDir, 'generators/block/templates');
|
||||
|
||||
const store = memFs.create();
|
||||
const filesystem = editor.create(store);
|
||||
|
||||
const files = ['package.json', 'README.md', '.editorconfig', '.gitignore'];
|
||||
|
||||
for (let file of files) {
|
||||
await filesystem.copyTplAsync(
|
||||
`${generatorsPath}/${file}`,
|
||||
`${pathDist}/${file}`,
|
||||
data
|
||||
);
|
||||
}
|
||||
|
||||
return filesystem.commit(); // Promise
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user