wp-advads 1.0.33 → 1.0.35
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/.github/workflows/test.yml +17 -0
- package/CHANGELOG.md +23 -1
- package/LICENSE +15 -0
- package/README.md +86 -66
- package/package.json +9 -7
- package/src/app.js +17 -11
- package/src/commands/build.js +72 -59
- package/src/commands/class.js +34 -40
- package/src/commands/css.js +13 -19
- package/src/commands/init.js +4 -1
- package/src/commands/javascript.js +13 -19
- package/src/commands/release/change-version.js +14 -17
- package/src/commands/release/changelog.js +23 -31
- package/src/commands/release/git.js +25 -11
- package/src/commands/release/github.js +63 -12
- package/src/commands/release/semver.js +22 -25
- package/src/commands/release/translations.js +17 -23
- package/src/commands/release.js +3 -4
- package/src/commands/updates.js +20 -17
- package/src/commands/views.js +16 -18
- package/src/commands/wp-glotpress.js +125 -126
- package/src/commands/wp-pot.js +17 -9
- package/src/utilities/filesystem.js +57 -36
- package/src/utilities/flow.js +21 -0
- package/src/utilities/formatting.js +13 -4
- package/src/utilities/index.js +1 -1
- package/src/utilities/misc.js +1 -6
- package/src/utilities/settings.js +34 -14
- package/src/utilities/shell.js +60 -8
- package/template/files/class-singleton.php +5 -0
- package/template/files/javascript.js +0 -2
- package/template/files/view.php +2 -0
- package/test/build.test.js +168 -0
- package/test/changelog-locales.test.js +49 -0
- package/test/class.test.js +47 -0
- package/test/compile-templates.test.js +70 -0
- package/test/deps-hygiene.test.js +46 -0
- package/test/engines.test.js +11 -0
- package/test/get-latest-tag.test.js +51 -0
- package/test/git-precheck.test.js +44 -0
- package/test/github-final.test.js +93 -0
- package/test/glotpress-download.test.js +176 -0
- package/test/nested-path.test.js +39 -0
- package/test/no-fs-extra.test.js +11 -0
- package/test/package-identity.test.js +19 -0
- package/test/path-confine.test.js +42 -0
- package/test/pot-docs.test.js +27 -0
- package/test/pot-headers.test.js +49 -0
- package/test/project-root.test.js +26 -0
- package/test/release-waterfall.test.js +62 -0
- package/test/semver.test.js +25 -0
- package/test/settings-clone.test.js +34 -0
- package/test/settings-path.test.js +31 -0
- package/test/shell.test.js +100 -0
- package/test/singleton.test.js +14 -0
- package/test/stable-tag.test.js +13 -0
- package/test/stub-security.test.js +37 -0
- package/test/template-folder.test.js +19 -0
- package/test/translations.test.js +51 -0
- package/test/update-file-content.test.js +38 -0
- package/test/updates.test.js +39 -0
- package/test/version.test.js +22 -0
- package/test/view-escape.test.js +17 -0
- package/test/view.test.js +33 -0
- package/test/write-force.test.js +47 -0
- package/src/utilities/semver.js +0 -45
- package/template/.github/pull_request_template.md +0 -52
- package/template/configs/.editorconfig +0 -27
- package/template/configs/.eslintignore +0 -13
- package/template/configs/.eslintrc.js +0 -13
- package/template/configs/.phpcs.xml.dist +0 -87
- package/template/configs/.prettierignore +0 -49
- package/template/configs/.prettierrc.js +0 -3
- package/template/configs/.stylelintrc +0 -44
- package/template/configs/composer.json +0 -51
- package/template/configs/gitattributes +0 -34
- package/template/configs/gitignore +0 -43
- package/template/configs/package.json +0 -66
- package/template/configs/postcss.config.js +0 -6
- package/template/configs/tailwind.config.js +0 -8
- package/template/configs/webpack.mix.js +0 -65
- package/template/configs/webpack.mix.local.js +0 -3
- package/template/includes/index.php +0 -2
- package/template/index.js +0 -0
- package/template/index.php +0 -4
- package/template/plugin/assets/scss/app.scss +0 -0
- package/template/plugin/assets/src/app.js +0 -0
- package/template/tools/laravel-mix/wp-pot.js +0 -57
- package/template/tools/wp-glotpress.js +0 -162
package/src/commands/class.js
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External Dependencies
|
|
3
|
-
*/
|
|
4
|
-
import capitalize from 'lodash/capitalize.js';
|
|
5
|
-
|
|
6
1
|
/**
|
|
7
2
|
* Node Dependencies
|
|
8
3
|
*/
|
|
@@ -11,53 +6,52 @@ import path from 'path';
|
|
|
11
6
|
/**
|
|
12
7
|
* Internal Dependencies
|
|
13
8
|
*/
|
|
14
|
-
import { getSetting,
|
|
9
|
+
import { getSetting, filenameToHeading, heading, getProjectRoot, writeFromTemplate } from "../utilities/index.js";
|
|
15
10
|
|
|
16
11
|
function templateName(options) {
|
|
17
|
-
|
|
12
|
+
if ( options.i ) {
|
|
13
|
+
return 'class-initializer';
|
|
14
|
+
}
|
|
18
15
|
|
|
19
|
-
if (
|
|
20
|
-
return 'class-
|
|
16
|
+
if ( options.g ) {
|
|
17
|
+
return 'class-integration';
|
|
21
18
|
}
|
|
22
19
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
'g': 'class-integration',
|
|
26
|
-
'r': 'class-rest',
|
|
27
|
-
's': 'class-singleton',
|
|
20
|
+
if ( options.r ) {
|
|
21
|
+
return 'class-rest';
|
|
28
22
|
}
|
|
29
|
-
const has = Object.keys(options)[0]
|
|
30
23
|
|
|
31
|
-
|
|
24
|
+
if ( options.s ) {
|
|
25
|
+
return 'class-singleton';
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return 'class-empty';
|
|
32
29
|
}
|
|
33
30
|
|
|
34
31
|
export default (classname, options) => {
|
|
35
32
|
heading('Creating class file...')
|
|
36
33
|
const {
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
heading: header = null,
|
|
35
|
+
description = null,
|
|
39
36
|
} = options
|
|
40
37
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
msgErrorTitle('We failed!!!');
|
|
61
|
-
throw err;
|
|
62
|
-
}
|
|
38
|
+
const template = templateName(options);
|
|
39
|
+
const namespace = classname.split('\\');
|
|
40
|
+
const paths = classname.toLowerCase().split('\\');
|
|
41
|
+
const filename = paths.pop().replace(/_/g, '-') + '.php';
|
|
42
|
+
const folder = path.join(getProjectRoot(), getSetting('paths.php'), paths.join('/'));
|
|
43
|
+
|
|
44
|
+
writeFromTemplate(
|
|
45
|
+
folder,
|
|
46
|
+
`class-${filename}`,
|
|
47
|
+
`files/${template}.php`,
|
|
48
|
+
{
|
|
49
|
+
...getSetting(),
|
|
50
|
+
heading: header || filenameToHeading(filename) + ' template file',
|
|
51
|
+
description: description || 'Brief description of the styles in this file',
|
|
52
|
+
className: namespace.pop(),
|
|
53
|
+
namespace: namespace.length > 0 ? '\\' + namespace.join('\\') : '',
|
|
54
|
+
},
|
|
55
|
+
options.force
|
|
56
|
+
)
|
|
63
57
|
}
|
package/src/commands/css.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
/**
|
|
3
2
|
* Node Dependencies
|
|
4
3
|
*/
|
|
@@ -7,7 +6,7 @@ import path from 'path';
|
|
|
7
6
|
/**
|
|
8
7
|
* Internal Dependencies
|
|
9
8
|
*/
|
|
10
|
-
import { getSetting,
|
|
9
|
+
import { getSetting, heading, filenameToHeading, getProjectRoot, writeFromTemplate } from "../utilities/index.js";
|
|
11
10
|
|
|
12
11
|
export default (name, options) => {
|
|
13
12
|
heading('Creating CSS file...')
|
|
@@ -16,21 +15,16 @@ export default (name, options) => {
|
|
|
16
15
|
d: description = null,
|
|
17
16
|
} = options
|
|
18
17
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
catch (err) {
|
|
33
|
-
msgErrorTitle('We failed!!!');
|
|
34
|
-
throw err;
|
|
35
|
-
}
|
|
18
|
+
const dest = path.join( getProjectRoot(), getSetting( 'paths.css' ), name.toLowerCase().replaceAll( '\\', '/' ) ) + '.css'
|
|
19
|
+
writeFromTemplate(
|
|
20
|
+
path.dirname( dest ),
|
|
21
|
+
path.basename( dest ),
|
|
22
|
+
'files/stylesheet.css',
|
|
23
|
+
{
|
|
24
|
+
...getSetting(),
|
|
25
|
+
heading: header || filenameToHeading(name) + ' styles.',
|
|
26
|
+
description: description || 'Brief description of the styles in this file',
|
|
27
|
+
},
|
|
28
|
+
options.force
|
|
29
|
+
)
|
|
36
30
|
}
|
package/src/commands/init.js
CHANGED
|
@@ -2,13 +2,16 @@
|
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
4
|
import inquirer from 'inquirer'
|
|
5
|
-
import kebabCase from 'lodash/kebabCase.js'
|
|
6
5
|
|
|
7
6
|
/**
|
|
8
7
|
* Node dependencies
|
|
9
8
|
*/
|
|
10
9
|
import { getSetting, heading, saveConfig, msgSuccessTitle } from '../utilities/index.js'
|
|
11
10
|
|
|
11
|
+
function kebabCase( value ) {
|
|
12
|
+
return String( value ).toLowerCase().replace( /\s+/g, '-' )
|
|
13
|
+
}
|
|
14
|
+
|
|
12
15
|
export default async () => {
|
|
13
16
|
const questions = [
|
|
14
17
|
// Product
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
/**
|
|
3
2
|
* Node Dependencies
|
|
4
3
|
*/
|
|
@@ -7,7 +6,7 @@ import path from 'path';
|
|
|
7
6
|
/**
|
|
8
7
|
* Internal Dependencies
|
|
9
8
|
*/
|
|
10
|
-
import { getSetting,
|
|
9
|
+
import { getSetting, heading, filenameToHeading, getProjectRoot, writeFromTemplate } from "../utilities/index.js";
|
|
11
10
|
|
|
12
11
|
export default (name, options) => {
|
|
13
12
|
heading('Creating javascript file...')
|
|
@@ -16,21 +15,16 @@ export default (name, options) => {
|
|
|
16
15
|
d: description = null,
|
|
17
16
|
} = options
|
|
18
17
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
catch (err) {
|
|
33
|
-
msgErrorTitle('We failed!!!');
|
|
34
|
-
throw err;
|
|
35
|
-
}
|
|
18
|
+
const dest = path.join( getProjectRoot(), getSetting( 'paths.javascript' ), name.toLowerCase().replaceAll( '\\', '/' ) ) + '.js'
|
|
19
|
+
writeFromTemplate(
|
|
20
|
+
path.dirname( dest ),
|
|
21
|
+
path.basename( dest ),
|
|
22
|
+
'files/javascript.js',
|
|
23
|
+
{
|
|
24
|
+
...getSetting(),
|
|
25
|
+
heading: header || filenameToHeading(name) + ' module.',
|
|
26
|
+
description: description || 'Description of the module',
|
|
27
|
+
},
|
|
28
|
+
options.force
|
|
29
|
+
)
|
|
36
30
|
}
|
|
@@ -4,19 +4,18 @@
|
|
|
4
4
|
import fs from 'fs'
|
|
5
5
|
import path from 'path'
|
|
6
6
|
import logSymbols from 'log-symbols'
|
|
7
|
-
import { forEach, waterfall } from 'async'
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Internal Dependencies
|
|
11
|
-
*/
|
|
12
7
|
import { pluginData } from '../release.js'
|
|
13
|
-
import { getSetting, heading, onSameLine, saveConfig, updateFileContent, write } from "../../utilities/index.js"
|
|
8
|
+
import { getSetting, heading, onSameLine, runSteps, saveConfig, updateFileContent, write } from "../../utilities/index.js"
|
|
14
9
|
|
|
15
10
|
/**
|
|
16
11
|
* Update version in readme.txt file
|
|
17
12
|
*
|
|
18
13
|
* @example Stable tag: {version}
|
|
19
14
|
*/
|
|
15
|
+
export function applyStableTag( content, version ) {
|
|
16
|
+
return content.replace( /^(Stable tag:)[ \t]*.*$/mi, `$1 ${version}` )
|
|
17
|
+
}
|
|
18
|
+
|
|
20
19
|
function updateReadme(next) {
|
|
21
20
|
updateFileContent(
|
|
22
21
|
'./readme.txt',
|
|
@@ -27,16 +26,12 @@ function updateReadme(next) {
|
|
|
27
26
|
},
|
|
28
27
|
next,
|
|
29
28
|
(content) => {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
if (null !== regex) {
|
|
34
|
-
regex = regex.groups
|
|
35
|
-
content = content.replace(`${regex.prefix}${regex.version}`, `${regex.prefix} ${pluginData.semver.getNextVersionString()}`)
|
|
29
|
+
const updated = applyStableTag( content, pluginData.semver.getNextVersionString() )
|
|
30
|
+
if ( updated !== content ) {
|
|
36
31
|
pluginData.commitMessages.push('update version in readme.txt')
|
|
37
32
|
}
|
|
38
33
|
|
|
39
|
-
return
|
|
34
|
+
return updated
|
|
40
35
|
}
|
|
41
36
|
)
|
|
42
37
|
}
|
|
@@ -65,7 +60,7 @@ function updatePluginFiles(next) {
|
|
|
65
60
|
return next(true)
|
|
66
61
|
}
|
|
67
62
|
|
|
68
|
-
|
|
63
|
+
const steps = phpFiles.map( ( fileName ) => ( nextFile ) => {
|
|
69
64
|
updateFileContent(
|
|
70
65
|
fileName,
|
|
71
66
|
{
|
|
@@ -104,7 +99,9 @@ function updatePluginFiles(next) {
|
|
|
104
99
|
return content
|
|
105
100
|
}
|
|
106
101
|
)
|
|
107
|
-
}
|
|
102
|
+
} )
|
|
103
|
+
|
|
104
|
+
runSteps( steps, () => next() )
|
|
108
105
|
})
|
|
109
106
|
}
|
|
110
107
|
|
|
@@ -134,8 +131,8 @@ export default function updateVersionNumber(next) {
|
|
|
134
131
|
|
|
135
132
|
flow.push(updatePluginFiles)
|
|
136
133
|
|
|
137
|
-
|
|
134
|
+
runSteps(
|
|
138
135
|
flow,
|
|
139
|
-
() => next()
|
|
136
|
+
( err ) => next( err )
|
|
140
137
|
)
|
|
141
138
|
}
|
|
@@ -2,15 +2,9 @@
|
|
|
2
2
|
* External Dependencies
|
|
3
3
|
*/
|
|
4
4
|
import fs from 'fs'
|
|
5
|
-
import path from 'path'
|
|
6
5
|
import logSymbols from 'log-symbols'
|
|
7
|
-
import { forEach, waterfall } from 'async'
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Internal Dependencies
|
|
11
|
-
*/
|
|
12
6
|
import { pluginData } from '../release.js';
|
|
13
|
-
import { heading, execCommand, onSameLine, updateFileContent, write } from "../../utilities/index.js"
|
|
7
|
+
import { heading, execCommand, getSetting, onSameLine, runSteps, updateFileContent, write } from "../../utilities/index.js"
|
|
14
8
|
|
|
15
9
|
const LOCALES_CHANGELOG = {
|
|
16
10
|
updated: {
|
|
@@ -92,11 +86,11 @@ function writeLocalesChangelog(type, changes) {
|
|
|
92
86
|
* Update changelog for locales
|
|
93
87
|
*/
|
|
94
88
|
function updateLocalesChangelog(next) {
|
|
95
|
-
const
|
|
89
|
+
const destination = getSetting('glotpress.destination') || './languages/'
|
|
96
90
|
|
|
97
91
|
write('Generating translations changelog...')
|
|
98
92
|
|
|
99
|
-
execCommand('git ls-files '
|
|
93
|
+
execCommand( [ 'git', 'ls-files', '--', destination ], function(result) {
|
|
100
94
|
const files = result.split('\n').slice(0,-1)
|
|
101
95
|
const changes = loopLocales(pluginData.locales, files)
|
|
102
96
|
|
|
@@ -133,7 +127,7 @@ function generateEntries(next) {
|
|
|
133
127
|
return next(true)
|
|
134
128
|
}
|
|
135
129
|
|
|
136
|
-
|
|
130
|
+
for ( const fileName of files.sort() ) {
|
|
137
131
|
const parts = fileName.split('-')
|
|
138
132
|
|
|
139
133
|
if (allowed.includes(parts[0])) {
|
|
@@ -143,27 +137,25 @@ function generateEntries(next) {
|
|
|
143
137
|
`- ${labels[parts[0]]}: ${content.toString().trim()}`
|
|
144
138
|
)
|
|
145
139
|
}
|
|
140
|
+
}
|
|
146
141
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
onSameLine(`${logSymbols.success} Changelog entries generated successfully`)
|
|
165
|
-
next()
|
|
166
|
-
})
|
|
142
|
+
const currentDate = new Date();
|
|
143
|
+
const options = { year: 'numeric', month: 'long', day: 'numeric' };
|
|
144
|
+
pluginData.changelogChanges = [
|
|
145
|
+
...changes['feature'],
|
|
146
|
+
...changes['improvement'],
|
|
147
|
+
...changes['fix'],
|
|
148
|
+
]
|
|
149
|
+
|
|
150
|
+
pluginData.changelogChanges = pluginData.changelogChanges.length > 0
|
|
151
|
+
? [
|
|
152
|
+
`= ${pluginData.semver.getNextVersionString()} (${currentDate.toLocaleDateString('en', options)}) =`,
|
|
153
|
+
'',
|
|
154
|
+
...pluginData.changelogChanges
|
|
155
|
+
] : false
|
|
156
|
+
|
|
157
|
+
onSameLine(`${logSymbols.success} Changelog entries generated successfully`)
|
|
158
|
+
next()
|
|
167
159
|
})
|
|
168
160
|
}
|
|
169
161
|
|
|
@@ -257,5 +249,5 @@ export default function updateChangelog(next) {
|
|
|
257
249
|
flow.push(cleanChangelogDirectory)
|
|
258
250
|
}
|
|
259
251
|
|
|
260
|
-
|
|
252
|
+
runSteps( flow, ( err ) => next( err ) )
|
|
261
253
|
}
|
|
@@ -14,18 +14,32 @@ import { execCommand, onSameLine, getSetting, write } from "../../utilities/inde
|
|
|
14
14
|
*/
|
|
15
15
|
export function getLatestTag() {
|
|
16
16
|
return new Promise((resolve, reject) => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
17
|
+
execCommand( 'git describe --tags --abbrev=0', function(version, error, stderr) {
|
|
18
|
+
if ( error ) {
|
|
19
|
+
const text = String( stderr || error.message || '' )
|
|
20
|
+
if ( /No names found/i.test( text ) ) {
|
|
21
|
+
resolve( getSetting( 'wp.version', '0.0.0' ) )
|
|
22
|
+
return
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
reject( error )
|
|
26
|
+
return
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
version = String( version || '' ).trim().replace(/^v/, '')
|
|
30
|
+
resolve( '' !== version ? version : getSetting( 'wp.version', '0.0.0' ) )
|
|
31
|
+
} )
|
|
26
32
|
})
|
|
27
33
|
}
|
|
28
34
|
|
|
35
|
+
function gitRemoteFailed( error, stderr ) {
|
|
36
|
+
if ( error ) {
|
|
37
|
+
return true
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return typeof stderr === 'string' && ( stderr.includes( 'error:' ) || stderr.includes( 'fatal:' ) )
|
|
41
|
+
}
|
|
42
|
+
|
|
29
43
|
/**
|
|
30
44
|
* Check if user has permission to write to repo
|
|
31
45
|
*/
|
|
@@ -35,7 +49,7 @@ export function hasPermission(next) {
|
|
|
35
49
|
write(`${message}....`)
|
|
36
50
|
|
|
37
51
|
execCommand('git push --dry-run', function(result, error, stderr) {
|
|
38
|
-
if (
|
|
52
|
+
if ( gitRemoteFailed( error, stderr ) ) {
|
|
39
53
|
onSameLine(`${logSymbols.error} ${message}`)
|
|
40
54
|
return next(true)
|
|
41
55
|
}
|
|
@@ -54,7 +68,7 @@ export function gitFetch(next) {
|
|
|
54
68
|
write(`${message}....`)
|
|
55
69
|
|
|
56
70
|
execCommand('git fetch', function(result, error, stderr) {
|
|
57
|
-
if (
|
|
71
|
+
if ( gitRemoteFailed( error, stderr ) ) {
|
|
58
72
|
onSameLine(`${logSymbols.error} ${message}`)
|
|
59
73
|
return next(true)
|
|
60
74
|
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External Dependencies
|
|
3
3
|
*/
|
|
4
|
-
import
|
|
4
|
+
import fs from 'fs'
|
|
5
5
|
import logSymbols from 'log-symbols'
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Internal Dependencies
|
|
9
9
|
*/
|
|
10
10
|
import { pluginData } from '../release.js'
|
|
11
|
-
import { execCommand, heading, onSameLine, write } from "../../utilities/index.js"
|
|
11
|
+
import { execCommand, heading, onSameLine, runSteps, write } from "../../utilities/index.js"
|
|
12
12
|
import {
|
|
13
13
|
hasPermission,
|
|
14
14
|
gitFetch,
|
|
@@ -22,14 +22,14 @@ import {
|
|
|
22
22
|
export function githubPreTasks(next) {
|
|
23
23
|
heading('Github operations')
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
runSteps(
|
|
26
26
|
[
|
|
27
27
|
hasPermission,
|
|
28
28
|
gitFetch,
|
|
29
29
|
verifyNextVersion,
|
|
30
30
|
getCurrentBranchName,
|
|
31
31
|
],
|
|
32
|
-
( err
|
|
32
|
+
( err ) => {
|
|
33
33
|
if(err) {
|
|
34
34
|
return next(true)
|
|
35
35
|
}
|
|
@@ -48,13 +48,64 @@ export function githubFinalTasks(next) {
|
|
|
48
48
|
|
|
49
49
|
const version = pluginData.semver.getNextVersionString()
|
|
50
50
|
const message = pluginData.commitMessages.join('\n')
|
|
51
|
+
const files = releasePaths()
|
|
51
52
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
53
|
+
if ( files.length < 1 ) {
|
|
54
|
+
onSameLine(`${logSymbols.error} No release files to commit`)
|
|
55
|
+
return next( new Error( 'No release files to commit' ) )
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
runSteps(
|
|
59
|
+
[
|
|
60
|
+
( done ) => git( [ 'add', '--', ...files ], done ),
|
|
61
|
+
( done ) => git(
|
|
62
|
+
[
|
|
63
|
+
'commit',
|
|
64
|
+
'-m',
|
|
65
|
+
`bump version to ${version}`,
|
|
66
|
+
'-m',
|
|
67
|
+
message,
|
|
68
|
+
],
|
|
69
|
+
done
|
|
70
|
+
),
|
|
71
|
+
( done ) => git( [ 'push' ], done ),
|
|
72
|
+
],
|
|
73
|
+
( error ) => {
|
|
74
|
+
if ( error ) {
|
|
75
|
+
return next( error )
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
onSameLine(`${logSymbols.success} Git commit successful`)
|
|
79
|
+
next()
|
|
80
|
+
}
|
|
81
|
+
)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function releasePaths() {
|
|
85
|
+
let phpFiles = []
|
|
86
|
+
try {
|
|
87
|
+
phpFiles = fs.readdirSync( '.' ).filter( ( file ) => {
|
|
88
|
+
return file.toLowerCase().endsWith( '.php' ) && file.toLowerCase() !== 'index.php'
|
|
89
|
+
} )
|
|
90
|
+
} catch ( _ ) {}
|
|
91
|
+
|
|
92
|
+
return [
|
|
93
|
+
'readme.txt',
|
|
94
|
+
'changelog.txt',
|
|
95
|
+
'wp.advads',
|
|
96
|
+
'languages',
|
|
97
|
+
'.changelog',
|
|
98
|
+
...phpFiles,
|
|
99
|
+
].filter( ( file ) => fs.existsSync( file ) )
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function git( args, done ) {
|
|
103
|
+
execCommand( [ 'git', ...args ], ( stdout, error, stderr ) => {
|
|
104
|
+
if ( error ) {
|
|
105
|
+
onSameLine(`${logSymbols.error} ${stderr || error.message}`)
|
|
106
|
+
return done( error )
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
done()
|
|
110
|
+
} )
|
|
60
111
|
}
|
|
@@ -17,7 +17,7 @@ const PRE_RELEASE_NAMES = [ 'alpha', 'beta', 'rc' ]
|
|
|
17
17
|
/**
|
|
18
18
|
* Semantic version generator
|
|
19
19
|
*/
|
|
20
|
-
class SemVer {
|
|
20
|
+
export class SemVer {
|
|
21
21
|
constructor(baseVersion, increment, preRelease) {
|
|
22
22
|
this.baseVersion = baseVersion
|
|
23
23
|
this.increment = increment
|
|
@@ -40,14 +40,21 @@ class SemVer {
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
parseVersion() {
|
|
43
|
-
const regex = new RegExp('(?<major>\\d+)\\.(?<minor>\\d+)\\.(?<patch>\\d+)(?:-(?<pre>alpha|beta|rc))?(?:\\.(?<pre_count>\\d+))?', '
|
|
44
|
-
|
|
43
|
+
const regex = new RegExp('(?<major>\\d+)\\.(?<minor>\\d+)\\.(?<patch>\\d+)(?:-(?<pre>alpha|beta|rc))?(?:\\.(?<pre_count>\\d+))?', 'm')
|
|
44
|
+
const match = regex.exec(this.baseVersion)
|
|
45
|
+
|
|
46
|
+
if ( ! match || ! match.groups ) {
|
|
47
|
+
console.log(`${logSymbols.error} ${chalk.bold.red(`Failed!`)} Invalid version: ${this.baseVersion}`)
|
|
48
|
+
throw new Error('failed')
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
this.baseVersion = { ...match.groups }
|
|
45
52
|
|
|
46
53
|
this.baseVersion.major = parseInt(this.baseVersion.major)
|
|
47
54
|
this.baseVersion.minor = parseInt(this.baseVersion.minor)
|
|
48
55
|
this.baseVersion.patch = parseInt(this.baseVersion.patch)
|
|
49
56
|
this.baseVersion.pre = undefined === this.baseVersion.pre ? false : this.baseVersion.pre
|
|
50
|
-
this.baseVersion.pre_count = undefined === this.baseVersion.pre_count ? false : this.baseVersion.pre_count
|
|
57
|
+
this.baseVersion.pre_count = undefined === this.baseVersion.pre_count ? false : parseInt(this.baseVersion.pre_count)
|
|
51
58
|
}
|
|
52
59
|
|
|
53
60
|
getNextVersion() {
|
|
@@ -68,17 +75,6 @@ class SemVer {
|
|
|
68
75
|
return this.versionString;
|
|
69
76
|
}
|
|
70
77
|
|
|
71
|
-
getLatestMinor() {
|
|
72
|
-
if (this.nextVersion.patch === 0) {
|
|
73
|
-
return this.getNextVersionString();
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const latestMinor = {...this.nextVersion}
|
|
77
|
-
latestMinor.patch = 0
|
|
78
|
-
|
|
79
|
-
return `${this.nextVersion.major}.${this.nextVersion.minor}.${this.nextVersion.patch}`
|
|
80
|
-
}
|
|
81
|
-
|
|
82
78
|
setupNextVersion() {
|
|
83
79
|
this.nextVersion = { ...this.baseVersion }
|
|
84
80
|
|
|
@@ -116,6 +112,13 @@ class SemVer {
|
|
|
116
112
|
}
|
|
117
113
|
|
|
118
114
|
createPreReleaseFromPreRelease() {
|
|
115
|
+
if (this.baseVersion.pre === this.preRelease) {
|
|
116
|
+
this.nextVersion.pre_count = this.baseVersion.pre_count
|
|
117
|
+
? this.baseVersion.pre_count + 1
|
|
118
|
+
: 1
|
|
119
|
+
return
|
|
120
|
+
}
|
|
121
|
+
|
|
119
122
|
let increment = 'patch'
|
|
120
123
|
if (this.baseVersion.patch === 0) {
|
|
121
124
|
increment = this.baseVersion.minor ? 'major' : 'minor'
|
|
@@ -125,14 +128,8 @@ class SemVer {
|
|
|
125
128
|
this.incrementVersion()
|
|
126
129
|
}
|
|
127
130
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
? 2
|
|
131
|
-
: this.baseVersion.pre_count + 1
|
|
132
|
-
} else {
|
|
133
|
-
this.nextVersion.pre = this.preRelease
|
|
134
|
-
this.nextVersion.pre_count = 1
|
|
135
|
-
}
|
|
131
|
+
this.nextVersion.pre = this.preRelease
|
|
132
|
+
this.nextVersion.pre_count = 1
|
|
136
133
|
|
|
137
134
|
this.checkPreReleaseLogic()
|
|
138
135
|
}
|
|
@@ -161,7 +158,7 @@ class SemVer {
|
|
|
161
158
|
*/
|
|
162
159
|
checkPreReleaseLogic() {
|
|
163
160
|
if (
|
|
164
|
-
|
|
161
|
+
this.baseVersion.pre
|
|
165
162
|
&& (
|
|
166
163
|
this.nextVersion[this.increment] !== this.baseVersion[this.increment]
|
|
167
164
|
|| this.nextVersion[this.increment] === 0
|
|
@@ -194,5 +191,5 @@ export default function getSemVer(next) {
|
|
|
194
191
|
catch (err) {
|
|
195
192
|
return next(true)
|
|
196
193
|
}
|
|
197
|
-
})
|
|
194
|
+
}).catch( () => next(true) )
|
|
198
195
|
}
|