chisel-scripts 1.0.0-alpha.8 → 2.0.0-alpha.0

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 (41) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/README.md +0 -23
  3. package/bin/chisel-scripts.js +5 -23
  4. package/composer.phar +0 -0
  5. package/fetch-packages.js +30 -0
  6. package/index.js +60 -0
  7. package/lib/PluginAPI.js +4 -44
  8. package/lib/Service.js +25 -181
  9. package/lib/commands/add-page.js +92 -0
  10. package/lib/commands/composer.js +22 -0
  11. package/lib/commands/create-block/index.js +45 -0
  12. package/lib/commands/create-block/templates/README.md +5 -0
  13. package/lib/commands/create-block/templates/acf/block/edit.js.mustache +38 -0
  14. package/lib/commands/create-block/templates/acf/block/editor.scss.mustache +9 -0
  15. package/lib/commands/create-block/templates/acf/block/index.js.mustache +45 -0
  16. package/lib/commands/create-block/templates/acf/block/render.php.mustache +10 -0
  17. package/lib/commands/create-block/templates/acf/block/save.js.mustache +26 -0
  18. package/lib/commands/create-block/templates/acf/block/style.scss.mustache +12 -0
  19. package/lib/commands/create-block/templates/acf/block/view.js.mustache +25 -0
  20. package/lib/commands/create-block/templates/acf/index.js +3 -0
  21. package/lib/commands/wp-config.js +116 -0
  22. package/lib/commands/wp-scripts.mjs +70 -0
  23. package/lib/commands/wp.js +22 -0
  24. package/lib/extensions/stylesheets.mjs +51 -0
  25. package/lib/template/dev-vhost.chisel-tpl.conf +8 -0
  26. package/lib/template/wp-config-local.chisel-tpl.php +56 -0
  27. package/package.json +11 -37
  28. package/wp-cli.phar +0 -0
  29. package/lib/chisel.config.base.js +0 -31
  30. package/lib/commands/build/formatStats.js +0 -79
  31. package/lib/commands/build/index.js +0 -125
  32. package/lib/commands/inspect.js +0 -14
  33. package/lib/config/base.js +0 -201
  34. package/lib/config/css.js +0 -91
  35. package/lib/config/js.js +0 -52
  36. package/lib/generate-and-serialize-config.js +0 -9
  37. package/lib/webpack-loaders/sass-glob-loader.js +0 -41
  38. package/lib/webpack-plugins/DynamicPublicPath.js +0 -24
  39. package/lib/webpack-plugins/OptimizeCssnanoPlugin.js +0 -125
  40. package/webpack.config-sync.js +0 -16
  41. package/webpack.config.js +0 -9
package/CHANGELOG.md CHANGED
@@ -2,6 +2,27 @@
2
2
 
3
3
  <!-- INSERT-NEW-ENTRIES-HERE -->
4
4
 
5
+ ## 2.0.0-alpha.0 (2024-09-08)
6
+
7
+ - add block creator ([ea0e956](https://github.com/xfiveco/generator-chisel/commit/ea0e956))
8
+ - Add Coding Standards, Minor Improvements ([cfcb017](https://github.com/xfiveco/generator-chisel/commit/cfcb017))
9
+ - add styles indexing ([192b71d](https://github.com/xfiveco/generator-chisel/commit/192b71d))
10
+ - adjust patterns ([b48eabb](https://github.com/xfiveco/generator-chisel/commit/b48eabb))
11
+ - cleanup ([e78d5d4](https://github.com/xfiveco/generator-chisel/commit/e78d5d4))
12
+ - cleanup, working start and build ([0f82f3b](https://github.com/xfiveco/generator-chisel/commit/0f82f3b))
13
+ - create design styles ([a395fb5](https://github.com/xfiveco/generator-chisel/commit/a395fb5))
14
+ - more cleanup, remove hooks ([dd9243b](https://github.com/xfiveco/generator-chisel/commit/dd9243b))
15
+ - more cleanup, use default command ([e1fcf10](https://github.com/xfiveco/generator-chisel/commit/e1fcf10))
16
+ - New chisel theme ([a05665b](https://github.com/xfiveco/generator-chisel/commit/a05665b))
17
+ - remove engines, cleanup ([d562e69](https://github.com/xfiveco/generator-chisel/commit/d562e69))
18
+ - remove wordpress plugin and move code to chisel scripts ([bb90260](https://github.com/xfiveco/generator-chisel/commit/bb90260))
19
+ - WiP ([802891c](https://github.com/xfiveco/generator-chisel/commit/802891c))
20
+ - working setup with composer ([abd16db](https://github.com/xfiveco/generator-chisel/commit/abd16db))
21
+
22
+ ## 1.0.0 (2021-12-17)
23
+
24
+ - Rewrite with Webpack (#509) ([14fa2d0](https://github.com/xfiveco/generator-chisel/commit/14fa2d0)), closes [#509](https://github.com/xfiveco/generator-chisel/issues/509)
25
+
5
26
  ## 1.0.0-alpha.8 (2021-12-16)
6
27
 
7
28
  ## 1.0.0-alpha.7 (2020-09-21)
package/README.md CHANGED
@@ -1,26 +1,3 @@
1
1
  # chisel-scripts
2
2
 
3
3
  Main package containing scripts and configuration used by Chisel projects.
4
-
5
- ## Injected commands
6
-
7
- - **`chisel-scripts build`**
8
-
9
- ```text
10
- Usage: chisel-scripts build [options]
11
-
12
- build for production
13
-
14
- Options:
15
- --no-clean do not remove the dist directory before building the project
16
- --watch watch for changes
17
- --report generate report to help analyze bundles content
18
- ```
19
-
20
- - **`chisel-scripts inspect`**
21
-
22
- ```text
23
- Usage: chisel-scripts inspect [options]
24
-
25
- inspect internal webpack config
26
- ```
@@ -2,26 +2,8 @@
2
2
 
3
3
  const Service = require('../lib/Service');
4
4
 
5
- // console.log('CREATE SERVICE');
6
-
7
- if (!Object.fromEntries) {
8
- Object.fromEntries = function fromEntries(iterable) {
9
- return [...iterable].reduce((obj, [key, val]) => {
10
- obj[key] = val;
11
- return obj;
12
- }, {});
13
- };
14
- }
15
-
16
- if (typeof jest !== 'undefined') {
17
- module.exports = (argv) => {
18
- const service = new Service();
19
- return service.run(argv[0], argv.slice(1));
20
- };
21
- } else {
22
- const service = new Service();
23
- service.run(process.argv[2], process.argv.slice(3)).catch((err) => {
24
- console.error(err);
25
- process.exit(1);
26
- });
27
- }
5
+ const service = new Service();
6
+ service.run(process.argv[2], process.argv.slice(3)).catch((err) => {
7
+ console.error(err);
8
+ process.exit(1);
9
+ });
package/composer.phar ADDED
Binary file
@@ -0,0 +1,30 @@
1
+ const fs = require('fs');
2
+ const { execa } = require('chisel-shared-utils');
3
+
4
+ const get = (url) =>
5
+ fetch(url).then((res) => {
6
+ if (!res.ok) {
7
+ throw new Error(
8
+ `Failed to fetch ${url} with ${res.statusText} (${res.status})`,
9
+ );
10
+ }
11
+
12
+ return res.arrayBuffer();
13
+ });
14
+
15
+ (async () => {
16
+ const fileWpCli = await get(
17
+ 'https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar',
18
+ );
19
+ fs.writeFileSync('./wp-cli.phar', new Uint8Array(fileWpCli));
20
+ await execa('php', ['./wp-cli.phar', '--info']);
21
+
22
+ const fileComposer = await get(
23
+ 'https://getcomposer.org/download/latest-2.x/composer.phar',
24
+ );
25
+ fs.writeFileSync('./composer.phar', new Uint8Array(fileComposer));
26
+ await execa('php', ['./composer.phar', '--version']);
27
+ })().catch((err) => {
28
+ console.error(err);
29
+ process.exit(1);
30
+ });
package/index.js ADDED
@@ -0,0 +1,60 @@
1
+ function adjustWebpackConfig(baseConfig, directory) {
2
+ const { sync: glob } = require('fast-glob');
3
+ const pathMod = require('path');
4
+
5
+ const src = pathMod.join(directory, 'src');
6
+ const isProduction = process.env.NODE_ENV === 'production';
7
+ const packageJson = require(pathMod.join(directory, 'package.json'));
8
+
9
+ const [blockMetadataFiles, scriptsFiles, stylesFiles] = [
10
+ '**/block.json',
11
+ 'scripts/*.{js,jsx,ts,tsx}',
12
+ 'styles/*.scss',
13
+ ].map((pattern) =>
14
+ glob(pattern, {
15
+ absolute: true,
16
+ cwd: src,
17
+ }),
18
+ );
19
+
20
+ const entriesFromFiles = (files) =>
21
+ Object.fromEntries(
22
+ files.map((file) => {
23
+ const name = pathMod.join(
24
+ pathMod.dirname(pathMod.relative(src, file)),
25
+ pathMod.basename(file, pathMod.extname(file)),
26
+ );
27
+ return [name, file];
28
+ }),
29
+ );
30
+
31
+ const entry = {
32
+ ...(blockMetadataFiles.length > 0 && baseConfig.entry()),
33
+ ...entriesFromFiles(scriptsFiles),
34
+ ...entriesFromFiles(stylesFiles),
35
+ };
36
+
37
+ const updatedConfig = {
38
+ ...baseConfig,
39
+ entry,
40
+ resolve: {
41
+ ...baseConfig.resolve,
42
+ alias: {
43
+ ...baseConfig.resolve.alias,
44
+ '~design$': pathMod.join(src, 'design'),
45
+ },
46
+ },
47
+ devServer: baseConfig.devServer && {
48
+ ...baseConfig.devServer,
49
+ allowedHosts: [new URL(packageJson.chisel.url).host],
50
+ },
51
+ optimization: {
52
+ ...baseConfig.optimization,
53
+ ...(!isProduction && { runtimeChunk: 'single' }),
54
+ },
55
+ };
56
+
57
+ return updatedConfig;
58
+ }
59
+
60
+ module.exports.adjustWebpackConfig = adjustWebpackConfig;
package/lib/PluginAPI.js CHANGED
@@ -1,5 +1,4 @@
1
1
  const path = require('path');
2
- const tapable = require('tapable');
3
2
 
4
3
  // Based on https://github.com/vuejs/vue-cli/blob/80b93951b1710733a66765cbd535b12b7bb59279/packages/%40vue/cli-service/lib/PluginAPI.js
5
4
 
@@ -8,12 +7,6 @@ module.exports = class PluginAPI {
8
7
  this.id = id;
9
8
  /** @type import('./Service') */
10
9
  this.service = service;
11
-
12
- this.tapable = tapable;
13
- }
14
-
15
- get hooks() {
16
- return this.service.hooks;
17
10
  }
18
11
 
19
12
  /**
@@ -40,43 +33,6 @@ module.exports = class PluginAPI {
40
33
  }
41
34
  }
42
35
 
43
- registerHooks(scope, hooks = {}) {
44
- if (this.service.hooksFromPlugins[scope]) {
45
- throw new Error(`Hooks scope ${scope} is already registered`);
46
- }
47
-
48
- this.service.hooksFromPlugins[scope] = Object.freeze({ ...hooks });
49
- this.service.hooks = Object.freeze({
50
- ...this.service.hooksBase,
51
- ...this.service.hooksFromPlugins,
52
- });
53
- }
54
-
55
- /**
56
- * Register a function that will receive a chainable webpack config
57
- * the function is lazy and won't be called until `resolveWebpackConfig` is
58
- * called
59
- *
60
- * @param {function} fn
61
- */
62
- chainWebpack(fn) {
63
- this.service.webpackChainFns.push(fn);
64
- }
65
-
66
- /**
67
- * Register
68
- * - a webpack configuration object that will be merged into the config
69
- * OR
70
- * - a function that will receive the raw webpack config.
71
- * the function can either mutate the config directly or return an object
72
- * that will be merged into the config.
73
- *
74
- * @param {object | function} fn
75
- */
76
- configureWebpack(fn) {
77
- this.service.webpackRawConfigFns.push(fn);
78
- }
79
-
80
36
  /**
81
37
  * Resolve path for a project.
82
38
  *
@@ -86,4 +42,8 @@ module.exports = class PluginAPI {
86
42
  resolve(..._path) {
87
43
  return path.resolve(this.service.context, ..._path.filter(Boolean));
88
44
  }
45
+
46
+ resolveRoot(..._path) {
47
+ return this.resolve('../../..', ..._path);
48
+ }
89
49
  };
package/lib/Service.js CHANGED
@@ -1,180 +1,76 @@
1
1
  // Based on https://github.com/vuejs/vue-cli/blob/80b93951b1710733a66765cbd535b12b7bb59279/packages/%40vue/cli-service/lib/Service.js
2
2
 
3
- const merge = require('webpack-merge');
4
- const Config = require('webpack-chain');
5
3
  const path = require('path');
6
4
  const { defaultsDeep } = require('lodash');
7
5
  const { Command } = require('commander');
8
- const { AsyncSeriesHook } = require('tapable');
9
6
  const PluginAPI = require('./PluginAPI');
10
7
 
11
- function cloneRuleNames(to, from) {
12
- if (!to || !from) {
13
- return;
14
- }
15
- from.forEach((r, i) => {
16
- if (to[i]) {
17
- Object.defineProperty(to[i], '__ruleNames', {
18
- // eslint-disable-next-line no-underscore-dangle
19
- value: r.__ruleNames,
20
- });
21
- cloneRuleNames(to[i].oneOf, r.oneOf);
22
- }
23
- });
24
- }
25
-
26
8
  module.exports = class Service {
27
9
  constructor(context) {
28
10
  this.initialized = false;
29
11
  this.webpackChainFns = [];
30
12
  this.webpackRawConfigFns = [];
31
13
 
32
- this.hooksBase = Object.freeze({
33
- pluginsToInitialize: new AsyncSeriesHook(['plugins']),
34
- pluginsInitialized: new AsyncSeriesHook([]),
35
- projectOptionsLoaded: new AsyncSeriesHook(['options']),
36
- configHooksLoaded: new AsyncSeriesHook(['service']),
37
- });
38
- this.hooksFromPlugins = {};
39
- this.hooks = this.hooksBase;
40
-
41
14
  this.program = new Command('chisel-scripts');
42
15
  this.programCommands = {};
43
16
  this.context = context || process.env.CHISEL_CONTEXT || process.cwd();
44
- this.plugins = this.loadPlugins();
17
+ this.plugins = [];
18
+ this.projectOptions = {};
45
19
  }
46
20
 
47
21
  // eslint-disable-next-line class-methods-use-this
48
- loadPlugins() {
22
+ async loadPlugins() {
49
23
  const idToPlugin = (id) => ({
50
24
  id: id.replace(/^.\//, 'built-in:'),
51
25
  apply: require(id),
52
26
  });
53
27
 
54
28
  const builtInPlugins = [
55
- // './commands/serve',
56
- './commands/build',
57
- './commands/inspect',
58
- // config plugins are order sensitive
59
- './config/base',
60
- './config/js',
61
- './config/css',
62
- // './config/prod',
63
- ];
29
+ 'wp-scripts.mjs', // start, build
30
+ 'composer',
31
+ 'wp',
32
+ 'wp-config',
33
+ 'add-page',
34
+ 'create-block',
35
+ ].map((id) => `./commands/${id}`);
64
36
 
65
37
  const plugins = [];
66
38
 
67
- plugins.push(...builtInPlugins.map(idToPlugin));
39
+ for (const id of builtInPlugins) {
40
+ if (id.endsWith('.mjs')) {
41
+ plugins.push({
42
+ id: id.replace(/^.\//, 'built-in:'),
43
+ apply: (await import(id)).default,
44
+ });
45
+ } else {
46
+ plugins.push(idToPlugin(id));
47
+ }
48
+ }
68
49
 
69
- return plugins;
50
+ this.plugins = plugins;
70
51
  }
71
52
 
72
53
  async initializePlugins() {
73
54
  const plugins = [...this.plugins];
74
- await this.hooks.pluginsToInitialize.promise(plugins);
75
55
 
76
56
  for (const { id, apply } of plugins) {
77
57
  await apply(new PluginAPI(id, this), this.projectOptions);
78
58
  }
79
-
80
- await this.hooks.pluginsInitialized.promise();
81
59
  }
82
60
 
83
61
  async init() {
84
62
  if (this.initialized) return;
85
63
  this.initialized = true;
86
64
 
65
+ await this.loadPlugins();
66
+
87
67
  this.program.version(require('../package.json').version);
88
68
 
89
- const baseOptions = require('./chisel.config.base.js');
90
- const userOptions = require(path.resolve(this.context, 'chisel.config.js'));
91
- let userLocalOptions = {};
92
- try {
93
- userLocalOptions = require(path.resolve(
94
- this.context,
95
- 'chisel.config.local.js',
96
- ));
97
- } catch (e) {
98
- //
99
- }
69
+ const packageJson = require(path.resolve(this.context, 'package.json'));
100
70
 
101
- this.projectOptions = defaultsDeep(
102
- {},
103
- userLocalOptions,
104
- userOptions,
105
- baseOptions,
106
- );
107
-
108
- await this.hooks.projectOptionsLoaded.promise(this.projectOptions);
109
-
110
- this.initializeProjectOptionsHooks();
111
-
112
- await this.hooks.configHooksLoaded.promise(this);
113
-
114
- if (Array.isArray(userOptions.plugins)) {
115
- userOptions.plugins.forEach((plugin, index) => {
116
- if (typeof plugin === 'string') {
117
- this.plugins.push({ id: plugin, apply: require(plugin) });
118
- } else if (typeof plugin === 'function') {
119
- this.plugins.push({
120
- id: plugin.name || `plugin${index}`,
121
- apply: plugin,
122
- });
123
- }
124
- });
125
- }
71
+ this.projectOptions = { ...packageJson.chisel };
126
72
 
127
73
  await this.initializePlugins();
128
-
129
- // apply webpack configs from project config file
130
- if (this.projectOptions.chainWebpack) {
131
- this.webpackChainFns.push(this.projectOptions.chainWebpack);
132
- }
133
-
134
- if (this.projectOptions.configureWebpack) {
135
- this.webpackRawConfigFns.push(this.projectOptions.configureWebpack);
136
- }
137
- }
138
-
139
- initializeProjectOptionsHooks() {
140
- const { hooks: optionsHooks } = this.projectOptions;
141
- if (!optionsHooks) return;
142
-
143
- const subscribe = (hooks, taps) => {
144
- Object.entries(taps).forEach(([name, tap]) => {
145
- const hook = hooks[name];
146
-
147
- if (hook instanceof AsyncSeriesHook) {
148
- hook.tapPromise('ChiselConfig', (...args) =>
149
- Promise.resolve(tap(...args)),
150
- );
151
- } else {
152
- throw new Error(`Don't know how to tap to ${name} hook`);
153
- }
154
- });
155
- };
156
-
157
- const hooksToSubscribe = Object.fromEntries(
158
- Object.entries(optionsHooks).filter(
159
- ([, value]) => typeof value === 'function',
160
- ),
161
- );
162
-
163
- const hooksFromPlugins = Object.fromEntries(
164
- Object.entries(optionsHooks).filter(
165
- ([, value]) => typeof value === 'object',
166
- ),
167
- );
168
-
169
- subscribe(this.hooks, hooksToSubscribe);
170
-
171
- if (Object.keys(hooksFromPlugins).length > 0) {
172
- this.hooks.pluginsInitialized.tap('Service', () => {
173
- Object.entries(hooksFromPlugins).forEach(([plugin, taps]) => {
174
- subscribe(this.hooks[plugin], taps);
175
- });
176
- });
177
- }
178
74
  }
179
75
 
180
76
  async run(name, args = []) {
@@ -194,56 +90,4 @@ module.exports = class Service {
194
90
 
195
91
  return undefined;
196
92
  }
197
-
198
- async resolveChainableWebpackConfig() {
199
- const chainableConfig = new Config();
200
- for (const fn of this.webpackChainFns) {
201
- await fn(chainableConfig);
202
- }
203
- return chainableConfig;
204
- }
205
-
206
- async resolveWebpackConfig(chainableConfig) {
207
- if (!chainableConfig) {
208
- chainableConfig = await this.resolveChainableWebpackConfig();
209
- }
210
-
211
- // get raw config
212
- let config = chainableConfig.toConfig();
213
- const original = config;
214
-
215
- if (typeof config.node === 'undefined') {
216
- config.node = false;
217
- }
218
-
219
- if (!Array.isArray(config.externals)) {
220
- config.externals =
221
- typeof config.externals === 'undefined' ? [] : [config.externals];
222
- }
223
-
224
- // apply raw config fns
225
- this.webpackRawConfigFns.forEach((fn) => {
226
- if (typeof fn === 'function') {
227
- // function with optional return value
228
- const res = fn(config);
229
- if (res) {
230
- config = merge(config, res);
231
- }
232
- } else if (fn) {
233
- // merge literal values
234
- config = merge(config, fn);
235
- }
236
- });
237
-
238
- // #2206 If config is merged by merge-webpack, it discards the __ruleNames
239
- // information injected by webpack-chain. Restore the info so that
240
- // vue inspect works properly.
241
- if (config !== original) {
242
- cloneRuleNames(
243
- config.module && config.module.rules,
244
- original.module && original.module.rules,
245
- );
246
- }
247
- return config;
248
- }
249
93
  };
@@ -0,0 +1,92 @@
1
+ module.exports = (api, options) => {
2
+ api.registerCommand(
3
+ 'add-page <page...>',
4
+ (command) =>
5
+ command.description(
6
+ 'add page(s) (creates twig templates and entries in WP)',
7
+ ),
8
+ async (pages) => {
9
+ const fs = require('fs-extra');
10
+ const { runLocal, chalk } = require('chisel-shared-utils');
11
+ const { kebabCase, template } = require('lodash');
12
+
13
+ const wp = (args, opts) =>
14
+ runLocal(['chisel-scripts', 'wp', ...args], {
15
+ ...opts,
16
+ cwd: api.resolve(),
17
+ });
18
+
19
+ const { wp: wpOptions } = options;
20
+ const theme = `${wpOptions.directoryName}/wp-content/themes/${wpOptions.themeName}`;
21
+ const templatesFiles = [
22
+ api.resolve(theme, options.source.templates, 'layouts/page.twig'),
23
+ ];
24
+
25
+ let templateFileSelected;
26
+
27
+ for (const file of templatesFiles) {
28
+ if (await fs.pathExists(file)) {
29
+ templateFileSelected = file;
30
+ break;
31
+ }
32
+ }
33
+
34
+ const templateBody = await fs.readFile(templateFileSelected, {
35
+ encoding: 'utf8',
36
+ });
37
+ const templateCompiled = template(templateBody, {
38
+ sourceURL: templateFileSelected,
39
+ });
40
+
41
+ console.log();
42
+
43
+ for (const page of pages) {
44
+ // let slug = '';
45
+
46
+ const createPost = await wp(
47
+ [
48
+ 'post',
49
+ 'create',
50
+ { post_type: 'page', post_title: page, post_status: 'publish' },
51
+ ],
52
+ { silent: true },
53
+ );
54
+
55
+ const id = /Created post (\d+)\./.exec(createPost.stdout)[1];
56
+
57
+ if (!id) {
58
+ throw new Error('Post id not found');
59
+ }
60
+
61
+ const postDetailsCmd = await wp(
62
+ ['post', 'get', id, { format: 'json' }],
63
+ { silent: true },
64
+ );
65
+
66
+ const postDetails = JSON.parse(postDetailsCmd.stdout);
67
+
68
+ const slug = postDetails.post_name;
69
+ const targetFileName = `page-${slug}.twig`;
70
+ const targetPath = api.resolve(
71
+ theme,
72
+ options.source.templates,
73
+ targetFileName,
74
+ );
75
+
76
+ await fs.outputFile(
77
+ targetPath,
78
+ templateCompiled({
79
+ ...options.creatorData,
80
+ pageName: page,
81
+ pageSlug: slug,
82
+ }),
83
+ );
84
+
85
+ console.log(chalk.greenBright.bold(`Page ${page} created!`));
86
+ console.log(`${chalk.bold(`Template:`)} ${targetPath}`);
87
+ console.log(`${chalk.bold(`URL:`)} ${postDetails.guid}`);
88
+ console.log();
89
+ }
90
+ },
91
+ );
92
+ };
@@ -0,0 +1,22 @@
1
+ const { runWithExit } = require('chisel-shared-utils');
2
+
3
+ module.exports = (api) => {
4
+ api.registerCommand(
5
+ 'composer',
6
+ (command) =>
7
+ command
8
+ .description('run Composer command')
9
+ .allowUnknownOption()
10
+ .helpOption('--chisel-help'),
11
+ async () => {
12
+ const path = require('path');
13
+
14
+ const args = process.argv.slice(3);
15
+ const composerPath = path.resolve(__dirname, '../..', 'composer.phar');
16
+
17
+ await runWithExit(['php', composerPath, '--ansi', ...args], {
18
+ cwd: api.resolve(),
19
+ });
20
+ },
21
+ );
22
+ };
@@ -0,0 +1,45 @@
1
+ const { runWithExit } = require('chisel-shared-utils');
2
+ const fs = require('fs-extra');
3
+
4
+ module.exports = (api) => {
5
+ api.registerCommand(
6
+ 'create-block',
7
+ (command) =>
8
+ command
9
+ .description('create a Gutenberg block')
10
+ .option('-t, --template <template>', 'template to use')
11
+ .allowUnknownOption()
12
+ .helpOption('--chisel-help'),
13
+ async ({ template = 'standard' }, args = []) => {
14
+ const path = require('path');
15
+
16
+ const targetDir = api.resolve(
17
+ 'src',
18
+ template === 'acf' ? 'acf-blocks' : 'blocks',
19
+ );
20
+
21
+ const maybeTemplatePath =
22
+ template && path.resolve(__dirname, 'templates', template);
23
+ if (maybeTemplatePath && (await fs.pathExists(maybeTemplatePath))) {
24
+ template = maybeTemplatePath;
25
+ }
26
+
27
+ await fs.ensureDir(targetDir);
28
+
29
+ await runWithExit(
30
+ [
31
+ 'npx',
32
+ '--yes',
33
+ '@wordpress/create-block@latest',
34
+ '--template',
35
+ template,
36
+ '--no-plugin',
37
+ ...args,
38
+ ],
39
+ {
40
+ cwd: targetDir,
41
+ },
42
+ );
43
+ },
44
+ );
45
+ };
@@ -0,0 +1,5 @@
1
+ # Custom Block Templates
2
+
3
+ See https://developer.wordpress.org/block-editor/reference-guides/packages/packages-create-block/packages-create-block-external-template to learn more about creating custom block templates.
4
+
5
+ Please note that `--no-plugin` is always passed to `@wordpress/create-block` when using `chisel-scripts create-block`.