wp-advads 1.0.7 → 1.0.10

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
@@ -7,134 +7,156 @@ const fs = require('fs');
7
7
  const { resolve } = require('path');
8
8
  const async = require('async');
9
9
 
10
- // Settings.
11
10
  const packageDetails = require('../package.json');
12
- const BASEURL = 'https://translate.wpadvancedads.com/api/projects';
13
-
14
- // Validation of settings.
15
- function validateSettings() {
16
- if (
17
- undefined === packageDetails.glotpress ||
18
- Object.keys(packageDetails.glotpress).length < 1
19
- ) {
20
- console.log(
21
- chalk.bgRed.bold('Error:') +
22
- ' The GlotPress settings is not defined.'
23
- );
24
- return false;
11
+ class GlotPressDownloader {
12
+ baseURL = 'https://translate.wpadvancedads.com/api/projects';
13
+
14
+ log(msg) {
15
+ if (!this.isNoConsole) {
16
+ console.log(msg);
17
+ }
25
18
  }
26
19
 
27
- if (
28
- undefined === packageDetails.glotpress.project ||
29
- ('' === undefined) === packageDetails.glotpress.project
30
- ) {
31
- console.log(
32
- chalk.bgRed.bold('Error:') +
33
- ' The GlotPress project name is not defined.'
34
- );
35
- return false;
20
+ run() {
21
+ this.isNoConsole = process.argv.includes('--no-console');
22
+
23
+ try {
24
+ this.log(
25
+ chalk
26
+ .hex('#FADC00')
27
+ .inverse.bold('Downloading Translations from GlotPress')
28
+ );
29
+ this.validateData();
30
+ this.maybeDirectory();
31
+ this.download();
32
+ } catch (error) {
33
+ this.log(chalk.bgRed.bold('Error:') + ' ' + error.message);
34
+ }
36
35
  }
37
36
 
38
- if (
39
- undefined === packageDetails.glotpress.destination ||
40
- ('' === undefined) === packageDetails.glotpress.destination
41
- ) {
42
- console.log(
43
- chalk.bgRed.bold('Error:') +
44
- ' The destination directory is not defined.'
37
+ async download() {
38
+ const locales = await this.getGlotPressData();
39
+
40
+ if (false === locales) {
41
+ return;
42
+ }
43
+
44
+ // Download files.
45
+ async.map(
46
+ Object.keys(locales),
47
+ (locale, callback) => {
48
+ const localeData = locales[locale];
49
+
50
+ this.log('');
51
+ this.log(
52
+ chalk.yellow.bold('Updating Language:') +
53
+ ` ${chalk.italic(localeData.name)}`
54
+ );
55
+
56
+ async.map(['mo', 'po'], (format) => {
57
+ if (this.isNoConsole) {
58
+ process.stdout.write(
59
+ `${this.destination.replace('./', '')}${
60
+ this.potPrefix
61
+ }-${locale}.${format}=${localeData.name}` + '\n'
62
+ );
63
+ }
64
+ this.downloadFile(locale, localeData, format);
65
+ });
66
+
67
+ callback(null, true);
68
+ },
69
+ () => {
70
+ this.log('');
71
+ this.log(
72
+ chalk.bgGreen.bold('Success:') +
73
+ ' All files has been downloaded.'
74
+ );
75
+ }
45
76
  );
46
- return false;
47
77
  }
48
78
 
49
- return true;
50
- }
79
+ validateData() {
80
+ if (
81
+ undefined === packageDetails.glotpress ||
82
+ Object.keys(packageDetails.glotpress).length < 1
83
+ ) {
84
+ throw new Error('The GlotPress settings is not defined.');
85
+ }
51
86
 
52
- const { glotpress } = packageDetails;
53
- const { project } = glotpress;
54
- let { potPrefix, destination } = glotpress;
55
- potPrefix = potPrefix ?? project;
56
- destination = resolve(destination);
87
+ if (
88
+ undefined === packageDetails.glotpress.project ||
89
+ ('' === undefined) === packageDetails.glotpress.project
90
+ ) {
91
+ throw new Error('The GlotPress project name is not defined.');
92
+ }
57
93
 
58
- if (!fs.existsSync(destination)) {
59
- fs.mkdirSync(destination);
60
- }
94
+ if (
95
+ undefined === packageDetails.glotpress.destination ||
96
+ ('' === undefined) === packageDetails.glotpress.destination
97
+ ) {
98
+ throw new Error('The destination directory is not defined.');
99
+ }
61
100
 
62
- async function getGlotPressData() {
63
- const response = await fetch(
64
- `${BASEURL}/${packageDetails.glotpress.project}`
65
- );
66
- const data = await response.json();
67
- const sets = {};
101
+ // Set data.
102
+ const { project, destination } = packageDetails.glotpress;
103
+ const { domain } = packageDetails.wpPot;
68
104
 
69
- if (undefined !== data.success && !data.success) {
70
- console.log(chalk.bgRed.bold('Error:') + ' ' + data.error);
71
- return false;
105
+ this.project = project;
106
+ this.potPrefix = domain ?? project;
107
+ this.destination = destination;
72
108
  }
73
109
 
74
- data.translation_sets.map((set) => {
75
- if (set.current_count > 0) {
76
- let id = set.wp_locale;
77
- if ('default' !== set.slug) {
78
- id += '_' + set.slug;
79
- }
110
+ maybeDirectory() {
111
+ const destination = resolve(this.destination);
80
112
 
81
- sets[id] = set;
113
+ if (!fs.existsSync(destination)) {
114
+ fs.mkdirSync(destination);
82
115
  }
116
+ }
83
117
 
84
- return false;
85
- });
86
-
87
- return sets;
88
- }
89
-
90
- // Download Handler.
91
- async function downloadFile(locale, data, format) {
92
- console.log(chalk.bold('Downloading: ' + format));
118
+ async getGlotPressData() {
119
+ const response = await fetch(`${this.baseURL}/${this.project}`);
120
+ const data = await response.json();
121
+ const sets = {};
93
122
 
94
- const target = `${destination}/${potPrefix}-${locale}.${format}`;
95
- const endpoint = `${BASEURL}/${project}/${data.locale}/${data.slug}/export-translations?format=${format}`;
123
+ if (undefined !== data.success && !data.success) {
124
+ this.log(chalk.bgRed.bold('Error:') + ' ' + data.error);
125
+ return false;
126
+ }
96
127
 
97
- // Download.
98
- const response = await fetch(endpoint);
99
- const content = await response.text();
128
+ data.translation_sets.map((set) => {
129
+ if (set.current_count > 0) {
130
+ let id = set.wp_locale;
131
+ if ('default' !== set.slug) {
132
+ id += '_' + set.slug;
133
+ }
100
134
 
101
- fs.writeFileSync(target, content);
102
- }
135
+ sets[id] = set;
136
+ }
103
137
 
104
- async function runCommand() {
105
- const locales = await getGlotPressData();
138
+ return false;
139
+ });
106
140
 
107
- if (false === locales) {
108
- return;
141
+ return sets;
109
142
  }
110
143
 
111
- // Download files.
112
- async.map(
113
- Object.keys(locales),
114
- (locale, callback) => {
115
- const localeData = locales[locale];
144
+ // Download Handler.
145
+ async downloadFile(locale, data, format) {
146
+ this.log(
147
+ chalk.bold(`Downloading: ${this.potPrefix}-${locale}.${format}`)
148
+ );
116
149
 
117
- console.log('');
118
- console.log(
119
- chalk.bgGreen.bold('Updating Language:') +
120
- ` ${chalk.italic(localeData.name)}`
121
- );
122
- async.map(['mo', 'po'], (format) =>
123
- downloadFile(locale, localeData, format)
124
- );
150
+ const target = `${this.destination}/${this.potPrefix}-${locale}.${format}`;
151
+ const endpoint = `${this.baseURL}/${this.project}/${data.locale}/${data.slug}/export-translations?format=${format}`;
125
152
 
126
- callback(null, true);
127
- },
128
- function () {
129
- console.log('');
130
- console.log(
131
- chalk.bgGreen.bold('Success:') +
132
- ' All files has been downloaded.'
133
- );
134
- }
135
- );
136
- }
153
+ // Download.
154
+ const response = await fetch(endpoint);
155
+ const content = await response.text();
137
156
 
138
- if (validateSettings()) {
139
- runCommand();
157
+ fs.writeFileSync(target, content);
158
+ }
140
159
  }
160
+
161
+ const downlaoder = new GlotPressDownloader();
162
+ downlaoder.run();
package/src/helpers.js DELETED
@@ -1,135 +0,0 @@
1
- /**
2
- * External dependencies
3
- */
4
- import chalk from 'chalk'
5
- import argv from 'yargs-parser'
6
- import logSymbols from 'log-symbols'
7
- import flatCache from 'flat-cache'
8
- import { spawn } from 'node:child_process'
9
-
10
- /**
11
- * Node dependencies
12
- */
13
- import fs from 'fs'
14
- import { join } from 'path'
15
- import { createRequire } from 'node:module'
16
-
17
- const CACHE_FILE = 'adv-ads-scaffolding'
18
-
19
- const getArguments = function() {
20
- return argv( process.argv.slice( 2 ) )
21
- }
22
-
23
- const folderEmptiness = function( folder ) {
24
- const folderFiles = fs.readdirSync( folder )
25
- if (1 === folderFiles.length || 0 === folderFiles.length) {
26
- return true
27
- }
28
-
29
- return false
30
- }
31
-
32
- export function heading(title) {
33
- console.log('')
34
- console.log( chalk.bold.green( 'Ⓞ ' + title ) )
35
- }
36
-
37
- export function onNewLine(text) {
38
- console.log('')
39
- console.log(text)
40
- }
41
-
42
- export function getCommand() {
43
- const args = getArguments()
44
- const { _, ...rest } = args
45
- const command = _[0] || 'help'
46
-
47
- return {
48
- command,
49
- args: rest || []
50
- }
51
- }
52
-
53
- export function getCurrentFolder() {
54
- let folder = process.cwd()
55
-
56
- return folder
57
- }
58
-
59
- export function getRootFolder() {
60
- let counter = 0
61
- const check = function( folder ) {
62
- const isEmptyFolder = folderEmptiness(folder)
63
-
64
- if (isEmptyFolder) {
65
- return folder
66
- }
67
-
68
- const existsConfig = fs.existsSync( folder + '/' + CACHE_FILE )
69
- const existsPkg = fs.existsSync( folder + '/package.json' )
70
- if (existsConfig || existsPkg) {
71
- return folder
72
- }
73
-
74
- if ( 5 === counter ) {
75
- return process.cwd()
76
- }
77
-
78
- counter++
79
- return check(join(folder, '../'))
80
- }
81
-
82
- return check(process.cwd())
83
- }
84
-
85
- export function getTemplateFolder() {
86
- const require = createRequire( import.meta.url )
87
- return require.resolve( '../template' )
88
- .replace( '/index.js', '' )
89
- }
90
-
91
- export function backupFile(name, file) {
92
- if ( ! fs.existsSync(file) ) {
93
- console.log( `${logSymbols.error} ${chalk.red(`${name} file not found!`)}` )
94
- return
95
- }
96
-
97
- fs.renameSync(
98
- file,
99
- file + '.bak'
100
- )
101
- console.log( `${logSymbols.success} ${chalk.dim(`${name} backed up!`)}` )
102
- }
103
-
104
- export function deleteFile(name, file) {
105
- if ( ! fs.existsSync(file) ) {
106
- console.log( `${logSymbols.error} ${chalk.red(`${name} file not found!`)}` )
107
- return
108
- }
109
-
110
- fs.rmSync(file)
111
- console.log( `${logSymbols.success} ${chalk.dim(`${name} deleted!`)}` )
112
- }
113
-
114
- export function getCacheStore() {
115
- return flatCache.load( CACHE_FILE, getRootFolder() )
116
- }
117
-
118
- export function runCommand( command, args, next ) {
119
- const commandSpawn = spawn( command, args, {
120
- shell: true,
121
- stdio: [ 'inherit' ]
122
- } )
123
-
124
- commandSpawn.stdout.on( 'data', (data) => {
125
- console.log(data.toString())
126
- })
127
-
128
- commandSpawn.stderr.on( 'data', (data) => {
129
- console.error(data.toString())
130
- })
131
-
132
- commandSpawn.on( 'close', (code) => {
133
- next()
134
- })
135
- }
@@ -1,4 +0,0 @@
1
- #!/usr/bin/env sh
2
- . "$(dirname -- "$0")/_/husky.sh"
3
-
4
- pnpm lint-staged
@@ -1,25 +0,0 @@
1
- # Set the default behavior, in case people don't have `core.autocrlf` set.
2
- * text=auto
3
-
4
- # Declare files that will always have LF line endings on checkout.
5
- *.php text eol=lf
6
-
7
- # Denote all files that are truly binary and should not be modified.
8
- *.aar binary
9
- *.gif binary
10
- *.jar binary
11
- *.jpg binary
12
- *.png binary
13
- *.ttf binary
14
- *.webp binary
15
-
16
- # Remove files for archives generated using `git archive`.
17
- /.* export-ignore
18
- .changelog/ export-ignore
19
- bin/ export-ignore
20
- changelog.txt export-ignore
21
- composer.* export-ignore
22
- package*.json export-ignore
23
- phpunit.* export-ignore
24
- README.md export-ignore
25
- tests export-ignore
@@ -1,38 +0,0 @@
1
- # Wordpress - ignore core, configuration, examples, uploads and logs.
2
- # https://github.com/github/gitignore/blob/main/WordPress.gitignore
3
-
4
- # Operating System files
5
- .DS_Store
6
- Thumbs.db
7
-
8
- # IDE files
9
- .vscode/*
10
- project.xml
11
- project.properties
12
- .project
13
- .settings*
14
- *.sublime-project
15
- *.sublime-workspace
16
- .sublimelinterrc
17
-
18
- # Caches
19
- .eslintcache
20
- .stylelintcache
21
-
22
- # Environment files
23
- wp-cli.local.yml
24
- .wp-env.override.json
25
- npm-debug.log
26
- .pnpm-debug.log
27
-
28
- # Node Package Dependencies
29
- node_modules/
30
-
31
- # Composer
32
- vendor/
33
- bin/composer/**/vendor/
34
-
35
- # Support .gitkeep Files
36
- !.gitkeep
37
- webpack.mix.local.js
38
- mix-manifest.json
@@ -1,3 +0,0 @@
1
- module.exports = {
2
- wpUrl: '{{wp.proxy}}',
3
- };
File without changes