chisel-scripts 1.0.0 → 2.0.0-alpha.1
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.
- package/CHANGELOG.md +22 -0
- package/README.md +0 -23
- package/bin/chisel-scripts.js +5 -23
- package/composer.phar +0 -0
- package/fetch-packages.js +30 -0
- package/index.js +75 -0
- package/lib/PluginAPI.js +4 -44
- package/lib/Service.js +25 -181
- package/lib/commands/add-page.js +92 -0
- package/lib/commands/composer.js +22 -0
- package/lib/commands/create-block/index.js +45 -0
- package/lib/commands/create-block/templates/README.md +5 -0
- package/lib/commands/create-block/templates/acf/block/edit.js.mustache +38 -0
- package/lib/commands/create-block/templates/acf/block/editor.scss.mustache +9 -0
- package/lib/commands/create-block/templates/acf/block/index.js.mustache +45 -0
- package/lib/commands/create-block/templates/acf/block/render.php.mustache +10 -0
- package/lib/commands/create-block/templates/acf/block/save.js.mustache +26 -0
- package/lib/commands/create-block/templates/acf/block/style.scss.mustache +12 -0
- package/lib/commands/create-block/templates/acf/block/view.js.mustache +25 -0
- package/lib/commands/create-block/templates/acf/index.js +3 -0
- package/lib/commands/wp-config.js +116 -0
- package/lib/commands/wp-scripts.mjs +70 -0
- package/lib/commands/wp.js +22 -0
- package/lib/extensions/stylesheets.mjs +51 -0
- package/lib/template/dev-vhost.chisel-tpl.conf +8 -0
- package/lib/template/wp-config-local.chisel-tpl.php +56 -0
- package/package.json +11 -37
- package/wp-cli.phar +0 -0
- package/lib/chisel.config.base.js +0 -31
- package/lib/commands/build/formatStats.js +0 -79
- package/lib/commands/build/index.js +0 -125
- package/lib/commands/inspect.js +0 -14
- package/lib/config/base.js +0 -201
- package/lib/config/css.js +0 -91
- package/lib/config/js.js +0 -52
- package/lib/generate-and-serialize-config.js +0 -9
- package/lib/webpack-loaders/sass-glob-loader.js +0 -41
- package/lib/webpack-plugins/DynamicPublicPath.js +0 -24
- package/lib/webpack-plugins/OptimizeCssnanoPlugin.js +0 -125
- package/webpack.config-sync.js +0 -16
- package/webpack.config.js +0 -9
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,28 @@
|
|
|
2
2
|
|
|
3
3
|
<!-- INSERT-NEW-ENTRIES-HERE -->
|
|
4
4
|
|
|
5
|
+
## 2.0.0-alpha.1 (2024-09-10)
|
|
6
|
+
|
|
7
|
+
- copy twig files ([67ff991](https://github.com/xfiveco/generator-chisel/commit/67ff991))
|
|
8
|
+
- fix whitespace ([9d58dba](https://github.com/xfiveco/generator-chisel/commit/9d58dba))
|
|
9
|
+
|
|
10
|
+
## 2.0.0-alpha.0 (2024-09-08)
|
|
11
|
+
|
|
12
|
+
- add block creator ([ea0e956](https://github.com/xfiveco/generator-chisel/commit/ea0e956))
|
|
13
|
+
- Add Coding Standards, Minor Improvements ([cfcb017](https://github.com/xfiveco/generator-chisel/commit/cfcb017))
|
|
14
|
+
- add styles indexing ([192b71d](https://github.com/xfiveco/generator-chisel/commit/192b71d))
|
|
15
|
+
- adjust patterns ([b48eabb](https://github.com/xfiveco/generator-chisel/commit/b48eabb))
|
|
16
|
+
- cleanup ([e78d5d4](https://github.com/xfiveco/generator-chisel/commit/e78d5d4))
|
|
17
|
+
- cleanup, working start and build ([0f82f3b](https://github.com/xfiveco/generator-chisel/commit/0f82f3b))
|
|
18
|
+
- create design styles ([a395fb5](https://github.com/xfiveco/generator-chisel/commit/a395fb5))
|
|
19
|
+
- more cleanup, remove hooks ([dd9243b](https://github.com/xfiveco/generator-chisel/commit/dd9243b))
|
|
20
|
+
- more cleanup, use default command ([e1fcf10](https://github.com/xfiveco/generator-chisel/commit/e1fcf10))
|
|
21
|
+
- New chisel theme ([a05665b](https://github.com/xfiveco/generator-chisel/commit/a05665b))
|
|
22
|
+
- remove engines, cleanup ([d562e69](https://github.com/xfiveco/generator-chisel/commit/d562e69))
|
|
23
|
+
- remove wordpress plugin and move code to chisel scripts ([bb90260](https://github.com/xfiveco/generator-chisel/commit/bb90260))
|
|
24
|
+
- WiP ([802891c](https://github.com/xfiveco/generator-chisel/commit/802891c))
|
|
25
|
+
- working setup with composer ([abd16db](https://github.com/xfiveco/generator-chisel/commit/abd16db))
|
|
26
|
+
|
|
5
27
|
## 1.0.0 (2021-12-17)
|
|
6
28
|
|
|
7
29
|
- Rewrite with Webpack (#509) ([14fa2d0](https://github.com/xfiveco/generator-chisel/commit/14fa2d0)), closes [#509](https://github.com/xfiveco/generator-chisel/issues/509)
|
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
|
-
```
|
package/bin/chisel-scripts.js
CHANGED
|
@@ -2,26 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
const Service = require('../lib/Service');
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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,75 @@
|
|
|
1
|
+
function adjustWebpackConfig(baseConfig, directory) {
|
|
2
|
+
const { sync: glob } = require('fast-glob');
|
|
3
|
+
const pathMod = require('path');
|
|
4
|
+
const CopyWebpackPlugin = require(require.resolve('copy-webpack-plugin', {
|
|
5
|
+
paths: [directory],
|
|
6
|
+
}));
|
|
7
|
+
|
|
8
|
+
const src = pathMod.join(directory, 'src');
|
|
9
|
+
const isProduction = process.env.NODE_ENV === 'production';
|
|
10
|
+
const packageJson = require(pathMod.join(directory, 'package.json'));
|
|
11
|
+
|
|
12
|
+
const [blockMetadataFiles, scriptsFiles, stylesFiles] = [
|
|
13
|
+
'**/block.json',
|
|
14
|
+
'scripts/*.{js,jsx,ts,tsx}',
|
|
15
|
+
'styles/*.scss',
|
|
16
|
+
].map((pattern) =>
|
|
17
|
+
glob(pattern, {
|
|
18
|
+
absolute: true,
|
|
19
|
+
cwd: src,
|
|
20
|
+
}),
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
const entriesFromFiles = (files) =>
|
|
24
|
+
Object.fromEntries(
|
|
25
|
+
files.map((file) => {
|
|
26
|
+
const name = pathMod.join(
|
|
27
|
+
pathMod.dirname(pathMod.relative(src, file)),
|
|
28
|
+
pathMod.basename(file, pathMod.extname(file)),
|
|
29
|
+
);
|
|
30
|
+
return [name, file];
|
|
31
|
+
}),
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
const entry = {
|
|
35
|
+
...(blockMetadataFiles.length > 0 && baseConfig.entry()),
|
|
36
|
+
...entriesFromFiles(scriptsFiles),
|
|
37
|
+
...entriesFromFiles(stylesFiles),
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const updatedConfig = {
|
|
41
|
+
...baseConfig,
|
|
42
|
+
entry,
|
|
43
|
+
resolve: {
|
|
44
|
+
...baseConfig.resolve,
|
|
45
|
+
alias: {
|
|
46
|
+
...baseConfig.resolve.alias,
|
|
47
|
+
'~design$': pathMod.join(src, 'design'),
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
devServer: baseConfig.devServer && {
|
|
51
|
+
...baseConfig.devServer,
|
|
52
|
+
allowedHosts: [new URL(packageJson.chisel.url).host],
|
|
53
|
+
},
|
|
54
|
+
optimization: {
|
|
55
|
+
...baseConfig.optimization,
|
|
56
|
+
...(!isProduction && { runtimeChunk: 'single' }),
|
|
57
|
+
},
|
|
58
|
+
plugins: [
|
|
59
|
+
...baseConfig.plugins,
|
|
60
|
+
new CopyWebpackPlugin({
|
|
61
|
+
patterns: [
|
|
62
|
+
{
|
|
63
|
+
from: '**/*.twig',
|
|
64
|
+
context: 'src',
|
|
65
|
+
noErrorOnMissing: true,
|
|
66
|
+
},
|
|
67
|
+
],
|
|
68
|
+
}),
|
|
69
|
+
],
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
return updatedConfig;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
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 =
|
|
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
|
-
|
|
56
|
-
'
|
|
57
|
-
'
|
|
58
|
-
|
|
59
|
-
'
|
|
60
|
-
'
|
|
61
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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 =
|
|
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`.
|