chisel-scripts 1.0.0 → 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 +17 -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
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Retrieves the translation of text.
3
+ *
4
+ * @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-i18n/
5
+ */
6
+ import { __ } from '@wordpress/i18n';
7
+
8
+ /**
9
+ * React hook that is used to mark the block wrapper element.
10
+ * It provides all the necessary props like the class name.
11
+ *
12
+ * @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-block-editor/#useblockprops
13
+ */
14
+ import { useBlockProps } from '@wordpress/block-editor';
15
+
16
+ /**
17
+ * Lets webpack process CSS, SASS or SCSS files referenced in JavaScript files.
18
+ * Those files can contain any CSS code that gets applied to the editor.
19
+ *
20
+ * @see https://www.npmjs.com/package/@wordpress/scripts#using-css
21
+ */
22
+ import './editor.scss';
23
+
24
+ /**
25
+ * The edit function describes the structure of your block in the context of the
26
+ * editor. This represents what the editor will render when the block is used.
27
+ *
28
+ * @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-edit-save/#edit
29
+ *
30
+ * @return {Element} Element to render.
31
+ */
32
+ export default function Edit() {
33
+ return (
34
+ <p { ...useBlockProps() }>
35
+ { __( '{{title}} – hello from the editor!', '{{textdomain}}' ) }
36
+ </p>
37
+ );
38
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * The following styles get applied inside the editor only.
3
+ *
4
+ * Replace them with your own styles or remove the file completely.
5
+ */
6
+
7
+ .wp-block-{{namespace}}-{{slug}} {
8
+ border: 1px dotted #f00;
9
+ }
@@ -0,0 +1,45 @@
1
+ // this is custom acf block
2
+
3
+ /**
4
+ * Registers a new block provided a unique name and an object defining its behavior.
5
+ *
6
+ * @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-registration/
7
+ */
8
+ import { registerBlockType } from '@wordpress/blocks';
9
+
10
+ /**
11
+ * Lets webpack process CSS, SASS or SCSS files referenced in JavaScript files.
12
+ * All files containing `style` keyword are bundled together. The code used
13
+ * gets applied both to the front of your site and to the editor.
14
+ *
15
+ * @see https://www.npmjs.com/package/@wordpress/scripts#using-css
16
+ */
17
+ import './style.scss';
18
+
19
+ /**
20
+ * Internal dependencies
21
+ */
22
+ import Edit from './edit';
23
+ {{#isStaticVariant}}
24
+ import save from './save';
25
+ {{/isStaticVariant}}
26
+ import metadata from './block.json';
27
+
28
+ /**
29
+ * Every block starts by registering a new block type definition.
30
+ *
31
+ * @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-registration/
32
+ */
33
+ registerBlockType( metadata.name, {
34
+ /**
35
+ * @see ./edit.js
36
+ */
37
+ edit: Edit,
38
+ {{#isStaticVariant}}
39
+
40
+ /**
41
+ * @see ./save.js
42
+ */
43
+ save,
44
+ {{/isStaticVariant}}
45
+ } );
@@ -0,0 +1,10 @@
1
+ {{#isDynamicVariant}}
2
+ <?php
3
+ /**
4
+ * @see https://github.com/WordPress/gutenberg/blob/trunk/docs/reference-guides/block-api/block-metadata.md#render
5
+ */
6
+ ?>
7
+ <p <?php echo get_block_wrapper_attributes(); ?>>
8
+ <?php esc_html_e( '{{title}} – hello from a dynamic block!', '{{textdomain}}' ); ?>
9
+ </p>
10
+ {{/isDynamicVariant}}
@@ -0,0 +1,26 @@
1
+ {{#isStaticVariant}}
2
+ /**
3
+ * React hook that is used to mark the block wrapper element.
4
+ * It provides all the necessary props like the class name.
5
+ *
6
+ * @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-block-editor/#useblockprops
7
+ */
8
+ import { useBlockProps } from '@wordpress/block-editor';
9
+
10
+ /**
11
+ * The save function defines the way in which the different attributes should
12
+ * be combined into the final markup, which is then serialized by the block
13
+ * editor into `post_content`.
14
+ *
15
+ * @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-edit-save/#save
16
+ *
17
+ * @return {Element} Element to render.
18
+ */
19
+ export default function save() {
20
+ return (
21
+ <p { ...useBlockProps.save() }>
22
+ { '{{title}} – hello from the saved content!' }
23
+ </p>
24
+ );
25
+ }
26
+ {{/isStaticVariant}}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * The following styles get applied both on the front of your site
3
+ * and in the editor.
4
+ *
5
+ * Replace them with your own styles or remove the file completely.
6
+ */
7
+
8
+ .wp-block-{{namespace}}-{{slug}} {
9
+ background-color: #21759b;
10
+ color: #fff;
11
+ padding: 2px;
12
+ }
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Use this file for JavaScript code that you want to run in the front-end
3
+ * on posts/pages that contain this block.
4
+ *
5
+ * When this file is defined as the value of the `viewScript` property
6
+ * in `block.json` it will be enqueued on the front end of the site.
7
+ *
8
+ * Example:
9
+ *
10
+ * ```js
11
+ * {
12
+ * "viewScript": "file:./view.js"
13
+ * }
14
+ * ```
15
+ *
16
+ * If you're not making any changes to this file because your project doesn't need any
17
+ * JavaScript running in the front-end, then you should delete this file and remove
18
+ * the `viewScript` property from `block.json`.
19
+ *
20
+ * @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-metadata/#view-script
21
+ */
22
+
23
+ /* eslint-disable no-console */
24
+ console.log("Hello World! (from {{namespace}}-{{slug}} block)");
25
+ /* eslint-enable no-console */
@@ -0,0 +1,3 @@
1
+ module.exports = {
2
+ blockTemplatesPath: require('path').join(__dirname, 'block'),
3
+ };
@@ -0,0 +1,116 @@
1
+ module.exports = (api, options) => {
2
+ api.registerCommand(
3
+ 'wp-config',
4
+ (command) =>
5
+ command.description(
6
+ 'configure WP (writes wp/wp-config-local.php an dev-vhost.conf)',
7
+ ),
8
+ async () => {
9
+ const { runLocal, copy } = require('chisel-shared-utils');
10
+ const wp = (args, opts) =>
11
+ runLocal(['chisel-scripts', 'wp', ...args], {
12
+ ...opts,
13
+ cwd: api.resolve(),
14
+ });
15
+ const inquirer = require('inquirer');
16
+ const path = require('path');
17
+
18
+ const prompts = [
19
+ {
20
+ name: 'databaseHost',
21
+ message: 'Enter the database host:',
22
+ default: '127.0.0.1',
23
+ },
24
+ {
25
+ type: 'number',
26
+ name: 'databasePort',
27
+ message: 'Enter the database port:',
28
+ default: 3306,
29
+ },
30
+ {
31
+ name: 'databaseName',
32
+ message: 'Enter the database name:',
33
+ default: require(api.resolve('package.json')).name,
34
+ },
35
+ {
36
+ name: 'databaseUser',
37
+ message: 'Enter the database user:',
38
+ default: 'root',
39
+ },
40
+ {
41
+ type: 'password',
42
+ name: 'databasePassword',
43
+ message: 'Enter the database password:',
44
+ },
45
+ ];
46
+
47
+ const promptAndCreateDB = async () => {
48
+ const answers = await inquirer.prompt(prompts);
49
+
50
+ answers.databaseHostPort = `${answers.databaseHost}:${answers.databasePort}`;
51
+
52
+ const { url, tablePrefix } = options;
53
+
54
+ console.log('Creating database...');
55
+ console.log(api.resolve());
56
+
57
+ await copy({
58
+ from: path.join(__dirname, '../template'),
59
+ to: api.resolveRoot(),
60
+ templateData: {
61
+ ...answers,
62
+ documentRoot: api.resolveRoot(),
63
+ serverName: new URL(url).hostname,
64
+ tablePrefix,
65
+ },
66
+ });
67
+
68
+ const res = await wp(['db', 'query', 'SELECT 1'], {
69
+ reject: false,
70
+ silent: true,
71
+ });
72
+
73
+ if (res.exitCode !== 0) {
74
+ if (
75
+ res.stderr.includes('ERROR 1049') ||
76
+ res.stderr.includes('Unknown database')
77
+ ) {
78
+ await wp(['db', 'create']);
79
+ } else {
80
+ console.log(res.stdout);
81
+ console.log(res.stderr);
82
+ throw res;
83
+ }
84
+ } else {
85
+ // exists
86
+ const { useExisting } = await inquirer.prompt([
87
+ {
88
+ type: 'confirm',
89
+ name: 'useExisting',
90
+ message:
91
+ 'Database already exist, do you want to use existing database?',
92
+ },
93
+ ]);
94
+
95
+ if (!useExisting) {
96
+ await wp(['db', 'drop', '--yes']);
97
+ await wp(['db', 'create']);
98
+ }
99
+ }
100
+ };
101
+
102
+ // eslint-disable-next-line no-constant-condition
103
+ while (true) {
104
+ try {
105
+ await promptAndCreateDB();
106
+ break;
107
+ } catch (e) {
108
+ console.log(e); // TODO: remove
109
+ console.log('');
110
+ console.log('Trying again...');
111
+ console.log('');
112
+ }
113
+ }
114
+ },
115
+ );
116
+ };
@@ -0,0 +1,70 @@
1
+ import chiselSharedUtils from 'chisel-shared-utils';
2
+ import { join } from 'path';
3
+ import fs from 'fs';
4
+ import { pathToFileURL } from 'url';
5
+
6
+ const { runLocalWithExit } = chiselSharedUtils;
7
+
8
+ function loadExtensions() {
9
+ const extensionsDir = join(import.meta.dirname, '..', 'extensions');
10
+ const files = fs
11
+ .readdirSync(join(extensionsDir))
12
+ .filter((file) => file.endsWith('.mjs'))
13
+ .sort();
14
+
15
+ return Promise.all(
16
+ files.map((file) => import(pathToFileURL(join(extensionsDir, file)))),
17
+ );
18
+ }
19
+
20
+ export default function wpScripts(api) {
21
+ api.registerCommand(
22
+ 'build',
23
+ (command) => command.description('build for production'),
24
+ // .option(
25
+ // '--no-clean',
26
+ // 'do not remove the dist directory before building the project',
27
+ // )
28
+ // .option('--watch', 'watch for changes')
29
+ // .option('--report', 'generate report to help analyze bundles content')
30
+ async () => {
31
+ process.env.NODE_ENV = 'production';
32
+
33
+ for (const extension of await loadExtensions()) {
34
+ if (!extension.build) continue;
35
+
36
+ await extension.build(api);
37
+ }
38
+
39
+ await runLocalWithExit(['wp-scripts', 'build'], {
40
+ cwd: api.resolve(),
41
+ });
42
+ },
43
+ );
44
+
45
+ api.registerCommand(
46
+ 'start',
47
+ (command) => command.description('start development server'),
48
+ async () => {
49
+ process.env.NODE_ENV = 'development';
50
+
51
+ const extensions = await loadExtensions();
52
+
53
+ for (const extension of extensions) {
54
+ if (!extension.build) continue;
55
+
56
+ await extension.build(api);
57
+ }
58
+
59
+ for (const extension of extensions) {
60
+ if (!extension.start) continue;
61
+
62
+ await extension.start(api);
63
+ }
64
+
65
+ await runLocalWithExit(['wp-scripts', 'start', '--hot'], {
66
+ cwd: api.resolve(),
67
+ });
68
+ },
69
+ );
70
+ }
@@ -0,0 +1,22 @@
1
+ const { runWithExit } = require('chisel-shared-utils');
2
+
3
+ module.exports = (api) => {
4
+ api.registerCommand(
5
+ 'wp',
6
+ (command) =>
7
+ command
8
+ .description('run WP-CLI command')
9
+ .allowUnknownOption()
10
+ .helpOption('--chisel-help'),
11
+ async () => {
12
+ const path = require('path');
13
+
14
+ const args = process.argv.slice(3);
15
+ const wpCliPath = path.resolve(__dirname, '../..', 'wp-cli.phar');
16
+
17
+ await runWithExit(['php', wpCliPath, '--color', ...args], {
18
+ cwd: api.resolveRoot(),
19
+ });
20
+ },
21
+ );
22
+ };
@@ -0,0 +1,51 @@
1
+ import { relative, join } from 'path';
2
+ import fastGlob from 'fast-glob';
3
+ import fs from 'fs/promises';
4
+
5
+ const { convertPathToPattern } = fastGlob;
6
+
7
+ export const build = async (api) => {
8
+ const stylesDir = api.resolve('src/styles');
9
+ const pattern = convertPathToPattern(stylesDir) + '/*/**/*.scss';
10
+ const files = (await fastGlob(pattern)).sort();
11
+
12
+ const groups = files.sort().reduce((acc, file) => {
13
+ const group = convertPathToPattern(relative(stylesDir, file)).split('/')[0];
14
+ acc[group] = acc[group] || [];
15
+ acc[group].push(file);
16
+ return acc;
17
+ }, {});
18
+
19
+ for (const [group, files] of Object.entries(groups)) {
20
+ const dir = join(stylesDir, group);
21
+ const content = [
22
+ '// stylelint-disable',
23
+ '// This file is auto generated. Do not edit directly.',
24
+ '',
25
+ ...files
26
+ .map((file) => {
27
+ const finalPath = convertPathToPattern(relative(dir, file));
28
+ if (finalPath === '_index.scss') return '';
29
+ return `@use '${finalPath}';`;
30
+ })
31
+ .filter(Boolean),
32
+ '',
33
+ ].join('\n');
34
+
35
+ await fs.writeFile(join(stylesDir, group, '_index.scss'), content);
36
+ }
37
+ };
38
+
39
+ export const start = async (api) => {
40
+ const { default: chokidar } = await import('chokidar');
41
+
42
+ const stylesDir = api.resolve('src/styles');
43
+ const pattern = convertPathToPattern(stylesDir) + '/*/**/*.scss';
44
+
45
+ const watcher = chokidar.watch(convertPathToPattern(pattern), {
46
+ persistent: false,
47
+ ignoreInitial: true,
48
+ });
49
+ watcher.on('add', () => build(api));
50
+ watcher.on('unlink', () => build(api));
51
+ };
@@ -0,0 +1,8 @@
1
+ <VirtualHost *:80>
2
+ DocumentRoot "<%= documentRoot %>"
3
+ ServerName <%= serverName %>
4
+ <Directory "<%= documentRoot %>">
5
+ AllowOverride All
6
+ Require all granted
7
+ </Directory>
8
+ </VirtualHost>
@@ -0,0 +1,56 @@
1
+ <?php
2
+ /**
3
+ * The base configuration for WordPress local installation
4
+ *
5
+ * This file contains the following configurations:
6
+ *
7
+ * * MySQL settings
8
+ * * Database table prefix
9
+ * * External settings when needed
10
+ *
11
+ */
12
+
13
+ // ** MySQL settings - You can get this info from your web host ** //
14
+ /** The name of the database for WordPress */
15
+ define( 'DB_NAME', '<%= databaseName %>' );
16
+
17
+ /** MySQL database username */
18
+ define( 'DB_USER', '<%= databaseUser %>' );
19
+
20
+ /** MySQL database password */
21
+ define( 'DB_PASSWORD', '<%= databasePassword %>' );
22
+
23
+ /** MySQL hostname */
24
+ define( 'DB_HOST', '<%= databaseHostPort %>' );
25
+
26
+
27
+ /**
28
+ * WordPress Database Table prefix.
29
+ *
30
+ * You can have multiple installations in one database if you give each
31
+ * a unique prefix. Only numbers, letters, and underscores please!
32
+ */
33
+ $table_prefix = '<%= tablePrefix %>';
34
+
35
+ /**
36
+ * For developers: WordPress debugging mode.
37
+ *
38
+ * Change this to true to enable the display of notices during development.
39
+ * It is strongly recommended that plugin and theme developers use WP_DEBUG
40
+ * in their development environments.
41
+ *
42
+ * For information on other constants that can be used for debugging,
43
+ * visit the Codex.
44
+ *
45
+ * @link https://codex.wordpress.org/Debugging_in_WordPress
46
+ */
47
+ define( 'WP_DEBUG', true );
48
+ define( 'WP_DEBUG_LOG', true );
49
+ define( 'WP_DEBUG_DISPLAY', true );
50
+ define( 'SCRIPT_DEBUG', true );
51
+
52
+ // Required for the theme fast refresh mode.
53
+ define( 'WP_ENVIRONMENT_TYPE', 'development' );
54
+
55
+ /** The Database Collate type. Don't change this if in doubt. */
56
+ define( 'DB_COLLATE', '' );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chisel-scripts",
3
- "version": "1.0.0",
3
+ "version": "2.0.0-alpha.0",
4
4
  "description": "TODO",
5
5
  "bin": {
6
6
  "chisel-scripts": "bin/chisel-scripts.js"
@@ -18,50 +18,24 @@
18
18
  "homepage": "https://www.getchisel.co/",
19
19
  "license": "MIT",
20
20
  "scripts": {
21
- "test": "echo \"Error: run tests from root\" && exit 1"
21
+ "test": "echo \"Error: run tests from root\" && exit 1",
22
+ "prepare": "node ./fetch-packages.js"
22
23
  },
23
24
  "bugs": {
24
25
  "url": "https://github.com/xfiveco/generator-chisel/issues"
25
26
  },
26
- "engines": {
27
- "node": ">=10"
28
- },
29
27
  "dependencies": {
30
- "@babel/core": "^7.10.2",
31
- "babel-loader": "^8.1.0",
32
- "case-sensitive-paths-webpack-plugin": "^2.3.0",
33
- "chisel-shared-utils": "^1.0.0",
34
- "cli-highlight": "^2.1.4",
35
- "cliui": "^6.0.0",
28
+ "chisel-shared-utils": "^2.0.0-alpha.0",
29
+ "chokidar": "^3.6.0",
36
30
  "commander": "^5.1.0",
37
- "css-loader": "^3.5.3",
38
- "cssnano": "^4.1.10",
39
- "file-loader": "^6.0.0",
31
+ "fast-glob": "^3.3.2",
40
32
  "fs-extra": "^9.0.1",
41
33
  "globby": "^11.0.1",
42
- "hash-sum": "^2.0.0",
43
- "lodash": "^4.17.15",
44
- "mini-css-extract-plugin": "^0.9.0",
45
- "mini-svg-data-uri": "^1.2.3",
46
- "open": "^7.0.4",
47
- "postcss": "^7.0.32",
48
- "postcss-loader": "^3.0.0",
49
- "sass": "^1.26.7",
50
- "sass-loader": "^8.0.2",
51
- "source-map-explorer": "^2.4.2",
52
- "tapable": "^1.1.3",
53
- "terser-webpack-plugin": "^3.0.5",
54
- "unminified-webpack-plugin": "^2.0.0",
55
- "url-loader": "^4.1.0",
56
- "webpack": "^4.43.0",
57
- "webpack-bundle-analyzer": "^3.8.0",
58
- "webpack-chain": "^6.4.0",
59
- "webpack-fix-style-only-entries": "^0.5.0",
60
- "webpack-merge": "^4.2.2",
61
- "webpackbar": "^4.0.0"
34
+ "inquirer": "^7.1.0",
35
+ "lodash": "^4.17.15"
62
36
  },
63
- "optionalDependencies": {
64
- "fibers": "^5.0.0"
37
+ "peerDependencies": {
38
+ "@wordpress/scripts": "^27.9.0"
65
39
  },
66
- "gitHead": "a879e91b61e119d27439c9bd9e7298c89776a4fb"
40
+ "gitHead": "694c57055488e434f25c3397be312771a8763527"
67
41
  }
package/wp-cli.phar ADDED
Binary file
@@ -1,31 +0,0 @@
1
- module.exports = {
2
- source: {
3
- base: 'src',
4
- scripts: 'scripts',
5
- styles: 'styles',
6
- assets: 'assets',
7
- templates: 'templates',
8
- content: '../content',
9
- public: '../public',
10
- },
11
-
12
- output: {
13
- base: 'dist',
14
- scripts: 'scripts',
15
- styles: 'styles',
16
- assets: 'assets',
17
- },
18
-
19
- wp: {
20
- directoryName: 'wp',
21
- },
22
-
23
- staticFrontend: {
24
- serveDist: false,
25
- skipHtmlExtension: false,
26
- buildFormat: 'prettify', // prettify, minify, as-is/undefined
27
- htmlHint: true,
28
- },
29
-
30
- plugins: [],
31
- };