@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/commands/sync.js
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import fs from 'fs';
|
|
6
|
+
import loadConfig from '@wordpress/env/lib/config/load-config.js';
|
|
7
|
+
import axios from 'axios';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Internal dependencies
|
|
11
|
+
*/
|
|
12
|
+
import {
|
|
13
|
+
appPath,
|
|
14
|
+
getTaxonomies,
|
|
15
|
+
createTaxonomies
|
|
16
|
+
} from '../lib/index.js';
|
|
17
|
+
|
|
18
|
+
const errors = [];
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Sync Environments.
|
|
23
|
+
*
|
|
24
|
+
* @param {Object} options
|
|
25
|
+
* @param {Object} options.spinner A CLI spinner which indicates progress.
|
|
26
|
+
* @param {boolean} options.from Remote Site URL with current changes.
|
|
27
|
+
* @param {boolean} options.to Destination Site URL that should be synced.
|
|
28
|
+
* @param {boolean} options.debug True if debug mode is enabled.
|
|
29
|
+
*/
|
|
30
|
+
export default async function sync({
|
|
31
|
+
spinner,
|
|
32
|
+
debug,
|
|
33
|
+
from,
|
|
34
|
+
to
|
|
35
|
+
} ) {
|
|
36
|
+
|
|
37
|
+
const localFile = path.join(appPath, 'caweb.json');
|
|
38
|
+
const {workDirectoryPath} = await loadConfig(path.resolve('.'));
|
|
39
|
+
|
|
40
|
+
process.env.WP_CLI_CONFIG_PATH = path.join(workDirectoryPath, 'config.yml');
|
|
41
|
+
|
|
42
|
+
// if caweb.json file doesn't exist we don't do anything
|
|
43
|
+
if( ! fs.existsSync(localFile) ){
|
|
44
|
+
spinner.fail('caweb.json file not found.')
|
|
45
|
+
process.exit(1)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// read configuration file
|
|
49
|
+
const serviceConfig = JSON.parse( fs.readFileSync(localFile) );
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* make sure instances are in the file.
|
|
53
|
+
* must have sync property
|
|
54
|
+
* each instance has to have a url, user, pwd property
|
|
55
|
+
*/
|
|
56
|
+
if(
|
|
57
|
+
! serviceConfig.sync ||
|
|
58
|
+
! serviceConfig.sync[from] ||
|
|
59
|
+
! serviceConfig.sync[from].url ||
|
|
60
|
+
! serviceConfig.sync[from].user ||
|
|
61
|
+
! serviceConfig.sync[from].pwd ||
|
|
62
|
+
! serviceConfig.sync[to] ||
|
|
63
|
+
! serviceConfig.sync[to].url ||
|
|
64
|
+
! serviceConfig.sync[to].user ||
|
|
65
|
+
! serviceConfig.sync[to].pwd
|
|
66
|
+
){
|
|
67
|
+
spinner.fail(`caweb.json is not configured properly for ${from} and ${to}.`);
|
|
68
|
+
process.exit(1)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// get instance data
|
|
72
|
+
from = serviceConfig.sync[from];
|
|
73
|
+
let fromOptions = {
|
|
74
|
+
url: from.url,
|
|
75
|
+
headers: {
|
|
76
|
+
Authorization: 'Basic ' + Buffer.from(`${from.user}:${from.pwd}`).toString('base64')
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
let ssh = 'local' !== to ? to : `docker:${path.basename(workDirectoryPath)}-cli-1`;
|
|
81
|
+
|
|
82
|
+
to = serviceConfig.sync[to];
|
|
83
|
+
|
|
84
|
+
let toOptions = {
|
|
85
|
+
url: to.url,
|
|
86
|
+
ssh,
|
|
87
|
+
headers: {
|
|
88
|
+
Authorization: 'Basic ' + Buffer.from(`${to.user}:${to.pwd}`).toString('base64'),
|
|
89
|
+
'content-type': 'multipart/form-data',
|
|
90
|
+
'accept': '*/*'
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// get all settings
|
|
95
|
+
spinner.text = `Getting Site Settings from ${from.url}`;
|
|
96
|
+
let settings = await getTaxonomies({
|
|
97
|
+
...fromOptions,
|
|
98
|
+
fields: [
|
|
99
|
+
'show_on_front',
|
|
100
|
+
'page_on_front'
|
|
101
|
+
],
|
|
102
|
+
}, 'settings')
|
|
103
|
+
|
|
104
|
+
// get all pages/posts
|
|
105
|
+
spinner.text = `Gathering all pages/posts from ${from.url}`;
|
|
106
|
+
let pages = await getTaxonomies(fromOptions);
|
|
107
|
+
let posts = await getTaxonomies(fromOptions, 'posts');
|
|
108
|
+
|
|
109
|
+
spinner.text = `Collecting all attached/featured images from ${from.url}`;
|
|
110
|
+
/**
|
|
111
|
+
* Media Library Handling
|
|
112
|
+
* 1) attached media items by default are only possible on pages.
|
|
113
|
+
* 2) featured media by default are only possible on posts.
|
|
114
|
+
*/
|
|
115
|
+
const mediaFields = [
|
|
116
|
+
'id',
|
|
117
|
+
'source_url',
|
|
118
|
+
'title',
|
|
119
|
+
'caption',
|
|
120
|
+
'alt_text',
|
|
121
|
+
'date',
|
|
122
|
+
'mime_type'
|
|
123
|
+
];
|
|
124
|
+
let attachedMedia = await getTaxonomies({
|
|
125
|
+
...fromOptions,
|
|
126
|
+
fields: mediaFields,
|
|
127
|
+
parent: pages.map((p) => { return p.id })
|
|
128
|
+
},
|
|
129
|
+
'media'
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
let featuredMedia = await getTaxonomies({
|
|
133
|
+
...fromOptions,
|
|
134
|
+
fields: mediaFields,
|
|
135
|
+
include: posts.map((p) => { if(p.featured_media){return p.featured_media } })
|
|
136
|
+
},
|
|
137
|
+
'media'
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
// before we can upload media files.
|
|
141
|
+
for( let mediaObj of [].concat( attachedMedia, featuredMedia ) ){
|
|
142
|
+
// generate a blob from the media object source_url.
|
|
143
|
+
const mediaBlob = await axios.request(
|
|
144
|
+
{
|
|
145
|
+
...fromOptions,
|
|
146
|
+
url: mediaObj.source_url,
|
|
147
|
+
responseType: 'arraybuffer'
|
|
148
|
+
}
|
|
149
|
+
)
|
|
150
|
+
.then( (img) => { return new Blob([img.data]) })
|
|
151
|
+
.catch( (error) => {
|
|
152
|
+
errors.push(`${mediaObj.source_url} could not be downloaded.`)
|
|
153
|
+
return false;
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
if( mediaBlob ){
|
|
157
|
+
mediaObj.data = mediaBlob;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
spinner.text = `Collecting assigned navigation menus from ${from.url}`;
|
|
162
|
+
// get all menus and navigation links
|
|
163
|
+
let menus = await getTaxonomies({
|
|
164
|
+
...fromOptions,
|
|
165
|
+
fields: [
|
|
166
|
+
'id',
|
|
167
|
+
'description',
|
|
168
|
+
'name',
|
|
169
|
+
'slug',
|
|
170
|
+
'meta',
|
|
171
|
+
'locations'
|
|
172
|
+
]
|
|
173
|
+
}, 'menus');
|
|
174
|
+
|
|
175
|
+
let menuNavItems = await getTaxonomies(
|
|
176
|
+
{
|
|
177
|
+
...fromOptions,
|
|
178
|
+
fields: [
|
|
179
|
+
'id',
|
|
180
|
+
'title',
|
|
181
|
+
'url',
|
|
182
|
+
'status',
|
|
183
|
+
'attr_title',
|
|
184
|
+
'description',
|
|
185
|
+
'type',
|
|
186
|
+
'type_label',
|
|
187
|
+
'object',
|
|
188
|
+
'object_id',
|
|
189
|
+
'parent',
|
|
190
|
+
'menu_order',
|
|
191
|
+
'target',
|
|
192
|
+
'classes',
|
|
193
|
+
'xfn',
|
|
194
|
+
'meta',
|
|
195
|
+
'menus'
|
|
196
|
+
],
|
|
197
|
+
menus: menus.map((menu) => { return menu.id; })
|
|
198
|
+
},
|
|
199
|
+
'menu-items'
|
|
200
|
+
)
|
|
201
|
+
|
|
202
|
+
// create all pages/posts
|
|
203
|
+
spinner.text = `Creating all pages/posts to ${to.url}`;
|
|
204
|
+
await createTaxonomies( pages, toOptions, 'pages', spinner );
|
|
205
|
+
await createTaxonomies( posts, toOptions, 'posts', spinner );
|
|
206
|
+
|
|
207
|
+
// create media attachments
|
|
208
|
+
spinner.text = `Uploading media files to ${to.url}`;
|
|
209
|
+
await createTaxonomies(
|
|
210
|
+
[].concat( attachedMedia, featuredMedia ).filter((img) => { return img.data }),
|
|
211
|
+
toOptions,
|
|
212
|
+
'media',
|
|
213
|
+
spinner
|
|
214
|
+
)
|
|
215
|
+
|
|
216
|
+
// create menus and navigation links
|
|
217
|
+
spinner.text = `Reconstructing navigation menus to ${to.url}`;
|
|
218
|
+
await createTaxonomies(menus, toOptions, 'menus', spinner);
|
|
219
|
+
await createTaxonomies(menuNavItems, toOptions, 'menu-items', spinner);
|
|
220
|
+
|
|
221
|
+
// update settings
|
|
222
|
+
await createTaxonomies(settings, toOptions, 'settings', spinner);
|
|
223
|
+
|
|
224
|
+
spinner.text = `Sync from ${from.url} to ${to.url} completed successfully.`
|
|
225
|
+
|
|
226
|
+
};
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import path from '
|
|
4
|
+
import path from 'path';
|
|
5
5
|
import loadConfig from '@wordpress/env/lib/config/load-config.js';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Internal dependencies
|
|
9
9
|
*/
|
|
10
|
-
import {runCLICmds} from '../../
|
|
10
|
+
import {runCLICmds} from '../../lib/index.js';
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Promisified dependencies
|
package/commands/test.js
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import axios from 'axios';
|
|
6
|
+
import fs from 'fs';
|
|
7
|
+
import loadConfig from '@wordpress/env/lib/config/load-config.js';
|
|
8
|
+
import cp from 'child_process';
|
|
9
|
+
|
|
10
|
+
//var WP = require('wp-cli');
|
|
11
|
+
/**
|
|
12
|
+
* Internal dependencies
|
|
13
|
+
*/
|
|
14
|
+
import { runCLICmds, runCmd, projectPath } from '../lib/index.js';
|
|
15
|
+
/*
|
|
16
|
+
import generateOverridesMD from '../admin.js';
|
|
17
|
+
import { CAWEB_OPTIONS, DIVI_OPTIONS } from '../options.js';
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* Promisified dependencies
|
|
21
|
+
*/
|
|
22
|
+
import os from 'os';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Test code.
|
|
26
|
+
*
|
|
27
|
+
* @param {Object} options
|
|
28
|
+
* @param {Object} options.spinner A CLI spinner which indicates progress.
|
|
29
|
+
* @param {boolean} options.environment Which environment to test in.
|
|
30
|
+
* @param {boolean} options.debug True if debug mode is enabled.
|
|
31
|
+
*/
|
|
32
|
+
export default async function test({
|
|
33
|
+
spinner,
|
|
34
|
+
debug,
|
|
35
|
+
environment
|
|
36
|
+
} ) {
|
|
37
|
+
|
|
38
|
+
spinner.text = "Testing Code Functionality";
|
|
39
|
+
const config = await loadConfig(path.resolve('.'));
|
|
40
|
+
|
|
41
|
+
process.env.WP_CLI_CONFIG_PATH = path.join(config.workDirectoryPath, 'config.yml');
|
|
42
|
+
// update post meta.
|
|
43
|
+
let id = 35;
|
|
44
|
+
let newId = 30
|
|
45
|
+
let tbl = `wp_term_taxonomy`;
|
|
46
|
+
|
|
47
|
+
let result = await runCmd(
|
|
48
|
+
'php',
|
|
49
|
+
[
|
|
50
|
+
path.join(projectPath, 'bin', 'wp-cli.phar'),
|
|
51
|
+
'--ssh=docker:' + path.basename(config.workDirectoryPath) + '-cli-1',
|
|
52
|
+
`db query 'UPDATE ${tbl} SET term_taxonomy_id=${newId},term_id=${newId} WHERE term_id=${id}'`,
|
|
53
|
+
]
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
console.log( result );
|
|
57
|
+
/*
|
|
58
|
+
let q = `UPDATE wp_posts SET id=1 WHERE id=10 `;
|
|
59
|
+
let u = 'http://danny.com/wp-json/wp/v2/pages/2827';
|
|
60
|
+
let result = await axios.request({
|
|
61
|
+
url: u,
|
|
62
|
+
method: 'POST',
|
|
63
|
+
data: {
|
|
64
|
+
title: 'Audio',
|
|
65
|
+
meta: {
|
|
66
|
+
_et_pb_use_builder: 'on'
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
headers: {
|
|
70
|
+
Authorization: 'Basic ' + Buffer.from(`admin:9RUG nPuo u581 cY2A uSJd FE2P`).toString('base64')
|
|
71
|
+
}
|
|
72
|
+
})
|
|
73
|
+
.then( async (res) => { return res.data; } )
|
|
74
|
+
.catch( async (err) => { return err; } )
|
|
75
|
+
|
|
76
|
+
*/
|
|
77
|
+
/*
|
|
78
|
+
let result = await runCmd(
|
|
79
|
+
'php',
|
|
80
|
+
[
|
|
81
|
+
//'-r',
|
|
82
|
+
path.join(projectPath, 'bin', 'wp-cli.phar'),
|
|
83
|
+
'--ssh=' + `docker:${path.basename(config.workDirectoryPath)}-cli-1`,
|
|
84
|
+
//'@dev',
|
|
85
|
+
//`db query '${q}'`,
|
|
86
|
+
'post list',
|
|
87
|
+
//'--info',
|
|
88
|
+
'--skip-themes',
|
|
89
|
+
//`--url=${new URL(u).origin}`
|
|
90
|
+
// '--format=json'
|
|
91
|
+
//'--skip-column-names',
|
|
92
|
+
//'post list path=/nas/content/live/cawebdev/ --http=https://dev.sites.ca.gov --url=https://dev.sites.ca.gov',
|
|
93
|
+
],
|
|
94
|
+
config
|
|
95
|
+
)*/
|
|
96
|
+
|
|
97
|
+
//console.log( 'Result', result.toString() );
|
|
98
|
+
//console.log( 'Output', result.stdout.toString() );
|
|
99
|
+
//console.log( 'Error', result.stderr.toString() );
|
|
100
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration for Accessibility Checker
|
|
3
|
+
* @link https://www.npmjs.com/package/accessibility-checker
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export default {
|
|
7
|
+
ruleArchive: "latest",
|
|
8
|
+
policies: [
|
|
9
|
+
'WCAG_2_1'
|
|
10
|
+
],
|
|
11
|
+
failLevels: [
|
|
12
|
+
'violation',
|
|
13
|
+
'potentialviolation'
|
|
14
|
+
],
|
|
15
|
+
reportLevels: [
|
|
16
|
+
'violation',
|
|
17
|
+
'potentialviolation',
|
|
18
|
+
'recommendation',
|
|
19
|
+
'potentialrecommendation',
|
|
20
|
+
'manual',
|
|
21
|
+
'pass'
|
|
22
|
+
],
|
|
23
|
+
outputFolder: "a11y",
|
|
24
|
+
outputFormat: [
|
|
25
|
+
'html'
|
|
26
|
+
],
|
|
27
|
+
outputFilenameTimestamp: false
|
|
28
|
+
}
|
|
@@ -1,78 +1,47 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import path from '
|
|
5
|
-
import fs from 'fs
|
|
6
|
-
import yaml from 'js-yaml';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import fs from 'fs';
|
|
7
6
|
import getHostUser from '@wordpress/env/lib/get-host-user.js';
|
|
7
|
+
import yaml from 'js-yaml';
|
|
8
|
+
import os from 'os';
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
|
-
*
|
|
11
|
+
* Internal Dependencies
|
|
11
12
|
*/
|
|
12
|
-
const { writeFile } = fs.promises;
|
|
13
|
-
|
|
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
13
|
|
|
17
14
|
/**
|
|
18
|
-
*
|
|
15
|
+
* Generate config.yml
|
|
19
16
|
*
|
|
20
|
-
* @param {
|
|
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.
|
|
17
|
+
* @param {string} workDirectoryPath Path to the work directory located in ~/.wp-env.
|
|
24
18
|
*
|
|
25
|
-
* @returns
|
|
19
|
+
* @returns void
|
|
26
20
|
*/
|
|
27
|
-
|
|
28
|
-
let
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
}
|
|
21
|
+
async function generateCLIConfig(workDirectoryPath){
|
|
22
|
+
let yml = {
|
|
23
|
+
path: '/var/www/html',
|
|
24
|
+
apache_modules: ['mod_rewrite']
|
|
25
|
+
};
|
|
48
26
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
27
|
+
let { homedir } = os.userInfo();
|
|
28
|
+
|
|
29
|
+
// add any ssh hosts to the config
|
|
30
|
+
if( fs.existsSync( path.join( homedir, '.ssh', 'config' )) ){
|
|
31
|
+
|
|
32
|
+
let ssh_hosts = fs.readFileSync(path.join( homedir, '.ssh', 'config' )).toString().match(/Host\s+(.*)[^\n\r]/g);
|
|
52
33
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
config.config['WP_DEFAULT_THEME'] = 'CAWeb';
|
|
56
|
-
}
|
|
57
|
-
}
|
|
34
|
+
ssh_hosts.forEach((host) => {
|
|
35
|
+
let s = host.replace(/Host\s+/, '');
|
|
58
36
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// add plugins if sources were added
|
|
65
|
-
if( plugins.length ){
|
|
66
|
-
config['plugins'] = plugins;
|
|
67
|
-
}
|
|
37
|
+
yml[`@${s}`] = { ssh: s};
|
|
38
|
+
})
|
|
39
|
+
}
|
|
68
40
|
|
|
69
|
-
// add themes if sources were added
|
|
70
|
-
if( themes.length ){
|
|
71
|
-
config['themes'] = themes;
|
|
72
|
-
}
|
|
73
41
|
|
|
74
|
-
|
|
75
|
-
|
|
42
|
+
fs.writeFileSync(
|
|
43
|
+
path.join(workDirectoryPath, 'config.yml'),
|
|
44
|
+
yaml.dump(yml));
|
|
76
45
|
}
|
|
77
46
|
|
|
78
47
|
/**
|
|
@@ -81,8 +50,8 @@ const buildWPEnvConfig = (bare, multisite, plugin, theme) => {
|
|
|
81
50
|
* @param {string} workDirectoryPath Path to the work directory located in ~/.wp-env.
|
|
82
51
|
* @returns object
|
|
83
52
|
*/
|
|
84
|
-
|
|
85
|
-
|
|
53
|
+
export default function dockerConfig ( workDirectoryPath ) {
|
|
54
|
+
const {name} = getHostUser();
|
|
86
55
|
|
|
87
56
|
// generate cli config file for cli containers.
|
|
88
57
|
generateCLIConfig(workDirectoryPath);
|
|
@@ -175,27 +144,5 @@ const buildDockerComposeConfig = (workDirectoryPath) => {
|
|
|
175
144
|
}
|
|
176
145
|
|
|
177
146
|
return dockerConfig;
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
/**
|
|
181
|
-
* Generate config.yml
|
|
182
|
-
*
|
|
183
|
-
* @param {string} workDirectoryPath Path to the work directory located in ~/.wp-env.
|
|
184
|
-
*
|
|
185
|
-
* @returns void
|
|
186
|
-
*/
|
|
187
|
-
async function generateCLIConfig(workDirectoryPath){
|
|
188
|
-
const yml = {
|
|
189
|
-
path: '/var/www/html',
|
|
190
|
-
apache_modules: ['mod_rewrite']
|
|
191
|
-
};
|
|
192
|
-
|
|
193
|
-
await writeFile(
|
|
194
|
-
path.join(workDirectoryPath, 'config.yml'),
|
|
195
|
-
yaml.dump(yml));
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
export {
|
|
199
|
-
buildWPEnvConfig,
|
|
200
|
-
buildDockerComposeConfig
|
|
147
|
+
|
|
201
148
|
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WebPack Configuration for California Department of Technology
|
|
3
|
+
*
|
|
4
|
+
* Utilizes WordPress Scripts Webpack configuration as base.
|
|
5
|
+
* s
|
|
6
|
+
* @link https://webpack.js.org/configuration/
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* External dependencies
|
|
11
|
+
*/
|
|
12
|
+
import baseConfig from '@wordpress/scripts/config/webpack.config.js';
|
|
13
|
+
import path from 'path';
|
|
14
|
+
import fs from 'fs';
|
|
15
|
+
import MiniCssExtractPlugin from "mini-css-extract-plugin";
|
|
16
|
+
import CopyWebpackPlugin from 'copy-webpack-plugin';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Internal dependencies
|
|
20
|
+
*/
|
|
21
|
+
import SiteGenerator from '../gen/site-generator.js';
|
|
22
|
+
|
|
23
|
+
// fallback to env variable
|
|
24
|
+
let isProduction = "production" === process.env.NODE_ENV;
|
|
25
|
+
|
|
26
|
+
// because we use WordPress default WebPack config
|
|
27
|
+
// 'mode' is defined by process.env.NODE_ENV
|
|
28
|
+
// some of the webpack cli flags are ignored
|
|
29
|
+
// so let's make some corrections.
|
|
30
|
+
let corrections = {};
|
|
31
|
+
|
|
32
|
+
process.argv.splice( 2 ).forEach(element => {
|
|
33
|
+
// if flag
|
|
34
|
+
if( element.startsWith( '--' ) ){
|
|
35
|
+
let splitterIndex = element.indexOf( '=' );
|
|
36
|
+
let flag = element.substring(2, splitterIndex );
|
|
37
|
+
let value = element.substring( splitterIndex + 1 );
|
|
38
|
+
|
|
39
|
+
// if flag is a webpack flag add corrections.
|
|
40
|
+
switch( flag ){
|
|
41
|
+
case 'mode':
|
|
42
|
+
// if cli arg was passed use that value
|
|
43
|
+
isProduction = "production" === value;
|
|
44
|
+
|
|
45
|
+
corrections[flag] = value
|
|
46
|
+
break
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
// update the WordPress default webpack rules with ours.
|
|
55
|
+
baseConfig.module.rules.forEach((rule, i) => {
|
|
56
|
+
const r = new RegExp(rule.test).toString();
|
|
57
|
+
|
|
58
|
+
// WordPress adds a hash to asset file names we remove that hash
|
|
59
|
+
if( r === new RegExp(/\.(bmp|png|jpe?g|gif|webp)$/i).toString() ){
|
|
60
|
+
baseConfig.module.rules[i].generator = {
|
|
61
|
+
filename: 'images/[name][ext]'
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if( r === new RegExp(/\.(woff|woff2|eot|ttf|otf)$/i).toString() ){
|
|
65
|
+
baseConfig.module.rules[i].generator = {
|
|
66
|
+
filename: 'fonts/[name][ext]'
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
// SVG rules
|
|
70
|
+
if( r === new RegExp(/\.svg$/).toString() ){
|
|
71
|
+
// we don't want SVG to be inline move them to fonts folder
|
|
72
|
+
if( 'asset/inline' === rule.type ){
|
|
73
|
+
baseConfig.module.rules[i].type = 'asset/resource';
|
|
74
|
+
baseConfig.module.rules[i].generator = {
|
|
75
|
+
filename: 'fonts/[name][ext]'
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
// Our Webpack Configuration.
|
|
82
|
+
let webpackConfig = {
|
|
83
|
+
...baseConfig,
|
|
84
|
+
target: 'browserslist',
|
|
85
|
+
devtool: false,
|
|
86
|
+
output: {
|
|
87
|
+
...baseConfig.output,
|
|
88
|
+
publicPath: `/`,
|
|
89
|
+
clean: false
|
|
90
|
+
},
|
|
91
|
+
plugins: [
|
|
92
|
+
...baseConfig.plugins,
|
|
93
|
+
new MiniCssExtractPlugin(
|
|
94
|
+
{
|
|
95
|
+
linkType: "text/css",
|
|
96
|
+
filename: '[name].css'
|
|
97
|
+
}
|
|
98
|
+
)
|
|
99
|
+
],
|
|
100
|
+
module: {
|
|
101
|
+
rules: [
|
|
102
|
+
...baseConfig.module.rules,
|
|
103
|
+
{
|
|
104
|
+
test: /\.html$/,
|
|
105
|
+
loader: 'handlebars-loader'
|
|
106
|
+
}
|
|
107
|
+
]
|
|
108
|
+
},
|
|
109
|
+
performance: {
|
|
110
|
+
maxAssetSize: 500000,
|
|
111
|
+
maxEntrypointSize: 500000
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
if( ! isProduction ){
|
|
116
|
+
SiteGenerator( webpackConfig );
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export default webpackConfig;
|