diff --git a/create-block.js b/create-block.js index 341c8c9..9dc5e33 100755 --- a/create-block.js +++ b/create-block.js @@ -7,17 +7,23 @@ import fs from "fs"; import http from "http"; import https from "https"; import unzipper from "unzipper"; -import {createTechnicalFiles, defaultGitRepo} from "./generators/block/index.js"; import {fileURLToPath} from 'url'; -import config from 'config'; +import memFs from 'mem-fs'; +import editor from 'mem-fs-editor'; + +export const defaultGitRepo = 'git+https://git.devdevdev.life/axe-web-public/create-block.git#master'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); -const isDev = process.env.NODE_ENV === 'development' || (config.has('isDev') && config.get('isDev')); // Check README file in case you get "missing files" error. +const isDev = process.env.NODE_ENV === 'development'; // Check README file in case you get "missing files" error. const blocksRegistry = isDev ? 'http://localhost:3020' : 'https://axe-web-blocks-registry.captain.devdevdev.life'; const blocksDirectory = isDev ? 'blocks/' : ''; +if (isDev) { + console.log(`Development Mode Active`); +} + try { const blockName = await init(); console.log(`🎉 Done! \n\nCheck the "${blocksDirectory}${blockName}" directory. \n`); @@ -177,3 +183,22 @@ async function downloadFile(url, fileName) { }); }) } + +export async function createTechnicalFiles(data, baseDir, distPath) { + const pathDist = distPath; //path.join(baseDir, distPath); + const generatorsPath = path.join(baseDir, 'generators/block/templates'); + + const store = memFs.create(); + const filesystem = editor.create(store); + + const files = ['package.json', 'README.md', '.editorconfig', {from: 'gitignore', to: '.gitignore'}, 'block.json']; + + for (let file of files) { + const from = typeof file !== 'string' ? `${generatorsPath}/${file.from}` : `${generatorsPath}/${file}`; + const to = typeof file !== 'string' ? `${pathDist}/${file.to}` : `${pathDist}/${file}`; + + await filesystem.copyTplAsync(from, to, data); + } + + return filesystem.commit(); // Promise +} diff --git a/generators/block/index-old.js b/generators/block/index-old.js new file mode 100644 index 0000000..2ff418e --- /dev/null +++ b/generators/block/index-old.js @@ -0,0 +1,133 @@ +console.log('Not in use.'); + +// import path from 'path'; +// import Generator from "yeoman-generator"; +// import mkdirp from "mkdirp"; +// import {fileURLToPath} from 'url'; +// import {capitalize} from "../../helpers.js"; +// import {createTechnicalFiles, defaultGitRepo} from "../../create-block.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: defaultGitRepo +// } +// ]); +// } +// +// writing() { +// const title = capitalize(this.data.name); +// const group = capitalize(this.data.group); +// const data = Object.assign(this.data, { +// title, +// version: '1.0.0', +// 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('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')), +// 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 +// ); +// +// // Design Directory +// mkdirp.sync(path.join(pathDist, 'design')); +// +// // Data Files +// 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 +// ); +// +// // Technical Project files. +// createTechnicalFiles(data, baseDir, `blocks/${data.name}`).then(); +// } +// } +// diff --git a/generators/block/index.js b/generators/block/index.js deleted file mode 100644 index ddf768f..0000000 --- a/generators/block/index.js +++ /dev/null @@ -1,152 +0,0 @@ -import path from 'path'; -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://git.devdevdev.life/axe-web-public/create-block.git#master'; - -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: defaultGitRepo - } - ]); - } - - writing() { - const title = capitalize(this.data.name); - const group = capitalize(this.data.group); - const data = Object.assign(this.data, { - title, - version: '1.0.0', - 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('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')), - 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 - ); - - // Design Directory - mkdirp.sync(path.join(pathDist, 'design')); - - // Data Files - 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 - ); - - // Technical Project files. - createTechnicalFiles(data, baseDir, `blocks/${data.name}`).then(); - } -} - -export async function createTechnicalFiles(data, baseDir, distPath) { - const pathDist = distPath; //path.join(baseDir, distPath); - const generatorsPath = path.join(baseDir, 'generators/block/templates'); - - const store = memFs.create(); - const filesystem = editor.create(store); - - const files = ['package.json', 'README.md', '.editorconfig', {from: 'gitignore', to: '.gitignore'}, 'block.json']; - - for (let file of files) { - const from = typeof file !== 'string' ? `${generatorsPath}/${file.from}` : `${generatorsPath}/${file}`; - const to = typeof file !== 'string' ? `${pathDist}/${file.to}` : `${pathDist}/${file}`; - - await filesystem.copyTplAsync(from, to, data); - } - - return filesystem.commit(); // Promise -} diff --git a/package-lock.json b/package-lock.json index 8be02fd..a83fa00 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@axe-web/create-block", - "version": "1.0.12", + "version": "1.0.15", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@axe-web/create-block", - "version": "1.0.12", + "version": "1.0.15", "license": "ISC", "dependencies": { "@braintree/sanitize-url": "^6.0.0", diff --git a/package.json b/package.json index 64d3da1..a95750d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@axe-web/create-block", - "version": "1.0.12", + "version": "1.0.15", "author": { "name": "AXE-WEB", "email": "office@axe-web.com", @@ -10,6 +10,7 @@ "start": "component-dev", "dev": "NODE_ENV=development node server.js", "create-block": "node ./create-block.js pull", + "create-block-dev": "NODE_ENV=development node ./create-block.js pull", "build": "rollup --config rollup.config.js", "build-platform": "NODE_ENV=development node ./build.js", "build-platform-cli": "component-build",