@40q/40q-cli 1.0.17 → 1.0.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/Readme.md +2 -1
  2. package/dist/src/commands/Codegen/Codegen.command.js +29 -7
  3. package/dist/src/commands/Codegen/Generators/FetchComponents.js +5 -5
  4. package/dist/src/commands/Codegen/Generators/GenerateBlock.js +11 -5
  5. package/dist/src/utils/paths.js +3 -3
  6. package/dist/src/utils/utils.js +7 -2
  7. package/package.json +1 -1
  8. package/templates/blocks/default/tsx.txt +2 -2
  9. package/dist/165.index.js +0 -1
  10. package/dist/216.index.js +0 -1
  11. package/dist/284.index.js +0 -1
  12. package/dist/350.index.js +0 -1
  13. package/dist/522.index.js +0 -1
  14. package/dist/62.index.js +0 -2
  15. package/dist/62.index.js.LICENSE.txt +0 -9
  16. package/dist/758.index.js +0 -1
  17. package/dist/index.js.LICENSE.txt +0 -14
  18. package/dist/resources/scripts/editor/blocks/default/default.block.js +0 -39
  19. package/dist/resources/scripts/editor/blocks/hello-today/hello-today.block.js +0 -39
  20. package/dist/resources/scripts/editor/blocks/here-we-go-again/here-we-go-again.block.js +0 -39
  21. package/dist/resources/scripts/editor/blocks/section-header/section-header.block.js +0 -39
  22. package/dist/resources/scripts/editor/blocks/section-header.js +0 -39
  23. package/dist/src/commands/Codegen/Generator.factory.js +0 -11
  24. package/dist/src/commands/Codegen/Generator.js +0 -3
  25. package/dist/src/commands/Codegen/Generators/BaseGeneratorOptions.js +0 -4
  26. package/dist/src/commands/Codegen/Generators/GeneratorStrategy.factory.js +0 -11
  27. package/dist/src/commands/Codegen/Generators/GeneratorStrategy.js +0 -2
  28. package/dist/src/commands/Codegen/Generators/strategies/BlockGenerator.strategy.js +0 -88
  29. package/dist/src/commands/Codegen/Prompts/PromptSrategy.js +0 -5
  30. package/dist/src/commands/Codegen/Prompts/PromptStrategy.factory.js +0 -11
  31. package/dist/src/commands/Codegen/Prompts/PromptStrategy.js +0 -2
  32. package/dist/src/commands/Codegen/Prompts/strategies/BlockPrompt.strategy.js +0 -43
  33. package/dist/src/commands/Codegen/StrategyFactory.js +0 -63
  34. package/dist/src/commands/Setup.command.js +0 -53
package/Readme.md CHANGED
@@ -29,7 +29,8 @@ Codegen generates code for you.
29
29
  ```
30
30
 
31
31
  Supported Types:
32
- * block: generates code for Gutenberg blocks
32
+ * block: generates code for Gutenberg blocks and allows selecting inner components from block library repo.
33
+ * get: fetches selected block/s, component/s, and utils from block library repo.
33
34
 
34
35
  Templates are optional, if empty, it creates an example boilerplate for a Gutenberg block.
35
36
 
@@ -98,6 +98,18 @@ function handleBlock(template) {
98
98
  message: 'Please enter a name for the block:',
99
99
  default: template || 'section-header',
100
100
  },
101
+ {
102
+ type: 'input',
103
+ name: 'category',
104
+ message: 'Enter the block category:',
105
+ default: '40q',
106
+ },
107
+ {
108
+ type: 'input',
109
+ name: 'icon',
110
+ message: 'Enter the icon name (dashicons):',
111
+ default: 'block-default',
112
+ },
101
113
  {
102
114
  type: 'checkbox',
103
115
  name: 'components',
@@ -105,10 +117,10 @@ function handleBlock(template) {
105
117
  choices: componentChoices
106
118
  }
107
119
  ]);
108
- const { name, components } = answers;
120
+ const { name, category, icon, components } = answers;
109
121
  (0, FetchComponents_1.downloadAndSaveItems)(components, 'component', tempDirs);
110
122
  const componentNames = components.map((component) => component.name);
111
- const blockGenerator = new GenerateBlock_1.GenerateBlock(template, name, componentNames);
123
+ const blockGenerator = new GenerateBlock_1.GenerateBlock(template, name, category, icon, componentNames);
112
124
  return blockGenerator.run();
113
125
  }
114
126
  finally {
@@ -123,10 +135,17 @@ function handleGet() {
123
135
  type: 'list',
124
136
  name: 'type',
125
137
  message: 'What do you want to get?',
126
- choices: ['block', 'component']
138
+ choices: ['block', 'component', 'utils']
139
+ },
140
+ {
141
+ type: 'confirm',
142
+ name: 'overwrite',
143
+ message: 'Overwrite existing files?',
144
+ default: false,
127
145
  }
128
146
  ]);
129
147
  const type = answers.type;
148
+ const overwrite = answers.overwrite;
130
149
  const tempDirs = (0, paths_1.tempPaths)(`temp-block-library-${(0, uuid_1.v4)()}`);
131
150
  if (fs.existsSync(tempDirs.tempDir))
132
151
  (0, child_process_1.execSync)(`rm -rf ${tempDirs.tempDir}`);
@@ -147,9 +166,9 @@ function handleGet() {
147
166
  }
148
167
  ]);
149
168
  const { blocks } = answers;
150
- (0, FetchComponents_1.downloadAndSaveItems)(blocks, 'block', tempDirs);
169
+ (0, FetchComponents_1.downloadAndSaveItems)(blocks, 'block', tempDirs, overwrite);
151
170
  const innerComponents = getInnerComponents(blocks, tempDirs.tempComponentsDir);
152
- (0, FetchComponents_1.downloadAndSaveItems)(innerComponents, 'component', tempDirs);
171
+ (0, FetchComponents_1.downloadAndSaveItems)(innerComponents, 'component', tempDirs, overwrite);
153
172
  }
154
173
  else if (type === 'component') {
155
174
  const repoComponents = (0, FetchComponents_1.fetchRepoComponents)(tempDirs.tempComponentsDir);
@@ -166,9 +185,12 @@ function handleGet() {
166
185
  }
167
186
  ]);
168
187
  const { components } = answers;
169
- (0, FetchComponents_1.downloadAndSaveItems)(components, 'component', tempDirs);
188
+ (0, FetchComponents_1.downloadAndSaveItems)(components, 'component', tempDirs, overwrite);
189
+ }
190
+ else if (type === 'utils') {
191
+ (0, paths_1.copyDirectory)(tempDirs.tempUtilsDir, paths_1.utilsDir, ['mocks.ts'], overwrite);
170
192
  }
171
- console.log(`Selected ${type}s have been added to your project.`);
193
+ console.log(`Selected ${type}${type.endsWith('s') ? '' : 's'} have been added to your project.`);
172
194
  }
173
195
  finally {
174
196
  (0, child_process_1.execSync)(`rm -rf ${tempDirs.tempDir}`);
@@ -41,7 +41,7 @@ function fetchRepoBlocks(tempBlocksDir) {
41
41
  return blockFiles;
42
42
  }
43
43
  exports.fetchRepoBlocks = fetchRepoBlocks;
44
- function downloadAndSaveItems(items, type, tempDirs) {
44
+ function downloadAndSaveItems(items, type, tempDirs, overwrite = false) {
45
45
  items.forEach(item => {
46
46
  const paths = (0, paths_1.getPaths)(item.name, type, tempDirs);
47
47
  if (!fs.existsSync(paths.destTsxDir))
@@ -50,10 +50,10 @@ function downloadAndSaveItems(items, type, tempDirs) {
50
50
  fs.mkdirSync(paths.destPhpDir, { recursive: true });
51
51
  if (!fs.existsSync(paths.destBladeDir))
52
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'));
53
+ (0, utils_1.writeFile)(paths.destTsxPath, fs.readFileSync(paths.sourceTsxPath, 'utf-8'), overwrite);
54
+ (0, utils_1.writeFile)(paths.destPhpPath, fs.readFileSync(paths.sourcePhpPath, 'utf-8'), overwrite);
55
+ (0, utils_1.writeFile)(paths.destBladePath, fs.readFileSync(paths.sourceBladePath, 'utf-8'), overwrite);
56
56
  });
57
- (0, paths_1.copyDirectory)(tempDirs.tempUtilsDir, paths_1.utilsDir, ['mocks.ts']);
57
+ (0, paths_1.copyDirectory)(tempDirs.tempUtilsDir, paths_1.utilsDir, ['mocks.ts'], overwrite);
58
58
  }
59
59
  exports.downloadAndSaveItems = downloadAndSaveItems;
@@ -33,14 +33,18 @@ const child_process_1 = require("child_process");
33
33
  const cliRoot_1 = require("../../../lib/cliRoot");
34
34
  const utils_1 = require("../../../utils/utils");
35
35
  class GenerateBlock {
36
- constructor(template, name, components) {
36
+ constructor(template, name, category, icon, components) {
37
37
  this.template = 'default';
38
38
  this.name = '';
39
+ this.icon = '';
40
+ this.category = '';
39
41
  this.components = [];
40
42
  this.title = '';
41
43
  this.pascalCaseName = '';
42
44
  this.template = template;
43
45
  this.name = name !== null && name !== void 0 ? name : '';
46
+ this.category = category !== null && category !== void 0 ? category : '';
47
+ this.icon = icon !== null && icon !== void 0 ? icon : '';
44
48
  this.pascalCaseName = (0, utils_1.toPascalCase)(this.name);
45
49
  this.title = this.parseName(this.name);
46
50
  this.components = components;
@@ -53,7 +57,7 @@ class GenerateBlock {
53
57
  (0, child_process_1.execSync)(`mkdir -p resources/scripts/editor/blocks/${this.name}`);
54
58
  }
55
59
  createBlockFiles() {
56
- var _a, _b;
60
+ var _a, _b, _c, _d;
57
61
  let imports = '';
58
62
  let attributes = '';
59
63
  let viewAttributes = '';
@@ -77,7 +81,7 @@ class GenerateBlock {
77
81
  if (editMatch) {
78
82
  importStatements.push(`Edit as ${componentNamePascal}Edit`);
79
83
  if (editMatch[1].includes('setAttributes')) {
80
- editComponent = `<${componentNamePascal}Edit attributes={${componentNameCamel} as ${componentNamePascal}Type} setAttributes={setAttributes} />\n`;
84
+ editComponent = `<${componentNamePascal}Edit attributes={${componentNameCamel} as ${componentNamePascal}Type} setAttributes={(${componentNameCamel}) => setAttributes({${componentNameCamel}})} />\n`;
81
85
  editProps = '{ attributes, setAttributes }';
82
86
  }
83
87
  else {
@@ -87,7 +91,7 @@ class GenerateBlock {
87
91
  if (sidebarMatch) {
88
92
  importStatements.push(`Sidebar as ${componentNamePascal}Sidebar`);
89
93
  if (sidebarMatch[1].includes('setAttributes')) {
90
- sidebarComponent = `<${componentNamePascal}Sidebar attributes={${componentNameCamel} as ${componentNamePascal}Type} setAttributes={setAttributes} />\n`;
94
+ sidebarComponent = `<${componentNamePascal}Sidebar attributes={${componentNameCamel} as ${componentNamePascal}Type} setAttributes={(${componentNameCamel}) => setAttributes({${componentNameCamel}})} />\n`;
91
95
  }
92
96
  else {
93
97
  sidebarComponent = `<${componentNamePascal}Sidebar attributes={${componentNameCamel} as ${componentNamePascal}Type} />\n`;
@@ -111,6 +115,8 @@ class GenerateBlock {
111
115
  const destructuring = attributeNames.join(', ');
112
116
  (0, utils_1.writeFile)(path_1.default.join(process.cwd(), `resources/scripts/editor/blocks/${this.name}/${this.name}.block.tsx`), this.getTemplate('tsx')
113
117
  .replace(/{{name}}/g, (_a = this.name) !== null && _a !== void 0 ? _a : '')
118
+ .replace(/{{category}}/g, (_b = this.category) !== null && _b !== void 0 ? _b : '')
119
+ .replace(/{{icon}}/g, (_c = this.icon) !== null && _c !== void 0 ? _c : '')
114
120
  .replace(/{{title}}/g, this.title)
115
121
  .replace(/{{imports}}/g, imports)
116
122
  .replace(/{{attributes}}/g, attributes)
@@ -119,7 +125,7 @@ class GenerateBlock {
119
125
  .replace(/{{editComponents}}/g, editComponents));
120
126
  (0, utils_1.writeFile)(path_1.default.join(process.cwd(), `resources/views/blocks/${this.name}.blade.php`), this.getTemplate('blade'));
121
127
  (0, utils_1.writeFile)(path_1.default.join(process.cwd(), `app/Blocks/${this.pascalCaseName}.php`), this.getTemplate('php')
122
- .replace(/{{name}}/g, (_b = this.name) !== null && _b !== void 0 ? _b : '')
128
+ .replace(/{{name}}/g, (_d = this.name) !== null && _d !== void 0 ? _d : '')
123
129
  .replace(/{{pascalCaseName}}/g, this.pascalCaseName)
124
130
  .replace(/{{viewAttributes}}/g, viewAttributes));
125
131
  }
@@ -72,7 +72,7 @@ const getPaths = (name, type, tempDirs) => {
72
72
  };
73
73
  };
74
74
  exports.getPaths = getPaths;
75
- function copyDirectory(sourceDir, destDir, excludeFiles = []) {
75
+ function copyDirectory(sourceDir, destDir, excludeFiles = [], overwrite = false) {
76
76
  if (!fs.existsSync(destDir)) {
77
77
  fs.mkdirSync(destDir, { recursive: true });
78
78
  }
@@ -83,10 +83,10 @@ function copyDirectory(sourceDir, destDir, excludeFiles = []) {
83
83
  return;
84
84
  }
85
85
  if (fs.lstatSync(sourcePath).isDirectory()) {
86
- copyDirectory(sourcePath, destPath, excludeFiles);
86
+ copyDirectory(sourcePath, destPath, excludeFiles, overwrite);
87
87
  }
88
88
  else {
89
- (0, utils_1.writeFile)(destPath, fs.readFileSync(sourcePath, 'utf-8'));
89
+ (0, utils_1.writeFile)(destPath, fs.readFileSync(sourcePath, 'utf-8'), overwrite);
90
90
  }
91
91
  });
92
92
  }
@@ -25,13 +25,18 @@ var __importStar = (this && this.__importStar) || function (mod) {
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.toPascalCase = exports.toCamelCase = exports.writeFile = void 0;
27
27
  const fs = __importStar(require("fs"));
28
- function writeFile(filePath, content) {
28
+ function writeFile(filePath, content, overwrite = false) {
29
29
  const yellow = "\x1b[33m";
30
30
  const green = "\x1b[32m";
31
+ const cyan = "\x1b[36m";
31
32
  const reset = "\x1b[0m";
32
- if (fs.existsSync(filePath)) {
33
+ if (fs.existsSync(filePath) && !overwrite) {
33
34
  console.log(`${yellow}File ${filePath} already exists. Skipping file creation.${reset}`);
34
35
  }
36
+ else if (fs.existsSync(filePath) && overwrite) {
37
+ fs.writeFileSync(filePath, content);
38
+ console.log(`${cyan}File ${filePath} has been overwritten.${reset}`);
39
+ }
35
40
  else {
36
41
  fs.writeFileSync(filePath, content);
37
42
  console.log(`${green}File ${filePath} has been created.${reset}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@40q/40q-cli",
3
- "version": "1.0.17",
3
+ "version": "1.0.18",
4
4
  "description": "40q CLI tool",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -19,10 +19,10 @@ export const name = "by40q/{{name}}";
19
19
  export const title = __("{{title}}", "40q");
20
20
 
21
21
  /* Block category */
22
- export const category = "40q";
22
+ export const category = "{{category}}";
23
23
 
24
24
  /* Block icon */
25
- export const icon = "admin-tools";
25
+ export const icon = "{{icon}}";
26
26
 
27
27
  /* Block attributes */
28
28
  export const attributes = {
package/dist/165.index.js DELETED
@@ -1 +0,0 @@
1
- "use strict";exports.id=165,exports.ids=[165],exports.modules={41165:(s,e,r)=>{r.r(e)}};
package/dist/216.index.js DELETED
@@ -1 +0,0 @@
1
- "use strict";exports.id=216,exports.ids=[216,522],exports.modules={32522:(e,t,s)=>{s.r(t),s.d(t,{BlockGenerator:()=>l});var r=s(57147),a=s(71017),i=s.n(a),c=s(32081);class l{constructor(e){this.template="",this.name="",this.title="",this.camelCaseName="",console.log(e),this.template=""===e.template?"default":e.template,this.name=e.name||"default",this.camelCaseName=this.toCamelCase(this.name),this.title=this.parseName(this.name)}run(){this.createBlockFolder(),this.createBlockFiles()}createBlockFolder(){(0,c.execSync)(`mkdir -p resources/scripts/editor/blocks/${this.name}`)}createBlockFiles(){r.writeFileSync(i().join(process.cwd(),`resources/scripts/editor/blocks/${this.name}/${this.name}.block.tsx`),this.getTemplate("tsx").replace(/{{name}}/g,this.name??"").replace(/{{title}}/g,this.title)),r.writeFileSync(i().join(process.cwd(),`resources/views/blocks/${this.name}.blade.php`),this.getTemplate("blade")),r.writeFileSync(i().join(process.cwd(),`app/Blocks/${this.camelCaseName}.php`),this.getTemplate("php").replace(/{{name}}/g,this.name??"").replace(/{{camelCaseName}}/g,this.camelCaseName))}parseName(e){return e.split("-").map((e=>e.charAt(0).toUpperCase()+e.slice(1))).join(" ")}toCamelCase(e){return e.split("-").reduce(((e,t)=>e+t.charAt(0).toUpperCase()+t.slice(1)),"")??""}getTemplate(e){try{const t=function(e){let t=__dirname;for(;t!==a.parse(t).root;){if(r.existsSync(a.join(t,".cliroot")))return t;t=a.dirname(t)}throw new Error("CLI root directory with .cliroot marker not found.")}(),s=`templates/blocks/${this.template}`;return r.readFileSync(i().join(t,`${s}/${e}.txt`),"utf8")}catch(e){return""}}}},34216:(e,t,s)=>{s.r(t),s.d(t,{BlockGenerator:()=>r.BlockGenerator});var r=s(32522)}};
package/dist/284.index.js DELETED
@@ -1 +0,0 @@
1
- "use strict";exports.id=284,exports.ids=[284,350],exports.modules={63350:(e,t,a)=>{a.r(t),a.d(t,{BlockPromptStrategy:()=>o});var m=a(96062),r=a.n(m),s=a(78913);class o{async prompt(){const e=await r().prompt([{type:"list",name:"template",message:"Please select a template:",choices:s.v.templateChoices.block,default:""}]),t=e?.template||"",a=await r().prompt([{type:"input",name:"name",message:"Please enter a name for the block:",default:t||"block-name"}]);return{name:a?.name||"",template:t}}}},79284:(e,t,a)=>{a.r(t),a.d(t,{BlockPromptStrategy:()=>m.BlockPromptStrategy});var m=a(63350)}};
package/dist/350.index.js DELETED
@@ -1 +0,0 @@
1
- "use strict";exports.id=350,exports.ids=[350],exports.modules={63350:(e,t,a)=>{a.r(t),a.d(t,{BlockPromptStrategy:()=>l});var s=a(96062),m=a.n(s),p=a(78913);class l{async prompt(){const e=await m().prompt([{type:"list",name:"template",message:"Please select a template:",choices:p.v.templateChoices.block,default:""}]),t=e?.template||"",a=await m().prompt([{type:"input",name:"name",message:"Please enter a name for the block:",default:t||"block-name"}]);return{name:a?.name||"",template:t}}}}};
package/dist/522.index.js DELETED
@@ -1 +0,0 @@
1
- "use strict";exports.id=522,exports.ids=[522],exports.modules={32522:(e,t,s)=>{s.r(t),s.d(t,{BlockGenerator:()=>l});var a=s(57147),r=s(71017),i=s.n(r),c=s(32081);class l{constructor(e){this.template="",this.name="",this.title="",this.camelCaseName="",console.log(e),this.template=""===e.template?"default":e.template,this.name=e.name||"default",this.camelCaseName=this.toCamelCase(this.name),this.title=this.parseName(this.name)}run(){this.createBlockFolder(),this.createBlockFiles()}createBlockFolder(){(0,c.execSync)(`mkdir -p resources/scripts/editor/blocks/${this.name}`)}createBlockFiles(){a.writeFileSync(i().join(process.cwd(),`resources/scripts/editor/blocks/${this.name}/${this.name}.block.tsx`),this.getTemplate("tsx").replace(/{{name}}/g,this.name??"").replace(/{{title}}/g,this.title)),a.writeFileSync(i().join(process.cwd(),`resources/views/blocks/${this.name}.blade.php`),this.getTemplate("blade")),a.writeFileSync(i().join(process.cwd(),`app/Blocks/${this.camelCaseName}.php`),this.getTemplate("php").replace(/{{name}}/g,this.name??"").replace(/{{camelCaseName}}/g,this.camelCaseName))}parseName(e){return e.split("-").map((e=>e.charAt(0).toUpperCase()+e.slice(1))).join(" ")}toCamelCase(e){return e.split("-").reduce(((e,t)=>e+t.charAt(0).toUpperCase()+t.slice(1)),"")??""}getTemplate(e){try{const t=function(e){let t=__dirname;for(;t!==r.parse(t).root;){if(a.existsSync(r.join(t,".cliroot")))return t;t=r.dirname(t)}throw new Error("CLI root directory with .cliroot marker not found.")}(),s=`templates/blocks/${this.template}`;return a.readFileSync(i().join(t,`${s}/${e}.txt`),"utf8")}catch(e){return""}}}}};