@caweb/cli 1.2.0 → 1.3.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/README.md +11 -6
- package/bin/caweb +1 -1
- package/bin/wp-cli.phar +0 -0
- package/commands/a11y.js +74 -0
- package/{lib/commands → commands}/blocks/create-block.js +7 -8
- package/{lib/commands → commands}/blocks/update-block.js +3 -9
- package/commands/build.js +73 -0
- package/{lib/commands → commands/env}/destroy.js +15 -22
- package/{lib/commands → commands/env}/start.js +41 -27
- package/{lib/commands → commands/env}/stop.js +4 -10
- package/{lib/commands → commands}/index.js +51 -43
- package/commands/serve.js +78 -0
- package/commands/sync.js +226 -0
- package/{lib/commands → commands}/tasks/update-plugins.js +2 -2
- package/commands/test.js +100 -0
- package/configs/aceconfig.js +28 -0
- package/{lib/configs.js → configs/docker-compose.js} +30 -83
- package/configs/webpack.config.js +119 -0
- package/configs/wp-env.js +76 -0
- package/gen/parser.js +166 -0
- package/gen/site-generator.js +111 -0
- package/lib/admin.js +1 -1
- package/lib/cli.js +106 -64
- package/lib/helpers.js +109 -0
- package/lib/index.js +53 -0
- package/lib/spinner.js +36 -8
- package/lib/wordpress/api.js +392 -0
- package/lib/{caweb.js → wordpress/caweb.js} +1 -1
- package/lib/{divi.js → wordpress/divi.js} +1 -1
- package/lib/{download-sources.js → wordpress/download-sources.js} +74 -78
- package/lib/wordpress/index.js +19 -0
- package/lib/{wordpress.js → wordpress/wordpress.js} +4 -8
- package/package.json +41 -27
- package/lib/commands/test.js +0 -46
- package/lib/utils.js +0 -150
- /package/{lib/commands → commands/tasks}/shell.js +0 -0
- /package/lib/{options.js → wordpress/options.js} +0 -0
- /package/{lib/template → template}/assets/css/popover.css +0 -0
- /package/{lib/template → template}/assets/js/popover.js +0 -0
- /package/{lib/template → template}/block/edit.js.mustache +0 -0
- /package/{lib/template → template}/block/editor.scss.mustache +0 -0
- /package/{lib/template → template}/block/index.js.mustache +0 -0
- /package/{lib/template → template}/block/save.js.mustache +0 -0
- /package/{lib/template → template}/block/style.scss.mustache +0 -0
- /package/{lib/template → template}/index.cjs +0 -0
- /package/{lib/template → template}/plugin/$slug.php.mustache +0 -0
- /package/{lib/template → template}/plugin/core/cdec-api.php.mustache +0 -0
- /package/{lib/template → template}/plugin/core/filters.php.mustache +0 -0
- /package/{lib/template → template}/plugin/core/functions.php.mustache +0 -0
- /package/{lib/template → template}/plugin/inc/renderer.php.mustache +0 -0
package/README.md
CHANGED
|
@@ -7,10 +7,11 @@ The following WordPress packages are used:
|
|
|
7
7
|
[create-block](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-create-block/)
|
|
8
8
|
|
|
9
9
|
## Prerequisites
|
|
10
|
-
- Latest version of [Docker Desktop](https://www.docker.com/products/docker-desktop), which includes [Compose v2
|
|
10
|
+
- Latest version of [Docker Desktop](https://www.docker.com/products/docker-desktop), which includes [Compose v2](https://docs.docker.com/compose/migrate/), is installed.
|
|
11
11
|
- <strong>For Debian-Based Linux distributions:</strong> <code>docker-compose</code> may need to be installed with: <code>sudo apt-get install docker-compose</code>.
|
|
12
12
|
- <strong>For Windows users:</strong> [WSL should be set to version 2 for Windows Docker Desktop compatibility](https://docs.docker.com/desktop/windows/wsl/).
|
|
13
13
|
- git is installed.
|
|
14
|
+
- php is installed.
|
|
14
15
|
|
|
15
16
|
## Additional Features
|
|
16
17
|
- Downloads and configures the [CAWeb Theme](https://github.com/CAWebPublishing/CAWeb)
|
|
@@ -20,13 +21,17 @@ The following WordPress packages are used:
|
|
|
20
21
|
- phpMyAdmin development site starts at http://localhost:8080
|
|
21
22
|
- phpMyAdmin test site started at http://localhost:9090
|
|
22
23
|
- Uses CAWebPublishing [External Project Template Configuration](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-create-block/packages-create-block-external-template/) when creating Gutenberg Blocks, see configurations [here](https://github.com/CAWebPublishing/cli/lib/template)
|
|
23
|
-
-
|
|
24
|
+
- Allows for syncing of WordPress instance via Rest API and CLI, requires ssh.
|
|
25
|
+
- Adds config.yml to both cli containers, alias are added for each ssh connection.
|
|
26
|
+
<b>Example config.yml file</b>
|
|
24
27
|
<pre>
|
|
25
|
-
path: /var/www/html
|
|
26
|
-
apache_modules:
|
|
27
|
-
|
|
28
|
+
path: /var/www/html
|
|
29
|
+
apache_modules:
|
|
30
|
+
- mod_rewrite
|
|
31
|
+
@staging:
|
|
32
|
+
ssh: wpcli@staging.wp-cli.org
|
|
28
33
|
</pre>
|
|
29
|
-
|
|
34
|
+
|
|
30
35
|
|
|
31
36
|
## Command Reference
|
|
32
37
|
### `caweb start`
|
package/bin/caweb
CHANGED
package/bin/wp-cli.phar
ADDED
|
Binary file
|
package/commands/a11y.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* External dependencies
|
|
5
|
+
*/
|
|
6
|
+
import path from 'path';
|
|
7
|
+
import fs from 'fs';
|
|
8
|
+
import resolveBin from 'resolve-bin';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Internal dependencies
|
|
12
|
+
*/
|
|
13
|
+
// Our default A11y Checker Configuration
|
|
14
|
+
import defaultConfig from '../configs/aceconfig.js';
|
|
15
|
+
|
|
16
|
+
import {
|
|
17
|
+
runCmd,
|
|
18
|
+
} from '../lib/index.js';
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Run accessibility checks
|
|
24
|
+
*
|
|
25
|
+
* @param {Object} options
|
|
26
|
+
* @param {Object} options.spinner A CLI spinner which indicates progress.
|
|
27
|
+
* @param {boolean} options.debug True if debug mode is enabled.
|
|
28
|
+
*/
|
|
29
|
+
export default async function a11y({
|
|
30
|
+
spinner,
|
|
31
|
+
debug,
|
|
32
|
+
} ) {
|
|
33
|
+
|
|
34
|
+
// Spinner not needed at the moment
|
|
35
|
+
spinner.stop()
|
|
36
|
+
const {
|
|
37
|
+
ruleArchive,
|
|
38
|
+
policies,
|
|
39
|
+
failLevels,
|
|
40
|
+
reportLevels,
|
|
41
|
+
outputFolder,
|
|
42
|
+
outputFormat,
|
|
43
|
+
outputFilenameTimestamp
|
|
44
|
+
} = defaultConfig;
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
// pass any arguments from the cli
|
|
48
|
+
// overwriting our default config flags.
|
|
49
|
+
// users can overwrite any values by creating a .achecker.yml or aceconfig.js.
|
|
50
|
+
let acheckerArgs = [
|
|
51
|
+
'--ruleArchive',
|
|
52
|
+
ruleArchive,
|
|
53
|
+
'--policies',
|
|
54
|
+
Array.isArray(policies) ? policies.join(',') : policies,
|
|
55
|
+
'--failLevels',
|
|
56
|
+
Array.isArray(failLevels) ? failLevels.join(',') : failLevels,
|
|
57
|
+
'--reportLevels',
|
|
58
|
+
Array.isArray(reportLevels) ? reportLevels.join(',') : reportLevels,
|
|
59
|
+
'--outputFolder',
|
|
60
|
+
outputFolder,
|
|
61
|
+
'--outputFormat',
|
|
62
|
+
outputFormat,
|
|
63
|
+
'---outputFilenameTimestamp',
|
|
64
|
+
outputFilenameTimestamp,
|
|
65
|
+
process.argv.pop()
|
|
66
|
+
];
|
|
67
|
+
|
|
68
|
+
// run webpack with our arguments.
|
|
69
|
+
await runCmd(
|
|
70
|
+
'achecker',
|
|
71
|
+
acheckerArgs,
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
};
|
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import path from '
|
|
5
|
-
import fs from 'fs
|
|
6
|
-
import { spawn } from 'node:child_process';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import fs from 'fs';
|
|
7
6
|
import inquirer from 'inquirer';
|
|
8
7
|
|
|
9
8
|
/**
|
|
10
9
|
* Internal dependencies
|
|
11
10
|
*/
|
|
12
|
-
import {runCmd} from '../../
|
|
11
|
+
import {runCmd, projectPath} from '../../lib/index.js';
|
|
13
12
|
import updateBlock from './update-block.js';
|
|
14
13
|
|
|
15
|
-
const
|
|
16
|
-
const pkg = JSON.parse(
|
|
14
|
+
const localFile = path.join(projectPath, 'package.json');
|
|
15
|
+
const pkg = JSON.parse( fs.readFileSync(localFile) );
|
|
17
16
|
|
|
18
17
|
/**
|
|
19
18
|
* Get NPM Package Latest Version
|
|
@@ -74,7 +73,7 @@ export default async function createBlock({
|
|
|
74
73
|
[
|
|
75
74
|
`@wordpress/create-block`,
|
|
76
75
|
slug,
|
|
77
|
-
'--template=' + path.
|
|
76
|
+
'--template=' + path.join(projectPath, 'template', 'index.cjs')
|
|
78
77
|
],
|
|
79
78
|
spinner,
|
|
80
79
|
{
|
|
@@ -96,7 +95,7 @@ export default async function createBlock({
|
|
|
96
95
|
],
|
|
97
96
|
spinner,
|
|
98
97
|
{
|
|
99
|
-
cwd: path.
|
|
98
|
+
cwd: path.join(process.cwd(), slug ),
|
|
100
99
|
stdio: 'inherit'
|
|
101
100
|
}
|
|
102
101
|
)
|
|
@@ -1,22 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import path from '
|
|
5
|
-
import fs from 'fs
|
|
6
|
-
import { spawn } from 'node:child_process';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import fs from 'fs';
|
|
7
6
|
|
|
8
7
|
/**
|
|
9
8
|
* Internal dependencies
|
|
10
9
|
*/
|
|
11
|
-
import {runCmd} from '../../utils.js';
|
|
12
10
|
import createBlock from './create-block.js';
|
|
13
11
|
|
|
14
|
-
const localPath = path.resolve( path.join(process.cwd(), 'node_modules/@caweb/cli/package.json') )
|
|
15
|
-
const pkg = JSON.parse( await fs.readFile(localPath) );
|
|
16
|
-
|
|
17
|
-
|
|
18
12
|
/**
|
|
19
|
-
*
|
|
13
|
+
* Update Block
|
|
20
14
|
*
|
|
21
15
|
* @param {Object} options
|
|
22
16
|
* @param {Object} options.spinner A CLI spinner which indicates progress.
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* External dependencies
|
|
5
|
+
*/
|
|
6
|
+
import path from 'path';
|
|
7
|
+
import fs from 'fs';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Internal dependencies
|
|
11
|
+
*/
|
|
12
|
+
import {
|
|
13
|
+
runCmd,
|
|
14
|
+
projectPath,
|
|
15
|
+
appPath
|
|
16
|
+
} from '../lib/index.js';
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Build the current project
|
|
21
|
+
*
|
|
22
|
+
* @param {Object} options
|
|
23
|
+
* @param {Object} options.spinner A CLI spinner which indicates progress.
|
|
24
|
+
* @param {boolean} options.debug True if debug mode is enabled.
|
|
25
|
+
*/
|
|
26
|
+
export default async function build({
|
|
27
|
+
spinner,
|
|
28
|
+
debug,
|
|
29
|
+
} ) {
|
|
30
|
+
|
|
31
|
+
// Spinner not needed at the moment
|
|
32
|
+
spinner.stop()
|
|
33
|
+
|
|
34
|
+
// Since we use @wordpress/scripts webpack config we can leverage
|
|
35
|
+
// the environment variables as well.
|
|
36
|
+
process.env.WP_COPY_PHP_FILES_TO_DIST = true;
|
|
37
|
+
|
|
38
|
+
// Our default Webpack Configuration
|
|
39
|
+
const defaultConfig = path.join( projectPath, 'configs', 'webpack.config.js' );
|
|
40
|
+
|
|
41
|
+
// pass any arguments from the cli
|
|
42
|
+
// add our default config as an extension.
|
|
43
|
+
// users can overwrite any values by creating a webconfig of their own.
|
|
44
|
+
let webPackArgs = [
|
|
45
|
+
'--mode=none',
|
|
46
|
+
'--progress',
|
|
47
|
+
'--config',
|
|
48
|
+
defaultConfig
|
|
49
|
+
];
|
|
50
|
+
|
|
51
|
+
// CommonJS
|
|
52
|
+
if( fs.existsSync( path.join(appPath, 'webpack.config.cjs' ))){
|
|
53
|
+
webPackArgs.push(
|
|
54
|
+
'--config',
|
|
55
|
+
path.join(appPath, 'webpack.config.cjs' ),
|
|
56
|
+
'--merge'
|
|
57
|
+
)
|
|
58
|
+
// ESM
|
|
59
|
+
}else if( fs.existsSync(path.join(appPath, 'webpack.config.js' )) ){
|
|
60
|
+
webPackArgs.push(
|
|
61
|
+
'--config',
|
|
62
|
+
path.join(appPath, 'webpack.config.js' ),
|
|
63
|
+
'--merge'
|
|
64
|
+
)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// run webpack with our arguments.
|
|
68
|
+
await runCmd(
|
|
69
|
+
'webpack',
|
|
70
|
+
webPackArgs,
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
};
|
|
@@ -2,9 +2,13 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* External dependencies
|
|
4
4
|
*/
|
|
5
|
-
import { spawn } from 'node:child_process';
|
|
6
5
|
import { default as wpEnvDestroy } from '@wordpress/env/lib/commands/destroy.js';
|
|
7
6
|
|
|
7
|
+
/**
|
|
8
|
+
* Internal dependencies
|
|
9
|
+
*/
|
|
10
|
+
import { runCmd } from '../../lib/index.js';
|
|
11
|
+
|
|
8
12
|
/**
|
|
9
13
|
* Destroys the development server.
|
|
10
14
|
*
|
|
@@ -28,27 +32,16 @@ export default async function destroy({
|
|
|
28
32
|
|
|
29
33
|
// Stop phpMyAdmin as well
|
|
30
34
|
// wp-env doesn't destroy the phpmyadmin image so we have to do it ourselves.
|
|
31
|
-
await
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
);
|
|
42
|
-
|
|
43
|
-
childProc.on( 'error', reject );
|
|
44
|
-
childProc.on( 'exit', ( code ) => {
|
|
45
|
-
if ( code === 0 ) {
|
|
46
|
-
resolve();
|
|
47
|
-
} else {
|
|
48
|
-
reject( `Command failed with exit code ${ code }` );
|
|
49
|
-
}
|
|
50
|
-
} );
|
|
51
|
-
});
|
|
35
|
+
await runCmd(
|
|
36
|
+
'docker',
|
|
37
|
+
[
|
|
38
|
+
'image',
|
|
39
|
+
'rm',
|
|
40
|
+
'phpmyadmin'
|
|
41
|
+
],
|
|
42
|
+
{ stdio: 'ignore' }
|
|
43
|
+
)
|
|
44
|
+
|
|
52
45
|
spinner.text = "Removed WordPress environment.'";
|
|
53
46
|
|
|
54
47
|
}
|
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import fs from 'fs';
|
|
6
|
+
import { v2 as dockerCompose } from 'docker-compose';
|
|
4
7
|
import yaml from 'js-yaml';
|
|
5
|
-
import dockerCompose from 'docker-compose';
|
|
6
8
|
|
|
9
|
+
/**
|
|
10
|
+
* WordPress dependencies
|
|
11
|
+
*/
|
|
7
12
|
import { default as wpEnvStart} from '@wordpress/env/lib/commands/start.js';
|
|
8
|
-
import
|
|
9
|
-
checkDatabaseConnection,
|
|
10
|
-
canAccessWPORG
|
|
11
|
-
} from '@wordpress/env/lib/wordpress.js';
|
|
12
|
-
|
|
13
|
+
import loadConfig from '@wordpress/env/lib/config/load-config.js';
|
|
13
14
|
import retry from '@wordpress/env/lib/retry.js';
|
|
15
|
+
import { didCacheChange, getCache } from '@wordpress/env/lib/cache.js';
|
|
16
|
+
import { canAccessWPORG } from '@wordpress/env/lib/wordpress.js';
|
|
14
17
|
|
|
15
18
|
const CONFIG_CACHE_KEY = 'config_checksum';
|
|
16
19
|
|
|
17
|
-
import loadConfig from '@wordpress/env/lib/config/load-config.js';
|
|
18
|
-
import { didCacheChange, getCache } from '@wordpress/env/lib/cache.js';
|
|
19
|
-
|
|
20
20
|
/**
|
|
21
21
|
* Internal dependencies
|
|
22
22
|
*/
|
|
23
|
+
import {
|
|
24
|
+
appPath,
|
|
25
|
+
projectPath,
|
|
26
|
+
configureCAWeb,
|
|
27
|
+
downloadSources,
|
|
28
|
+
configureWordPress,
|
|
29
|
+
runCmd
|
|
30
|
+
} from '../../lib/index.js';
|
|
31
|
+
import wpEnvConfig from '../../configs/wp-env.js';
|
|
32
|
+
import dockerConfig from '../../configs/docker-compose.js';
|
|
23
33
|
|
|
24
|
-
import { configureCAWeb } from '../caweb.js';
|
|
25
|
-
import {downloadSources } from '../download-sources.js';
|
|
26
|
-
import { configureWordPress } from '../wordpress.js';
|
|
27
|
-
import { buildWPEnvConfig, buildDockerComposeConfig } from '../configs.js';
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Promisified dependencies
|
|
31
|
-
*/
|
|
32
|
-
const sleep = util.promisify( setTimeout );
|
|
33
|
-
const { writeFile } = fs.promises;
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
36
|
* Starts the development server.
|
|
@@ -64,9 +64,9 @@ export default async function start({
|
|
|
64
64
|
spinner.text = 'Writing configuration file...';
|
|
65
65
|
|
|
66
66
|
// Write CAWeb .wp-env.json file.
|
|
67
|
-
|
|
68
|
-
path.join(
|
|
69
|
-
JSON.stringify(
|
|
67
|
+
fs.writeFileSync(
|
|
68
|
+
path.join(appPath, '.wp-env.json'),
|
|
69
|
+
JSON.stringify( wpEnvConfig(bare, multisite, plugin, theme), null, 4 )
|
|
70
70
|
);
|
|
71
71
|
|
|
72
72
|
// Get current wp-env cache key
|
|
@@ -107,9 +107,9 @@ export default async function start({
|
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
// Write docker-compose.override.yml file to workDirectoryPath.
|
|
110
|
-
|
|
110
|
+
fs.writeFileSync(
|
|
111
111
|
path.join(workDirectoryPath, 'docker-compose.override.yml'),
|
|
112
|
-
yaml.dump(
|
|
112
|
+
yaml.dump( dockerConfig(workDirectoryPath) )
|
|
113
113
|
);
|
|
114
114
|
|
|
115
115
|
// Only run configurations when config has changed.
|
|
@@ -147,6 +147,19 @@ export default async function start({
|
|
|
147
147
|
} ),
|
|
148
148
|
] );
|
|
149
149
|
|
|
150
|
+
// Create an Application Password for the user.
|
|
151
|
+
/*
|
|
152
|
+
const devAppPwd = await runCmd(
|
|
153
|
+
'php',
|
|
154
|
+
[
|
|
155
|
+
path.join(projectPath, 'bin', 'wp-cli.phar'),
|
|
156
|
+
`--ssh=docker:${path.basename(workDirectoryPath)}-cli-1`,
|
|
157
|
+
`user application-password create 1 caweb`,
|
|
158
|
+
'--porcelain'
|
|
159
|
+
]
|
|
160
|
+
);
|
|
161
|
+
*/
|
|
162
|
+
|
|
150
163
|
}
|
|
151
164
|
|
|
152
165
|
// Start phpMyAdmin Service.
|
|
@@ -164,6 +177,7 @@ export default async function start({
|
|
|
164
177
|
spinner.prefixText = preText +
|
|
165
178
|
`phpMyAdmin site started at http://localhost:8080\n\n`;
|
|
166
179
|
|
|
180
|
+
|
|
167
181
|
spinner.text = 'Done!';
|
|
168
182
|
|
|
169
183
|
};
|
|
@@ -1,18 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import path from 'path';
|
|
3
5
|
import loadConfig from '@wordpress/env/lib/config/load-config.js';
|
|
4
6
|
import { v2 as dockerCompose } from 'docker-compose';
|
|
5
7
|
|
|
6
8
|
import { default as wpEnvStop } from '@wordpress/env/lib/commands/stop.js';
|
|
7
9
|
|
|
8
|
-
/**
|
|
9
|
-
* Internal dependencies
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Promisified dependencies
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
10
|
/**
|
|
17
11
|
* Starts the development server.
|
|
18
12
|
*
|
|
@@ -1,44 +1,52 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
import
|
|
17
|
-
import
|
|
18
|
-
import
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
import
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* These are default wp-env commands. No need to overwrite these commands
|
|
6
|
+
*/
|
|
7
|
+
import clean from '@wordpress/env/lib/commands/clean.js';
|
|
8
|
+
import logs from '@wordpress/env/lib/commands/logs.js';
|
|
9
|
+
import run from '@wordpress/env/lib/commands/run.js';
|
|
10
|
+
import installPath from '@wordpress/env/lib/commands/install-path.js';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Internal dependencies
|
|
14
|
+
*/
|
|
15
|
+
import build from './build.js';
|
|
16
|
+
import serve from './serve.js';
|
|
17
|
+
import a11y from './a11y.js';
|
|
18
|
+
import shell from './tasks/shell.js';
|
|
19
|
+
|
|
20
|
+
import sync from './sync.js';
|
|
21
|
+
|
|
22
|
+
import updatePlugins from './tasks/update-plugins.js'
|
|
23
|
+
import createBlock from './blocks/create-block.js'
|
|
24
|
+
import updateBlock from './blocks/update-block.js'
|
|
25
|
+
|
|
26
|
+
import test from './test.js';
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* These are default wp-env commands, we overwrite these commands so we can run additional steps.
|
|
30
|
+
*/
|
|
31
|
+
import start from './env/start.js';
|
|
32
|
+
import destroy from './env/destroy.js';
|
|
33
|
+
import stop from './env/stop.js';
|
|
34
|
+
|
|
35
|
+
export {
|
|
36
|
+
clean,
|
|
37
|
+
logs,
|
|
38
|
+
run,
|
|
39
|
+
installPath,
|
|
40
|
+
start,
|
|
41
|
+
stop,
|
|
42
|
+
destroy,
|
|
43
|
+
build,
|
|
44
|
+
serve,
|
|
45
|
+
a11y,
|
|
46
|
+
sync,
|
|
47
|
+
updatePlugins,
|
|
48
|
+
shell,
|
|
49
|
+
createBlock,
|
|
50
|
+
updateBlock,
|
|
51
|
+
test
|
|
44
52
|
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* External dependencies
|
|
5
|
+
*/
|
|
6
|
+
import path from 'path';
|
|
7
|
+
import fs from 'fs';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Internal dependencies
|
|
11
|
+
*/
|
|
12
|
+
import {
|
|
13
|
+
projectPath,
|
|
14
|
+
appPath,
|
|
15
|
+
runCmd
|
|
16
|
+
} from '../lib/index.js';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Serves the current project
|
|
20
|
+
*
|
|
21
|
+
* @param {Object} options
|
|
22
|
+
* @param {Object} options.spinner A CLI spinner which indicates progress.
|
|
23
|
+
* @param {boolean} options.debug True if debug mode is enabled.
|
|
24
|
+
* @param {boolean} options.template Disables inclusion of the template page header & footer, starting off with a plain html page.
|
|
25
|
+
*/
|
|
26
|
+
export default async function serve({
|
|
27
|
+
spinner,
|
|
28
|
+
debug,
|
|
29
|
+
template,
|
|
30
|
+
} ) {
|
|
31
|
+
spinner.stop();
|
|
32
|
+
|
|
33
|
+
// Since we use @wordpress/scripts webpack config we can leverage
|
|
34
|
+
// the environment variables as well.
|
|
35
|
+
process.env.WP_COPY_PHP_FILES_TO_DIST = true;
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
// This lets the parser know to include the template
|
|
39
|
+
// Otherwise we load a blank html page
|
|
40
|
+
process.env.CDT_TEMPLATE = template;
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
// Our default Webpack Configuration
|
|
44
|
+
const defaultConfig = path.join( projectPath, 'configs', 'webpack.config.js' );
|
|
45
|
+
|
|
46
|
+
let webPackArgs = [
|
|
47
|
+
'serve',
|
|
48
|
+
'--open',
|
|
49
|
+
'--mode=development',
|
|
50
|
+
'--config',
|
|
51
|
+
defaultConfig
|
|
52
|
+
];
|
|
53
|
+
|
|
54
|
+
// merge user configurations
|
|
55
|
+
// CommonJS
|
|
56
|
+
if( fs.existsSync(path.join( appPath, 'webpack.config.cjs' ))){
|
|
57
|
+
webPackArgs.push(
|
|
58
|
+
'--config',
|
|
59
|
+
path.join( appPath, 'webpack.config.cjs' ),
|
|
60
|
+
'--merge'
|
|
61
|
+
)
|
|
62
|
+
// ESM
|
|
63
|
+
}else if( fs.existsSync(path.join( appPath, 'webpack.config.js' )) ){
|
|
64
|
+
webPackArgs.push(
|
|
65
|
+
'--config',
|
|
66
|
+
path.join( appPath, 'webpack.config.js' ),
|
|
67
|
+
'--merge'
|
|
68
|
+
)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// run webpack with our configuration.
|
|
72
|
+
await runCmd(
|
|
73
|
+
'webpack',
|
|
74
|
+
webPackArgs
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
};
|