@40q/40q-cli 1.0.15 → 1.0.17

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,27 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
26
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
27
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -13,14 +36,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
36
  };
14
37
  Object.defineProperty(exports, "__esModule", { value: true });
15
38
  exports.CodegenCommand = void 0;
39
+ const child_process_1 = require("child_process");
40
+ const fs = __importStar(require("fs"));
16
41
  const inquirer_1 = __importDefault(require("inquirer"));
17
- const GenerateBlock_1 = require("./Generators/GenerateBlock");
42
+ const uuid_1 = require("uuid");
43
+ const paths_1 = require("../../utils/paths");
18
44
  const Codegen_types_1 = require("./Codegen.types");
45
+ const FetchComponents_1 = require("./Generators/FetchComponents");
46
+ const GenerateBlock_1 = require("./Generators/GenerateBlock");
47
+ const REPO_URL = 'git@github.com:40q/block-library.git';
19
48
  class CodegenCommand {
20
49
  static builder(yargs) {
21
50
  yargs.positional('type', {
22
51
  describe: 'Type of code piece to generate',
23
- choices: Codegen_types_1.typeChoices,
52
+ choices: [...Codegen_types_1.typeChoices],
24
53
  demandOption: true,
25
54
  type: 'string',
26
55
  });
@@ -36,20 +65,128 @@ class CodegenCommand {
36
65
  return __awaiter(this, void 0, void 0, function* () {
37
66
  const type = argv.type;
38
67
  const template = ((_a = argv.template) !== null && _a !== void 0 ? _a : 'default');
68
+ switch (type) {
69
+ case 'block':
70
+ yield handleBlock(template);
71
+ break;
72
+ case 'get':
73
+ yield handleGet();
74
+ break;
75
+ default:
76
+ console.error(`Unknown type: ${type}`);
77
+ }
78
+ });
79
+ }
80
+ }
81
+ exports.CodegenCommand = CodegenCommand;
82
+ function handleBlock(template) {
83
+ return __awaiter(this, void 0, void 0, function* () {
84
+ const tempDirs = (0, paths_1.tempPaths)(`temp-block-library-${(0, uuid_1.v4)()}`);
85
+ if (fs.existsSync(tempDirs.tempDir))
86
+ (0, child_process_1.execSync)(`rm -rf ${tempDirs.tempDir}`);
87
+ (0, child_process_1.execSync)(`git clone ${REPO_URL} ${tempDirs.tempDir}`);
88
+ try {
89
+ const repoComponents = (0, FetchComponents_1.fetchRepoComponents)(tempDirs.tempComponentsDir);
90
+ const componentChoices = repoComponents.map(component => ({
91
+ name: component.name.replace('.tsx', ''),
92
+ value: component
93
+ }));
94
+ const answers = yield inquirer_1.default.prompt([
95
+ {
96
+ type: 'input',
97
+ name: 'name',
98
+ message: 'Please enter a name for the block:',
99
+ default: template || 'section-header',
100
+ },
101
+ {
102
+ type: 'checkbox',
103
+ name: 'components',
104
+ message: 'Select inner components to include:',
105
+ choices: componentChoices
106
+ }
107
+ ]);
108
+ const { name, components } = answers;
109
+ (0, FetchComponents_1.downloadAndSaveItems)(components, 'component', tempDirs);
110
+ const componentNames = components.map((component) => component.name);
111
+ const blockGenerator = new GenerateBlock_1.GenerateBlock(template, name, componentNames);
112
+ return blockGenerator.run();
113
+ }
114
+ finally {
115
+ (0, child_process_1.execSync)(`rm -rf ${tempDirs.tempDir}`);
116
+ }
117
+ });
118
+ }
119
+ function handleGet() {
120
+ return __awaiter(this, void 0, void 0, function* () {
121
+ const answers = yield inquirer_1.default.prompt([
122
+ {
123
+ type: 'list',
124
+ name: 'type',
125
+ message: 'What do you want to get?',
126
+ choices: ['block', 'component']
127
+ }
128
+ ]);
129
+ const type = answers.type;
130
+ const tempDirs = (0, paths_1.tempPaths)(`temp-block-library-${(0, uuid_1.v4)()}`);
131
+ if (fs.existsSync(tempDirs.tempDir))
132
+ (0, child_process_1.execSync)(`rm -rf ${tempDirs.tempDir}`);
133
+ (0, child_process_1.execSync)(`git clone ${REPO_URL} ${tempDirs.tempDir}`);
134
+ try {
39
135
  if (type === 'block') {
136
+ const repoBlocks = (0, FetchComponents_1.fetchRepoBlocks)(tempDirs.tempBlocksDir);
137
+ const blockChoices = repoBlocks.map(block => ({
138
+ name: block.name.replace('.block.tsx', ''),
139
+ value: block
140
+ }));
141
+ const answers = yield inquirer_1.default.prompt([
142
+ {
143
+ type: 'checkbox',
144
+ name: 'blocks',
145
+ message: 'Select blocks to add:',
146
+ choices: blockChoices
147
+ }
148
+ ]);
149
+ const { blocks } = answers;
150
+ (0, FetchComponents_1.downloadAndSaveItems)(blocks, 'block', tempDirs);
151
+ const innerComponents = getInnerComponents(blocks, tempDirs.tempComponentsDir);
152
+ (0, FetchComponents_1.downloadAndSaveItems)(innerComponents, 'component', tempDirs);
153
+ }
154
+ else if (type === 'component') {
155
+ const repoComponents = (0, FetchComponents_1.fetchRepoComponents)(tempDirs.tempComponentsDir);
156
+ const componentChoices = repoComponents.map(component => ({
157
+ name: component.name.replace('.tsx', ''),
158
+ value: component
159
+ }));
40
160
  const answers = yield inquirer_1.default.prompt([
41
161
  {
42
- type: 'input',
43
- name: 'name',
44
- message: 'Please enter a name for the block:',
45
- default: template || 'section-header',
46
- },
162
+ type: 'checkbox',
163
+ name: 'components',
164
+ message: 'Select components to add:',
165
+ choices: componentChoices
166
+ }
47
167
  ]);
48
- const name = (answers === null || answers === void 0 ? void 0 : answers.name) || null;
49
- const blockGenerator = new GenerateBlock_1.GenerateBlock(template, name);
50
- return blockGenerator.run();
168
+ const { components } = answers;
169
+ (0, FetchComponents_1.downloadAndSaveItems)(components, 'component', tempDirs);
170
+ }
171
+ console.log(`Selected ${type}s have been added to your project.`);
172
+ }
173
+ finally {
174
+ (0, child_process_1.execSync)(`rm -rf ${tempDirs.tempDir}`);
175
+ }
176
+ });
177
+ }
178
+ function getInnerComponents(blocks, tempComponentsDir) {
179
+ const innerComponents = [];
180
+ blocks.forEach(block => {
181
+ const blockPath = (0, paths_1.getBlockPath)(block.name, tempComponentsDir);
182
+ const fileContent = fs.readFileSync(blockPath, 'utf-8');
183
+ const componentImports = fileContent.match(/from "scripts\/editor\/components\/(.*?)\/(.*?)"/g) || [];
184
+ componentImports.forEach(importLine => {
185
+ const matches = /from "scripts\/editor\/components\/(.*?)\/(.*?)"/.exec(importLine);
186
+ if (matches && matches[1]) {
187
+ innerComponents.push({ name: matches[1] });
51
188
  }
52
189
  });
53
- }
190
+ });
191
+ return innerComponents;
54
192
  }
55
- exports.CodegenCommand = CodegenCommand;
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.downloadAndSaveItems = exports.fetchRepoBlocks = exports.fetchRepoComponents = void 0;
27
+ const fs = __importStar(require("fs"));
28
+ const paths_1 = require("../../../utils/paths");
29
+ const utils_1 = require("../../../utils/utils");
30
+ function fetchRepoComponents(tempComponentsDir) {
31
+ const componentFiles = fs.readdirSync(tempComponentsDir).map(file => ({
32
+ name: file
33
+ }));
34
+ return componentFiles;
35
+ }
36
+ exports.fetchRepoComponents = fetchRepoComponents;
37
+ function fetchRepoBlocks(tempBlocksDir) {
38
+ const blockFiles = fs.readdirSync(tempBlocksDir).map(file => ({
39
+ name: file
40
+ }));
41
+ return blockFiles;
42
+ }
43
+ exports.fetchRepoBlocks = fetchRepoBlocks;
44
+ function downloadAndSaveItems(items, type, tempDirs) {
45
+ items.forEach(item => {
46
+ const paths = (0, paths_1.getPaths)(item.name, type, tempDirs);
47
+ if (!fs.existsSync(paths.destTsxDir))
48
+ fs.mkdirSync(paths.destTsxDir, { recursive: true });
49
+ if (!fs.existsSync(paths.destPhpDir))
50
+ fs.mkdirSync(paths.destPhpDir, { recursive: true });
51
+ if (!fs.existsSync(paths.destBladeDir))
52
+ fs.mkdirSync(paths.destBladeDir, { recursive: true });
53
+ (0, utils_1.writeFile)(paths.destTsxPath, fs.readFileSync(paths.sourceTsxPath, 'utf-8'));
54
+ (0, utils_1.writeFile)(paths.destPhpPath, fs.readFileSync(paths.sourcePhpPath, 'utf-8'));
55
+ (0, utils_1.writeFile)(paths.destBladePath, fs.readFileSync(paths.sourceBladePath, 'utf-8'));
56
+ });
57
+ (0, paths_1.copyDirectory)(tempDirs.tempUtilsDir, paths_1.utilsDir, ['mocks.ts']);
58
+ }
59
+ exports.downloadAndSaveItems = downloadAndSaveItems;
@@ -31,16 +31,19 @@ const fs = __importStar(require("fs"));
31
31
  const path_1 = __importDefault(require("path"));
32
32
  const child_process_1 = require("child_process");
33
33
  const cliRoot_1 = require("../../../lib/cliRoot");
34
+ const utils_1 = require("../../../utils/utils");
34
35
  class GenerateBlock {
35
- constructor(template, name) {
36
+ constructor(template, name, components) {
36
37
  this.template = 'default';
37
38
  this.name = '';
39
+ this.components = [];
38
40
  this.title = '';
39
- this.camelCaseName = '';
41
+ this.pascalCaseName = '';
40
42
  this.template = template;
41
43
  this.name = name !== null && name !== void 0 ? name : '';
42
- this.camelCaseName = this.toCamelCase(this.name);
44
+ this.pascalCaseName = (0, utils_1.toPascalCase)(this.name);
43
45
  this.title = this.parseName(this.name);
46
+ this.components = components;
44
47
  }
45
48
  run() {
46
49
  this.createBlockFolder();
@@ -51,13 +54,74 @@ class GenerateBlock {
51
54
  }
52
55
  createBlockFiles() {
53
56
  var _a, _b;
54
- fs.writeFileSync(path_1.default.join(process.cwd(), `resources/scripts/editor/blocks/${this.name}/${this.name}.block.tsx`), this.getTemplate('tsx')
57
+ let imports = '';
58
+ let attributes = '';
59
+ let viewAttributes = '';
60
+ let panelBody = '';
61
+ let editComponents = '';
62
+ let attributeNames = ['title'];
63
+ this.components.forEach(component => {
64
+ const componentNamePascal = (0, utils_1.toPascalCase)(component);
65
+ const componentNameCamel = (0, utils_1.toCamelCase)(component);
66
+ const basePath = `scripts/editor/components/${component}/${component}`;
67
+ const componentPath = path_1.default.join(process.cwd(), `resources/scripts/editor/components/${component}/${component}.tsx`);
68
+ let importStatements = [];
69
+ let sidebarComponent = '';
70
+ let editComponent = '';
71
+ let editProps = '{ attributes }';
72
+ const fileContent = fs.readFileSync(componentPath, 'utf-8');
73
+ const editRegex = /export const Edit = \(\s*{([\s\S]*?)}\s*\)/;
74
+ const sidebarRegex = /export const Sidebar = \(\s*{([\s\S]*?)}\s*\)/;
75
+ const editMatch = editRegex.exec(fileContent);
76
+ const sidebarMatch = sidebarRegex.exec(fileContent);
77
+ if (editMatch) {
78
+ importStatements.push(`Edit as ${componentNamePascal}Edit`);
79
+ if (editMatch[1].includes('setAttributes')) {
80
+ editComponent = `<${componentNamePascal}Edit attributes={${componentNameCamel} as ${componentNamePascal}Type} setAttributes={setAttributes} />\n`;
81
+ editProps = '{ attributes, setAttributes }';
82
+ }
83
+ else {
84
+ editComponent = `<${componentNamePascal}Edit attributes={${componentNameCamel} as ${componentNamePascal}Type} />\n`;
85
+ }
86
+ }
87
+ if (sidebarMatch) {
88
+ importStatements.push(`Sidebar as ${componentNamePascal}Sidebar`);
89
+ if (sidebarMatch[1].includes('setAttributes')) {
90
+ sidebarComponent = `<${componentNamePascal}Sidebar attributes={${componentNameCamel} as ${componentNamePascal}Type} setAttributes={setAttributes} />\n`;
91
+ }
92
+ else {
93
+ sidebarComponent = `<${componentNamePascal}Sidebar attributes={${componentNameCamel} as ${componentNamePascal}Type} />\n`;
94
+ }
95
+ }
96
+ importStatements.push(`defaultAttributes as default${componentNamePascal}Attributes`, `BlockAttributeValues as ${componentNamePascal}Type`);
97
+ imports += `import { ${importStatements.join(', ')} } from "${basePath}";\n`;
98
+ attributes += `${componentNameCamel}: {
99
+ type: "object",
100
+ default: default${componentNamePascal}Attributes,
101
+ },\n`;
102
+ viewAttributes += `'${componentNameCamel}' => $block['attrs']['${componentNameCamel}'] ?? [],\n`;
103
+ if (sidebarComponent) {
104
+ panelBody += sidebarComponent;
105
+ }
106
+ if (editComponent) {
107
+ editComponents += editComponent;
108
+ }
109
+ attributeNames.push(componentNameCamel);
110
+ });
111
+ const destructuring = attributeNames.join(', ');
112
+ (0, utils_1.writeFile)(path_1.default.join(process.cwd(), `resources/scripts/editor/blocks/${this.name}/${this.name}.block.tsx`), this.getTemplate('tsx')
55
113
  .replace(/{{name}}/g, (_a = this.name) !== null && _a !== void 0 ? _a : '')
56
- .replace(/{{title}}/g, this.title));
57
- fs.writeFileSync(path_1.default.join(process.cwd(), `resources/views/blocks/${this.name}.blade.php`), this.getTemplate('blade'));
58
- fs.writeFileSync(path_1.default.join(process.cwd(), `app/Blocks/${this.camelCaseName}.php`), this.getTemplate('php')
114
+ .replace(/{{title}}/g, this.title)
115
+ .replace(/{{imports}}/g, imports)
116
+ .replace(/{{attributes}}/g, attributes)
117
+ .replace(/{{panelBody}}/g, panelBody)
118
+ .replace(/{{destructure_attributes}}/g, destructuring)
119
+ .replace(/{{editComponents}}/g, editComponents));
120
+ (0, utils_1.writeFile)(path_1.default.join(process.cwd(), `resources/views/blocks/${this.name}.blade.php`), this.getTemplate('blade'));
121
+ (0, utils_1.writeFile)(path_1.default.join(process.cwd(), `app/Blocks/${this.pascalCaseName}.php`), this.getTemplate('php')
59
122
  .replace(/{{name}}/g, (_b = this.name) !== null && _b !== void 0 ? _b : '')
60
- .replace(/{{camelCaseName}}/g, this.camelCaseName));
123
+ .replace(/{{pascalCaseName}}/g, this.pascalCaseName)
124
+ .replace(/{{viewAttributes}}/g, viewAttributes));
61
125
  }
62
126
  parseName(name) {
63
127
  return name
@@ -67,12 +131,6 @@ class GenerateBlock {
67
131
  })
68
132
  .join(' ');
69
133
  }
70
- toCamelCase(name) {
71
- var _a;
72
- return ((_a = name.split('-').reduce((acc, word) => {
73
- return acc + word.charAt(0).toUpperCase() + word.slice(1);
74
- }, '')) !== null && _a !== void 0 ? _a : '');
75
- }
76
134
  getTemplate(name) {
77
135
  try {
78
136
  const cliRoot = (0, cliRoot_1.findCliRoot)(__dirname);
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.config = void 0;
4
4
  exports.config = {
5
- typeChoices: ['block'],
5
+ typeChoices: ['block', 'get'],
6
6
  templateChoices: {
7
7
  block: ['section-header']
8
8
  },
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.copyDirectory = exports.getPaths = exports.getComponentPath = exports.getBlockPath = exports.tempDir = exports.utilsDir = exports.blocksDir = exports.componentsDir = exports.tempPaths = void 0;
30
+ const path_1 = __importDefault(require("path"));
31
+ const fs = __importStar(require("fs"));
32
+ const utils_1 = require("./utils");
33
+ const tempDir = (dirName) => path_1.default.join(process.cwd(), dirName);
34
+ exports.tempDir = tempDir;
35
+ const componentsDir = 'resources/scripts/editor/components';
36
+ exports.componentsDir = componentsDir;
37
+ const blocksDir = 'resources/scripts/editor/blocks';
38
+ exports.blocksDir = blocksDir;
39
+ const utilsDir = path_1.default.join(process.cwd(), 'resources/scripts/editor/utils');
40
+ exports.utilsDir = utilsDir;
41
+ const tempPaths = (dirName) => ({
42
+ tempDir: tempDir(dirName),
43
+ tempComponentsDir: path_1.default.join(tempDir(dirName), componentsDir),
44
+ tempBlocksDir: path_1.default.join(tempDir(dirName), blocksDir),
45
+ tempBlockPhpDir: path_1.default.join(tempDir(dirName), 'app/Blocks'),
46
+ tempBlockBladeDir: path_1.default.join(tempDir(dirName), 'resources/views/blocks'),
47
+ tempComponentPhpDir: path_1.default.join(tempDir(dirName), 'app/View/Components'),
48
+ tempComponentBladeDir: path_1.default.join(tempDir(dirName), 'resources/views/components'),
49
+ tempUtilsDir: path_1.default.join(tempDir(dirName), 'resources/scripts/editor/utils')
50
+ });
51
+ exports.tempPaths = tempPaths;
52
+ const getBlockPath = (blockName, tempDir) => path_1.default.join(tempDir.replace('components', 'blocks'), blockName, `${blockName}.block.tsx`);
53
+ exports.getBlockPath = getBlockPath;
54
+ const getComponentPath = (componentName, tempDir) => path_1.default.join(tempDir, componentName, `${componentName}.tsx`);
55
+ exports.getComponentPath = getComponentPath;
56
+ const getPaths = (name, type, tempDirs) => {
57
+ const namePascal = (0, utils_1.toPascalCase)(name);
58
+ const isBlock = type === 'block';
59
+ const dirType = isBlock ? 'blocks' : 'components';
60
+ const tsxFile = isBlock ? `${name}.block.tsx` : `${name}.tsx`;
61
+ return {
62
+ sourceTsxPath: path_1.default.join(tempDirs[`temp${isBlock ? 'Blocks' : 'Components'}Dir`], name, tsxFile),
63
+ destTsxDir: path_1.default.join(process.cwd(), `resources/scripts/editor/${dirType}`, name),
64
+ destTsxPath: path_1.default.join(process.cwd(), `resources/scripts/editor/${dirType}`, name, tsxFile),
65
+ sourcePhpPath: path_1.default.join(tempDirs[`temp${isBlock ? 'Block' : 'Component'}PhpDir`], `${namePascal}.php`),
66
+ destPhpDir: path_1.default.join(process.cwd(), isBlock ? 'app/Blocks' : 'app/View/Components'),
67
+ destPhpPath: path_1.default.join(process.cwd(), isBlock ? 'app/Blocks' : 'app/View/Components', `${namePascal}.php`),
68
+ sourceBladePath: path_1.default.join(tempDirs[`temp${isBlock ? 'Block' : 'Component'}BladeDir`], `${name}.blade.php`),
69
+ destBladeDir: path_1.default.join(process.cwd(), `resources/views/${dirType}`),
70
+ destBladePath: path_1.default.join(process.cwd(), `resources/views/${dirType}`, `${name}.blade.php`),
71
+ utilsDir: utilsDir
72
+ };
73
+ };
74
+ exports.getPaths = getPaths;
75
+ function copyDirectory(sourceDir, destDir, excludeFiles = []) {
76
+ if (!fs.existsSync(destDir)) {
77
+ fs.mkdirSync(destDir, { recursive: true });
78
+ }
79
+ fs.readdirSync(sourceDir).forEach(file => {
80
+ const sourcePath = path_1.default.join(sourceDir, file);
81
+ const destPath = path_1.default.join(destDir, file);
82
+ if (excludeFiles.includes(file)) {
83
+ return;
84
+ }
85
+ if (fs.lstatSync(sourcePath).isDirectory()) {
86
+ copyDirectory(sourcePath, destPath, excludeFiles);
87
+ }
88
+ else {
89
+ (0, utils_1.writeFile)(destPath, fs.readFileSync(sourcePath, 'utf-8'));
90
+ }
91
+ });
92
+ }
93
+ exports.copyDirectory = copyDirectory;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.toPascalCase = exports.toCamelCase = exports.writeFile = void 0;
27
+ const fs = __importStar(require("fs"));
28
+ function writeFile(filePath, content) {
29
+ const yellow = "\x1b[33m";
30
+ const green = "\x1b[32m";
31
+ const reset = "\x1b[0m";
32
+ if (fs.existsSync(filePath)) {
33
+ console.log(`${yellow}File ${filePath} already exists. Skipping file creation.${reset}`);
34
+ }
35
+ else {
36
+ fs.writeFileSync(filePath, content);
37
+ console.log(`${green}File ${filePath} has been created.${reset}`);
38
+ }
39
+ }
40
+ exports.writeFile = writeFile;
41
+ function toCamelCase(name) {
42
+ return name
43
+ .split('-')
44
+ .map((word, index) => {
45
+ if (index === 0) {
46
+ return word.charAt(0).toLowerCase() + word.slice(1);
47
+ }
48
+ return word.charAt(0).toUpperCase() + word.slice(1);
49
+ })
50
+ .join('');
51
+ }
52
+ exports.toCamelCase = toCamelCase;
53
+ function toPascalCase(name) {
54
+ return name
55
+ .split('-')
56
+ .map(word => word.charAt(0).toUpperCase() + word.slice(1))
57
+ .join('');
58
+ }
59
+ exports.toPascalCase = toPascalCase;
package/package.json CHANGED
@@ -1,13 +1,15 @@
1
1
  {
2
2
  "name": "@40q/40q-cli",
3
- "version": "1.0.15",
3
+ "version": "1.0.17",
4
4
  "description": "40q CLI tool",
5
5
  "main": "index.js",
6
6
  "bin": {
7
7
  "40q": "./dist/index.js"
8
8
  },
9
9
  "dependencies": {
10
+ "axios": "^1.6.8",
10
11
  "inquirer": "^8.0.0",
12
+ "uuidv4": "^6.2.13",
11
13
  "yargs": "^17.7.2"
12
14
  },
13
15
  "scripts": {
@@ -4,12 +4,13 @@ namespace App\Blocks;
4
4
 
5
5
  use BlockHandler\Contracts\BlockHandler;
6
6
 
7
- class {{camelCaseName}} implements BlockHandler
7
+ class {{pascalCaseName}} implements BlockHandler
8
8
  {
9
9
  public function __invoke($block_content, $block)
10
10
  {
11
11
  return view('blocks.{{name}}', [
12
12
  'title' => $block['attrs']['title'] ?? null,
13
+ {{viewAttributes}}
13
14
  ]);
14
15
  }
15
16
  }
@@ -9,6 +9,8 @@ import {
9
9
  RichText,
10
10
  useBlockProps,
11
11
  } from "@wordpress/block-editor";
12
+ import { BlockStyle } from "@wordpress/blocks";
13
+ {{imports}}
12
14
 
13
15
  /* Block name */
14
16
  export const name = "by40q/{{name}}";
@@ -20,7 +22,7 @@ export const title = __("{{title}}", "40q");
20
22
  export const category = "40q";
21
23
 
22
24
  /* Block icon */
23
- export const icon = "editor-paragraph";
25
+ export const icon = "admin-tools";
24
26
 
25
27
  /* Block attributes */
26
28
  export const attributes = {
@@ -28,6 +30,7 @@ export const attributes = {
28
30
  type: "string",
29
31
  default: "40Q",
30
32
  },
33
+ {{attributes}}
31
34
  } as const;
32
35
 
33
36
  /* Block types */
@@ -42,14 +45,14 @@ export const edit = ({
42
45
  attributes: BlockAttributeValues;
43
46
  setAttributes: SetAttributesFunction;
44
47
  }) => {
45
- const { title } = attributes;
48
+ const { {{destructure_attributes}} } = attributes;
46
49
 
47
50
  const blockProps = useBlockProps();
48
51
 
49
52
  return (
50
53
  <>
51
54
  <InspectorControls>
52
- <PanelBody title={__("{{title}} Settings")} initialOpen></PanelBody>
55
+ <PanelBody title={__("{{title}} Settings")} initialOpen>{{panelBody}}</PanelBody>
53
56
  </InspectorControls>
54
57
 
55
58
  <div {...blockProps}>
@@ -59,6 +62,7 @@ export const edit = ({
59
62
  value={title}
60
63
  onChange={(title) => setAttributes({ title })}
61
64
  />
65
+ {{editComponents}}
62
66
  </div>
63
67
  </>
64
68
  );
@@ -68,4 +72,4 @@ export const edit = ({
68
72
  export const save = () => <></>;
69
73
 
70
74
  /* Block styles */
71
- export const styles = [];
75
+ export const styles: BlockStyle[] = [];
@@ -4,7 +4,7 @@ namespace App\Blocks;
4
4
 
5
5
  use BlockHandler\Contracts\BlockHandler;
6
6
 
7
- class {{camelCaseName}} implements BlockHandler
7
+ class {{pascalCaseName}} implements BlockHandler
8
8
  {
9
9
  public function __invoke($block_content, $block)
10
10
  {