wp-advads 1.0.31 → 1.0.34

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 (89) hide show
  1. package/.github/workflows/test.yml +17 -0
  2. package/CHANGELOG.md +23 -1
  3. package/LICENSE +15 -0
  4. package/README.md +8 -7
  5. package/package.json +9 -7
  6. package/src/app.js +17 -11
  7. package/src/commands/build.js +72 -59
  8. package/src/commands/class.js +34 -40
  9. package/src/commands/css.js +13 -19
  10. package/src/commands/init.js +4 -1
  11. package/src/commands/javascript.js +13 -19
  12. package/src/commands/release/change-version.js +14 -17
  13. package/src/commands/release/changelog.js +23 -31
  14. package/src/commands/release/git.js +25 -13
  15. package/src/commands/release/github.js +63 -12
  16. package/src/commands/release/semver.js +22 -25
  17. package/src/commands/release/translations.js +17 -23
  18. package/src/commands/release.js +3 -4
  19. package/src/commands/updates.js +20 -17
  20. package/src/commands/views.js +16 -18
  21. package/src/commands/wp-glotpress.js +125 -126
  22. package/src/commands/wp-pot.js +17 -9
  23. package/src/utilities/filesystem.js +57 -36
  24. package/src/utilities/flow.js +21 -0
  25. package/src/utilities/formatting.js +13 -4
  26. package/src/utilities/index.js +1 -1
  27. package/src/utilities/misc.js +1 -6
  28. package/src/utilities/settings.js +34 -14
  29. package/src/utilities/shell.js +60 -8
  30. package/template/files/class-singleton.php +5 -0
  31. package/template/files/javascript.js +0 -2
  32. package/template/files/view.php +2 -0
  33. package/test/build.test.js +168 -0
  34. package/test/changelog-locales.test.js +49 -0
  35. package/test/class.test.js +47 -0
  36. package/test/compile-templates.test.js +70 -0
  37. package/test/deps-hygiene.test.js +46 -0
  38. package/test/engines.test.js +11 -0
  39. package/test/get-latest-tag.test.js +51 -0
  40. package/test/git-precheck.test.js +44 -0
  41. package/test/github-final.test.js +93 -0
  42. package/test/glotpress-download.test.js +176 -0
  43. package/test/nested-path.test.js +39 -0
  44. package/test/no-fs-extra.test.js +11 -0
  45. package/test/package-identity.test.js +19 -0
  46. package/test/path-confine.test.js +42 -0
  47. package/test/pot-docs.test.js +27 -0
  48. package/test/pot-headers.test.js +49 -0
  49. package/test/project-root.test.js +26 -0
  50. package/test/release-waterfall.test.js +62 -0
  51. package/test/semver.test.js +25 -0
  52. package/test/settings-clone.test.js +34 -0
  53. package/test/settings-path.test.js +31 -0
  54. package/test/shell.test.js +100 -0
  55. package/test/singleton.test.js +14 -0
  56. package/test/stable-tag.test.js +13 -0
  57. package/test/stub-security.test.js +37 -0
  58. package/test/template-folder.test.js +19 -0
  59. package/test/translations.test.js +51 -0
  60. package/test/update-file-content.test.js +38 -0
  61. package/test/updates.test.js +39 -0
  62. package/test/version.test.js +22 -0
  63. package/test/view-escape.test.js +17 -0
  64. package/test/view.test.js +33 -0
  65. package/test/write-force.test.js +47 -0
  66. package/src/utilities/semver.js +0 -45
  67. package/template/.github/pull_request_template.md +0 -52
  68. package/template/configs/.editorconfig +0 -27
  69. package/template/configs/.eslintignore +0 -13
  70. package/template/configs/.eslintrc.js +0 -13
  71. package/template/configs/.phpcs.xml.dist +0 -87
  72. package/template/configs/.prettierignore +0 -49
  73. package/template/configs/.prettierrc.js +0 -3
  74. package/template/configs/.stylelintrc +0 -44
  75. package/template/configs/composer.json +0 -51
  76. package/template/configs/gitattributes +0 -34
  77. package/template/configs/gitignore +0 -43
  78. package/template/configs/package.json +0 -66
  79. package/template/configs/postcss.config.js +0 -6
  80. package/template/configs/tailwind.config.js +0 -8
  81. package/template/configs/webpack.mix.js +0 -65
  82. package/template/configs/webpack.mix.local.js +0 -3
  83. package/template/includes/index.php +0 -2
  84. package/template/index.js +0 -0
  85. package/template/index.php +0 -4
  86. package/template/plugin/assets/scss/app.scss +0 -0
  87. package/template/plugin/assets/src/app.js +0 -0
  88. package/template/tools/laravel-mix/wp-pot.js +0 -57
  89. package/template/tools/wp-glotpress.js +0 -162
@@ -1,162 +0,0 @@
1
- #!/usr/bin/env node
2
- /* eslint-disable no-console */
3
-
4
- // Packages.
5
- const chalk = require('chalk');
6
- const fs = require('fs');
7
- const { resolve } = require('path');
8
- const async = require('async');
9
-
10
- const packageDetails = require('../package.json');
11
- class GlotPressDownloader {
12
- baseURL = 'https://translate.wpadvancedads.com/api/projects';
13
-
14
- log(msg) {
15
- if (!this.isNoConsole) {
16
- console.log(msg);
17
- }
18
- }
19
-
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
- }
35
- }
36
-
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
- }
76
- );
77
- }
78
-
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
- }
86
-
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
- }
93
-
94
- if (
95
- undefined === packageDetails.glotpress.destination ||
96
- ('' === undefined) === packageDetails.glotpress.destination
97
- ) {
98
- throw new Error('The destination directory is not defined.');
99
- }
100
-
101
- // Set data.
102
- const { project, destination } = packageDetails.glotpress;
103
- const { domain } = packageDetails.wpPot;
104
-
105
- this.project = project;
106
- this.potPrefix = domain ?? project;
107
- this.destination = destination;
108
- }
109
-
110
- maybeDirectory() {
111
- const destination = resolve(this.destination);
112
-
113
- if (!fs.existsSync(destination)) {
114
- fs.mkdirSync(destination);
115
- }
116
- }
117
-
118
- async getGlotPressData() {
119
- const response = await fetch(`${this.baseURL}/${this.project}`);
120
- const data = await response.json();
121
- const sets = {};
122
-
123
- if (undefined !== data.success && !data.success) {
124
- this.log(chalk.bgRed.bold('Error:') + ' ' + data.error);
125
- return false;
126
- }
127
-
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
- }
134
-
135
- sets[id] = set;
136
- }
137
-
138
- return false;
139
- });
140
-
141
- return sets;
142
- }
143
-
144
- // Download Handler.
145
- async downloadFile(locale, data, format) {
146
- this.log(
147
- chalk.bold(`Downloading: ${this.potPrefix}-${locale}.${format}`)
148
- );
149
-
150
- const target = `${this.destination}/${this.potPrefix}-${locale}.${format}`;
151
- const endpoint = `${this.baseURL}/${this.project}/${data.locale}/${data.slug}/export-translations?format=${format}`;
152
-
153
- // Download.
154
- const response = await fetch(endpoint);
155
- const content = await response.text();
156
-
157
- fs.writeFileSync(target, content);
158
- }
159
- }
160
-
161
- const downlaoder = new GlotPressDownloader();
162
- downlaoder.run();