wp-advads 1.0.5 → 1.0.7

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "wp-advads",
4
- "version": "1.0.5",
4
+ "version": "1.0.7",
5
5
  "description": "Create a Advanced Ads wordPress plugin eco system.",
6
6
  "author": {
7
7
  "name": "Shakeeb Ahmed",
package/src/app.js CHANGED
@@ -11,9 +11,11 @@ import logSymbols from 'log-symbols'
11
11
  * Internal Dependencies
12
12
  */
13
13
  import { getCommand } from './helpers.js'
14
- import { execute as helpCommand } from './commands/help/index.js'
15
14
  import { execute as backupCommand } from './commands/backup/index.js'
15
+ import { execute as helpCommand } from './commands/help/index.js'
16
+ import { execute as releaseCommand } from './commands/release/index.js'
16
17
  import { execute as setupCommand } from './commands/setup/index.js'
18
+ import packageDetails from '../package.json' assert { type: "json" }
17
19
 
18
20
  /**
19
21
  * App
@@ -22,7 +24,7 @@ async function app() {
22
24
  console.log(
23
25
  [
24
26
  chalk.hex('#FADC00').inverse.bold('Advanced Ads WordPress Plugin Scaffolding'),
25
- chalk.white( 'v1.0.0' ),
27
+ chalk.white( 'v' + packageDetails.version ),
26
28
  chalk.dim( 'by Shakeeb Ahmed' )
27
29
  ].join(" ")
28
30
  );
@@ -41,6 +43,10 @@ async function app() {
41
43
  setupCommand()
42
44
  }
43
45
 
46
+ if ( 'release' === command ) {
47
+ releaseCommand(args)
48
+ }
49
+
44
50
  // if ( 'make:file' === command ) {
45
51
  // waterfall(
46
52
  // [
@@ -54,18 +60,6 @@ async function app() {
54
60
  // }
55
61
  // )
56
62
  // }
57
-
58
- // if ( 'make:plugin' === command ) {
59
- // waterfall(
60
- // [
61
- // prompts,
62
- // createPlugin,
63
- // ],
64
- // ( err, results ) => {
65
- // console.log( `${logSymbols.success} ${chalk.bold.green(`All done!`)}` )
66
- // }
67
- // )
68
- // }
69
63
  }
70
64
 
71
65
  app()
@@ -5,4 +5,5 @@ export function execute() {
5
5
  onNewLine('List of commands')
6
6
  console.log(' npx wp-advads backup');
7
7
  console.log(' npx wp-advads setup');
8
+ console.log(' npx wp-advads release');
8
9
  }
@@ -0,0 +1,70 @@
1
+ /**
2
+ * External Dependencies
3
+ */
4
+ import chalk from 'chalk'
5
+ import { waterfall } from 'async'
6
+ import logSymbols from 'log-symbols'
7
+
8
+ /**
9
+ * Internal Dependencies
10
+ */
11
+ import { heading, runCommand } from "../../helpers.js"
12
+
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
18
+ }
19
+
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...')
26
+
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 )
32
+
33
+ console.log( logSymbols.success + ' Done' )
34
+ } catch {
35
+ console.log( logSymbols.error + ' Error' )
36
+ }
37
+ }
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) {
46
+ heading('Releasing the plugin...')
47
+ 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
+ waterfall(
65
+ falls,
66
+ ( err, results ) => {
67
+ console.log( `${logSymbols.success} ${chalk.bold.green(`All done!`)}` )
68
+ }
69
+ )
70
+ }
@@ -148,7 +148,7 @@ class CreatePlugin {
148
148
  'async',
149
149
  'browser-sync',
150
150
  'browser-sync-webpack-plugin',
151
- 'chalk',
151
+ 'chalk@4.1.2',
152
152
  'eslint-plugin-prettier',
153
153
  'husky',
154
154
  'laravel-mix',
@@ -158,7 +158,6 @@ class CreatePlugin {
158
158
  'sass',
159
159
  'sass-loader',
160
160
  'shelljs',
161
- 'stylelint',
162
161
  'webpack',
163
162
  ]
164
163
 
package/src/helpers.js CHANGED
@@ -41,10 +41,12 @@ export function onNewLine(text) {
41
41
 
42
42
  export function getCommand() {
43
43
  const args = getArguments()
44
+ const { _, ...rest } = args
45
+ const command = _[0] || 'help'
44
46
 
45
47
  return {
46
- command: args._[0] || 'help',
47
- args: args._[1] || []
48
+ command,
49
+ args: rest || []
48
50
  }
49
51
  }
50
52
 
@@ -55,5 +55,10 @@
55
55
  "glotpress": {
56
56
  "project": "{{package.name}}",
57
57
  "destination": "./languages/"
58
+ },
59
+ "wpPot": {
60
+ "output": "/languages/",
61
+ "file": "{{wp.textDomain}}.pot",
62
+ "domain": "{{wp.textDomain}}"
58
63
  }
59
64
  }
@@ -27,8 +27,6 @@ class WordPressPot {
27
27
 
28
28
  const rootPath = process.cwd()
29
29
 
30
- console.log(`${rootPath}${output}${file}`);
31
-
32
30
  sh.exec(`wp i18n make-pot ${rootPath} ${rootPath}${output}${file} --domain=${domain} --exclude=${exclude.join(',')}`)
33
31
  if ( false !== skipJS ) {
34
32
  sh.exec(`wp i18n make-json ${rootPath}${output}`, { silent: true })
@@ -1,68 +1,101 @@
1
1
  #!/usr/bin/env node
2
+ /* eslint-disable no-console */
2
3
 
3
4
  // Packages.
4
- const chalk = require("chalk");
5
- const fs = require("fs");
6
- const { resolve } = require("path");
7
- const async = require("async");
5
+ const chalk = require('chalk');
6
+ const fs = require('fs');
7
+ const { resolve } = require('path');
8
+ const async = require('async');
8
9
 
9
10
  // Settings.
10
- const package = require("../package.json");
11
+ const packageDetails = require('../package.json');
11
12
  const BASEURL = 'https://translate.wpadvancedads.com/api/projects';
12
13
 
13
14
  // Validation of settings.
14
- if ( undefined === package.glotpress || Object.keys(package.glotpress).length < 1 ) {
15
- console.log( chalk.bgRed.bold("Error:") + " The GlotPress settings is not defined." );
16
- return;
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;
25
+ }
26
+
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;
36
+ }
37
+
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.'
45
+ );
46
+ return false;
47
+ }
48
+
49
+ return true;
17
50
  }
18
51
 
19
- if ( undefined === package.glotpress.project || '' === undefined === package.glotpress.project ) {
20
- console.log( chalk.bgRed.bold("Error:") + " The GlotPress project name is not defined." );
21
- return;
22
- }
23
-
24
- if ( undefined === package.glotpress.destination || '' === undefined === package.glotpress.destination ) {
25
- console.log( chalk.bgRed.bold("Error:") + " The destination directory is not defined." );
26
- return;
27
- }
28
-
29
- const { glotpress } = package
30
- const { project } = glotpress
31
- let { potPrefix, destination } = glotpress
32
- potPrefix = potPrefix ?? project
33
- destination =resolve(destination)
52
+ const { glotpress } = packageDetails;
53
+ const { project } = glotpress;
54
+ let { potPrefix, destination } = glotpress;
55
+ potPrefix = potPrefix ?? project;
56
+ destination = resolve(destination);
34
57
 
35
58
  if (!fs.existsSync(destination)) {
36
59
  fs.mkdirSync(destination);
37
60
  }
38
61
 
39
62
  async function getGlotPressData() {
40
- const response = await fetch(`${BASEURL}/${package.glotpress.project}`);
63
+ const response = await fetch(
64
+ `${BASEURL}/${packageDetails.glotpress.project}`
65
+ );
41
66
  const data = await response.json();
42
- const sets = {}
67
+ const sets = {};
68
+
69
+ if (undefined !== data.success && !data.success) {
70
+ console.log(chalk.bgRed.bold('Error:') + ' ' + data.error);
71
+ return false;
72
+ }
73
+
43
74
  data.translation_sets.map((set) => {
44
- if ( set.current_count > 0 ) {
75
+ if (set.current_count > 0) {
45
76
  let id = set.wp_locale;
46
- if ( 'default' !== set.slug ) {
77
+ if ('default' !== set.slug) {
47
78
  id += '_' + set.slug;
48
79
  }
49
80
 
50
- sets[ id ] = set
81
+ sets[id] = set;
51
82
  }
52
- })
53
83
 
54
- return sets
84
+ return false;
85
+ });
86
+
87
+ return sets;
55
88
  }
56
89
 
57
90
  // Download Handler.
58
91
  async function downloadFile(locale, data, format) {
59
- console.log( chalk.bold("Downloading: " + format));
92
+ console.log(chalk.bold('Downloading: ' + format));
60
93
 
61
- const target = `${destination}/${potPrefix}-${locale}.${format}`
62
- const endpoint = `${BASEURL}/${project}/${data.locale}/${data.slug}/export-translations?format=${format}`
94
+ const target = `${destination}/${potPrefix}-${locale}.${format}`;
95
+ const endpoint = `${BASEURL}/${project}/${data.locale}/${data.slug}/export-translations?format=${format}`;
63
96
 
64
97
  // Download.
65
- const response = await fetch(endpoint)
98
+ const response = await fetch(endpoint);
66
99
  const content = await response.text();
67
100
 
68
101
  fs.writeFileSync(target, content);
@@ -71,25 +104,37 @@ async function downloadFile(locale, data, format) {
71
104
  async function runCommand() {
72
105
  const locales = await getGlotPressData();
73
106
 
107
+ if (false === locales) {
108
+ return;
109
+ }
110
+
74
111
  // Download files.
75
112
  async.map(
76
113
  Object.keys(locales),
77
114
  (locale, callback) => {
78
- const localeData = locales[locale]
79
-
80
- console.log("");
81
- console.log( chalk.bgGreen.bold("Updating Language:") + ` ${chalk.italic(localeData.name)}`);
82
- async.map(
83
- ['mo', 'po'],
84
- (format) => downloadFile(locale, localeData, format)
85
- )
86
-
87
- callback(null, true)
115
+ const localeData = locales[locale];
116
+
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
+ );
125
+
126
+ callback(null, true);
88
127
  },
89
- function(err, results) {
90
- console.log("");
91
- console.log(chalk.bgGreen.bold("Success:") + " All files has been downloaded.");
128
+ function () {
129
+ console.log('');
130
+ console.log(
131
+ chalk.bgGreen.bold('Success:') +
132
+ ' All files has been downloaded.'
133
+ );
92
134
  }
93
135
  );
94
136
  }
95
- runCommand()
137
+
138
+ if (validateSettings()) {
139
+ runCommand();
140
+ }