@40q/40q-cli 1.0.6 → 1.0.7
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.js +5 -0
- package/dist/resources/scripts/editor/blocks/section-header.js +39 -0
- package/dist/src/40qCli.js +19 -0
- package/dist/src/commands/Codegen/Codegen.command.js +55 -0
- package/dist/src/commands/Codegen/Codegen.types.js +6 -0
- package/dist/src/commands/Codegen/Generators/GenerateBlock.js +87 -0
- package/dist/src/commands/Command.js +8 -0
- package/dist/src/commands/Setup/Setup.command.js +53 -0
- package/{src/commands/Setup/Setup.command.ts → dist/src/commands/Setup.command.js} +15 -27
- package/dist/src/config.js +9 -0
- package/dist/src/lib/cliRoot.js +39 -0
- package/package.json +5 -2
- package/.cliroot +0 -0
- package/index.ts +0 -5
- package/src/40qCli.ts +0 -23
- package/src/commands/Codegen/Codegen.command.ts +0 -46
- package/src/commands/Codegen/Codegen.types.ts +0 -7
- package/src/commands/Codegen/Generators/GenerateBlock.ts +0 -85
- package/src/commands/Command.ts +0 -6
- package/src/config.ts +0 -6
- package/src/lib/cliRoot.ts +0 -16
- package/templates/blocks/default/php.txt +0 -15
- package/templates/blocks/default/tsx.txt +0 -54
- package/templates/blocks/section-header/php.txt +0 -17
- package/templates/blocks/section-header/tsx.txt +0 -120
- package/tsconfig.json +0 -12
package/dist/index.js
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.styles = exports.save = exports.edit = exports.attributes = exports.category = exports.title = exports.name = void 0;
|
4
|
+
const i18n_1 = require("@wordpress/i18n");
|
5
|
+
const components_1 = require("@wordpress/components");
|
6
|
+
const block_editor_1 = require("@wordpress/block-editor");
|
7
|
+
/* Block name */
|
8
|
+
exports.name = "by40q/section-header";
|
9
|
+
/* Block title */
|
10
|
+
exports.title = (0, i18n_1.__)("Section Header", "40q");
|
11
|
+
/* Block category */
|
12
|
+
exports.category = "text";
|
13
|
+
/* Block attributes */
|
14
|
+
exports.attributes = {
|
15
|
+
title: {
|
16
|
+
type: "string",
|
17
|
+
default: "40Q",
|
18
|
+
},
|
19
|
+
};
|
20
|
+
/* Block edit */
|
21
|
+
const edit = ({ attributes, setAttributes }) => {
|
22
|
+
const { title } = attributes;
|
23
|
+
const blockProps = (0, block_editor_1.useBlockProps)();
|
24
|
+
return (<>
|
25
|
+
<block_editor_1.InspectorControls>
|
26
|
+
<components_1.PanelBody title={(0, i18n_1.__)("Section Header Settings")} initialOpen></components_1.PanelBody>
|
27
|
+
</block_editor_1.InspectorControls>
|
28
|
+
|
29
|
+
<div {...blockProps}>
|
30
|
+
<block_editor_1.RichText tagName="h2" placeholder={(0, i18n_1.__)("40Q")} value={title} onChange={(title) => setAttributes({ title })}/>
|
31
|
+
</div>
|
32
|
+
</>);
|
33
|
+
};
|
34
|
+
exports.edit = edit;
|
35
|
+
/* Block save */
|
36
|
+
const save = ({ attributes }) => <></>;
|
37
|
+
exports.save = save;
|
38
|
+
/* Block styles */
|
39
|
+
exports.styles = [];
|
@@ -0,0 +1,19 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
exports.q40Cli = void 0;
|
7
|
+
const yargs_1 = __importDefault(require("yargs"));
|
8
|
+
const helpers_1 = require("yargs/helpers");
|
9
|
+
const Setup_command_1 = require("./commands/Setup/Setup.command");
|
10
|
+
const Codegen_command_1 = require("./commands/Codegen/Codegen.command");
|
11
|
+
class q40Cli {
|
12
|
+
static init() {
|
13
|
+
(0, yargs_1.default)((0, helpers_1.hideBin)(process.argv))
|
14
|
+
.command('setup [tool]', 'Setup a tool', Setup_command_1.SetupCommand.builder, Setup_command_1.SetupCommand.handler)
|
15
|
+
.command('codegen [type] [template]', 'Generate code from a template', Codegen_command_1.CodegenCommand.builder, Codegen_command_1.CodegenCommand.handler)
|
16
|
+
.help().argv;
|
17
|
+
}
|
18
|
+
}
|
19
|
+
exports.q40Cli = q40Cli;
|
@@ -0,0 +1,55 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
+
});
|
10
|
+
};
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
13
|
+
};
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
15
|
+
exports.CodegenCommand = void 0;
|
16
|
+
const inquirer_1 = __importDefault(require("inquirer"));
|
17
|
+
const GenerateBlock_1 = require("./Generators/GenerateBlock");
|
18
|
+
const Codegen_types_1 = require("./Codegen.types");
|
19
|
+
class CodegenCommand {
|
20
|
+
static builder(yargs) {
|
21
|
+
yargs.positional('type', {
|
22
|
+
describe: 'Type of code piece to generate',
|
23
|
+
choices: Codegen_types_1.typeChoices,
|
24
|
+
demandOption: true,
|
25
|
+
type: 'string',
|
26
|
+
});
|
27
|
+
yargs.positional('template', {
|
28
|
+
describe: 'Template to use for code generation',
|
29
|
+
choices: Codegen_types_1.templateChoices,
|
30
|
+
demandOption: false,
|
31
|
+
type: 'string',
|
32
|
+
});
|
33
|
+
}
|
34
|
+
static handler(argv) {
|
35
|
+
var _a;
|
36
|
+
return __awaiter(this, void 0, void 0, function* () {
|
37
|
+
const type = argv.type;
|
38
|
+
const template = ((_a = argv.template) !== null && _a !== void 0 ? _a : 'default');
|
39
|
+
if (type === 'block') {
|
40
|
+
const answers = yield inquirer_1.default.prompt([
|
41
|
+
{
|
42
|
+
type: 'input',
|
43
|
+
name: 'name',
|
44
|
+
message: 'Please enter a name for the block:',
|
45
|
+
default: template || 'section-header',
|
46
|
+
},
|
47
|
+
]);
|
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();
|
51
|
+
}
|
52
|
+
});
|
53
|
+
}
|
54
|
+
}
|
55
|
+
exports.CodegenCommand = CodegenCommand;
|
@@ -0,0 +1,6 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.templateChoices = exports.typeChoices = void 0;
|
4
|
+
const config_1 = require("../../config");
|
5
|
+
exports.typeChoices = config_1.config.typeChoices;
|
6
|
+
exports.templateChoices = config_1.config.templateChoices.block;
|
@@ -0,0 +1,87 @@
|
|
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.GenerateBlock = void 0;
|
30
|
+
const fs = __importStar(require("fs"));
|
31
|
+
const path_1 = __importDefault(require("path"));
|
32
|
+
const child_process_1 = require("child_process");
|
33
|
+
const cliRoot_1 = require("../../../lib/cliRoot");
|
34
|
+
class GenerateBlock {
|
35
|
+
constructor(template, name) {
|
36
|
+
this.template = 'default';
|
37
|
+
this.name = '';
|
38
|
+
this.title = '';
|
39
|
+
this.camelCaseName = '';
|
40
|
+
this.template = template;
|
41
|
+
this.name = name !== null && name !== void 0 ? name : '';
|
42
|
+
this.camelCaseName = this.toCamelCase(this.name);
|
43
|
+
this.title = this.parseName(this.name);
|
44
|
+
}
|
45
|
+
run() {
|
46
|
+
this.createBlockFolder();
|
47
|
+
this.createBlockFiles();
|
48
|
+
}
|
49
|
+
createBlockFolder() {
|
50
|
+
(0, child_process_1.execSync)(`mkdir -p resources/scripts/editor/blocks/${this.name}`);
|
51
|
+
}
|
52
|
+
createBlockFiles() {
|
53
|
+
var _a, _b;
|
54
|
+
fs.writeFileSync(path_1.default.join(process.cwd(), `resources/scripts/editor/blocks/${this.name}/${this.name}.tsx`), this.getTemplate('tsx')
|
55
|
+
.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')
|
59
|
+
.replace(/{{name}}/g, (_b = this.name) !== null && _b !== void 0 ? _b : '')
|
60
|
+
.replace(/{{camelCaseName}}/g, this.camelCaseName));
|
61
|
+
}
|
62
|
+
parseName(name) {
|
63
|
+
return name
|
64
|
+
.split('-')
|
65
|
+
.map((word) => {
|
66
|
+
return word.charAt(0).toUpperCase() + word.slice(1);
|
67
|
+
})
|
68
|
+
.join(' ');
|
69
|
+
}
|
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
|
+
getTemplate(name) {
|
77
|
+
try {
|
78
|
+
const cliRoot = (0, cliRoot_1.findCliRoot)(__dirname);
|
79
|
+
const templateFolder = `templates/blocks/${this.template}`;
|
80
|
+
return fs.readFileSync(path_1.default.join(cliRoot, `${templateFolder}/${name}.txt`), 'utf8');
|
81
|
+
}
|
82
|
+
catch (e) {
|
83
|
+
return '';
|
84
|
+
}
|
85
|
+
}
|
86
|
+
}
|
87
|
+
exports.GenerateBlock = GenerateBlock;
|
@@ -0,0 +1,53 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.SetupCommand = void 0;
|
4
|
+
const child_process_1 = require("child_process");
|
5
|
+
const eslintrc = `
|
6
|
+
{
|
7
|
+
"extends": ["@40q/eslint-config"]
|
8
|
+
}
|
9
|
+
`;
|
10
|
+
const huskyrc = `
|
11
|
+
{
|
12
|
+
"hooks": {
|
13
|
+
"pre-commit": "lint-staged"
|
14
|
+
}
|
15
|
+
}
|
16
|
+
`;
|
17
|
+
const lintstagedrc = `
|
18
|
+
{
|
19
|
+
"*.{js,jsx,ts,tsx}": ["eslint --fix"]
|
20
|
+
}
|
21
|
+
`;
|
22
|
+
class SetupCommand {
|
23
|
+
static builder(yargs) {
|
24
|
+
yargs.positional('tool', {
|
25
|
+
describe: 'Name of the tool to setup',
|
26
|
+
type: 'string',
|
27
|
+
});
|
28
|
+
}
|
29
|
+
static handler(argv) {
|
30
|
+
SetupCommand.setupTool(argv.tool);
|
31
|
+
}
|
32
|
+
static setupTool(tool) {
|
33
|
+
switch (tool) {
|
34
|
+
case 'eslint':
|
35
|
+
this.setupEslint();
|
36
|
+
break;
|
37
|
+
default:
|
38
|
+
console.error(`Unknown tool: ${tool}. Please specify a supported tool.`);
|
39
|
+
}
|
40
|
+
}
|
41
|
+
static setupEslint() {
|
42
|
+
console.log('Installing dependencies...');
|
43
|
+
(0, child_process_1.execSync)('yarn add --dev eslint @40q/eslint-config husky lint-staged');
|
44
|
+
console.log('Creating .eslintrc.json...');
|
45
|
+
(0, child_process_1.execSync)(`echo '${eslintrc}' > .eslintrc.json`);
|
46
|
+
console.log('Creating .huskyrc.json...');
|
47
|
+
(0, child_process_1.execSync)(`echo '${huskyrc}' > .huskyrc.json`);
|
48
|
+
console.log('Creating .lintstagedrc.json...');
|
49
|
+
(0, child_process_1.execSync)(`echo '${lintstagedrc}' > .lintstagedrc.json`);
|
50
|
+
console.log('Done!');
|
51
|
+
}
|
52
|
+
}
|
53
|
+
exports.SetupCommand = SetupCommand;
|
@@ -1,13 +1,12 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.SetupCommand = void 0;
|
4
|
+
const child_process_1 = require("child_process");
|
5
5
|
const eslintrc = `
|
6
6
|
{
|
7
7
|
"extends": ["@40q/eslint-config"]
|
8
8
|
}
|
9
9
|
`;
|
10
|
-
|
11
10
|
const huskyrc = `
|
12
11
|
{
|
13
12
|
"hooks": {
|
@@ -15,51 +14,40 @@ const huskyrc = `
|
|
15
14
|
}
|
16
15
|
}
|
17
16
|
`;
|
18
|
-
|
19
17
|
const lintstagedrc = `
|
20
18
|
{
|
21
19
|
"*.{js,jsx,ts,tsx}": ["eslint --fix"]
|
22
20
|
}
|
23
21
|
`;
|
24
|
-
|
25
|
-
|
26
|
-
static builder(yargs: Argv<{}>) {
|
22
|
+
class SetupCommand {
|
23
|
+
static builder(yargs) {
|
27
24
|
yargs.positional('tool', {
|
28
25
|
describe: 'Name of the tool to setup',
|
29
26
|
type: 'string',
|
30
27
|
});
|
31
28
|
}
|
32
|
-
|
33
|
-
|
34
|
-
SetupCommand.setupTool(argv.tool as string);
|
29
|
+
static handler(argv) {
|
30
|
+
SetupCommand.setupTool(argv.tool);
|
35
31
|
}
|
36
|
-
|
37
|
-
static setupTool(tool: string) {
|
32
|
+
static setupTool(tool) {
|
38
33
|
switch (tool) {
|
39
34
|
case 'eslint':
|
40
35
|
this.setupEslint();
|
41
36
|
break;
|
42
|
-
|
43
37
|
default:
|
44
|
-
console.error(
|
45
|
-
`Unknown tool: ${tool}. Please specify a supported tool.`
|
46
|
-
);
|
38
|
+
console.error(`Unknown tool: ${tool}. Please specify a supported tool.`);
|
47
39
|
}
|
48
40
|
}
|
49
|
-
|
50
41
|
static setupEslint() {
|
51
42
|
console.log('Installing dependencies...');
|
52
|
-
execSync('yarn add --dev eslint @40q/eslint-config husky lint-staged');
|
53
|
-
|
43
|
+
(0, child_process_1.execSync)('yarn add --dev eslint @40q/eslint-config husky lint-staged');
|
54
44
|
console.log('Creating .eslintrc.json...');
|
55
|
-
execSync(`echo '${eslintrc}' > .eslintrc.json`);
|
56
|
-
|
45
|
+
(0, child_process_1.execSync)(`echo '${eslintrc}' > .eslintrc.json`);
|
57
46
|
console.log('Creating .huskyrc.json...');
|
58
|
-
execSync(`echo '${huskyrc}' > .huskyrc.json`);
|
59
|
-
|
47
|
+
(0, child_process_1.execSync)(`echo '${huskyrc}' > .huskyrc.json`);
|
60
48
|
console.log('Creating .lintstagedrc.json...');
|
61
|
-
execSync(`echo '${lintstagedrc}' > .lintstagedrc.json`);
|
62
|
-
|
49
|
+
(0, child_process_1.execSync)(`echo '${lintstagedrc}' > .lintstagedrc.json`);
|
63
50
|
console.log('Done!');
|
64
51
|
}
|
65
52
|
}
|
53
|
+
exports.SetupCommand = SetupCommand;
|
@@ -0,0 +1,39 @@
|
|
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.findCliRoot = void 0;
|
27
|
+
const fs = __importStar(require("fs"));
|
28
|
+
const path = __importStar(require("path"));
|
29
|
+
function findCliRoot(startDir) {
|
30
|
+
let currentDir = startDir;
|
31
|
+
while (currentDir !== path.parse(currentDir).root) {
|
32
|
+
if (fs.existsSync(path.join(currentDir, '.cliroot'))) {
|
33
|
+
return currentDir;
|
34
|
+
}
|
35
|
+
currentDir = path.dirname(currentDir);
|
36
|
+
}
|
37
|
+
throw new Error('CLI root directory with .cliroot marker not found.');
|
38
|
+
}
|
39
|
+
exports.findCliRoot = findCliRoot;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@40q/40q-cli",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.7",
|
4
4
|
"description": "40q CLI tool",
|
5
5
|
"main": "index.js",
|
6
6
|
"bin": {
|
@@ -26,5 +26,8 @@
|
|
26
26
|
"@types/yargs": "^17.0.29",
|
27
27
|
"ts-node": "^10.9.1",
|
28
28
|
"typescript": "^5.2.2"
|
29
|
-
}
|
29
|
+
},
|
30
|
+
"files": [
|
31
|
+
"dist/"
|
32
|
+
]
|
30
33
|
}
|
package/.cliroot
DELETED
File without changes
|
package/index.ts
DELETED
package/src/40qCli.ts
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
import yargs from 'yargs';
|
2
|
-
import { hideBin } from 'yargs/helpers';
|
3
|
-
import { SetupCommand } from './commands/Setup/Setup.command';
|
4
|
-
import { CodegenCommand } from './commands/Codegen/Codegen.command';
|
5
|
-
|
6
|
-
export class q40Cli {
|
7
|
-
static init() {
|
8
|
-
yargs(hideBin(process.argv))
|
9
|
-
.command(
|
10
|
-
'setup [tool]',
|
11
|
-
'Setup a tool',
|
12
|
-
SetupCommand.builder,
|
13
|
-
SetupCommand.handler
|
14
|
-
)
|
15
|
-
.command(
|
16
|
-
'codegen [type] [template]',
|
17
|
-
'Generate code from a template',
|
18
|
-
CodegenCommand.builder,
|
19
|
-
CodegenCommand.handler
|
20
|
-
)
|
21
|
-
.help().argv;
|
22
|
-
}
|
23
|
-
}
|
@@ -1,46 +0,0 @@
|
|
1
|
-
import { ArgumentsCamelCase, Argv } from 'yargs';
|
2
|
-
import { Command } from '../Command';
|
3
|
-
import inquirer from 'inquirer';
|
4
|
-
import { GenerateBlock } from './Generators/GenerateBlock';
|
5
|
-
import { Templates, Types, templateChoices, typeChoices } from './Codegen.types';
|
6
|
-
|
7
|
-
export class CodegenCommand implements Command {
|
8
|
-
static builder(yargs: Argv<{}>) {
|
9
|
-
yargs.positional('type', {
|
10
|
-
describe: 'Type of code piece to generate',
|
11
|
-
choices: typeChoices,
|
12
|
-
demandOption: true,
|
13
|
-
type: 'string',
|
14
|
-
});
|
15
|
-
|
16
|
-
yargs.positional('template', {
|
17
|
-
describe: 'Template to use for code generation',
|
18
|
-
choices: templateChoices,
|
19
|
-
demandOption: false,
|
20
|
-
type: 'string',
|
21
|
-
});
|
22
|
-
}
|
23
|
-
|
24
|
-
static async handler(argv: ArgumentsCamelCase<{}>) {
|
25
|
-
const type = argv.type as Types;
|
26
|
-
const template = (argv.template ?? 'default') as Templates;
|
27
|
-
|
28
|
-
if (type === 'block') {
|
29
|
-
const answers = await inquirer.prompt(
|
30
|
-
[
|
31
|
-
{
|
32
|
-
type: 'input',
|
33
|
-
name: 'name',
|
34
|
-
message: 'Please enter a name for the block:',
|
35
|
-
default: template || 'section-header',
|
36
|
-
},
|
37
|
-
],
|
38
|
-
);
|
39
|
-
|
40
|
-
const name = (answers?.name as string) || null;
|
41
|
-
|
42
|
-
const blockGenerator = new GenerateBlock(template, name);
|
43
|
-
return blockGenerator.run();
|
44
|
-
}
|
45
|
-
}
|
46
|
-
}
|
@@ -1,7 +0,0 @@
|
|
1
|
-
import { config } from '../../config';
|
2
|
-
|
3
|
-
export const typeChoices = config.typeChoices;
|
4
|
-
export type Types = (typeof typeChoices)[number];
|
5
|
-
|
6
|
-
export const templateChoices = config.templateChoices.block;
|
7
|
-
export type Templates = (typeof templateChoices)[number] | 'default';
|
@@ -1,85 +0,0 @@
|
|
1
|
-
import * as fs from 'fs';
|
2
|
-
import path from 'path';
|
3
|
-
import { execSync } from 'child_process';
|
4
|
-
import { Templates } from '../Codegen.types';
|
5
|
-
import { findCliRoot } from '../../../lib/cliRoot';
|
6
|
-
|
7
|
-
export class GenerateBlock {
|
8
|
-
private template: Templates = 'default';
|
9
|
-
private name: string = '';
|
10
|
-
private title: string = '';
|
11
|
-
private camelCaseName: string = '';
|
12
|
-
|
13
|
-
constructor(template: Templates, name: string | null) {
|
14
|
-
this.template = template;
|
15
|
-
this.name = name ?? '';
|
16
|
-
this.camelCaseName = this.toCamelCase(this.name);
|
17
|
-
this.title = this.parseName(this.name);
|
18
|
-
}
|
19
|
-
|
20
|
-
public run() {
|
21
|
-
this.createBlockFolder();
|
22
|
-
this.createBlockFiles();
|
23
|
-
}
|
24
|
-
|
25
|
-
private createBlockFolder() {
|
26
|
-
execSync(`mkdir -p resources/scripts/editor/blocks/${this.name}`);
|
27
|
-
}
|
28
|
-
|
29
|
-
private createBlockFiles() {
|
30
|
-
fs.writeFileSync(
|
31
|
-
path.join(
|
32
|
-
process.cwd(),
|
33
|
-
`resources/scripts/editor/blocks/${this.name}/${this.name}.tsx`
|
34
|
-
),
|
35
|
-
this.getTemplate('tsx')
|
36
|
-
.replace(/{{name}}/g, this.name ?? '')
|
37
|
-
.replace(/{{title}}/g, this.title)
|
38
|
-
);
|
39
|
-
|
40
|
-
fs.writeFileSync(
|
41
|
-
path.join(
|
42
|
-
process.cwd(),
|
43
|
-
`resources/views/blocks/${this.name}.blade.php`
|
44
|
-
),
|
45
|
-
this.getTemplate('blade')
|
46
|
-
);
|
47
|
-
|
48
|
-
fs.writeFileSync(
|
49
|
-
path.join(process.cwd(), `app/Blocks/${this.camelCaseName}.php`),
|
50
|
-
this.getTemplate('php')
|
51
|
-
.replace(/{{name}}/g, this.name ?? '')
|
52
|
-
.replace(/{{camelCaseName}}/g, this.camelCaseName)
|
53
|
-
);
|
54
|
-
}
|
55
|
-
|
56
|
-
private parseName(name: string) {
|
57
|
-
return name
|
58
|
-
.split('-')
|
59
|
-
.map((word) => {
|
60
|
-
return word.charAt(0).toUpperCase() + word.slice(1);
|
61
|
-
})
|
62
|
-
.join(' ');
|
63
|
-
}
|
64
|
-
|
65
|
-
private toCamelCase(name: string) {
|
66
|
-
return (
|
67
|
-
name.split('-').reduce((acc, word) => {
|
68
|
-
return acc + word.charAt(0).toUpperCase() + word.slice(1);
|
69
|
-
}, '') ?? ''
|
70
|
-
);
|
71
|
-
}
|
72
|
-
|
73
|
-
private getTemplate(name: string) {
|
74
|
-
try {
|
75
|
-
const cliRoot = findCliRoot(__dirname);
|
76
|
-
const templateFolder = `templates/blocks/${this.template}`;
|
77
|
-
return fs.readFileSync(
|
78
|
-
path.join(cliRoot, `${templateFolder}/${name}.txt`),
|
79
|
-
'utf8'
|
80
|
-
);
|
81
|
-
} catch (e) {
|
82
|
-
return '';
|
83
|
-
}
|
84
|
-
}
|
85
|
-
}
|
package/src/commands/Command.ts
DELETED
package/src/config.ts
DELETED
package/src/lib/cliRoot.ts
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
import * as fs from 'fs';
|
2
|
-
import * as path from 'path';
|
3
|
-
|
4
|
-
export function findCliRoot(startDir: string): string {
|
5
|
-
let currentDir = startDir;
|
6
|
-
|
7
|
-
while (currentDir !== path.parse(currentDir).root) {
|
8
|
-
if (fs.existsSync(path.join(currentDir, '.cliroot'))) {
|
9
|
-
return currentDir;
|
10
|
-
}
|
11
|
-
|
12
|
-
currentDir = path.dirname(currentDir);
|
13
|
-
}
|
14
|
-
|
15
|
-
throw new Error('CLI root directory with .cliroot marker not found.');
|
16
|
-
}
|
@@ -1,15 +0,0 @@
|
|
1
|
-
<?php
|
2
|
-
|
3
|
-
namespace App\Blocks;
|
4
|
-
|
5
|
-
use BlockHandler\Contracts\BlockHandler;
|
6
|
-
|
7
|
-
class {{camelCaseName}} extends BlockHandler
|
8
|
-
{
|
9
|
-
public function __invoke($block_content, $block)
|
10
|
-
{
|
11
|
-
return view('blocks.{{name}}', [
|
12
|
-
'title' => $block['attrs']['title'] ?? null,
|
13
|
-
]);
|
14
|
-
}
|
15
|
-
}
|
@@ -1,54 +0,0 @@
|
|
1
|
-
import { __ } from "@wordpress/i18n";
|
2
|
-
import { PanelBody } from "@wordpress/components";
|
3
|
-
import {
|
4
|
-
InspectorControls,
|
5
|
-
RichText,
|
6
|
-
useBlockProps,
|
7
|
-
} from "@wordpress/block-editor";
|
8
|
-
|
9
|
-
/* Block name */
|
10
|
-
export const name = "by40q/{{name}}";
|
11
|
-
|
12
|
-
/* Block title */
|
13
|
-
export const title = __("{{title}}", "40q");
|
14
|
-
|
15
|
-
/* Block category */
|
16
|
-
export const category = "text";
|
17
|
-
|
18
|
-
/* Block attributes */
|
19
|
-
export const attributes = {
|
20
|
-
title: {
|
21
|
-
type: "string",
|
22
|
-
default: "40Q",
|
23
|
-
},
|
24
|
-
};
|
25
|
-
|
26
|
-
/* Block edit */
|
27
|
-
export const edit = ({ attributes, setAttributes }) => {
|
28
|
-
const { title } = attributes;
|
29
|
-
|
30
|
-
const blockProps = useBlockProps();
|
31
|
-
|
32
|
-
return (
|
33
|
-
<>
|
34
|
-
<InspectorControls>
|
35
|
-
<PanelBody title={__("{{title}} Settings")} initialOpen></PanelBody>
|
36
|
-
</InspectorControls>
|
37
|
-
|
38
|
-
<div {...blockProps}>
|
39
|
-
<RichText
|
40
|
-
tagName="h2"
|
41
|
-
placeholder={__("40Q")}
|
42
|
-
value={title}
|
43
|
-
onChange={(title) => setAttributes({ title })}
|
44
|
-
/>
|
45
|
-
</div>
|
46
|
-
</>
|
47
|
-
);
|
48
|
-
};
|
49
|
-
|
50
|
-
/* Block save */
|
51
|
-
export const save = () => <></>;
|
52
|
-
|
53
|
-
/* Block styles */
|
54
|
-
export const styles = [];
|
@@ -1,17 +0,0 @@
|
|
1
|
-
<?php
|
2
|
-
|
3
|
-
namespace App\Blocks;
|
4
|
-
|
5
|
-
use BlockHandler\Contracts\BlockHandler;
|
6
|
-
|
7
|
-
class {{camelCaseName}} extends BlockHandler
|
8
|
-
{
|
9
|
-
public function __invoke($block_content, $block)
|
10
|
-
{
|
11
|
-
return view('blocks.{{name}}', [
|
12
|
-
'eyebrow' => $block['attrs']['eyebrow'] ?? null,
|
13
|
-
'title' => $block['attrs']['title'] ?? null,
|
14
|
-
'description' => $block['attrs']['description'] ?? null,
|
15
|
-
]);
|
16
|
-
}
|
17
|
-
}
|
@@ -1,120 +0,0 @@
|
|
1
|
-
import { __ } from "@wordpress/i18n";
|
2
|
-
import { PanelBody, ToggleControl } from "@wordpress/components";
|
3
|
-
import {
|
4
|
-
InspectorControls,
|
5
|
-
RichText,
|
6
|
-
useBlockProps,
|
7
|
-
useInnerBlocksProps,
|
8
|
-
} from "@wordpress/block-editor";
|
9
|
-
|
10
|
-
/* Block name */
|
11
|
-
export const name = "by40q/{{name}}";
|
12
|
-
|
13
|
-
/* Block title */
|
14
|
-
export const title = __("{{title}}", "40q");
|
15
|
-
|
16
|
-
/* Block category */
|
17
|
-
export const category = "text";
|
18
|
-
|
19
|
-
/* Block attributes */
|
20
|
-
export const attributes = {
|
21
|
-
showEyebrow: {
|
22
|
-
type: "boolean",
|
23
|
-
default: true,
|
24
|
-
},
|
25
|
-
eyebrow: {
|
26
|
-
type: "string",
|
27
|
-
default: "Introducing",
|
28
|
-
},
|
29
|
-
title: {
|
30
|
-
type: "string",
|
31
|
-
default: "40Q",
|
32
|
-
},
|
33
|
-
showDescription: {
|
34
|
-
type: "boolean",
|
35
|
-
default: true,
|
36
|
-
},
|
37
|
-
description: {
|
38
|
-
type: "string",
|
39
|
-
default:
|
40
|
-
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed euismod, diam id tincidunt ultrices, nunc nisl ultrices nunc, vitae aliquam nisl nunc eu nisl. Sed euismod, diam id tincidunt ultrices, nunc nisl ultrices nunc, vitae aliquam nisl nunc eu nisl.",
|
41
|
-
},
|
42
|
-
showCta: {
|
43
|
-
type: "boolean",
|
44
|
-
default: false,
|
45
|
-
},
|
46
|
-
};
|
47
|
-
|
48
|
-
/* Block edit */
|
49
|
-
export const edit = ({ attributes, setAttributes }) => {
|
50
|
-
const { showEyeBrow, eyebrow, title, showDescription, description, showCta } =
|
51
|
-
attributes;
|
52
|
-
|
53
|
-
const blockProps = useBlockProps();
|
54
|
-
|
55
|
-
const innerBlocksProps = useInnerBlocksProps(blockProps, {
|
56
|
-
template: [["core/button"]],
|
57
|
-
allowedBlocks: [],
|
58
|
-
templateLock: "all",
|
59
|
-
});
|
60
|
-
|
61
|
-
return (
|
62
|
-
<>
|
63
|
-
<InspectorControls>
|
64
|
-
<PanelBody title={__("Section Header Settings")} initialOpen>
|
65
|
-
<ToggleControl
|
66
|
-
label="Eyebrow"
|
67
|
-
checked={!!showEyeBrow}
|
68
|
-
onChange={(showEyeBrow) => setAttributes({ showEyeBrow })}
|
69
|
-
/>
|
70
|
-
<ToggleControl
|
71
|
-
label="Description"
|
72
|
-
checked={!!showDescription}
|
73
|
-
onChange={(showDescription) => setAttributes({ showDescription })}
|
74
|
-
/>
|
75
|
-
|
76
|
-
<ToggleControl
|
77
|
-
label="Cta"
|
78
|
-
checked={!!showCta}
|
79
|
-
onChange={(showCta) => setAttributes({ showCta })}
|
80
|
-
/>
|
81
|
-
</PanelBody>
|
82
|
-
</InspectorControls>
|
83
|
-
|
84
|
-
<div {...blockProps}>
|
85
|
-
{!!showEyeBrow && (
|
86
|
-
<RichText
|
87
|
-
className=""
|
88
|
-
tagName="p"
|
89
|
-
placeholder={__("Eyebrow")}
|
90
|
-
value={eyebrow}
|
91
|
-
onChange={(eyebrow) => setAttributes({ eyebrow })}
|
92
|
-
/>
|
93
|
-
)}
|
94
|
-
<RichText
|
95
|
-
className=""
|
96
|
-
tagName="h2"
|
97
|
-
placeholder={__("40Q")}
|
98
|
-
value={title}
|
99
|
-
onChange={(title) => setAttributes({ title })}
|
100
|
-
/>
|
101
|
-
{!!showDescription && (
|
102
|
-
<RichText
|
103
|
-
className=""
|
104
|
-
tagName="p"
|
105
|
-
placeholder={__("Lorem ipsum dolor sit amet.")}
|
106
|
-
value={description}
|
107
|
-
onChange={(description) => setAttributes({ description })}
|
108
|
-
/>
|
109
|
-
)}
|
110
|
-
{!!showCta && <div {...innerBlocksProps} />}
|
111
|
-
</div>
|
112
|
-
</>
|
113
|
-
);
|
114
|
-
};
|
115
|
-
|
116
|
-
/* Block save */
|
117
|
-
export const save = <></>;
|
118
|
-
|
119
|
-
/* Block styles */
|
120
|
-
export const styles = [];
|
package/tsconfig.json
DELETED