wp-advads 1.0.0
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 +0 -0
- package/package.json +43 -0
- package/src/app.js +71 -0
- package/src/commands/backup/index.js +46 -0
- package/src/commands/help/index.js +8 -0
- package/src/commands/setup/create-plugin.js +175 -0
- package/src/commands/setup/index.js +28 -0
- package/src/commands/setup/prompts.js +137 -0
- package/src/helpers.js +133 -0
- package/template/.husky/pre-commit +4 -0
- package/template/assets/app.js +0 -0
- package/template/assets/app.scss +0 -0
- package/template/configs/.editorconfig +27 -0
- package/template/configs/.eslintignore +10 -0
- package/template/configs/.eslintrc.js +4 -0
- package/template/configs/.gitattributes +25 -0
- package/template/configs/.phpcs.xml +82 -0
- package/template/configs/.prettierignore +46 -0
- package/template/configs/.prettierrc.js +3 -0
- package/template/configs/.stylelintrc +9 -0
- package/template/configs/composer.json +45 -0
- package/template/configs/package.json +59 -0
- package/template/configs/webpack.mix.js +64 -0
- package/template/includes/index.php +2 -0
- package/template/includes/interfaces/interface-integration.php +23 -0
- package/template/index.js +0 -0
- package/template/index.php +4 -0
- package/template/tools/laravel-mix/wp-pot.js +39 -0
- package/template/tools/wp-glotpress.js +95 -0
package/README.md
ADDED
|
File without changes
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"type": "module",
|
|
3
|
+
"name": "wp-advads",
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"description": "Create a Advanced Ads wordPress plugin eco system.",
|
|
6
|
+
"author": {
|
|
7
|
+
"name": "Shakeeb Ahmed",
|
|
8
|
+
"email": "me@shakeebahmed.com",
|
|
9
|
+
"url": "https://shakeebahmed.com"
|
|
10
|
+
},
|
|
11
|
+
"main": "src/app.js",
|
|
12
|
+
"bin": {
|
|
13
|
+
"wp-advads": "src/app.js"
|
|
14
|
+
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"start": "node src/app.js"
|
|
17
|
+
},
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/advanced-ads/npm-scaffolding.git"
|
|
21
|
+
},
|
|
22
|
+
"keywords": [
|
|
23
|
+
"wordpress",
|
|
24
|
+
"plugin",
|
|
25
|
+
"generator"
|
|
26
|
+
],
|
|
27
|
+
"license": "ISC",
|
|
28
|
+
"bugs": {
|
|
29
|
+
"url": "https://github.com/advanced-ads/npm-scaffolding/issues"
|
|
30
|
+
},
|
|
31
|
+
"homepage": "https://github.com/advanced-ads/npm-scaffolding#readme",
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"async": "^3.2.4",
|
|
34
|
+
"chalk": "^5.0.1",
|
|
35
|
+
"flat-cache": "^3.0.4",
|
|
36
|
+
"fs-extra": "^10.1.0",
|
|
37
|
+
"globby": "^13.1.2",
|
|
38
|
+
"handlebars": "^4.7.7",
|
|
39
|
+
"inquirer": "^9.1.1",
|
|
40
|
+
"lodash": "^4.17.21",
|
|
41
|
+
"yargs-parser": "^21.1.1"
|
|
42
|
+
}
|
|
43
|
+
}
|
package/src/app.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* External dependencies
|
|
5
|
+
*/
|
|
6
|
+
import chalk from 'chalk'
|
|
7
|
+
import { waterfall } from 'async'
|
|
8
|
+
import logSymbols from 'log-symbols'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Internal Dependencies
|
|
12
|
+
*/
|
|
13
|
+
import { getCommand } from './helpers.js'
|
|
14
|
+
import { execute as helpCommand } from './commands/help/index.js'
|
|
15
|
+
import { execute as backupCommand } from './commands/backup/index.js'
|
|
16
|
+
import { execute as setupCommand } from './commands/setup/index.js'
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* App
|
|
20
|
+
*/
|
|
21
|
+
async function app() {
|
|
22
|
+
console.log(
|
|
23
|
+
[
|
|
24
|
+
chalk.hex('#FADC00').inverse.bold('Advanced Ads WordPress Plugin Scaffolding'),
|
|
25
|
+
chalk.white( 'v1.0.0' ),
|
|
26
|
+
chalk.dim( 'by Shakeeb Ahmed' )
|
|
27
|
+
].join(" ")
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
const { command, args } = getCommand()
|
|
32
|
+
if ( 'help' === command ) {
|
|
33
|
+
helpCommand()
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if ( 'backup' === command ) {
|
|
37
|
+
backupCommand()
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if ( 'setup' === command ) {
|
|
41
|
+
setupCommand()
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// if ( 'make:file' === command ) {
|
|
45
|
+
// waterfall(
|
|
46
|
+
// [
|
|
47
|
+
// function( next ) {
|
|
48
|
+
// next(null, args)
|
|
49
|
+
// },
|
|
50
|
+
// createFile,
|
|
51
|
+
// ],
|
|
52
|
+
// ( err, results ) => {
|
|
53
|
+
// console.log( `${logSymbols.success} ${chalk.bold.green(`All done!`)}` )
|
|
54
|
+
// }
|
|
55
|
+
// )
|
|
56
|
+
// }
|
|
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
|
+
}
|
|
70
|
+
|
|
71
|
+
app()
|
|
@@ -0,0 +1,46 @@
|
|
|
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, getCurrentFolder, backupFile, deleteFile } from "../../helpers.js"
|
|
12
|
+
|
|
13
|
+
function backupFiles(next) {
|
|
14
|
+
backupFile('Pre commit hook', getCurrentFolder() + '/.git/hooks/pre-commit')
|
|
15
|
+
next(null)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function deleteFiles(next) {
|
|
19
|
+
deleteFile('EditorConfig', getCurrentFolder() + '/.editorconfig')
|
|
20
|
+
deleteFile('Git Attribute', getCurrentFolder() + '/.gitattributes')
|
|
21
|
+
deleteFile('Git Ignore', getCurrentFolder() + '/.gitignore')
|
|
22
|
+
deleteFile('PHPCS diff', getCurrentFolder() + '/.phpcs-diff.txt')
|
|
23
|
+
deleteFile('PHPCS json', getCurrentFolder() + '/.phpcs.json')
|
|
24
|
+
deleteFile('PHPCS xml', getCurrentFolder() + '/.phpcs.xml')
|
|
25
|
+
deleteFile('Package lock', getCurrentFolder() + '/package-lock.json')
|
|
26
|
+
deleteFile('Package json', getCurrentFolder() + '/package.json')
|
|
27
|
+
deleteFile('Package local', getCurrentFolder() + '/package.local.json')
|
|
28
|
+
|
|
29
|
+
next(null)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
export function execute() {
|
|
34
|
+
heading('Doing backup now...')
|
|
35
|
+
console.log('');
|
|
36
|
+
|
|
37
|
+
waterfall(
|
|
38
|
+
[
|
|
39
|
+
backupFiles,
|
|
40
|
+
deleteFiles
|
|
41
|
+
],
|
|
42
|
+
( err, results ) => {
|
|
43
|
+
console.log( `${logSymbols.success} ${chalk.bold.green(`All done!`)}` )
|
|
44
|
+
}
|
|
45
|
+
)
|
|
46
|
+
}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import fs from 'fs-extra'
|
|
5
|
+
import chalk from 'chalk'
|
|
6
|
+
import Handlebars from 'handlebars'
|
|
7
|
+
import { series, eachSeries } from 'async'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Internal dependencies
|
|
11
|
+
*/
|
|
12
|
+
import { getCurrentFolder, runCommand, getTemplateFolder, heading } from '../../helpers.js'
|
|
13
|
+
|
|
14
|
+
class CreatePlugin {
|
|
15
|
+
run(settings, callback) {
|
|
16
|
+
this.settings = settings
|
|
17
|
+
this.folder = getCurrentFolder()
|
|
18
|
+
this.template = getTemplateFolder()
|
|
19
|
+
|
|
20
|
+
this.dirs = [
|
|
21
|
+
// Root
|
|
22
|
+
this.folder + '/languages',
|
|
23
|
+
this.folder + '/templates',
|
|
24
|
+
|
|
25
|
+
// Includes
|
|
26
|
+
this.folder + '/includes',
|
|
27
|
+
this.folder + '/includes/abstracts',
|
|
28
|
+
this.folder + '/includes/admin',
|
|
29
|
+
this.folder + '/includes/database',
|
|
30
|
+
this.folder + '/includes/interfaces',
|
|
31
|
+
this.folder + '/includes/models',
|
|
32
|
+
this.folder + '/includes/traits',
|
|
33
|
+
this.folder + '/includes/utilities',
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
series(
|
|
37
|
+
[
|
|
38
|
+
this.directories,
|
|
39
|
+
this.copyIndex,
|
|
40
|
+
this.copyConfigs,
|
|
41
|
+
this.copyTools,
|
|
42
|
+
this.prepareConfigs,
|
|
43
|
+
this.prepareFiles,
|
|
44
|
+
(next) => {
|
|
45
|
+
heading( 'Installing Composer' )
|
|
46
|
+
runCommand( 'composer', [ 'install' ], next )
|
|
47
|
+
},
|
|
48
|
+
(next) => {
|
|
49
|
+
runCommand( 'composer', [ 'dump' ], next )
|
|
50
|
+
},
|
|
51
|
+
(next) => {
|
|
52
|
+
heading( 'Checking GIT repo' )
|
|
53
|
+
runCommand( 'git rev-parse --is-inside-work-tree && echo "OK" || git init', [], next )
|
|
54
|
+
},
|
|
55
|
+
this.installNpm,
|
|
56
|
+
(next) => {
|
|
57
|
+
heading( 'Adding Pre-Commit' )
|
|
58
|
+
runCommand( 'npm run prepare', [], next )
|
|
59
|
+
},
|
|
60
|
+
(next) => {
|
|
61
|
+
runCommand( 'npx husky add .husky/pre-commit "npx lint-staged"', [], next )
|
|
62
|
+
}
|
|
63
|
+
],
|
|
64
|
+
( err, results ) => {
|
|
65
|
+
callback()
|
|
66
|
+
}
|
|
67
|
+
)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
directories = ( next ) => {
|
|
71
|
+
heading( 'Creating directories!!' )
|
|
72
|
+
|
|
73
|
+
eachSeries( this.dirs, ( dir, nextDir ) => {
|
|
74
|
+
fs.ensureDir( dir ).then( nextDir )
|
|
75
|
+
}, () => {
|
|
76
|
+
next()
|
|
77
|
+
} )
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
copyIndex = ( next ) => {
|
|
81
|
+
heading( 'Copying golden silence!!' )
|
|
82
|
+
const indexFile = this.template + '/index.php'
|
|
83
|
+
|
|
84
|
+
eachSeries( this.dirs, ( dir, nextCopy ) => {
|
|
85
|
+
fs.copy( indexFile, dir + '/index.php' ).then( nextCopy )
|
|
86
|
+
}, next )
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
copyConfigs = ( next ) => {
|
|
90
|
+
heading( 'Copying configuration files!!' )
|
|
91
|
+
fs.copySync(
|
|
92
|
+
this.template + '/configs',
|
|
93
|
+
this.folder
|
|
94
|
+
)
|
|
95
|
+
next()
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
copyTools = ( next ) => {
|
|
99
|
+
heading( 'Copying tools files!!' )
|
|
100
|
+
fs.copySync(
|
|
101
|
+
this.template + '/tools',
|
|
102
|
+
this.folder + '/tools',
|
|
103
|
+
)
|
|
104
|
+
next()
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
prepareConfigs = ( next ) => {
|
|
108
|
+
heading( 'Preparing configuration files!!' )
|
|
109
|
+
const configs =[
|
|
110
|
+
this.folder + '/.phpcs.xml',
|
|
111
|
+
this.folder + '/composer.json',
|
|
112
|
+
this.folder + '/package.json',
|
|
113
|
+
this.folder + '/webpack.mix.js',
|
|
114
|
+
this.folder + '/webpack.mix.local.js',
|
|
115
|
+
]
|
|
116
|
+
|
|
117
|
+
eachSeries( configs, ( file, nextConfig ) => {
|
|
118
|
+
this.renderFile( file, file, nextConfig )
|
|
119
|
+
}, next )
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
prepareFiles = ( next ) => {
|
|
123
|
+
heading( 'Preparing plugin files!!' )
|
|
124
|
+
const files =[
|
|
125
|
+
'/includes/interfaces/interface-integration.php',
|
|
126
|
+
]
|
|
127
|
+
|
|
128
|
+
eachSeries( files, ( file, nextFile ) => {
|
|
129
|
+
this.renderFile( this.template + file, this.folder + file, nextFile )
|
|
130
|
+
}, () => {
|
|
131
|
+
next()
|
|
132
|
+
} )
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
installNpm = (next) => {
|
|
136
|
+
heading( 'Installing NPM Packages' )
|
|
137
|
+
const packages =[
|
|
138
|
+
'@wordpress/eslint-plugin',
|
|
139
|
+
'@wordpress/stylelint-config',
|
|
140
|
+
'async',
|
|
141
|
+
'browser-sync',
|
|
142
|
+
'browser-sync-webpack-plugin',
|
|
143
|
+
'chalk',
|
|
144
|
+
'husky',
|
|
145
|
+
'laravel-mix',
|
|
146
|
+
'lint-staged',
|
|
147
|
+
'resolve-url-loader',
|
|
148
|
+
'sass',
|
|
149
|
+
'sass-loader',
|
|
150
|
+
'shelljs',
|
|
151
|
+
'stylelint',
|
|
152
|
+
'webpack',
|
|
153
|
+
]
|
|
154
|
+
|
|
155
|
+
eachSeries( packages, ( pack, nextPackage ) => {
|
|
156
|
+
console.log( chalk.yellow( 'npm i -D ' + pack ) )
|
|
157
|
+
runCommand( 'npm', [ 'i -D ' + pack ], nextPackage )
|
|
158
|
+
}, () => {
|
|
159
|
+
next()
|
|
160
|
+
} )
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
renderFile = ( src, dest, next ) => {
|
|
164
|
+
const content = fs.readFileSync( src, 'utf8' )
|
|
165
|
+
const template = Handlebars.compile( content )
|
|
166
|
+
const rendered = template( this.settings )
|
|
167
|
+
fs.outputFileSync( dest, rendered )
|
|
168
|
+
next()
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export default ( settings, next ) => {
|
|
173
|
+
const generator = new CreatePlugin()
|
|
174
|
+
generator.run( settings, next )
|
|
175
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
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 } from "../../helpers.js"
|
|
12
|
+
import prompts from './prompts.js'
|
|
13
|
+
import createPlugin from './create-plugin.js'
|
|
14
|
+
|
|
15
|
+
export function execute() {
|
|
16
|
+
heading('Setting up...')
|
|
17
|
+
console.log('');
|
|
18
|
+
|
|
19
|
+
waterfall(
|
|
20
|
+
[
|
|
21
|
+
prompts,
|
|
22
|
+
createPlugin,
|
|
23
|
+
],
|
|
24
|
+
( err, results ) => {
|
|
25
|
+
console.log( `${logSymbols.success} ${chalk.bold.green(`All done!`)}` )
|
|
26
|
+
}
|
|
27
|
+
)
|
|
28
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import inquirer from 'inquirer'
|
|
5
|
+
import get from 'lodash/get.js'
|
|
6
|
+
import kebabCase from 'lodash/kebabCase.js'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Node dependencies
|
|
10
|
+
*/
|
|
11
|
+
import { getCacheStore } from '../../helpers.js'
|
|
12
|
+
|
|
13
|
+
export default ( next ) => {
|
|
14
|
+
const cache = getCacheStore()
|
|
15
|
+
let saved = cache.all()
|
|
16
|
+
saved = saved ? saved.answers : {}
|
|
17
|
+
|
|
18
|
+
const getCache = ( key, defaultVal = '' ) => get( saved, key, defaultVal )
|
|
19
|
+
|
|
20
|
+
const questions = [
|
|
21
|
+
// Company
|
|
22
|
+
{
|
|
23
|
+
type: 'input',
|
|
24
|
+
name: 'company.name',
|
|
25
|
+
message: 'Enter company name',
|
|
26
|
+
default: getCache( 'company.name','Advanced Ads' ),
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
type: 'input',
|
|
30
|
+
name: 'company.url',
|
|
31
|
+
message: 'Enter company website url',
|
|
32
|
+
default: getCache( 'company.url', 'https://wpadvancedads.com/' ),
|
|
33
|
+
filter: ( val ) => val.toLowerCase()
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
// Author
|
|
37
|
+
{
|
|
38
|
+
type: 'input',
|
|
39
|
+
name: 'author.name',
|
|
40
|
+
message: 'Enter author name',
|
|
41
|
+
default: getCache( 'author.name', 'Advanced Ads' ),
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
type: 'input',
|
|
45
|
+
name: 'author.email',
|
|
46
|
+
message: 'Enter author email',
|
|
47
|
+
default: getCache( 'author.email', 'info@wpadvancedads.com' ),
|
|
48
|
+
filter: ( val ) => val.toLowerCase()
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
type: 'input',
|
|
52
|
+
name: 'author.url',
|
|
53
|
+
message: 'Enter author website url',
|
|
54
|
+
default: getCache( 'author.url', 'https://wpadvancedads.com' ),
|
|
55
|
+
filter: ( val ) => val.toLowerCase()
|
|
56
|
+
},
|
|
57
|
+
|
|
58
|
+
// WordPress
|
|
59
|
+
{
|
|
60
|
+
type: 'input',
|
|
61
|
+
name: 'wp.textDomain',
|
|
62
|
+
message: 'Enter text domain for i18n',
|
|
63
|
+
default: getCache( 'wp.textDomain' ),
|
|
64
|
+
filter: ( val ) => val.toLowerCase()
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
type: 'input',
|
|
68
|
+
name: 'wp.version',
|
|
69
|
+
message: 'Enter plugin version',
|
|
70
|
+
default: getCache( 'version', '1.0.0' ),
|
|
71
|
+
filter: ( val ) => val.toLowerCase()
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
type: 'input',
|
|
75
|
+
name: 'wp.name',
|
|
76
|
+
message: 'Enter plugin name',
|
|
77
|
+
default: getCache( 'wp.name' ),
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
type: 'input',
|
|
81
|
+
name: 'wp.description',
|
|
82
|
+
message: 'Enter plugin description',
|
|
83
|
+
default: getCache( 'wp.description' ),
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
type: 'input',
|
|
87
|
+
name: 'wp.proxy',
|
|
88
|
+
message: 'Enter wordpress installation url',
|
|
89
|
+
default: getCache( 'wp.proxy' ),
|
|
90
|
+
},
|
|
91
|
+
|
|
92
|
+
// PHP
|
|
93
|
+
{
|
|
94
|
+
type: 'input',
|
|
95
|
+
name: 'php.package',
|
|
96
|
+
message: 'Enter php package attribute',
|
|
97
|
+
default: getCache( 'php.package' ),
|
|
98
|
+
filter: ( val ) => val.replace( / /g, '' )
|
|
99
|
+
},
|
|
100
|
+
]
|
|
101
|
+
|
|
102
|
+
inquirer.prompt( questions )
|
|
103
|
+
.then( ( answers ) => {
|
|
104
|
+
const date = new Date()
|
|
105
|
+
answers.year = date.getFullYear()
|
|
106
|
+
|
|
107
|
+
// Validation.
|
|
108
|
+
if ( '' === answers.wp.textDomain ) {
|
|
109
|
+
answers.wp.textDomain = answers.company.name
|
|
110
|
+
.toLowerCase()
|
|
111
|
+
.replace( / /g, '-' )
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if ( '' === answers.wp.name ) {
|
|
115
|
+
answers.wp.name = answers.company.name
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if ( '' === answers.php.package ) {
|
|
119
|
+
answers.php.package = answers.company.name
|
|
120
|
+
.replace( / /g, '' )
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Formatting.
|
|
124
|
+
answers.package = {
|
|
125
|
+
vendor: kebabCase( answers.company.name ),
|
|
126
|
+
name: kebabCase( answers.wp.name )
|
|
127
|
+
}
|
|
128
|
+
answers.functionName = answers.php.package
|
|
129
|
+
.toLowerCase()
|
|
130
|
+
.replace( /\\/g, '_' )
|
|
131
|
+
|
|
132
|
+
// Cache.
|
|
133
|
+
cache.setKey( 'answers', answers )
|
|
134
|
+
cache.save()
|
|
135
|
+
next( null, answers )
|
|
136
|
+
} )
|
|
137
|
+
}
|
package/src/helpers.js
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
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
|
+
|
|
45
|
+
return {
|
|
46
|
+
command: args._[0] || 'help',
|
|
47
|
+
args: args._[1] || []
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function getCurrentFolder() {
|
|
52
|
+
let folder = process.cwd()
|
|
53
|
+
|
|
54
|
+
return folder
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function getRootFolder() {
|
|
58
|
+
let counter = 0
|
|
59
|
+
const check = function( folder ) {
|
|
60
|
+
const isEmptyFolder = folderEmptiness(folder)
|
|
61
|
+
|
|
62
|
+
if (isEmptyFolder) {
|
|
63
|
+
return folder
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const existsConfig = fs.existsSync( folder + '/' + CACHE_FILE )
|
|
67
|
+
const existsPkg = fs.existsSync( folder + '/package.json' )
|
|
68
|
+
if (existsConfig || existsPkg) {
|
|
69
|
+
return folder
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if ( 5 === counter ) {
|
|
73
|
+
return process.cwd()
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
counter++
|
|
77
|
+
return check(join(folder, '../'))
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return check(process.cwd())
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function getTemplateFolder() {
|
|
84
|
+
const require = createRequire( import.meta.url )
|
|
85
|
+
return require.resolve( '../template' )
|
|
86
|
+
.replace( '/index.js', '' )
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function backupFile(name, file) {
|
|
90
|
+
if ( ! fs.existsSync(file) ) {
|
|
91
|
+
console.log( `${logSymbols.error} ${chalk.red(`${name} file not found!`)}` )
|
|
92
|
+
return
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
fs.renameSync(
|
|
96
|
+
file,
|
|
97
|
+
file + '.bak'
|
|
98
|
+
)
|
|
99
|
+
console.log( `${logSymbols.success} ${chalk.dim(`${name} backed up!`)}` )
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function deleteFile(name, file) {
|
|
103
|
+
if ( ! fs.existsSync(file) ) {
|
|
104
|
+
console.log( `${logSymbols.error} ${chalk.red(`${name} file not found!`)}` )
|
|
105
|
+
return
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
fs.rmSync(file)
|
|
109
|
+
console.log( `${logSymbols.success} ${chalk.dim(`${name} deleted!`)}` )
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export function getCacheStore() {
|
|
113
|
+
return flatCache.load( CACHE_FILE, getRootFolder() )
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export function runCommand( command, args, next ) {
|
|
117
|
+
const commandSpawn = spawn( command, args, {
|
|
118
|
+
shell: true,
|
|
119
|
+
stdio: [ 'inherit' ]
|
|
120
|
+
} )
|
|
121
|
+
|
|
122
|
+
commandSpawn.stdout.on( 'data', (data) => {
|
|
123
|
+
console.log(data.toString())
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
commandSpawn.stderr.on( 'data', (data) => {
|
|
127
|
+
console.error(data.toString())
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
commandSpawn.on( 'close', (code) => {
|
|
131
|
+
next()
|
|
132
|
+
})
|
|
133
|
+
}
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# This file is for unifying the coding style for different editors and IDEs
|
|
2
|
+
# editorconfig.org
|
|
3
|
+
|
|
4
|
+
# WordPress Coding Standards
|
|
5
|
+
# https://make.wordpress.org/core/handbook/coding-standards/
|
|
6
|
+
|
|
7
|
+
root = true
|
|
8
|
+
|
|
9
|
+
[*]
|
|
10
|
+
charset = utf-8
|
|
11
|
+
end_of_line = lf
|
|
12
|
+
indent_size = 4
|
|
13
|
+
tab_width = 4
|
|
14
|
+
indent_style = tab
|
|
15
|
+
insert_final_newline = true
|
|
16
|
+
trim_trailing_whitespace = true
|
|
17
|
+
|
|
18
|
+
[*.txt]
|
|
19
|
+
trim_trailing_whitespace = false
|
|
20
|
+
|
|
21
|
+
[*.{md,json,yml,yaml}]
|
|
22
|
+
trim_trailing_whitespace = false
|
|
23
|
+
indent_style = space
|
|
24
|
+
indent_size = 2
|
|
25
|
+
|
|
26
|
+
[*.json]
|
|
27
|
+
indent_style = tab
|
|
@@ -0,0 +1,25 @@
|
|
|
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
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
<?xml version="1.0"?>
|
|
2
|
+
<ruleset name="{{company.name}}">
|
|
3
|
+
<description>{{company.name}} Coding Standards.</description>
|
|
4
|
+
|
|
5
|
+
<!-- PHPCS arguments: -->
|
|
6
|
+
<arg value="ps" />
|
|
7
|
+
<arg name="colors"/>
|
|
8
|
+
<arg name="parallel" value="20" />
|
|
9
|
+
<arg name="extensions" value="php"/>
|
|
10
|
+
|
|
11
|
+
<!-- Set files and paths: -->
|
|
12
|
+
<file>.</file>
|
|
13
|
+
|
|
14
|
+
<!-- Exclude paths -->
|
|
15
|
+
<exclude-pattern>*/languages/*</exclude-pattern>
|
|
16
|
+
<exclude-pattern>*/lib/*</exclude-pattern>
|
|
17
|
+
<exclude-pattern>*/node_modules/*</exclude-pattern>
|
|
18
|
+
<exclude-pattern>*/tests/*</exclude-pattern>
|
|
19
|
+
<exclude-pattern>*/vendor/*</exclude-pattern>
|
|
20
|
+
<exclude-pattern>*/index.php</exclude-pattern>
|
|
21
|
+
|
|
22
|
+
<!-- PHPCompatibility configs: -->
|
|
23
|
+
<config name="testVersion" value="7.2-" />
|
|
24
|
+
<config name="minimum_supported_wp_version" value="4.9" />
|
|
25
|
+
|
|
26
|
+
<rule ref="PHPCompatibility">
|
|
27
|
+
<include-pattern>*\.php$</include-pattern>
|
|
28
|
+
<exclude-pattern>tests/</exclude-pattern>
|
|
29
|
+
</rule>
|
|
30
|
+
|
|
31
|
+
<!-- Rules: -->
|
|
32
|
+
<rule ref="WordPress"/>
|
|
33
|
+
|
|
34
|
+
<rule ref="WordPress.WP.I18n">
|
|
35
|
+
<properties>
|
|
36
|
+
<property name="text_domain" type="array" value="{{wp.textDomain}}" />
|
|
37
|
+
</properties>
|
|
38
|
+
</rule>
|
|
39
|
+
|
|
40
|
+
<rule ref="WordPress.NamingConventions">
|
|
41
|
+
<exclude name="WordPress.NamingConventions.PrefixAllGlobals" />
|
|
42
|
+
</rule>
|
|
43
|
+
|
|
44
|
+
<rule ref="WordPress.NamingConventions.ValidHookName">
|
|
45
|
+
<properties>
|
|
46
|
+
<property name="additionalWordDelimiters" value="-"/>
|
|
47
|
+
</properties>
|
|
48
|
+
</rule>
|
|
49
|
+
|
|
50
|
+
<rule ref="WordPress.Files.FileName.InvalidClassFileName">
|
|
51
|
+
<exclude-pattern>includes/**/abstract-*.php</exclude-pattern>
|
|
52
|
+
<exclude-pattern>includes/**/interface-*.php</exclude-pattern>
|
|
53
|
+
</rule>
|
|
54
|
+
|
|
55
|
+
<!-- Elevate these rules to an error, so it gets printed on commit -->
|
|
56
|
+
<rule ref="Generic.Formatting.MultipleStatementAlignment">
|
|
57
|
+
<type>error</type>
|
|
58
|
+
</rule>
|
|
59
|
+
|
|
60
|
+
<rule ref="Generic.Arrays.DisallowLongArraySyntax">
|
|
61
|
+
<type>error</type>
|
|
62
|
+
</rule>
|
|
63
|
+
|
|
64
|
+
<!-- Method names MUST NOT be prefixed with a single underscore to indicate protected or private visibility. That is, an underscore prefix explicitly has no meaning. -->
|
|
65
|
+
<rule ref="PSR2.Methods.MethodDeclaration.Underscore">
|
|
66
|
+
<type>error</type>
|
|
67
|
+
<message>Method name "%s" must not be prefixed with an underscore to indicate visibility</message>
|
|
68
|
+
</rule>
|
|
69
|
+
|
|
70
|
+
<rule ref="WordPress.PHP.StrictInArray">
|
|
71
|
+
<type>error</type>
|
|
72
|
+
</rule>
|
|
73
|
+
|
|
74
|
+
<rule ref="WordPress.PHP.StrictComparisons">
|
|
75
|
+
<type>error</type>
|
|
76
|
+
</rule>
|
|
77
|
+
|
|
78
|
+
<rule ref="WordPress.CodeAnalysis.AssignmentInCondition">
|
|
79
|
+
<type>error</type>
|
|
80
|
+
</rule>
|
|
81
|
+
|
|
82
|
+
</ruleset>
|
|
@@ -0,0 +1,46 @@
|
|
|
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
|
+
# Eslint Cache
|
|
19
|
+
.eslintcache
|
|
20
|
+
|
|
21
|
+
# Environment files
|
|
22
|
+
wp-cli.local.yml
|
|
23
|
+
.wp-env.override.json
|
|
24
|
+
npm-debug.log
|
|
25
|
+
.pnpm-debug.log
|
|
26
|
+
|
|
27
|
+
# Node Package Dependencies
|
|
28
|
+
node_modules/
|
|
29
|
+
|
|
30
|
+
# Composer
|
|
31
|
+
vendor/
|
|
32
|
+
bin/composer/**/vendor/
|
|
33
|
+
composer.json
|
|
34
|
+
composer.lock
|
|
35
|
+
|
|
36
|
+
# Config files
|
|
37
|
+
.*
|
|
38
|
+
*-lock*
|
|
39
|
+
|
|
40
|
+
# Support .gitkeep Files
|
|
41
|
+
!.gitkeep
|
|
42
|
+
|
|
43
|
+
# Project files
|
|
44
|
+
assets/css
|
|
45
|
+
assets/js
|
|
46
|
+
tools/
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "{{package.vendor}}/{{package.name}}",
|
|
3
|
+
"description": "{{wp.description}}",
|
|
4
|
+
"homepage": "{{company.url}}",
|
|
5
|
+
"version": "1.42.1",
|
|
6
|
+
"type": "wordpress-plugin",
|
|
7
|
+
"license": "GPL-3.0-or-later",
|
|
8
|
+
"prefer-stable": true,
|
|
9
|
+
"minimum-stability": "dev",
|
|
10
|
+
"authors": [
|
|
11
|
+
{
|
|
12
|
+
"name": "{{author.name}}",
|
|
13
|
+
"email": "{{author.email}}",
|
|
14
|
+
"homepage": "{{author.url}}"
|
|
15
|
+
}
|
|
16
|
+
],
|
|
17
|
+
"require": {
|
|
18
|
+
"php": ">=7.2"
|
|
19
|
+
},
|
|
20
|
+
"require-dev": {
|
|
21
|
+
"dealerdirect/phpcodesniffer-composer-installer": "^1.0",
|
|
22
|
+
"phpcompatibility/phpcompatibility-wp": "*",
|
|
23
|
+
"wp-coding-standards/wpcs": "^2.3"
|
|
24
|
+
},
|
|
25
|
+
"config": {
|
|
26
|
+
"optimize-autoloader": true,
|
|
27
|
+
"sort-packages": true,
|
|
28
|
+
"platform": {
|
|
29
|
+
"php": "7.2"
|
|
30
|
+
},
|
|
31
|
+
"allow-plugins": {
|
|
32
|
+
"dealerdirect/phpcodesniffer-composer-installer": true
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"autoload": {
|
|
36
|
+
"classmap": [
|
|
37
|
+
"includes/"
|
|
38
|
+
]
|
|
39
|
+
},
|
|
40
|
+
"scripts": {
|
|
41
|
+
"post-install-cmd": [
|
|
42
|
+
"composer global require wp-cli/wp-cli"
|
|
43
|
+
]
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "{{package.name}}",
|
|
3
|
+
"title": "{{wp.name}}",
|
|
4
|
+
"description": "{{wp.description}}",
|
|
5
|
+
"homepage": "{{company.url}}",
|
|
6
|
+
"private": true,
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/advanced-ads/{{package.name}}.git"
|
|
10
|
+
},
|
|
11
|
+
"author": "AdvancedAds",
|
|
12
|
+
"license": "GPL-3.0-or-later",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/advanced-ads/{{package.name}}/issues"
|
|
15
|
+
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"prepare": "husky install",
|
|
18
|
+
"dev": "mix",
|
|
19
|
+
"watch": "mix watch",
|
|
20
|
+
"watch-poll": "mix watch -- --watch-options-poll=1000",
|
|
21
|
+
"hot": "mix watch --hot",
|
|
22
|
+
"dist": "mix --production",
|
|
23
|
+
"lint": "lint-staged",
|
|
24
|
+
"lint:css": "stylelint \"**/*.css\" --cache",
|
|
25
|
+
"lint:js": "eslint . --cache",
|
|
26
|
+
"lint:p": "prettier -c .",
|
|
27
|
+
"lint:php": "vendor/bin/phpcs",
|
|
28
|
+
"translations": "node ./tools/wp-glotpress.js"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
},
|
|
32
|
+
"browserslist": [
|
|
33
|
+
"> 1%",
|
|
34
|
+
"last 1 Android versions",
|
|
35
|
+
"last 1 ChromeAndroid versions",
|
|
36
|
+
"last 2 Chrome versions",
|
|
37
|
+
"last 2 Firefox versions",
|
|
38
|
+
"last 2 Safari versions",
|
|
39
|
+
"last 2 iOS versions",
|
|
40
|
+
"last 2 Edge versions",
|
|
41
|
+
"last 2 Opera versions"
|
|
42
|
+
],
|
|
43
|
+
"lint-staged": {
|
|
44
|
+
"*.js": [
|
|
45
|
+
"prettier -c",
|
|
46
|
+
"eslint --cache"
|
|
47
|
+
],
|
|
48
|
+
"*.(sa|sc|c)ss": [
|
|
49
|
+
"prettier -c",
|
|
50
|
+
"stylelint --cache"
|
|
51
|
+
],
|
|
52
|
+
"*.php": "vendor/bin/phpcs",
|
|
53
|
+
"*.md": "prettier -c"
|
|
54
|
+
},
|
|
55
|
+
"glotpress": {
|
|
56
|
+
"project": "{{package.name}}",
|
|
57
|
+
"destination": "./languages/"
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/* eslint-disable import/no-extraneous-dependencies */
|
|
2
|
+
// webpack.mix.js
|
|
3
|
+
|
|
4
|
+
const mix = require('laravel-mix');
|
|
5
|
+
const { join } = require('path');
|
|
6
|
+
require('./tools/laravel-mix/wp-pot');
|
|
7
|
+
|
|
8
|
+
// Local config.
|
|
9
|
+
let localConfig = {};
|
|
10
|
+
|
|
11
|
+
try {
|
|
12
|
+
localConfig = require('./webpack.mix.local');
|
|
13
|
+
} catch {}
|
|
14
|
+
|
|
15
|
+
// Webpack Config.
|
|
16
|
+
mix.webpackConfig({
|
|
17
|
+
externals: {
|
|
18
|
+
jquery: 'jQuery',
|
|
19
|
+
lodash: 'lodash',
|
|
20
|
+
moment: 'moment',
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
// Aliasing Paths.
|
|
25
|
+
mix.alias({
|
|
26
|
+
'@root': join(__dirname, 'assets/src'),
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
// Browsersync
|
|
30
|
+
if (undefined !== localConfig.wpUrl && '' !== localConfig.wpUrl) {
|
|
31
|
+
mix.browserSync({
|
|
32
|
+
proxy: localConfig.wpUrl,
|
|
33
|
+
ghostMode: false,
|
|
34
|
+
notify: false,
|
|
35
|
+
ui: false,
|
|
36
|
+
open: true,
|
|
37
|
+
online: false,
|
|
38
|
+
files: ['assets/css/*.min.css', 'assets/js/*.js', '**/*.php'],
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* CSS Files
|
|
44
|
+
*/
|
|
45
|
+
mix.sass('assets/scss/app.scss', 'assets/css/app.min.css', {
|
|
46
|
+
sassOptions: {
|
|
47
|
+
outputStyle: 'compressed',
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* JavaScript Files
|
|
53
|
+
*/
|
|
54
|
+
mix.js('assets/src/app.js', 'assets/js/app.js');
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* WordPress translation
|
|
58
|
+
*/
|
|
59
|
+
mix.wpPot({
|
|
60
|
+
output: '/languages/',
|
|
61
|
+
file: '{{wp.textDomain}}.pot',
|
|
62
|
+
skipJS: true,
|
|
63
|
+
domain: '{{wp.textDomain}}',
|
|
64
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
/**
|
|
3
|
+
* An interface for registering integrations with WordPress.
|
|
4
|
+
*
|
|
5
|
+
* @package {{php.package}}
|
|
6
|
+
* @author {{author.name}} <{{author.email}}>
|
|
7
|
+
* @since {{wp.version}}
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
namespace {{php.package}}\Interfaces;
|
|
11
|
+
|
|
12
|
+
defined( 'ABSPATH' ) || exit;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Integration interface.
|
|
16
|
+
*/
|
|
17
|
+
interface WordPress_Integration {
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Hook into WordPress.
|
|
21
|
+
*/
|
|
22
|
+
public function hooks();
|
|
23
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
const mix = require('laravel-mix')
|
|
2
|
+
|
|
3
|
+
class WordPressPot {
|
|
4
|
+
name() {
|
|
5
|
+
return 'wpPot'
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
dependencies() {
|
|
9
|
+
this.requiresReload = `
|
|
10
|
+
Dependencies have been installed. Please run again.
|
|
11
|
+
`
|
|
12
|
+
|
|
13
|
+
return ['shelljs']
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
register(config) {
|
|
17
|
+
this.config = config
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
boot() {
|
|
21
|
+
const sh = require('shelljs')
|
|
22
|
+
const {output, file, domain, skipJS = false, exclude = [] } = this.config
|
|
23
|
+
|
|
24
|
+
exclude.push(".github");
|
|
25
|
+
exclude.push("vendor");
|
|
26
|
+
exclude.push("tools");
|
|
27
|
+
|
|
28
|
+
const rootPath = process.cwd()
|
|
29
|
+
|
|
30
|
+
console.log(`${rootPath}${output}${file}`);
|
|
31
|
+
|
|
32
|
+
sh.exec(`wp i18n make-pot ${rootPath} ${rootPath}${output}${file} --domain=${domain} --exclude=${exclude.join(',')}`)
|
|
33
|
+
if ( false !== skipJS ) {
|
|
34
|
+
sh.exec(`wp i18n make-json ${rootPath}${output}`, { silent: true })
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
mix.extend('wpPot', new WordPressPot())
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// Packages.
|
|
4
|
+
const chalk = require("chalk");
|
|
5
|
+
const fs = require("fs");
|
|
6
|
+
const { resolve } = require("path");
|
|
7
|
+
const async = require("async");
|
|
8
|
+
|
|
9
|
+
// Settings.
|
|
10
|
+
const package = require("../package.json");
|
|
11
|
+
const BASEURL = 'https://translate.wpadvancedads.com/api/projects';
|
|
12
|
+
|
|
13
|
+
// 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;
|
|
17
|
+
}
|
|
18
|
+
|
|
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)
|
|
34
|
+
|
|
35
|
+
if (!fs.existsSync(destination)) {
|
|
36
|
+
fs.mkdirSync(destination);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async function getGlotPressData() {
|
|
40
|
+
const response = await fetch(`${BASEURL}/${package.glotpress.project}`);
|
|
41
|
+
const data = await response.json();
|
|
42
|
+
const sets = {}
|
|
43
|
+
data.translation_sets.map((set) => {
|
|
44
|
+
if ( set.current_count > 0 ) {
|
|
45
|
+
let id = set.wp_locale;
|
|
46
|
+
if ( 'default' !== set.slug ) {
|
|
47
|
+
id += '_' + set.slug;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
sets[ id ] = set
|
|
51
|
+
}
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
return sets
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Download Handler.
|
|
58
|
+
async function downloadFile(locale, data, format) {
|
|
59
|
+
console.log( chalk.bold("Downloading: " + format));
|
|
60
|
+
|
|
61
|
+
const target = `${destination}/${potPrefix}-${locale}.${format}`
|
|
62
|
+
const endpoint = `${BASEURL}/${project}/${data.locale}/${data.slug}/export-translations?format=${format}`
|
|
63
|
+
|
|
64
|
+
// Download.
|
|
65
|
+
const response = await fetch(endpoint)
|
|
66
|
+
const content = await response.text();
|
|
67
|
+
|
|
68
|
+
fs.writeFileSync(target, content);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async function runCommand() {
|
|
72
|
+
const locales = await getGlotPressData();
|
|
73
|
+
|
|
74
|
+
// Download files.
|
|
75
|
+
async.map(
|
|
76
|
+
Object.keys(locales),
|
|
77
|
+
(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)
|
|
88
|
+
},
|
|
89
|
+
function(err, results) {
|
|
90
|
+
console.log("");
|
|
91
|
+
console.log(chalk.bgGreen.bold("Success:") + " All files has been downloaded.");
|
|
92
|
+
}
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
runCommand()
|