@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
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import fs from 'fs';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Internal Dependencies
|
|
9
|
+
*/
|
|
10
|
+
import {
|
|
11
|
+
projectPath
|
|
12
|
+
} from '../lib/helpers.js';
|
|
13
|
+
|
|
14
|
+
const localFile = path.join(projectPath, 'package.json');
|
|
15
|
+
const pkg = JSON.parse( fs.readFileSync(localFile) );
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Build .wp-env.json
|
|
19
|
+
*
|
|
20
|
+
* @param {boolean} bare True if excluding any CAWeb Configurations.
|
|
21
|
+
* @param {boolean} multisite True if converting to multisite.
|
|
22
|
+
* @param {boolean} plugin True if root directory is a plugin.
|
|
23
|
+
* @param {boolean} theme True if root directory is a theme.
|
|
24
|
+
*
|
|
25
|
+
* @returns object
|
|
26
|
+
*/
|
|
27
|
+
export default function wpEnvConfig ( bare, multisite, plugin, theme ) {
|
|
28
|
+
let themes = [];
|
|
29
|
+
let plugins = [];
|
|
30
|
+
|
|
31
|
+
let config = {
|
|
32
|
+
core: `WordPress/WordPress#${pkg.config.WP_VER}`,
|
|
33
|
+
phpVersion: `${pkg.config.PHP_VER}`,
|
|
34
|
+
config: {
|
|
35
|
+
...pkg.config.DEFAULTS
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// if not bare then include our theme.
|
|
40
|
+
if( ! bare ){
|
|
41
|
+
themes.push('CAWebPublishing/CAWeb')
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// if root directory is a theme
|
|
45
|
+
if( theme ){
|
|
46
|
+
themes.push( '.' );
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// if is multisite
|
|
50
|
+
if( multisite ){
|
|
51
|
+
config.config['WP_ALLOW_MULTISITE'] = true;
|
|
52
|
+
|
|
53
|
+
// set CAWeb as Default Theme if it was downloaded
|
|
54
|
+
if( ! bare ){
|
|
55
|
+
config.config['WP_DEFAULT_THEME'] = 'CAWeb';
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// if root directory is a plugin
|
|
60
|
+
if( plugin ){
|
|
61
|
+
plugins.push( '.' );
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// add plugins if sources were added
|
|
65
|
+
if( plugins.length ){
|
|
66
|
+
config['plugins'] = plugins;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// add themes if sources were added
|
|
70
|
+
if( themes.length ){
|
|
71
|
+
config['themes'] = themes;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return config;
|
|
75
|
+
|
|
76
|
+
}
|
package/gen/parser.js
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import fs from 'fs';
|
|
5
|
+
import path from 'path';
|
|
6
|
+
import { HTMLToJSON } from 'html-to-json-parser';
|
|
7
|
+
import jsdom from 'jsdom';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Internal dependencies
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Path Directory Locations
|
|
15
|
+
* - appPath - Project Application Path
|
|
16
|
+
* - srcPath - Project Application Src Path
|
|
17
|
+
* - publicPath - Project Application Public Path
|
|
18
|
+
* - dataPath - Project Application Data Path
|
|
19
|
+
*/
|
|
20
|
+
const appPath = path.resolve(process.cwd());
|
|
21
|
+
const srcPath = path.join( appPath, 'src');
|
|
22
|
+
const dataPath = path.join( srcPath, 'data');
|
|
23
|
+
const assetsPath = path.join( srcPath, 'assets');
|
|
24
|
+
|
|
25
|
+
const fallbackPath = path.join( appPath, 'node_modules', '@cdt', 'template');
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Generate Pages
|
|
29
|
+
*
|
|
30
|
+
* @async
|
|
31
|
+
* @param {Object} siteData Data to use when creating pages
|
|
32
|
+
* @returns {string}
|
|
33
|
+
*/
|
|
34
|
+
async function generatePages(siteData){
|
|
35
|
+
|
|
36
|
+
// we start with a blank html and schema
|
|
37
|
+
let page = '<html><html>';
|
|
38
|
+
let schema = {};
|
|
39
|
+
|
|
40
|
+
// if src/index.html exists
|
|
41
|
+
if(fs.existsSync(path.join(srcPath, 'index.html'))){
|
|
42
|
+
|
|
43
|
+
// get index path file location
|
|
44
|
+
page = path.join(srcPath, 'index.html')
|
|
45
|
+
|
|
46
|
+
// generate page schema
|
|
47
|
+
schema = await convertHTMLtoJson(page, false);
|
|
48
|
+
|
|
49
|
+
// read contents of index file, we strip any newlines
|
|
50
|
+
//page = fs.readFileSync( page ).toString().replace(/\n[\s]+/g,'');
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// convert page to jsdom object
|
|
54
|
+
let dom = new jsdom.JSDOM( page );
|
|
55
|
+
|
|
56
|
+
// if we should be using the template
|
|
57
|
+
if( process.env.CDT_TEMPLATE ){
|
|
58
|
+
|
|
59
|
+
// read contents of template index file, we strip any newlines
|
|
60
|
+
page = fs.readFileSync( path.join(fallbackPath, 'src', 'index.html') ).toString().replace(/\n[\s]+/g,'');
|
|
61
|
+
|
|
62
|
+
// create template jsdom object
|
|
63
|
+
let templateDom = new jsdom.JSDOM( page );
|
|
64
|
+
|
|
65
|
+
// colorscheme
|
|
66
|
+
let colorCSS = path.join(fallbackPath, 'build', 'oceanside.css');
|
|
67
|
+
let colorJS = path.join(fallbackPath, 'build', 'oceanside.js');
|
|
68
|
+
|
|
69
|
+
dom.window.document.querySelector('head').append(
|
|
70
|
+
`<link rel="stylesheet" type="text/css" href="${colorCSS}">`
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
// update template dom by appending contents of existing dom body
|
|
75
|
+
// after the header
|
|
76
|
+
templateDom.window.document.querySelector('header').append(
|
|
77
|
+
dom.window.document.querySelector('body')
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
// update existing dom with templated changes.
|
|
81
|
+
dom = new jsdom.JSDOM( templateDom.window.document.documentElement.outerHTML);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// generate any data attributes
|
|
85
|
+
populateDataAttrs( dom, siteData, schema );
|
|
86
|
+
|
|
87
|
+
return dom.window.document.documentElement.outerHTML;
|
|
88
|
+
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Populate data-cagov attributes with siteData
|
|
94
|
+
*
|
|
95
|
+
* @param {jsdom.JSDOM} dom HTML
|
|
96
|
+
* @param {Object} siteData
|
|
97
|
+
* @param {Object} schema
|
|
98
|
+
*/
|
|
99
|
+
function populateDataAttrs(dom, siteData, schema){
|
|
100
|
+
for( const [attr, data] of Object.entries(siteData) ){
|
|
101
|
+
// if attribute isn't in the schema don't do anything
|
|
102
|
+
if( ! schema.data || ! Object.keys(schema.data).includes(attr) ){
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// any data- attributes should be prefixed with cagov
|
|
107
|
+
// get any elements with the appropriate data- attr
|
|
108
|
+
let elements = dom.window.document.querySelectorAll(`[data-cagov-${attr}]`);
|
|
109
|
+
|
|
110
|
+
// if the data is an array|object pass as data
|
|
111
|
+
let value = Array.isArray(data) || 'object' === typeof data ? JSON.stringify( data ) : data;
|
|
112
|
+
|
|
113
|
+
elements.forEach(element => {
|
|
114
|
+
element.setAttribute(`data-cagov-${attr}`, value);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Generates a page schema including any data attributes in src/data/index.json
|
|
123
|
+
*
|
|
124
|
+
* @async
|
|
125
|
+
* @param {*} file
|
|
126
|
+
* @param {boolean} [write=true]
|
|
127
|
+
* @param {string} [outputPath='']
|
|
128
|
+
* @returns {unknown}
|
|
129
|
+
*/
|
|
130
|
+
async function convertHTMLtoJson( file, write = true, outputPath = '' ){
|
|
131
|
+
if( fs.existsSync( file )){
|
|
132
|
+
let template = fs.readFileSync( file ).toString().replace(/\n[\s]+/g,'');
|
|
133
|
+
let markup = await HTMLToJSON(template, false )
|
|
134
|
+
|
|
135
|
+
let data = fs.existsSync( path.join(dataPath, 'index.json') ) ?
|
|
136
|
+
JSON.parse( fs.readFileSync( path.join(dataPath, 'index.json') ) ) : {};
|
|
137
|
+
|
|
138
|
+
// remove any examples data
|
|
139
|
+
delete data.examples;
|
|
140
|
+
|
|
141
|
+
let schema = {
|
|
142
|
+
title: "California Department of Technology Schema",
|
|
143
|
+
$schema: "http://json-schema.org/2019-09/schema",
|
|
144
|
+
$id: "https://json-schema.org/draft/2019-09/schema",
|
|
145
|
+
type: "object",
|
|
146
|
+
description: "California Department of Technology Schema",
|
|
147
|
+
data,
|
|
148
|
+
markup,
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
// Write schema file.
|
|
152
|
+
if( write ){
|
|
153
|
+
fs.writeFileSync(
|
|
154
|
+
path.join(outputPath, 'schema.json'),
|
|
155
|
+
JSON.stringify( schema, null, 4 )
|
|
156
|
+
);
|
|
157
|
+
}else{
|
|
158
|
+
return schema;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export {
|
|
165
|
+
generatePages
|
|
166
|
+
};
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import fs from 'fs';
|
|
6
|
+
import HtmlWebpackPlugin from 'html-webpack-plugin';
|
|
7
|
+
import jsdom from 'jsdom';
|
|
8
|
+
import { fileURLToPath } from 'url';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Internal dependencies
|
|
12
|
+
*/
|
|
13
|
+
import {
|
|
14
|
+
generatePages
|
|
15
|
+
} from './parser.js';
|
|
16
|
+
|
|
17
|
+
import {
|
|
18
|
+
projectPath,
|
|
19
|
+
appPath
|
|
20
|
+
} from '../lib/helpers.js';
|
|
21
|
+
|
|
22
|
+
const srcPath = path.join( appPath, 'src');
|
|
23
|
+
const dataPath = path.join( srcPath, 'data');
|
|
24
|
+
const assetsPath = path.join( srcPath, 'assets');
|
|
25
|
+
|
|
26
|
+
// default meta used for site generation when no meta is passed
|
|
27
|
+
const meta = {
|
|
28
|
+
"Author": "CAWebPublishing",
|
|
29
|
+
"Description": "State of California",
|
|
30
|
+
"Keywords": "California,government",
|
|
31
|
+
"viewport": "width=device-width, initial-scale=1.0, minimum-scale=1.0"
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Returns an object containing all data from site.json and src/data/examples.json
|
|
37
|
+
*
|
|
38
|
+
* @returns {Object}
|
|
39
|
+
*/
|
|
40
|
+
function getSiteData(){
|
|
41
|
+
|
|
42
|
+
// grab any sample data if it exists.
|
|
43
|
+
let sample = fs.existsSync( path.join(dataPath, 'examples.json') ) ? JSON.parse( fs.readFileSync( path.join(dataPath, 'examples.json') ) ) : {};
|
|
44
|
+
|
|
45
|
+
// grab any site data if it exists.
|
|
46
|
+
let site = fs.existsSync( path.join(appPath, 'site.json') ) ? JSON.parse( fs.readFileSync( path.join(appPath, 'site.json') ) ) : {};
|
|
47
|
+
|
|
48
|
+
// merge datasets together
|
|
49
|
+
let siteData = {
|
|
50
|
+
...sample,
|
|
51
|
+
...site
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
return siteData;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export default (webpackConfig) => {
|
|
58
|
+
// we only proceed if and index.html exists
|
|
59
|
+
if( ! fs.existsSync( path.join( srcPath, 'index.html' )) ){
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// we only want to display errors and warnings
|
|
64
|
+
webpackConfig.stats = 'errors-warnings';
|
|
65
|
+
|
|
66
|
+
// get site data
|
|
67
|
+
let siteData = getSiteData();
|
|
68
|
+
|
|
69
|
+
// if favicon doesn't exist use fallback asset.
|
|
70
|
+
let favicon = fs.existsSync(path.join(assetsPath, 'images', 'favicon.ico')) ?
|
|
71
|
+
path.join(assetsPath, 'images', 'favicon.ico') :
|
|
72
|
+
path.join(projectPath, 'assets', 'favicon.ico') ;
|
|
73
|
+
|
|
74
|
+
let defaultPage = {
|
|
75
|
+
minify: false,
|
|
76
|
+
favicon,
|
|
77
|
+
meta: siteData.meta || meta,
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// add html
|
|
81
|
+
webpackConfig.plugins = [
|
|
82
|
+
...webpackConfig.plugins,
|
|
83
|
+
new HtmlWebpackPlugin({
|
|
84
|
+
filename: path.join( process.cwd(), 'public', 'index.html'),
|
|
85
|
+
template: path.join(srcPath, 'index.html'),
|
|
86
|
+
//templateContent: generatePages(siteData),
|
|
87
|
+
title: 'Test Site',
|
|
88
|
+
...defaultPage
|
|
89
|
+
})
|
|
90
|
+
]
|
|
91
|
+
|
|
92
|
+
// add devServer
|
|
93
|
+
webpackConfig.devServer = {
|
|
94
|
+
devMiddleware: {
|
|
95
|
+
writeToDisk: true,
|
|
96
|
+
},
|
|
97
|
+
hot: false,
|
|
98
|
+
allowedHosts: 'auto',
|
|
99
|
+
host: 'localhost',
|
|
100
|
+
port: 9000,
|
|
101
|
+
compress: true,
|
|
102
|
+
proxy: {
|
|
103
|
+
'/public': {
|
|
104
|
+
pathRewrite: {
|
|
105
|
+
'^/build': '',
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
};
|
package/lib/admin.js
CHANGED
package/lib/cli.js
CHANGED
|
@@ -3,66 +3,54 @@
|
|
|
3
3
|
*/
|
|
4
4
|
//const wpenv_cli = require('@wordpress/env/lib/cli');
|
|
5
5
|
|
|
6
|
-
import path from '
|
|
6
|
+
import path from 'path';
|
|
7
7
|
import chalk from 'chalk';
|
|
8
|
-
import
|
|
9
|
-
import fs from 'fs-extra';
|
|
8
|
+
import fs from 'fs';
|
|
10
9
|
import terminalLink from 'terminal-link';
|
|
11
|
-
import { Command, Argument, Option
|
|
10
|
+
import { Command, Argument, Option } from 'commander';
|
|
12
11
|
|
|
13
12
|
/**
|
|
14
13
|
* Internal dependencies
|
|
15
14
|
*/
|
|
16
|
-
import * as env from '
|
|
15
|
+
import * as env from '../commands/index.js';
|
|
17
16
|
import {
|
|
18
17
|
wpPrimary,
|
|
19
18
|
wpGreen,
|
|
20
19
|
wpYellow,
|
|
21
20
|
wpRed,
|
|
22
|
-
withSpinner
|
|
23
|
-
|
|
21
|
+
withSpinner,
|
|
22
|
+
projectPath,
|
|
23
|
+
} from './index.js';
|
|
24
24
|
|
|
25
|
-
const
|
|
26
|
-
const pkg = JSON.parse(
|
|
25
|
+
const localFile = path.join(projectPath, 'package.json');
|
|
26
|
+
const pkg = JSON.parse( fs.readFileSync(localFile) );
|
|
27
27
|
const program = new Command();
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
.choices([
|
|
40
|
-
'mysql',
|
|
41
|
-
'tests-mysql',
|
|
42
|
-
'wordpress',
|
|
43
|
-
'tests-wordpress',
|
|
44
|
-
'cli',
|
|
45
|
-
'tests-cli',
|
|
46
|
-
])
|
|
47
|
-
.default('development');
|
|
29
|
+
const containerArg = new Argument('<container>', 'The underlying Docker service to run the command on.')
|
|
30
|
+
.choices([
|
|
31
|
+
'mysql',
|
|
32
|
+
'tests-mysql',
|
|
33
|
+
'wordpress',
|
|
34
|
+
'tests-wordpress',
|
|
35
|
+
'cli',
|
|
36
|
+
'tests-cli',
|
|
37
|
+
])
|
|
38
|
+
.default('development');
|
|
48
39
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
showGlobalOptions: true,
|
|
64
|
-
})
|
|
65
|
-
.addHelpCommand(false)
|
|
40
|
+
const envArg = new Argument('[environment]', 'Which environment to use.')
|
|
41
|
+
.choices([
|
|
42
|
+
'development',
|
|
43
|
+
'tests',
|
|
44
|
+
'all'
|
|
45
|
+
])
|
|
46
|
+
.default('development');
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Adds commands for wp-env
|
|
51
|
+
*/
|
|
52
|
+
function addWPEnvCommands(){
|
|
53
|
+
|
|
66
54
|
|
|
67
55
|
// Start command.
|
|
68
56
|
program.command('start')
|
|
@@ -128,13 +116,6 @@ export default function cli() {
|
|
|
128
116
|
.allowUnknownOption(true)
|
|
129
117
|
.action( withSpinner(env.destroy) )
|
|
130
118
|
|
|
131
|
-
// Shell Command.
|
|
132
|
-
program.command('shell')
|
|
133
|
-
.description('Open shell terminal in WordPress environment.')
|
|
134
|
-
.addArgument(envArg)
|
|
135
|
-
.allowUnknownOption(true)
|
|
136
|
-
.action( withSpinner(env.shell) )
|
|
137
|
-
|
|
138
119
|
// Stop Command.
|
|
139
120
|
program.command('stop')
|
|
140
121
|
.description(
|
|
@@ -145,6 +126,12 @@ export default function cli() {
|
|
|
145
126
|
.allowUnknownOption(true)
|
|
146
127
|
.action( withSpinner(env.stop) )
|
|
147
128
|
|
|
129
|
+
// Install Path Command.
|
|
130
|
+
program.command('install-path')
|
|
131
|
+
.description('Get the path where all of the environment files are stored. This includes the Docker files, WordPress, PHPUnit files, and any sources that were downloaded.')
|
|
132
|
+
.allowUnknownOption(true)
|
|
133
|
+
.action( withSpinner(env.installPath) )
|
|
134
|
+
|
|
148
135
|
// Clean Command.
|
|
149
136
|
program.command('clean')
|
|
150
137
|
.description(
|
|
@@ -172,7 +159,7 @@ export default function cli() {
|
|
|
172
159
|
)
|
|
173
160
|
.allowUnknownOption(true)
|
|
174
161
|
.action( withSpinner(env.logs) )
|
|
175
|
-
|
|
162
|
+
|
|
176
163
|
|
|
177
164
|
// Run Command.
|
|
178
165
|
program.command('run')
|
|
@@ -189,12 +176,60 @@ export default function cli() {
|
|
|
189
176
|
.allowUnknownOption(true)
|
|
190
177
|
.action( withSpinner(env.run) )
|
|
191
178
|
|
|
179
|
+
|
|
180
|
+
// Shell Command.
|
|
181
|
+
program.command('shell')
|
|
182
|
+
.description('Open shell terminal in WordPress environment.')
|
|
183
|
+
.addArgument(envArg)
|
|
184
|
+
.allowUnknownOption(true)
|
|
185
|
+
.action( withSpinner(env.shell) )
|
|
192
186
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export default function cli() {
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
program
|
|
193
|
+
.name(wpPrimary( 'caweb'))
|
|
194
|
+
.usage( wpYellow( '<command>' ) )
|
|
195
|
+
.description('Command Line Interface utilized by CAWebPublishing to accomplish several tasks.')
|
|
196
|
+
.version( pkg.version )
|
|
197
|
+
.option(
|
|
198
|
+
'--debug',
|
|
199
|
+
'Enable debug output.',
|
|
200
|
+
false
|
|
201
|
+
)
|
|
196
202
|
.allowUnknownOption(true)
|
|
197
|
-
.
|
|
203
|
+
.configureHelp({
|
|
204
|
+
sortSubcommands: true,
|
|
205
|
+
sortOptions: true,
|
|
206
|
+
showGlobalOptions: true,
|
|
207
|
+
})
|
|
208
|
+
.helpCommand(false)
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
// Build Command.
|
|
212
|
+
program.command('build')
|
|
213
|
+
.description('Builds the current project.')
|
|
214
|
+
.allowUnknownOption(true)
|
|
215
|
+
.action(withSpinner(env.build))
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
// Serve Command.
|
|
219
|
+
program.command('serve')
|
|
220
|
+
.description('Serve the current project')
|
|
221
|
+
.option(
|
|
222
|
+
'--no-template',
|
|
223
|
+
'Disables inclusion of the template page header & footer, starting off with a plain html page.'
|
|
224
|
+
)
|
|
225
|
+
.allowUnknownOption(true)
|
|
226
|
+
.action(withSpinner(env.serve))
|
|
227
|
+
|
|
228
|
+
// a11y Command.
|
|
229
|
+
program.command('a11y')
|
|
230
|
+
.description('Runs accessibility checks.')
|
|
231
|
+
.allowUnknownOption(true)
|
|
232
|
+
.action(withSpinner(env.a11y))
|
|
198
233
|
|
|
199
234
|
// Update Plugins Command.
|
|
200
235
|
program.command('update-plugins')
|
|
@@ -218,18 +253,25 @@ export default function cli() {
|
|
|
218
253
|
.allowUnknownOption(true)
|
|
219
254
|
.action( withSpinner(env.updateBlock) )
|
|
220
255
|
|
|
256
|
+
|
|
257
|
+
// Update a Design System Block Command.
|
|
258
|
+
program.command('sync')
|
|
259
|
+
.description('Sync changes from one destination to another.')
|
|
260
|
+
.argument('<from>', 'Target Site URL with current changes.')
|
|
261
|
+
.argument('<to>', 'Destination Site URL that should be synced.')
|
|
262
|
+
.allowUnknownOption(true)
|
|
263
|
+
.action( withSpinner(env.sync) )
|
|
264
|
+
|
|
221
265
|
// Test Command.
|
|
222
266
|
// Ensure this is commented out.
|
|
223
|
-
program.command('test')
|
|
267
|
+
/*program.command('test')
|
|
224
268
|
.description('Test commands on a WordPress environment')
|
|
225
|
-
|
|
226
|
-
.option(
|
|
227
|
-
'--scripts',
|
|
228
|
-
'Execute any configured lifecycle scripts.',
|
|
229
|
-
true
|
|
230
|
-
)
|
|
269
|
+
//.addArgument(envArg)
|
|
231
270
|
.allowUnknownOption(true)
|
|
232
271
|
.action(withSpinner(env.test))
|
|
272
|
+
*/
|
|
273
|
+
|
|
274
|
+
addWPEnvCommands();
|
|
233
275
|
|
|
234
276
|
return program;
|
|
235
277
|
};
|
package/lib/helpers.js
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import spawn from 'cross-spawn';
|
|
6
|
+
import { fileURLToPath } from 'url';
|
|
7
|
+
import { sync as resolveBin } from 'resolve-bin';
|
|
8
|
+
import { v2 as dockerCompose } from 'docker-compose';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Internal dependencies
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Path Directory Locations
|
|
16
|
+
* - currentPath - Current Directory
|
|
17
|
+
* - projectPath - Current Project Path
|
|
18
|
+
* - appPath - Current Application Path
|
|
19
|
+
*/
|
|
20
|
+
const currentPath = path.dirname(fileURLToPath(import.meta.url));
|
|
21
|
+
const projectPath = path.resolve( currentPath, '..' );
|
|
22
|
+
const appPath = path.resolve( projectPath, '../../../' );
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Runs command directly.
|
|
26
|
+
*
|
|
27
|
+
* @param string cmd Command to run.
|
|
28
|
+
* @param string[] args List of command arguments.
|
|
29
|
+
* @param string[] opts List of spawn options.
|
|
30
|
+
*
|
|
31
|
+
* @returns {Promise}
|
|
32
|
+
*/
|
|
33
|
+
async function runCmd(cmd, args,opts = { stdio: ['inherit', 'pipe'] }){
|
|
34
|
+
// fix various commands.
|
|
35
|
+
switch (cmd) {
|
|
36
|
+
case 'npm':
|
|
37
|
+
case 'npx':
|
|
38
|
+
/**
|
|
39
|
+
* On Windows we run npm.cmd, on Linux we run npm
|
|
40
|
+
*/
|
|
41
|
+
cmd += /^win/.test(process.platform) ? '.cmd' : '';
|
|
42
|
+
break;
|
|
43
|
+
case 'webpack':
|
|
44
|
+
cmd = resolveBin(cmd)
|
|
45
|
+
break
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return spawn.sync( cmd, args, {...opts, env: process.env});
|
|
49
|
+
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Runs commands on the given WordPress environment.
|
|
54
|
+
*
|
|
55
|
+
* @param {string} environment Which environment to run docker command on.
|
|
56
|
+
* @param {string[]} cmds Array of commands to run.
|
|
57
|
+
* @param {WPConfig} config The wp-env config object.
|
|
58
|
+
* @param {Object} spinner A CLI spinner which indicates progress.
|
|
59
|
+
*
|
|
60
|
+
* @returns {Promise}
|
|
61
|
+
*/
|
|
62
|
+
async function runCLICmds(
|
|
63
|
+
environment,
|
|
64
|
+
cmds,
|
|
65
|
+
config,
|
|
66
|
+
spinner
|
|
67
|
+
) {
|
|
68
|
+
|
|
69
|
+
// We return the promise whether there is an output or an error.
|
|
70
|
+
return await dockerCompose.run(
|
|
71
|
+
environment === 'development' ? 'cli' : 'tests-cli',
|
|
72
|
+
[ 'bash', '-c', cmds.join( ' && ' ) ],
|
|
73
|
+
{
|
|
74
|
+
cwd: config.workDirectoryPath,
|
|
75
|
+
env: process.env,
|
|
76
|
+
commandOptions: [],
|
|
77
|
+
log: config.debug,
|
|
78
|
+
callback: (buffer, result) => {
|
|
79
|
+
if( config.debug ){
|
|
80
|
+
spinner.text = buffer.toString();
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
).then(
|
|
85
|
+
(output) => {
|
|
86
|
+
// Remove the Container information and new lines.
|
|
87
|
+
output.err = output.err.replace(/\s*Container .*Running\n|\n/g, '')
|
|
88
|
+
output.out = output.out.replace(/\s*Container .*Running\n|\n/g, '')
|
|
89
|
+
|
|
90
|
+
return '' !== output.out ? output.out : output.err;
|
|
91
|
+
},
|
|
92
|
+
(error) => {
|
|
93
|
+
// Remove the Container information and new lines.
|
|
94
|
+
error.err = error.err.replace(/\s*Container .*Running\n|\n/g, '')
|
|
95
|
+
|
|
96
|
+
return error;
|
|
97
|
+
}
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
export {
|
|
104
|
+
currentPath,
|
|
105
|
+
projectPath,
|
|
106
|
+
appPath,
|
|
107
|
+
runCLICmds,
|
|
108
|
+
runCmd
|
|
109
|
+
};
|