wp-advads 1.0.7 → 1.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/package.json +1 -1
  2. package/src/app.js +16 -27
  3. package/src/commands/backup/index.js +11 -7
  4. package/src/commands/file/create-file.js +96 -0
  5. package/src/commands/file/index.js +29 -0
  6. package/src/commands/help/index.js +11 -4
  7. package/src/commands/index.js +5 -0
  8. package/src/commands/release/change-version.js +124 -0
  9. package/src/commands/release/changelog.js +259 -0
  10. package/src/commands/release/composer.js +37 -0
  11. package/src/commands/release/git.js +119 -0
  12. package/src/commands/release/github.js +62 -0
  13. package/src/commands/release/index.js +41 -45
  14. package/src/commands/release/prompts.js +59 -0
  15. package/src/commands/release/semver.js +198 -0
  16. package/src/commands/release/translations.js +66 -0
  17. package/src/commands/setup/create-plugin.js +213 -170
  18. package/src/commands/setup/index.js +2 -2
  19. package/src/commands/setup/prompts.js +15 -17
  20. package/src/utilities/cache.js +23 -0
  21. package/src/utilities/command.js +29 -0
  22. package/src/utilities/file.js +57 -0
  23. package/src/utilities/folder.js +64 -0
  24. package/src/utilities/formatting.js +97 -0
  25. package/src/utilities/index.js +6 -0
  26. package/src/utilities/shell.js +36 -0
  27. package/template/configs/.eslintignore +4 -1
  28. package/template/configs/.gitattributes +33 -0
  29. package/template/configs/{.phpcs.xml → .phpcs.xml.dist} +1 -0
  30. package/template/configs/.prettierignore +2 -0
  31. package/template/configs/.stylelintrc +19 -5
  32. package/template/configs/package.json +2 -2
  33. package/template/configs/webpack.mix.js +4 -3
  34. package/template/make/file-singleton.php +43 -0
  35. package/template/make/file.php +26 -0
  36. package/template/tools/laravel-mix/wp-pot.js +40 -28
  37. package/template/tools/wp-glotpress.js +125 -103
  38. package/src/helpers.js +0 -135
  39. package/template/.husky/pre-commit +0 -4
  40. package/template/configs/gitattributes +0 -25
  41. package/template/configs/gitignore +0 -38
  42. package/template/configs/webpack.mix.local.js +0 -3
  43. /package/template/{assets → plugin/assets/scss}/app.scss +0 -0
  44. /package/template/{assets → plugin/assets/src}/app.js +0 -0
@@ -0,0 +1,37 @@
1
+ /**
2
+ * External Dependencies
3
+ */
4
+ import fs from 'fs';
5
+ import logSymbols from 'log-symbols'
6
+
7
+ /**
8
+ * Internal Dependencies
9
+ */
10
+ import { pluginData } from './index.js';
11
+ import { heading, execCommand, onSameLine } from "../../utilities/index.js"
12
+
13
+ /**
14
+ * Execute routine
15
+ */
16
+ export function updateComposer(next) {
17
+ heading('Updating composer')
18
+
19
+ process.stderr.write('Dumping....')
20
+
21
+ if (fs.existsSync('./vendor')) {
22
+ fs.rmSync('./vendor', { recursive: true, force: true });
23
+ }
24
+
25
+ if (fs.existsSync('./packages')) {
26
+ fs.rmSync('./packages', { recursive: true, force: true });
27
+ }
28
+
29
+ execCommand('composer install -o -a -n --no-dev --no-scripts', function() {
30
+ fs.renameSync('./vendor', './packages')
31
+ execCommand('composer install --no-scripts', function() {
32
+ pluginData.commitMessages.push('update: 3rd party dependecies and composer dump-autoloader')
33
+ onSameLine(`${logSymbols.success} composer updated`)
34
+ next()
35
+ })
36
+ })
37
+ }
@@ -0,0 +1,119 @@
1
+ /**
2
+ * External Dependencies
3
+ */
4
+ import logSymbols from 'log-symbols'
5
+
6
+ /**
7
+ * Internal Dependencies
8
+ */
9
+ import { pluginData } from './index.js';
10
+ import { execCommand, onSameLine } from "../../utilities/index.js"
11
+
12
+
13
+ /**
14
+ * Get latest tag from GitHub
15
+ */
16
+ export function getLatestTag() {
17
+ return new Promise((resolve, reject) => {
18
+ try {
19
+ execCommand('git rev-list --tags --max-count=1', function(tags) {
20
+ execCommand( 'git describe --tags ' + tags.trim(), function(version) {
21
+ resolve(version.trim())
22
+ } )
23
+ })
24
+ }
25
+ catch (err) {
26
+ reject(err)
27
+ }
28
+ })
29
+ }
30
+
31
+ /**
32
+ * Check if user has permission to write to repo
33
+ */
34
+ export function hasPermission(next) {
35
+ const message = 'Checking github write permission'
36
+
37
+ process.stdout.write(`${message}....`)
38
+
39
+ execCommand('git push --dry-run', function(result, error, stderr) {
40
+ if (stderr.includes('error:') || stderr.includes('fatal:')) {
41
+ onSameLine(`${logSymbols.error} ${message}`)
42
+ return next(true)
43
+ }
44
+
45
+ onSameLine(`${logSymbols.success} ${message}`)
46
+ next()
47
+ })
48
+ }
49
+
50
+ /**
51
+ * Fetch remote changes
52
+ */
53
+ export function gitFetch(next) {
54
+ const message = 'Fetching remote changes'
55
+
56
+ process.stdout.write(`${message}....`)
57
+
58
+ execCommand('git fetch', function(result, error, stderr) {
59
+ if (stderr.includes('error:') || stderr.includes('fatal:')) {
60
+ onSameLine(`${logSymbols.error} ${message}`)
61
+ return next(true)
62
+ }
63
+
64
+ onSameLine(`${logSymbols.success} Remote changes fetched`)
65
+ next()
66
+ })
67
+ }
68
+
69
+ /**
70
+ * Verify if the tag already exists or not
71
+ */
72
+ export function verifyNextVersion(next) {
73
+ const message = 'Verifying next version'
74
+ const version = pluginData.semver.getNextVersionString()
75
+ const tag = 'refs/tags/v' + version
76
+
77
+ process.stdout.write(`${message}....`)
78
+
79
+ execCommand(`git rev-parse ${tag}`, function(result, error, stderr) {
80
+ if (null === error) {
81
+ onSameLine(`${logSymbols.error} Version tag: v${version} already exists.`)
82
+ return next(true)
83
+ }
84
+
85
+ onSameLine(`${logSymbols.success} Version tag verified`)
86
+ next()
87
+ })
88
+ }
89
+
90
+ /**
91
+ * Get current branch name
92
+ */
93
+ export function getCurrentBranchName(next) {
94
+ execCommand('git rev-parse --abbrev-ref HEAD', function(result) {
95
+ pluginData.gitCurrentBranch = result.trim()
96
+ next()
97
+ })
98
+ }
99
+
100
+ /**
101
+ * Create new branch with the release version
102
+ */
103
+ export function createReleaseBranch(next) {
104
+ const message = 'Creating release branch'
105
+ const version = pluginData.semver.getNextVersionString()
106
+ process.stdout.write(`${message}....`)
107
+
108
+ execCommand(`git checkout -b release/v${version}`, function(result, error, stderr) {
109
+ if (stderr.includes('fatal:') && stderr.includes('already exists')) {
110
+ onSameLine(`${logSymbols.error} Branch named: release/v${version} already exists.`)
111
+ return next(true)
112
+ }
113
+
114
+ execCommand(`git push --set-upstream origin release/v${version}`, function(result) {
115
+ onSameLine(`${logSymbols.success} Release branch created`)
116
+ next()
117
+ })
118
+ })
119
+ }
@@ -0,0 +1,62 @@
1
+ /**
2
+ * External Dependencies
3
+ */
4
+ import { waterfall } from 'async'
5
+ import logSymbols from 'log-symbols'
6
+
7
+ /**
8
+ * Internal Dependencies
9
+ */
10
+ import { execCommand, heading, onSameLine } from "../../utilities/index.js"
11
+ import {
12
+ hasPermission,
13
+ gitFetch,
14
+ verifyNextVersion,
15
+ getCurrentBranchName,
16
+ createReleaseBranch
17
+ } from './git.js'
18
+ import { pluginData } from './index.js'
19
+
20
+ /**
21
+ * Execute routine
22
+ */
23
+ export function githubPreTasks(next) {
24
+ heading('Github operations')
25
+
26
+ waterfall(
27
+ [
28
+ hasPermission,
29
+ gitFetch,
30
+ verifyNextVersion,
31
+ getCurrentBranchName,
32
+ createReleaseBranch
33
+ ],
34
+ ( err, results ) => {
35
+ if(err) {
36
+ return next(true)
37
+ }
38
+ next()
39
+ }
40
+ )
41
+ }
42
+
43
+ /**
44
+ * Execute routine
45
+ */
46
+ export function githubFinalTasks(next) {
47
+ heading('Github operations')
48
+
49
+ process.stdout.write('Committing to GitHub...')
50
+
51
+ const version = pluginData.semver.getNextVersionString()
52
+ const message = pluginData.commitMessages.join('\n')
53
+
54
+ execCommand('git add .', function() {
55
+ execCommand(`git commit --no-verify -m 'bump version to ${version}' -m '${message}'`, function(result, err, stderr) {
56
+ execCommand('git push', function() {
57
+ onSameLine(`${logSymbols.success} Git commit successful`)
58
+ next()
59
+ })
60
+ })
61
+ })
62
+ }
@@ -8,62 +8,58 @@ import logSymbols from 'log-symbols'
8
8
  /**
9
9
  * Internal Dependencies
10
10
  */
11
- import { heading, runCommand } from "../../helpers.js"
11
+ import prompts from './prompts.js'
12
+ import { heading } from "../../utilities/index.js"
13
+ import { wpPot, updateTranslations } from './translations.js'
14
+ import { updateChangelog } from './changelog.js'
15
+ import { getSemVer } from './semver.js'
16
+ import { githubPreTasks, githubFinalTasks } from './github.js'
17
+ import { updateComposer } from './composer.js'
18
+ import { updateVersionNumber } from './change-version.js'
12
19
 
13
- async function getPackage() {
14
- const rootPath = process.cwd()
15
- const { default: data } = await import( rootPath + '/package.json', { assert: { type: "json" } });
16
-
17
- return data
20
+ export const pluginData = {
21
+ commitMessages: [],
22
+ changelogChanges: false
18
23
  }
19
24
 
20
- function wpPot( next ) {
21
- const rootPath = process.cwd()
22
- const { wpPot = {} } = getPackage()
23
- const {output, file, domain, exclude = [] } = wpPot
24
-
25
- heading('Creating POT file...')
25
+ function getPackage( next ) {
26
+ (async () => {
27
+ const rootPath = process.cwd()
28
+ const { default: data } = await import( rootPath + '/package.json', { assert: { type: "json" } });
26
29
 
27
- try {
28
- exclude.push(".github")
29
- exclude.push("vendor")
30
- exclude.push("tools")
31
- runCommand( 'wp', [ 'i18n', 'make-pot', rootPath, `${rootPath}${output}${file} --domain=${domain} --exclude=${exclude.join(',')}` ], next )
30
+ return data
31
+ })().then((data) => {
32
+ pluginData.glotpress = data.glotpress
33
+ pluginData.wpPot = data.wpPot
32
34
 
33
- console.log( logSymbols.success + ' Done' )
34
- } catch {
35
- console.log( logSymbols.error + ' Error' )
36
- }
35
+ next()
36
+ })
37
37
  }
38
38
 
39
- function updateTranslations( next ) {
40
- heading('Downloading translations')
41
- runCommand( 'npm', [ 'run', 'translations' ], next )
42
- console.log( logSymbols.success + ' Done' )
43
- }
44
-
45
- export function execute(args) {
39
+ export default function(args) {
46
40
  heading('Releasing the plugin...')
47
41
  console.log('')
48
-
49
- const {
50
- potOnly = false,
51
- translationsOnly = false
52
- } = args
53
-
54
- const falls = []
55
-
56
- if (potOnly) {
57
- falls.push(wpPot)
58
- }
59
-
60
- if (translationsOnly) {
61
- falls.push(updateTranslations)
62
- }
63
-
64
42
  waterfall(
65
- falls,
43
+ [
44
+ prompts,
45
+ getPackage,
46
+ getSemVer,
47
+ githubPreTasks,
48
+ updateComposer,
49
+ wpPot,
50
+ updateTranslations,
51
+ updateVersionNumber,
52
+ updateChangelog,
53
+ githubFinalTasks
54
+ ],
66
55
  ( err, results ) => {
56
+ if (err) {
57
+ console.log('');
58
+ console.log( `${logSymbols.error} ${chalk.bold.red(`We failed somewhere! Work hard mate...`)}` )
59
+ return
60
+ }
61
+
62
+ console.log('');
67
63
  console.log( `${logSymbols.success} ${chalk.bold.green(`All done!`)}` )
68
64
  }
69
65
  )
@@ -0,0 +1,59 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import inquirer from 'inquirer'
5
+
6
+ /**
7
+ * Internal Dependencies
8
+ */
9
+ import { pluginData } from './index.js';
10
+
11
+ /**
12
+ * Execute routine
13
+ */
14
+ export default ( next ) => {
15
+ const questions = [
16
+ {
17
+ type: 'list',
18
+ name: 'version',
19
+ message: 'Select version type',
20
+ default: 'patch',
21
+ choices: [
22
+ { value: 'major', name: 'Major' },
23
+ { value: 'minor', name: 'Minor' },
24
+ { value: 'patch', name: 'Patch' },
25
+ ]
26
+ },
27
+ {
28
+ type: 'confirm',
29
+ name: 'preRelease',
30
+ message: 'Is this a Pre-Release',
31
+ default: false
32
+ },
33
+ {
34
+ type: 'list',
35
+ name: 'preVersion',
36
+ message: 'Select pre-releae version type',
37
+ default: 'patch',
38
+ choices: [
39
+ { value: 'alpha', name: 'Alpha' },
40
+ { value: 'beta', name: 'Beta' },
41
+ { value: 'rc', name: 'Release Candidate' },
42
+ ],
43
+ when: (ans) => ans.preRelease
44
+ },
45
+ ]
46
+
47
+ inquirer.prompt( questions )
48
+ .then( ( answers ) => {
49
+
50
+ if (answers.preRelease) {
51
+ answers.preRelease = answers.preVersion
52
+ delete answers.preVersion
53
+ }
54
+
55
+ pluginData.answers = answers
56
+
57
+ next()
58
+ } )
59
+ }
@@ -0,0 +1,198 @@
1
+ /**
2
+ * External Dependencies
3
+ */
4
+ import chalk from 'chalk'
5
+ import logSymbols from 'log-symbols'
6
+
7
+ /**
8
+ * Internal Dependencies
9
+ */
10
+ import { pluginData } from './index.js';
11
+ import { getLatestTag } from './git.js'
12
+ import { heading, onSameLine } from "../../utilities/index.js"
13
+
14
+ const VERSION_NAMES = [ 'major', 'minor', 'patch' ]
15
+ const PRE_RELEASE_NAMES = [ 'alpha', 'beta', 'rc' ]
16
+
17
+ /**
18
+ * Semantic version generator
19
+ */
20
+ class SemVer {
21
+ constructor(baseVersion, increment, preRelease) {
22
+ this.baseVersion = baseVersion
23
+ this.increment = increment
24
+ this.preRelease = preRelease
25
+ this.nextVersion = false
26
+ this.versionString = undefined
27
+
28
+ if ( ! VERSION_NAMES.includes(increment) ) {
29
+ console.log(`${logSymbols.error} ${chalk.bold.red(`Failed!`)} Please supply next release by specifying one of ${VERSION_NAMES.join(', ')}.`)
30
+ throw new Error('failed')
31
+ }
32
+
33
+ if ( preRelease && ! PRE_RELEASE_NAMES.includes(preRelease) ) {
34
+ console.log(`${logSymbols.error} ${chalk.bold.red(`Failed!`)} Please supply the pre-release version by specifying one of ${PRE_RELEASE_NAMES.join(', ')}.`)
35
+ throw new Error('failed')
36
+ }
37
+
38
+ this.parseVersion()
39
+ this.setupNextVersion()
40
+ }
41
+
42
+ parseVersion() {
43
+ const regex = new RegExp('(?<major>\\d+)\\.(?<minor>\\d+)\\.(?<patch>\\d+)(?:-(?<pre>alpha|beta|rc))?(?:\\.(?<pre_count>\\d+))?', 'gm')
44
+ this.baseVersion = { ...regex.exec(this.baseVersion).groups }
45
+
46
+ this.baseVersion.major = parseInt(this.baseVersion.major)
47
+ this.baseVersion.minor = parseInt(this.baseVersion.minor)
48
+ this.baseVersion.patch = parseInt(this.baseVersion.patch)
49
+ 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
51
+ }
52
+
53
+ getNextVersion() {
54
+ return this.nextVersion
55
+ }
56
+
57
+ getNextVersionString() {
58
+ if (undefined !== this.versionString) {
59
+ return this.versionString
60
+ }
61
+
62
+ this.versionString = `${this.nextVersion.major}.${this.nextVersion.minor}.${this.nextVersion.patch}`
63
+
64
+ if (this.preRelease && this.nextVersion.pre && this.nextVersion.pre_count) {
65
+ this.versionString += `-${this.nextVersion.pre}.${this.nextVersion.pre_count}`
66
+ }
67
+
68
+ return this.versionString;
69
+ }
70
+
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
+ setupNextVersion() {
83
+ this.nextVersion = { ...this.baseVersion }
84
+
85
+ // we're on a pre-release and creating a pre-release
86
+ if (this.preRelease && this.baseVersion.pre) {
87
+ return this.createPreReleaseFromPreRelease()
88
+ }
89
+
90
+ // we're on a pre-release and creating a proper release
91
+ if (!this.preRelease && this.baseVersion.pre) {
92
+ return this.createReleaseFromPreRelease()
93
+ }
94
+
95
+ // we're on a release and creating a pre-release.
96
+ if (this.preRelease) {
97
+ this.incrementVersion();
98
+ this.nextVersion.pre = this.preRelease;
99
+ this.nextVersion.pre_count = 1;
100
+
101
+ return
102
+ }
103
+
104
+ // we're on a release and creating a release.
105
+ this.incrementVersion()
106
+ }
107
+
108
+ incrementVersion() {
109
+ this.nextVersion[this.increment] = this.nextVersion[this.increment] + 1
110
+ if (this.increment !== 'patch') {
111
+ this.nextVersion.patch = 0
112
+ if (this.increment !== 'minor') {
113
+ this.nextVersion.minor = 0
114
+ }
115
+ }
116
+ }
117
+
118
+ createPreReleaseFromPreRelease() {
119
+ let increment = 'patch'
120
+ if (this.baseVersion.patch === 0) {
121
+ increment = this.baseVersion.minor ? 'major' : 'minor'
122
+ }
123
+
124
+ if (this.increment !== increment) {
125
+ this.incrementVersion()
126
+ }
127
+
128
+ if (this.baseVersion.pre === this.preRelease) {
129
+ this.nextVersion.pre_count = this.baseVersion.pre_count
130
+ ? 2
131
+ : this.baseVersion.pre_count + 1
132
+ } else {
133
+ this.nextVersion.pre = this.preRelease
134
+ this.nextVersion.pre_count = 1
135
+ }
136
+
137
+ this.checkPreReleaseLogic()
138
+ }
139
+
140
+ createReleaseFromPreRelease() {
141
+ // we're on a pre-release and creating a release.
142
+ if (
143
+ (this.increment === 'patch' && this.baseVersion.patch === 0)
144
+ || (this.increment === 'minor' && this.baseVersion.patch !== 0)
145
+ ) {
146
+ this.incrementVersion();
147
+ } else if (
148
+ this.increment === 'major'
149
+ && (this.baseVersion.minor !== 0 || this.baseVersion.patch !== 0)
150
+ ) {
151
+ this.nextVersion.patch = 0;
152
+ this.incrementVersion();
153
+ }
154
+
155
+ this.nextVersion.pre = false
156
+ this.nextVersion.pre_count = false
157
+ }
158
+
159
+ /**
160
+ * we can't create pre-releases from existing pre-releases, unless they haven't changed the version number.
161
+ */
162
+ checkPreReleaseLogic() {
163
+ if (
164
+ isset(this.baseVersion.pre)
165
+ && (
166
+ this.nextVersion[this.increment] !== this.baseVersion[this.increment]
167
+ || this.nextVersion[this.increment] === 0
168
+ )
169
+ ) {
170
+ console.log(`${logSymbols.error} ${chalk.bold.red(`Failed!`)} We can't create a release based on a non-existent version.`)
171
+ throw new Error('failed')
172
+ }
173
+ }
174
+ }
175
+
176
+ /**
177
+ * Execute routine
178
+ */
179
+ export function getSemVer(next) {
180
+ heading('Calculating next version')
181
+
182
+ process.stdout.write('Fetching latest version from github....')
183
+ getLatestTag().then((baseVersion) => {
184
+ onSameLine(`${logSymbols.success} Latest version on Github: ${baseVersion}`)
185
+
186
+ try {
187
+ const { version = 'patch', preRelease = false } = pluginData.answers
188
+ const semver = new SemVer(baseVersion, version, preRelease)
189
+ pluginData.semver = semver
190
+
191
+ console.log( `${logSymbols.success} Next version: v${semver.getNextVersionString()}`)
192
+ next()
193
+ }
194
+ catch (err) {
195
+ return next(true)
196
+ }
197
+ })
198
+ }
@@ -0,0 +1,66 @@
1
+ /**
2
+ * External Dependencies
3
+ */
4
+ import logSymbols from 'log-symbols'
5
+
6
+ /**
7
+ * Internal Dependencies
8
+ */
9
+ import { pluginData } from './index.js'
10
+ import { heading, execCommand } from "../../utilities/index.js"
11
+
12
+ /**
13
+ * Execute routine to generate POT files
14
+ */
15
+ export function wpPot( next ) {
16
+ const rootPath = process.cwd()
17
+ const { wpPot = {} } = pluginData
18
+ const {output, file, domain, exclude = [] } = wpPot
19
+
20
+ heading('Creating POT file')
21
+
22
+ try {
23
+ exclude.push(".github")
24
+ exclude.push(".husky")
25
+ exclude.push(".wordpress-org")
26
+ exclude.push("node_modules")
27
+ exclude.push("tools")
28
+ exclude.push("vendor")
29
+ execCommand(
30
+ [ 'wp', 'i18n', 'make-pot', rootPath, `${rootPath}${output}${file} --domain=${domain} --exclude=${exclude.join(',')}` ].join(' '),
31
+ () => {
32
+ pluginData.commitMessages.push('update: POT file')
33
+ console.log( logSymbols.success + ' POT file successfully generated!' )
34
+ next()
35
+ }
36
+ )
37
+ } catch {
38
+ throw new Error( logSymbols.error + ' Error' )
39
+ }
40
+ }
41
+
42
+ /**
43
+ * Execute routine to download translations from GlotPress
44
+ */
45
+ export function updateTranslations( next ) {
46
+ heading('Downloading translations from glotpress')
47
+
48
+ execCommand( 'npm run translations -- --no-console', function(locales) {
49
+ locales = locales.split('\n').slice(4).slice(0,-1)
50
+ console.log( logSymbols.success + ` Downloaded ${locales.length} files successfully` )
51
+
52
+ if (locales.length > 0) {
53
+ pluginData.commitMessages.push('add: Download translation from GlotPress')
54
+ }
55
+
56
+ const newLocales = {}
57
+ locales.map((locale) => {
58
+ const data = locale.split('=')
59
+ newLocales[ data[0] ] = data[1]
60
+ })
61
+
62
+ pluginData.locales = newLocales
63
+
64
+ next()
65
+ })
66
+ }