wp-advads 1.0.27 → 1.0.28
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/README.md +115 -29
- package/package.json +1 -1
- package/src/app.js +12 -6
- package/src/commands/index.js +2 -1
- package/src/commands/release/change-version.js +2 -2
- package/src/commands/release/changelog.js +3 -3
- package/src/commands/release/git.js +4 -4
- package/src/commands/release/github.js +2 -2
- package/src/commands/release/semver.js +2 -2
- package/src/commands/release/translations.js +1 -1
- package/src/commands/wp-glotpress.js +166 -0
- package/src/commands/wp-pot.js +43 -0
- package/src/utilities/filesystem.js +2 -2
- package/src/utilities/formatting.js +22 -1
- package/src/utilities/settings.js +3 -2
- package/src/commands/setup/create-plugin.js +0 -235
package/README.md
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
#
|
|
1
|
+
# wp-advads Scaffolding Tool
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
[](https://www.npmjs.com/package/wp-advads)
|
|
7
|
+
[](https://standardjs.com)
|
|
8
|
+
[](LICENSE)
|
|
9
|
+

|
|
4
10
|
|
|
5
11
|
<p align="center">
|
|
6
12
|
<img src="https://img.icons8.com/nolan/256/wordpress.png"/>
|
|
@@ -8,45 +14,125 @@
|
|
|
8
14
|
|
|
9
15
|
## 📃 Introduction
|
|
10
16
|
|
|
11
|
-
|
|
17
|
+
CLI tools to streamline development tasks for the Advanced Ads WordPress plugin.
|
|
18
|
+
Created by [Shakeeb Ahmed](https://github.com/shakeeb)
|
|
19
|
+
|
|
20
|
+
## 📦 Installation
|
|
21
|
+
Use via npx:
|
|
22
|
+
```bash
|
|
23
|
+
npx wp-advads
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## 🚀 Usage
|
|
27
|
+
Run the CLI using:
|
|
28
|
+
```bash
|
|
29
|
+
npx wp-advads <command> [options]
|
|
30
|
+
```
|
|
12
31
|
|
|
13
|
-
##
|
|
32
|
+
## 🔧 Commands
|
|
14
33
|
|
|
15
|
-
|
|
16
|
-
|
|
34
|
+
#### `init`
|
|
35
|
+
Initializes a new project configuration file.
|
|
36
|
+
```bash
|
|
37
|
+
npx wp-advads init
|
|
17
38
|
```
|
|
18
39
|
|
|
19
|
-
## 🕹 Usage
|
|
20
40
|
|
|
21
|
-
|
|
22
|
-
|
|
41
|
+
#### `release`
|
|
42
|
+
Creates a new release for the plugin.
|
|
43
|
+
```bash
|
|
44
|
+
npx wp-advads release
|
|
45
|
+
```
|
|
46
|
+
|
|
23
47
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
48
|
+
#### `class <classname> [options]`
|
|
49
|
+
Creates a new PHP class file with optional templates.
|
|
50
|
+
```bash
|
|
51
|
+
npx wp-advads class MyClass -h "Class Heading" -d "Description" -s
|
|
27
52
|
```
|
|
28
53
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
54
|
+
##### Required Argument:
|
|
55
|
+
- `<classname>` – The name of the class.
|
|
56
|
+
|
|
57
|
+
##### Optional Argument:
|
|
58
|
+
- `-h <heading>` – File heading
|
|
59
|
+
- `-d <description>` – File description
|
|
60
|
+
- `-i` – Initializer interface
|
|
61
|
+
- `-g` – Integration interface
|
|
62
|
+
- `-r` – REST interface
|
|
63
|
+
- `-s` – Singleton class
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
#### `view <viewname> [heading]`
|
|
67
|
+
Creates a new view file (e.g. template partial).
|
|
68
|
+
```bash
|
|
69
|
+
npx wp-advads view sidebar "Sidebar View"
|
|
38
70
|
```
|
|
39
71
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
3. This one generate a file name `class-dashboard.php` in `includes/admin/report` folder with namespace `${rootNamespace}\Admin\Report` and it will be a singleton class.
|
|
72
|
+
##### Required Argument:
|
|
73
|
+
- `<viewname>` – Name of the view file.
|
|
43
74
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
75
|
+
##### Optional Argument:
|
|
76
|
+
- `[heading]` – A heading comment added to the view file.
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
#### `updates <version>`
|
|
80
|
+
Creates update logic for the given plugin version.
|
|
81
|
+
```bash
|
|
82
|
+
npx wp-advads updates 1.2.3
|
|
48
83
|
```
|
|
49
84
|
|
|
50
|
-
|
|
85
|
+
##### Required Argument:
|
|
86
|
+
- `<version>` – Target version number (e.g. `1.2.0`)
|
|
87
|
+
|
|
88
|
+
#### `js <filename> [options]`
|
|
89
|
+
Creates a new JavaScript file.
|
|
90
|
+
```bash
|
|
91
|
+
npx wp-advads js script -h "Main JS" -d "Handles the frontend logic"
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
##### Required Argument:
|
|
95
|
+
- `<filename>` – Name of the JavaScript file (without extension).
|
|
96
|
+
|
|
97
|
+
##### Optional Argument:
|
|
98
|
+
- `-h <heading>` – Heading comment for the file.
|
|
99
|
+
- `-d <description>` – Description comment for the file.
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
#### `css <filename> [options]`
|
|
103
|
+
Creates a new CSS file.
|
|
104
|
+
```bash
|
|
105
|
+
npx wp-advads css styles -h "Main CSS" -d "Plugin styles"
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
##### Required Argument:
|
|
109
|
+
- `<filename>` – Name of the CSS file (without extension).
|
|
110
|
+
|
|
111
|
+
##### Optional Argument:
|
|
112
|
+
- `-h <heading>` – Heading comment for the file.
|
|
113
|
+
- `-d <description>` – Description comment for the file.
|
|
114
|
+
|
|
115
|
+
#### `pot`
|
|
116
|
+
Generates `.po` and `.mo` translation files.
|
|
117
|
+
```bash
|
|
118
|
+
npx wp-advads pot
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
#### `translations`
|
|
122
|
+
Downloads translation files from GlotPress.
|
|
123
|
+
```bash
|
|
124
|
+
npx wp-advads translations
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### ⚠️ Notes
|
|
128
|
+
A config file is required for all commands **except** init.
|
|
129
|
+
|
|
130
|
+
If one is missing, you'll be prompted to create it with `wp-advads init`.
|
|
131
|
+
|
|
132
|
+
### 👤 Author
|
|
133
|
+
Shakeeb Ahmed
|
|
134
|
+
GitHub: [@meshakeeb](http://github.com/meshakeeb)
|
|
135
|
+
|
|
136
|
+
### 📖 Changelog
|
|
51
137
|
|
|
52
138
|
[See the changelog file](./CHANGELOG.md)
|
package/package.json
CHANGED
package/src/app.js
CHANGED
|
@@ -46,12 +46,6 @@ const app = async () => {
|
|
|
46
46
|
.description('Create new config file for the project')
|
|
47
47
|
.action(commands.init);
|
|
48
48
|
|
|
49
|
-
// Command: plugin
|
|
50
|
-
// program
|
|
51
|
-
// .command('plugin')
|
|
52
|
-
// .description('Create a new plugin')
|
|
53
|
-
// .action(commands.plugin);
|
|
54
|
-
|
|
55
49
|
// Command: release
|
|
56
50
|
program
|
|
57
51
|
.command('release')
|
|
@@ -104,6 +98,18 @@ const app = async () => {
|
|
|
104
98
|
.option('-d <description>', 'Description of the file')
|
|
105
99
|
.action(commands.css);
|
|
106
100
|
|
|
101
|
+
// Command: wp-pot
|
|
102
|
+
program
|
|
103
|
+
.command('pot')
|
|
104
|
+
.description('Create po and mo files')
|
|
105
|
+
.action(commands.wpPot);
|
|
106
|
+
|
|
107
|
+
// Command: wp-glotpress
|
|
108
|
+
program
|
|
109
|
+
.command('translations')
|
|
110
|
+
.description('Download translations from GlotPress')
|
|
111
|
+
.action(commands.wpGlotpress);
|
|
112
|
+
|
|
107
113
|
// Lets begin
|
|
108
114
|
program.parse(process.argv)
|
|
109
115
|
}
|
package/src/commands/index.js
CHANGED
|
@@ -2,7 +2,8 @@ export { default as css } from './css.js'
|
|
|
2
2
|
export { default as classFile } from './class.js'
|
|
3
3
|
export { default as init } from './init.js'
|
|
4
4
|
export { default as javascript } from './javascript.js'
|
|
5
|
-
// export { default as plugin } from './plugin.js'
|
|
6
5
|
export { default as release } from './release.js'
|
|
7
6
|
export { default as updates } from './updates.js'
|
|
8
7
|
export { default as views } from './views.js'
|
|
8
|
+
export { default as wpGlotpress } from './wp-glotpress.js'
|
|
9
|
+
export { default as wpPot } from './wp-pot.js'
|
|
@@ -10,7 +10,7 @@ import { forEach, waterfall } from 'async'
|
|
|
10
10
|
* Internal Dependencies
|
|
11
11
|
*/
|
|
12
12
|
import { pluginData } from '../release.js'
|
|
13
|
-
import { getSetting, heading, onSameLine, saveConfig, updateFileContent } from "../../utilities/index.js"
|
|
13
|
+
import { getSetting, heading, onSameLine, saveConfig, updateFileContent, write } from "../../utilities/index.js"
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* Update version in readme.txt file
|
|
@@ -48,7 +48,7 @@ function updateReadme(next) {
|
|
|
48
48
|
* @example * define( 'AA_VERSION', '{version}' );
|
|
49
49
|
*/
|
|
50
50
|
function updatePluginFiles(next) {
|
|
51
|
-
|
|
51
|
+
write( 'Updating plugin files' )
|
|
52
52
|
|
|
53
53
|
fs.readdir('./', (err, files) => {
|
|
54
54
|
if ( null !== err ) {
|
|
@@ -9,7 +9,7 @@ import { forEach, waterfall } from 'async'
|
|
|
9
9
|
* Internal Dependencies
|
|
10
10
|
*/
|
|
11
11
|
import { pluginData } from '../release.js';
|
|
12
|
-
import { heading, execCommand, onSameLine, updateFileContent } from "../../utilities/index.js"
|
|
12
|
+
import { heading, execCommand, onSameLine, updateFileContent, write } from "../../utilities/index.js"
|
|
13
13
|
|
|
14
14
|
const LOCALES_CHANGELOG = {
|
|
15
15
|
updated: {
|
|
@@ -93,7 +93,7 @@ function writeLocalesChangelog(type, changes) {
|
|
|
93
93
|
function updateLocalesChangelog(next) {
|
|
94
94
|
const { glotpress = {} } = pluginData
|
|
95
95
|
|
|
96
|
-
|
|
96
|
+
write('Generating translations changelog...')
|
|
97
97
|
|
|
98
98
|
execCommand('git ls-files ' + glotpress.destination, function(result) {
|
|
99
99
|
const files = result.split('\n').slice(0,-1)
|
|
@@ -111,7 +111,7 @@ function updateLocalesChangelog(next) {
|
|
|
111
111
|
* Generate changelog entries from .changelog files
|
|
112
112
|
*/
|
|
113
113
|
function generateEntries(next) {
|
|
114
|
-
|
|
114
|
+
write('Generating changelog entries...')
|
|
115
115
|
|
|
116
116
|
const changes = {
|
|
117
117
|
fix: [],
|
|
@@ -7,7 +7,7 @@ import logSymbols from 'log-symbols'
|
|
|
7
7
|
* Internal Dependencies
|
|
8
8
|
*/
|
|
9
9
|
import { pluginData } from '../release.js'
|
|
10
|
-
import { execCommand, onSameLine, getSetting } from "../../utilities/index.js"
|
|
10
|
+
import { execCommand, onSameLine, getSetting, write } from "../../utilities/index.js"
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Get latest tag from GitHub
|
|
@@ -34,7 +34,7 @@ export function getLatestTag() {
|
|
|
34
34
|
export function hasPermission(next) {
|
|
35
35
|
const message = 'Checking github write permission'
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
write(`${message}....`)
|
|
38
38
|
|
|
39
39
|
execCommand('git push --dry-run', function(result, error, stderr) {
|
|
40
40
|
if (stderr.includes('error:') || stderr.includes('fatal:')) {
|
|
@@ -53,7 +53,7 @@ export function hasPermission(next) {
|
|
|
53
53
|
export function gitFetch(next) {
|
|
54
54
|
const message = 'Fetching remote changes'
|
|
55
55
|
|
|
56
|
-
|
|
56
|
+
write(`${message}....`)
|
|
57
57
|
|
|
58
58
|
execCommand('git fetch', function(result, error, stderr) {
|
|
59
59
|
if (stderr.includes('error:') || stderr.includes('fatal:')) {
|
|
@@ -74,7 +74,7 @@ export function verifyNextVersion(next) {
|
|
|
74
74
|
const version = pluginData.semver.getNextVersionString()
|
|
75
75
|
const tag = 'refs/tags/v' + version
|
|
76
76
|
|
|
77
|
-
|
|
77
|
+
write(`${message}....`)
|
|
78
78
|
|
|
79
79
|
execCommand(`git rev-parse ${tag}`, function(result, error, stderr) {
|
|
80
80
|
if (null === error) {
|
|
@@ -8,7 +8,7 @@ import logSymbols from 'log-symbols'
|
|
|
8
8
|
* Internal Dependencies
|
|
9
9
|
*/
|
|
10
10
|
import { pluginData } from '../release.js'
|
|
11
|
-
import { execCommand, heading, onSameLine } from "../../utilities/index.js"
|
|
11
|
+
import { execCommand, heading, onSameLine, write } from "../../utilities/index.js"
|
|
12
12
|
import {
|
|
13
13
|
hasPermission,
|
|
14
14
|
gitFetch,
|
|
@@ -44,7 +44,7 @@ export function githubPreTasks(next) {
|
|
|
44
44
|
export function githubFinalTasks(next) {
|
|
45
45
|
heading('Github operations')
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
write('Committing to GitHub...')
|
|
48
48
|
|
|
49
49
|
const version = pluginData.semver.getNextVersionString()
|
|
50
50
|
const message = pluginData.commitMessages.join('\n')
|
|
@@ -9,7 +9,7 @@ import logSymbols from 'log-symbols'
|
|
|
9
9
|
*/
|
|
10
10
|
import { pluginData } from '../release.js'
|
|
11
11
|
import { getLatestTag } from './git.js'
|
|
12
|
-
import { heading, onSameLine } from "../../utilities/index.js"
|
|
12
|
+
import { heading, onSameLine, write } from "../../utilities/index.js"
|
|
13
13
|
|
|
14
14
|
const VERSION_NAMES = [ 'major', 'minor', 'patch' ]
|
|
15
15
|
const PRE_RELEASE_NAMES = [ 'alpha', 'beta', 'rc' ]
|
|
@@ -179,7 +179,7 @@ class SemVer {
|
|
|
179
179
|
export default function getSemVer(next) {
|
|
180
180
|
heading('Calculating next version')
|
|
181
181
|
|
|
182
|
-
|
|
182
|
+
write('Fetching latest version from github....')
|
|
183
183
|
getLatestTag().then((baseVersion) => {
|
|
184
184
|
onSameLine(`${logSymbols.success} Latest version on Github: ${baseVersion}`)
|
|
185
185
|
|
|
@@ -23,7 +23,7 @@ export default function updateTranslations( next ) {
|
|
|
23
23
|
return;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
execCommand( '
|
|
26
|
+
execCommand( 'npx wp-advads translations', function(locales) {
|
|
27
27
|
locales = locales.split('\n').slice(4).slice(0,-1)
|
|
28
28
|
console.log( logSymbols.success + ` Downloaded ${locales.length} files successfully` )
|
|
29
29
|
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External Dependencies
|
|
3
|
+
*/
|
|
4
|
+
import fs from 'fs';
|
|
5
|
+
import chalk from 'chalk';
|
|
6
|
+
import { resolve } from 'path';
|
|
7
|
+
import eachSeries from 'async/eachSeries.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Internal Dependencies
|
|
11
|
+
*/
|
|
12
|
+
import { heading, msgError, getSetting, write, msgSuccessOnSameLine, onSameLine, msgErrorOnSameLine } from "../utilities/index.js";
|
|
13
|
+
|
|
14
|
+
class GlotPressDownloader {
|
|
15
|
+
baseURL = 'https://translate.wpadvancedads.com/api/projects';
|
|
16
|
+
|
|
17
|
+
run() {
|
|
18
|
+
heading('Downloading Translations from GlotPress...')
|
|
19
|
+
|
|
20
|
+
try {
|
|
21
|
+
this.validateData();
|
|
22
|
+
this.maybeDirectory();
|
|
23
|
+
this.download();
|
|
24
|
+
} catch (error) {
|
|
25
|
+
msgError(error.message);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
validateData() {
|
|
31
|
+
const glotpress = getSetting('glotpress')
|
|
32
|
+
write('Validating data...');
|
|
33
|
+
|
|
34
|
+
if (!glotpress) {
|
|
35
|
+
onSameLine('')
|
|
36
|
+
throw new Error('No glotpress project found');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if ('' === glotpress.project) {
|
|
40
|
+
throw new Error('The GlotPress project name is not defined.');
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (undefined === glotpress.destination || '' === glotpress.destination) {
|
|
44
|
+
throw new Error('The destination directory is not defined.');
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Set data.
|
|
48
|
+
const { project, destination } = glotpress;
|
|
49
|
+
const domain = getSetting('wpPot.domain');
|
|
50
|
+
|
|
51
|
+
this.project = project;
|
|
52
|
+
this.potPrefix = domain ?? project;
|
|
53
|
+
this.destination = destination;
|
|
54
|
+
|
|
55
|
+
msgSuccessOnSameLine('Validation done');
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
maybeDirectory() {
|
|
59
|
+
const destination = resolve(this.destination);
|
|
60
|
+
write('Checking if destination directory exists...');
|
|
61
|
+
|
|
62
|
+
if (!fs.existsSync(destination)) {
|
|
63
|
+
fs.mkdirSync(destination);
|
|
64
|
+
|
|
65
|
+
if (!fs.existsSync(destination)) {
|
|
66
|
+
throw new Error('The destination directory could not be created.');
|
|
67
|
+
} else {
|
|
68
|
+
msgSuccessOnSameLine('Directory created');
|
|
69
|
+
}
|
|
70
|
+
} else {
|
|
71
|
+
msgSuccessOnSameLine('Directory exists');
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
async download() {
|
|
76
|
+
const locales = await this.getLocales();
|
|
77
|
+
if (false === locales) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
eachSeries(
|
|
82
|
+
Object.keys(locales),
|
|
83
|
+
(locale, callback) => {
|
|
84
|
+
const set = locales[locale];
|
|
85
|
+
|
|
86
|
+
console.log('');
|
|
87
|
+
console.log(
|
|
88
|
+
chalk.yellow.bold('Updating Language:') +
|
|
89
|
+
` ${chalk.italic(set.name)}`
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
eachSeries(['mo', 'po'], (format, nextFormat) => {
|
|
93
|
+
this.downloadFile(locale, set, format, nextFormat);
|
|
94
|
+
}, (err) => {
|
|
95
|
+
callback();
|
|
96
|
+
})
|
|
97
|
+
},
|
|
98
|
+
(err, results) => {
|
|
99
|
+
if (err) {
|
|
100
|
+
msgError(err.message);
|
|
101
|
+
} else {
|
|
102
|
+
console.log('');
|
|
103
|
+
console.log(
|
|
104
|
+
chalk.bgGreen.bold('Success:') +
|
|
105
|
+
' All files has been downloaded.'
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
async getLocales() {
|
|
113
|
+
write('Downloading locales...');
|
|
114
|
+
const response = await fetch(`${this.baseURL}/${this.project}`);
|
|
115
|
+
const data = await response.json();
|
|
116
|
+
const sets = {};
|
|
117
|
+
|
|
118
|
+
if (undefined !== data.success && !data.success) {
|
|
119
|
+
msgErrorOnSameLine(data.error);
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
data.translation_sets.map((set) => {
|
|
124
|
+
if (set.current_count > 0) {
|
|
125
|
+
let id = set.wp_locale;
|
|
126
|
+
if ('default' !== set.slug) {
|
|
127
|
+
id += '_' + set.slug;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
sets[id] = set;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return false;
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
msgSuccessOnSameLine('Downloaded locales');
|
|
137
|
+
|
|
138
|
+
return sets;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
async downloadFile(locale, data, format, callback) {
|
|
142
|
+
write(
|
|
143
|
+
chalk.bold(`Downloading: ${this.potPrefix}-${locale}.${format}`)
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
const target = `${this.destination}/${this.potPrefix}-${locale}.${format}`;
|
|
147
|
+
const endpoint = `${this.baseURL}/${this.project}/${data.locale}/${data.slug}/export-translations?format=${format}`;
|
|
148
|
+
|
|
149
|
+
// Download.
|
|
150
|
+
const response = await fetch(endpoint);
|
|
151
|
+
const content = await response.text();
|
|
152
|
+
|
|
153
|
+
fs.writeFileSync(target, content);
|
|
154
|
+
|
|
155
|
+
onSameLine(
|
|
156
|
+
chalk.bold(`Downloaded: ${this.potPrefix}-${locale}.${format}`)
|
|
157
|
+
);
|
|
158
|
+
|
|
159
|
+
callback();
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export default () => {
|
|
164
|
+
const downloader = new GlotPressDownloader();
|
|
165
|
+
downloader.run();
|
|
166
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal Dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { heading, msgSuccess, runCommand, getSetting } from "../utilities/index.js"
|
|
5
|
+
|
|
6
|
+
export default () => {
|
|
7
|
+
heading('Generating PO and MO files...')
|
|
8
|
+
|
|
9
|
+
const settings = getSetting()
|
|
10
|
+
|
|
11
|
+
const output = settings.wpPot.output;
|
|
12
|
+
const file = settings.wpPot.file;
|
|
13
|
+
const domain = settings.wpPot.domain;
|
|
14
|
+
const headers = {
|
|
15
|
+
'Last-Translator': 'Shakeeb Ahmed <me@shakeebahmed.com>',
|
|
16
|
+
'Language-Team': 'Advanced Ads <support@wpadvancedads.com>',
|
|
17
|
+
};
|
|
18
|
+
const exclude = [
|
|
19
|
+
'.git',
|
|
20
|
+
'.github',
|
|
21
|
+
'.husky',
|
|
22
|
+
'.wordpress-org',
|
|
23
|
+
'node_modules',
|
|
24
|
+
'packages',
|
|
25
|
+
'tools',
|
|
26
|
+
'vendor',
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
// Execute.
|
|
30
|
+
const rootPath = process.cwd();
|
|
31
|
+
const command = [
|
|
32
|
+
'wp i18n make-pot',
|
|
33
|
+
rootPath,
|
|
34
|
+
rootPath + output + file,
|
|
35
|
+
`--domain=${domain}`,
|
|
36
|
+
`--exclude=${exclude.join(',')}`,
|
|
37
|
+
`--headers='${JSON.stringify(headers)}'`,
|
|
38
|
+
];
|
|
39
|
+
|
|
40
|
+
runCommand( command.join(' '), [], () => {
|
|
41
|
+
msgSuccess('PO and MO files generated successfully');
|
|
42
|
+
} );
|
|
43
|
+
}
|
|
@@ -14,7 +14,7 @@ import fs from 'fs-extra';
|
|
|
14
14
|
/**
|
|
15
15
|
* Internal Dependencies
|
|
16
16
|
*/
|
|
17
|
-
import {
|
|
17
|
+
import { msgSuccessOnSameLine, onSameLine, write } from './formatting.js'
|
|
18
18
|
|
|
19
19
|
let projectRoot = null
|
|
20
20
|
|
|
@@ -115,7 +115,7 @@ export function deleteFile(name, file) {
|
|
|
115
115
|
* @returns {void}
|
|
116
116
|
*/
|
|
117
117
|
export function updateFileContent(fileName, messages, next, callback) {
|
|
118
|
-
|
|
118
|
+
write(messages.updating)
|
|
119
119
|
|
|
120
120
|
fs.readFile(fileName, (err, buffer) => {
|
|
121
121
|
if ( null !== err ) {
|
|
@@ -39,7 +39,6 @@ export function onSameLine(text) {
|
|
|
39
39
|
if (process.stdout.clearLine) {
|
|
40
40
|
process.stdout.clearLine(); // Clear the current line
|
|
41
41
|
process.stdout.cursorTo(0); // Move the cursor to the start of the line
|
|
42
|
-
// process.stdout.write(message);
|
|
43
42
|
}
|
|
44
43
|
|
|
45
44
|
console.log(text)
|
|
@@ -67,6 +66,28 @@ export function msgErrorOnSameLine(text) {
|
|
|
67
66
|
onSameLine(`${logSymbols.error} ${text}`)
|
|
68
67
|
}
|
|
69
68
|
|
|
69
|
+
/**
|
|
70
|
+
* Print success text
|
|
71
|
+
*
|
|
72
|
+
* @param {String} msg Text to print
|
|
73
|
+
*
|
|
74
|
+
* @returns {void}
|
|
75
|
+
*/
|
|
76
|
+
export function msgSuccess(msg) {
|
|
77
|
+
console.log( `${logSymbols.success} ${msg}` )
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Print error text
|
|
82
|
+
*
|
|
83
|
+
* @param {String} msg Text to print
|
|
84
|
+
*
|
|
85
|
+
* @returns {void}
|
|
86
|
+
*/
|
|
87
|
+
export function msgError(msg) {
|
|
88
|
+
console.log( `${logSymbols.error} ${msg}` )
|
|
89
|
+
}
|
|
90
|
+
|
|
70
91
|
/**
|
|
71
92
|
* Print success text in bold green font
|
|
72
93
|
*
|
|
@@ -14,6 +14,7 @@ import path from 'path'
|
|
|
14
14
|
* Internal Dependencies
|
|
15
15
|
*/
|
|
16
16
|
import { getProjectRoot } from './filesystem.js'
|
|
17
|
+
import { write } from './formatting.js'
|
|
17
18
|
|
|
18
19
|
let settings = null
|
|
19
20
|
|
|
@@ -52,14 +53,14 @@ export function readConfigFile() {
|
|
|
52
53
|
* @param {Object} data - The data object to save
|
|
53
54
|
*/
|
|
54
55
|
export function saveConfig(data) {
|
|
55
|
-
|
|
56
|
+
write('Saving config file...');
|
|
56
57
|
try {
|
|
57
58
|
const savePath = path.join(process.cwd(), 'wp.advads')
|
|
58
59
|
const jsonData = JSON.stringify(data, null, 2);
|
|
59
60
|
fs.writeFileSync(savePath, jsonData);
|
|
60
61
|
settings = data;
|
|
61
62
|
} catch (err) {
|
|
62
|
-
|
|
63
|
+
write('Error writing config file:', err);
|
|
63
64
|
throw err;
|
|
64
65
|
}
|
|
65
66
|
}
|
|
@@ -1,235 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
import fs from 'fs-extra'
|
|
5
|
-
import chalk from 'chalk'
|
|
6
|
-
import Handlebars from 'handlebars'
|
|
7
|
-
import { eachSeries, waterfall } from 'async'
|
|
8
|
-
|
|
9
|
-
export const pluginData = {}
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Internal dependencies
|
|
13
|
-
*/
|
|
14
|
-
import { getCurrentFolder, getTemplateFolder, heading, write, msgSuccessOnSameLine, execCommand } from '../../utilities/index.js'
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Helper functions
|
|
18
|
-
*/
|
|
19
|
-
function prepareFile( src, dest, next ) {
|
|
20
|
-
const content = fs.readFileSync( src, 'utf8' )
|
|
21
|
-
const template = Handlebars.compile( content )
|
|
22
|
-
const rendered = template( pluginData.settings )
|
|
23
|
-
|
|
24
|
-
fs.outputFile( dest, rendered ).then( next )
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Flow functions
|
|
29
|
-
*/
|
|
30
|
-
function setPluginData(next) {
|
|
31
|
-
pluginData.folder = getCurrentFolder()
|
|
32
|
-
pluginData.template = getTemplateFolder()
|
|
33
|
-
|
|
34
|
-
pluginData.dirs = [
|
|
35
|
-
// Root
|
|
36
|
-
pluginData.folder,
|
|
37
|
-
pluginData.folder + '/languages',
|
|
38
|
-
pluginData.folder + '/views',
|
|
39
|
-
|
|
40
|
-
// Assets
|
|
41
|
-
pluginData.folder + '/assets/css',
|
|
42
|
-
pluginData.folder + '/assets/scss',
|
|
43
|
-
pluginData.folder + '/assets/js',
|
|
44
|
-
pluginData.folder + '/assets/src',
|
|
45
|
-
pluginData.folder + '/assets/img',
|
|
46
|
-
|
|
47
|
-
// Includes
|
|
48
|
-
pluginData.folder + '/includes',
|
|
49
|
-
pluginData.folder + '/includes/abstracts',
|
|
50
|
-
pluginData.folder + '/includes/admin',
|
|
51
|
-
pluginData.folder + '/includes/interfaces',
|
|
52
|
-
pluginData.folder + '/includes/traits',
|
|
53
|
-
pluginData.folder + '/includes/utilities',
|
|
54
|
-
]
|
|
55
|
-
|
|
56
|
-
next()
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function createDirectories(next) {
|
|
60
|
-
const indexFile = pluginData.template + '/index.php'
|
|
61
|
-
|
|
62
|
-
write('Creating directory required for the plugin...')
|
|
63
|
-
|
|
64
|
-
eachSeries( pluginData.dirs, ( dir, nextDir ) => {
|
|
65
|
-
fs.ensureDir( dir ).then(() => {
|
|
66
|
-
fs.copy( indexFile, dir + '/index.php' ).then( nextDir )
|
|
67
|
-
})
|
|
68
|
-
}, () => {
|
|
69
|
-
msgSuccessOnSameLine(`${pluginData.dirs.length} directories created`)
|
|
70
|
-
next()
|
|
71
|
-
} )
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function copyToolFiles(next) {
|
|
75
|
-
write('Copying tools files...')
|
|
76
|
-
fs.copySync(
|
|
77
|
-
pluginData.template + '/tools',
|
|
78
|
-
pluginData.folder + '/tools',
|
|
79
|
-
)
|
|
80
|
-
fs.copySync(
|
|
81
|
-
pluginData.template + '/.github',
|
|
82
|
-
pluginData.folder + '/.github',
|
|
83
|
-
)
|
|
84
|
-
|
|
85
|
-
msgSuccessOnSameLine('Tool files copied')
|
|
86
|
-
next()
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
function prepareConfigFiles(next) {
|
|
90
|
-
const template = pluginData.template + '/configs'
|
|
91
|
-
const files =[
|
|
92
|
-
'/.editorconfig',
|
|
93
|
-
'/.eslintignore',
|
|
94
|
-
'/.eslintrc.js',
|
|
95
|
-
'/gitattributes',
|
|
96
|
-
'/gitignore',
|
|
97
|
-
'/.phpcs.xml.dist',
|
|
98
|
-
'/.prettierignore',
|
|
99
|
-
'/.prettierrc.js',
|
|
100
|
-
'/.stylelintrc',
|
|
101
|
-
'/composer.json',
|
|
102
|
-
'/package.json',
|
|
103
|
-
'/postcss.config.js',
|
|
104
|
-
'/tailwind.config.js',
|
|
105
|
-
'/webpack.mix.js',
|
|
106
|
-
'/webpack.mix.local.js',
|
|
107
|
-
]
|
|
108
|
-
|
|
109
|
-
write('Preparing configuration files...')
|
|
110
|
-
|
|
111
|
-
eachSeries( files, ( file, nextConfig ) => {
|
|
112
|
-
let dest = file
|
|
113
|
-
if ( '/gitattributes' === file ) {
|
|
114
|
-
dest = '/.gitattributes'
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
if ( '/gitignore' === file ) {
|
|
118
|
-
dest = '/.gitignore'
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
prepareFile( template + file, pluginData.folder + dest, nextConfig )
|
|
122
|
-
}, () => {
|
|
123
|
-
msgSuccessOnSameLine(`${files.length} Configuration files prepared`)
|
|
124
|
-
next()
|
|
125
|
-
} )
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
function preparePluginFiles(next) {
|
|
129
|
-
const template = pluginData.template + '/plugin'
|
|
130
|
-
const files =[
|
|
131
|
-
'/assets/src/app.js',
|
|
132
|
-
'/assets/scss/app.scss',
|
|
133
|
-
]
|
|
134
|
-
|
|
135
|
-
write('Preparing plugin files...')
|
|
136
|
-
|
|
137
|
-
eachSeries( files, ( file, nextFile ) => {
|
|
138
|
-
prepareFile( template + file, pluginData.folder + file, nextFile )
|
|
139
|
-
}, () => {
|
|
140
|
-
msgSuccessOnSameLine(`${files.length} plugin files created with settings`)
|
|
141
|
-
next()
|
|
142
|
-
} )
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
function prepareGitRepository(next) {
|
|
146
|
-
write( 'Checking GIT repo' )
|
|
147
|
-
execCommand('git rev-parse --is-inside-work-tree && echo "OK" || git init', function() {
|
|
148
|
-
msgSuccessOnSameLine('Git repository initiated successfully')
|
|
149
|
-
next()
|
|
150
|
-
})
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
function installComposer(next) {
|
|
154
|
-
heading('Composer')
|
|
155
|
-
write('Installing Composer...')
|
|
156
|
-
execCommand('composer install -q', function() {
|
|
157
|
-
msgSuccessOnSameLine('Composer installed successfully')
|
|
158
|
-
next()
|
|
159
|
-
})
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
function installNodePackages(next) {
|
|
163
|
-
const packages =[
|
|
164
|
-
'@wordpress/eslint-plugin',
|
|
165
|
-
'@wordpress/stylelint-config',
|
|
166
|
-
'async',
|
|
167
|
-
'browser-sync',
|
|
168
|
-
'browser-sync-webpack-plugin',
|
|
169
|
-
'chalk@4.1.2',
|
|
170
|
-
'eslint-plugin-prettier',
|
|
171
|
-
'husky',
|
|
172
|
-
'laravel-mix',
|
|
173
|
-
'lint-staged',
|
|
174
|
-
'mix-tailwindcss',
|
|
175
|
-
'postcss',
|
|
176
|
-
'prettier',
|
|
177
|
-
'resolve-url-loader',
|
|
178
|
-
'sass',
|
|
179
|
-
'sass-loader',
|
|
180
|
-
'shelljs',
|
|
181
|
-
'tailwindcss',
|
|
182
|
-
'webpack',
|
|
183
|
-
]
|
|
184
|
-
|
|
185
|
-
heading( 'Node Packages' )
|
|
186
|
-
|
|
187
|
-
eachSeries( packages, ( pkg, nextPackage ) => {
|
|
188
|
-
write( chalk.red( 'Installing ' + pkg ) )
|
|
189
|
-
execCommand(`npm install -D ${pkg}`, function() {
|
|
190
|
-
msgSuccessOnSameLine(`Package: ${pkg} installed successfully`)
|
|
191
|
-
nextPackage()
|
|
192
|
-
})
|
|
193
|
-
}, () => {
|
|
194
|
-
next()
|
|
195
|
-
} )
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
function prepareNodePackages(next) {
|
|
199
|
-
write( 'Adding Pre-Commit' )
|
|
200
|
-
|
|
201
|
-
execCommand('npm run prepare', function() {
|
|
202
|
-
execCommand('npx husky add .husky/pre-commit "npx lint-staged"', function() {
|
|
203
|
-
msgSuccessOnSameLine('Pre-Commit hooks added successfully')
|
|
204
|
-
next()
|
|
205
|
-
})
|
|
206
|
-
})
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
export default ( settings, next ) => {
|
|
210
|
-
pluginData.settings = settings
|
|
211
|
-
|
|
212
|
-
console.log('');
|
|
213
|
-
heading('Scaffoling plugin...')
|
|
214
|
-
|
|
215
|
-
waterfall(
|
|
216
|
-
[
|
|
217
|
-
setPluginData,
|
|
218
|
-
createDirectories,
|
|
219
|
-
copyToolFiles,
|
|
220
|
-
prepareConfigFiles,
|
|
221
|
-
preparePluginFiles,
|
|
222
|
-
prepareGitRepository,
|
|
223
|
-
installComposer,
|
|
224
|
-
installNodePackages,
|
|
225
|
-
prepareNodePackages
|
|
226
|
-
],
|
|
227
|
-
(err) => {
|
|
228
|
-
if (err) {
|
|
229
|
-
return next(true)
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
next()
|
|
233
|
-
}
|
|
234
|
-
)
|
|
235
|
-
}
|