wp-advads 1.0.7 → 1.0.9

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
@@ -4,181 +4,224 @@
4
4
  import fs from 'fs-extra'
5
5
  import chalk from 'chalk'
6
6
  import Handlebars from 'handlebars'
7
- import { series, eachSeries } from 'async'
7
+ import { eachSeries, waterfall } from 'async'
8
+
9
+ export const pluginData = {}
8
10
 
9
11
  /**
10
12
  * Internal dependencies
11
13
  */
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
- fs.renameSync(
96
- this.folder + '/gitattributes',
97
- this.folder + '/.gitattributes',
98
- )
99
- fs.renameSync(
100
- this.folder + '/gitignore',
101
- this.folder + '/.gitignore',
102
- )
103
- next()
104
- }
105
-
106
- copyTools = ( next ) => {
107
- heading( 'Copying tools files!!' )
108
- fs.copySync(
109
- this.template + '/tools',
110
- this.folder + '/tools',
111
- )
112
- next()
113
- }
114
-
115
- prepareConfigs = ( next ) => {
116
- heading( 'Preparing configuration files!!' )
117
- const configs =[
118
- this.folder + '/.phpcs.xml',
119
- this.folder + '/composer.json',
120
- this.folder + '/package.json',
121
- this.folder + '/webpack.mix.js',
122
- this.folder + '/webpack.mix.local.js',
123
- ]
124
-
125
- eachSeries( configs, ( file, nextConfig ) => {
126
- this.renderFile( file, file, nextConfig )
127
- }, next )
128
- }
129
-
130
- prepareFiles = ( next ) => {
131
- heading( 'Preparing plugin files!!' )
132
- const files =[
133
- '/includes/interfaces/interface-integration.php',
134
- ]
135
-
136
- eachSeries( files, ( file, nextFile ) => {
137
- this.renderFile( this.template + file, this.folder + file, nextFile )
138
- }, () => {
139
- next()
140
- } )
141
- }
142
-
143
- installNpm = (next) => {
144
- heading( 'Installing NPM Packages' )
145
- const packages =[
146
- '@wordpress/eslint-plugin',
147
- '@wordpress/stylelint-config',
148
- 'async',
149
- 'browser-sync',
150
- 'browser-sync-webpack-plugin',
151
- 'chalk@4.1.2',
152
- 'eslint-plugin-prettier',
153
- 'husky',
154
- 'laravel-mix',
155
- 'lint-staged',
156
- 'prettier',
157
- 'resolve-url-loader',
158
- 'sass',
159
- 'sass-loader',
160
- 'shelljs',
161
- 'webpack',
162
- ]
163
-
164
- eachSeries( packages, ( pack, nextPackage ) => {
165
- console.log( chalk.yellow( 'npm i -D ' + pack ) )
166
- runCommand( 'npm', [ 'i -D ' + pack ], nextPackage )
167
- }, () => {
168
- next()
169
- } )
170
- }
171
-
172
- renderFile = ( src, dest, next ) => {
173
- const content = fs.readFileSync( src, 'utf8' )
174
- const template = Handlebars.compile( content )
175
- const rendered = template( this.settings )
176
- fs.outputFileSync( dest, rendered )
177
- next()
178
- }
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 + '/templates',
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
+ pluginData.folder + '/assets/acf',
47
+
48
+ // Includes
49
+ pluginData.folder + '/includes',
50
+ pluginData.folder + '/includes/abstracts',
51
+ pluginData.folder + '/includes/admin',
52
+ pluginData.folder + '/includes/database',
53
+ pluginData.folder + '/includes/interfaces',
54
+ pluginData.folder + '/includes/models',
55
+ pluginData.folder + '/includes/traits',
56
+ pluginData.folder + '/includes/utilities',
57
+ ]
58
+
59
+ next()
60
+ }
61
+
62
+ function createDirectories(next) {
63
+ const indexFile = pluginData.template + '/index.php'
64
+
65
+ write('Creating directory required for the plugin...')
66
+
67
+ eachSeries( pluginData.dirs, ( dir, nextDir ) => {
68
+ fs.ensureDir( dir ).then(() => {
69
+ fs.copy( indexFile, dir + '/index.php' ).then( nextDir )
70
+ })
71
+ }, () => {
72
+ msgSuccessOnSameLine(`${pluginData.dirs.length} directories created`)
73
+ next()
74
+ } )
75
+ }
76
+
77
+ function copyToolFiles(next) {
78
+ write('Copying tools files...')
79
+ fs.copySync(
80
+ pluginData.template + '/tools',
81
+ pluginData.folder + '/tools',
82
+ )
83
+
84
+ msgSuccessOnSameLine('Tool files copied')
85
+ next()
86
+ }
87
+
88
+ function prepareConfigFiles(next) {
89
+ const template = pluginData.template + '/configs'
90
+ const files =[
91
+ '/.editorconfig',
92
+ '/.eslintignore',
93
+ '/.eslintrc.js',
94
+ '/.gitattributes',
95
+ '/.gitignore',
96
+ '/.phpcs.xml.dist',
97
+ '/.prettierignore',
98
+ '/.prettierrc.js',
99
+ '/.stylelintrc',
100
+ '/composer.json',
101
+ '/package.json',
102
+ '/webpack.mix.js',
103
+ ]
104
+
105
+ write('Preparing configuration files...')
106
+
107
+ eachSeries( files, ( file, nextConfig ) => {
108
+ prepareFile( template + file, pluginData.folder + file, nextConfig )
109
+ }, () => {
110
+ msgSuccessOnSameLine(`${files.length} Configuration files prepared`)
111
+ next()
112
+ } )
113
+ }
114
+
115
+ function preparePluginFiles(next) {
116
+ const template = pluginData.template + '/plugin'
117
+ const files =[
118
+ '/assets/src/app.js',
119
+ '/assets/scss/app.scss',
120
+ // '/includes/admin/class-admin.php',
121
+ // '/includes/interfaces/interface-integration.php',
122
+ // '/includes/class-assets.php',
123
+ // '/includes/class-frontend.php',
124
+ // '/includes/class-plugin.php',
125
+ // '/plugin.php',
126
+ // '/uninstall.php',
127
+ ]
128
+
129
+ write('Preparing plugin files...')
130
+
131
+ eachSeries( files, ( file, nextFile ) => {
132
+ prepareFile( template + file, pluginData.folder + file, nextFile )
133
+ }, () => {
134
+ msgSuccessOnSameLine(`${files.length} plugin files created with settings`)
135
+ next()
136
+ } )
137
+ }
138
+
139
+ function prepareGitRepository(next) {
140
+ write( 'Checking GIT repo' )
141
+ execCommand('git rev-parse --is-inside-work-tree && echo "OK" || git init', function() {
142
+ msgSuccessOnSameLine('Git repository initiated successfully')
143
+ next()
144
+ })
145
+ }
146
+
147
+ function installComposer(next) {
148
+ heading('Composer')
149
+ write('Installing Composer...')
150
+ execCommand('composer install -q', function() {
151
+ msgSuccessOnSameLine('Composer installed successfully')
152
+ next()
153
+ })
154
+ }
155
+
156
+ function installNodePackages(next) {
157
+ const packages =[
158
+ '@wordpress/eslint-plugin',
159
+ '@wordpress/stylelint-config',
160
+ 'async',
161
+ 'browser-sync',
162
+ 'browser-sync-webpack-plugin',
163
+ 'chalk@4.1.2',
164
+ 'eslint-plugin-prettier',
165
+ 'husky',
166
+ 'laravel-mix',
167
+ 'lint-staged',
168
+ 'prettier',
169
+ 'resolve-url-loader',
170
+ 'sass',
171
+ 'sass-loader',
172
+ 'shelljs',
173
+ 'tailwindcss',
174
+ 'webpack',
175
+ ]
176
+
177
+ heading( 'Node Packages' )
178
+
179
+ eachSeries( packages, ( pkg, nextPackage ) => {
180
+ write( chalk.red( 'Installing ' + pkg ) )
181
+ execCommand(`npm install -D ${pkg}`, function() {
182
+ msgSuccessOnSameLine(`Package: ${pkg} installed successfully`)
183
+ nextPackage()
184
+ })
185
+ }, () => {
186
+ next()
187
+ } )
188
+ }
189
+
190
+ function prepareNodePackages(next) {
191
+ write( 'Adding Pre-Commit' )
192
+
193
+ execCommand('npm run prepare', function() {
194
+ execCommand('npx husky add .husky/pre-commit "npx lint-staged"', function() {
195
+ msgSuccessOnSameLine('Pre-Commit hooks added successfully')
196
+ next()
197
+ })
198
+ })
179
199
  }
180
200
 
181
201
  export default ( settings, next ) => {
182
- const generator = new CreatePlugin()
183
- generator.run( settings, next )
202
+ pluginData.settings = settings
203
+
204
+ console.log('');
205
+ heading('Scaffoling plugin...')
206
+
207
+ waterfall(
208
+ [
209
+ setPluginData,
210
+ createDirectories,
211
+ copyToolFiles,
212
+ prepareConfigFiles,
213
+ preparePluginFiles,
214
+ prepareGitRepository,
215
+ installComposer,
216
+ installNodePackages,
217
+ prepareNodePackages
218
+ ],
219
+ (err) => {
220
+ if (err) {
221
+ return next(true)
222
+ }
223
+
224
+ next()
225
+ }
226
+ )
184
227
  }
@@ -8,11 +8,11 @@ import logSymbols from 'log-symbols'
8
8
  /**
9
9
  * Internal Dependencies
10
10
  */
11
- import { heading } from "../../helpers.js"
11
+ import { heading } from "../../utilities/index.js"
12
12
  import prompts from './prompts.js'
13
13
  import createPlugin from './create-plugin.js'
14
14
 
15
- export function execute() {
15
+ export default function() {
16
16
  heading('Setting up...')
17
17
  console.log('');
18
18
 
@@ -1,21 +1,19 @@
1
1
  /**
2
2
  * External dependencies
3
3
  */
4
- import inquirer from 'inquirer'
5
4
  import get from 'lodash/get.js'
5
+ import inquirer from 'inquirer'
6
6
  import kebabCase from 'lodash/kebabCase.js'
7
7
 
8
8
  /**
9
9
  * Node dependencies
10
10
  */
11
- import { getCacheStore } from '../../helpers.js'
11
+ import { getCacheStore, getSettings, heading } from '../../utilities/index.js'
12
12
 
13
13
  export default ( next ) => {
14
14
  const cache = getCacheStore()
15
- let saved = cache.all()
16
- saved = saved ? saved.answers : {}
17
-
18
- const getCache = ( key, defaultVal = '' ) => get( saved, key, defaultVal )
15
+ const settings = getSettings()
16
+ const getAnswer = ( key, defaultVal = '' ) => get( settings, key, defaultVal )
19
17
 
20
18
  const questions = [
21
19
  // Company
@@ -23,13 +21,13 @@ export default ( next ) => {
23
21
  type: 'input',
24
22
  name: 'company.name',
25
23
  message: 'Enter company name',
26
- default: getCache( 'company.name','Advanced Ads' ),
24
+ default: getAnswer( 'company.name','Advanced Ads' ),
27
25
  },
28
26
  {
29
27
  type: 'input',
30
28
  name: 'company.url',
31
29
  message: 'Enter company website url',
32
- default: getCache( 'company.url', 'https://wpadvancedads.com/' ),
30
+ default: getAnswer( 'company.url', 'https://wpadvancedads.com/' ),
33
31
  filter: ( val ) => val.toLowerCase()
34
32
  },
35
33
 
@@ -38,20 +36,20 @@ export default ( next ) => {
38
36
  type: 'input',
39
37
  name: 'author.name',
40
38
  message: 'Enter author name',
41
- default: getCache( 'author.name', 'Advanced Ads' ),
39
+ default: getAnswer( 'author.name', 'Advanced Ads' ),
42
40
  },
43
41
  {
44
42
  type: 'input',
45
43
  name: 'author.email',
46
44
  message: 'Enter author email',
47
- default: getCache( 'author.email', 'info@wpadvancedads.com' ),
45
+ default: getAnswer( 'author.email', 'info@wpadvancedads.com' ),
48
46
  filter: ( val ) => val.toLowerCase()
49
47
  },
50
48
  {
51
49
  type: 'input',
52
50
  name: 'author.url',
53
51
  message: 'Enter author website url',
54
- default: getCache( 'author.url', 'https://wpadvancedads.com' ),
52
+ default: getAnswer( 'author.url', 'https://wpadvancedads.com' ),
55
53
  filter: ( val ) => val.toLowerCase()
56
54
  },
57
55
 
@@ -60,33 +58,33 @@ export default ( next ) => {
60
58
  type: 'input',
61
59
  name: 'wp.textDomain',
62
60
  message: 'Enter text domain for i18n',
63
- default: getCache( 'wp.textDomain' ),
61
+ default: getAnswer( 'wp.textDomain' ),
64
62
  filter: ( val ) => val.toLowerCase()
65
63
  },
66
64
  {
67
65
  type: 'input',
68
66
  name: 'wp.version',
69
67
  message: 'Enter plugin version',
70
- default: getCache( 'version', '1.0.0' ),
68
+ default: getAnswer( 'version', '1.0.0' ),
71
69
  filter: ( val ) => val.toLowerCase()
72
70
  },
73
71
  {
74
72
  type: 'input',
75
73
  name: 'wp.name',
76
74
  message: 'Enter plugin name',
77
- default: getCache( 'wp.name' ),
75
+ default: getAnswer( 'wp.name' ),
78
76
  },
79
77
  {
80
78
  type: 'input',
81
79
  name: 'wp.description',
82
80
  message: 'Enter plugin description',
83
- default: getCache( 'wp.description' ),
81
+ default: getAnswer( 'wp.description' ),
84
82
  },
85
83
  {
86
84
  type: 'input',
87
85
  name: 'wp.proxy',
88
86
  message: 'Enter wordpress installation url',
89
- default: getCache( 'wp.proxy' ),
87
+ default: getAnswer( 'wp.proxy' ),
90
88
  },
91
89
 
92
90
  // PHP
@@ -94,7 +92,7 @@ export default ( next ) => {
94
92
  type: 'input',
95
93
  name: 'php.package',
96
94
  message: 'Enter php package attribute',
97
- default: getCache( 'php.package' ),
95
+ default: getAnswer( 'php.package' ),
98
96
  filter: ( val ) => val.replace( / /g, '' )
99
97
  },
100
98
  ]
@@ -0,0 +1,23 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import flatCache from 'flat-cache'
5
+
6
+ /**
7
+ * Internal Dependencies
8
+ */
9
+ import { getRootFolder } from './folder.js'
10
+
11
+ export const CACHE_FILE = 'adv-ads-scaffolding'
12
+
13
+ export function getCacheStore() {
14
+ return flatCache.load( CACHE_FILE, getRootFolder() )
15
+ }
16
+
17
+ export function getSettings() {
18
+ const cache = getCacheStore()
19
+ let saved = cache.all()
20
+ saved = saved ? saved.answers : {}
21
+
22
+ return saved
23
+ }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * External Dependencies
3
+ */
4
+ import argv from 'yargs-parser'
5
+
6
+ /**
7
+ * Get arguments
8
+ *
9
+ * @returns {Array} arguments
10
+ */
11
+ export function getArguments() {
12
+ return argv( process.argv.slice( 2 ) )
13
+ }
14
+
15
+ /**
16
+ * Get command with arguments
17
+ *
18
+ * @returns {Object} command and arguments
19
+ */
20
+ export function getCommand() {
21
+ const args = getArguments()
22
+ const { _, ...rest } = args
23
+ const command = _[0] || 'help'
24
+
25
+ return {
26
+ command,
27
+ args: rest || []
28
+ }
29
+ }
@@ -0,0 +1,57 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import chalk from 'chalk'
5
+ import logSymbols from 'log-symbols'
6
+
7
+ /**
8
+ * Node dependencies
9
+ */
10
+ import fs from 'fs'
11
+ import { onSameLine } from './formatting.js'
12
+
13
+ export function backupFile(name, file) {
14
+ if ( ! fs.existsSync(file) ) {
15
+ console.log( `${logSymbols.error} ${chalk.red(`${name} file not found!`)}` )
16
+ return
17
+ }
18
+
19
+ fs.renameSync(
20
+ file,
21
+ file + '.bak'
22
+ )
23
+ console.log( `${logSymbols.success} ${chalk.dim(`${name} backed up!`)}` )
24
+ }
25
+
26
+ export function deleteFile(name, file) {
27
+ if ( ! fs.existsSync(file) ) {
28
+ console.log( `${logSymbols.error} ${chalk.red(`${name} file not found!`)}` )
29
+ return
30
+ }
31
+
32
+ fs.rmSync(file)
33
+ console.log( `${logSymbols.success} ${chalk.dim(`${name} deleted!`)}` )
34
+ }
35
+
36
+ export function updateFileContent(fileName, messages, next, callback) {
37
+ process.stdout.write(messages.updating)
38
+
39
+ fs.readFile(fileName, (err, buffer) => {
40
+ if ( null !== err ) {
41
+ onSameLine(`${logSymbols.error} ${messages.failed}`)
42
+ return next(true)
43
+ }
44
+
45
+ const content = callback(buffer.toString())
46
+
47
+ fs.writeFile(fileName, content, (err) => {
48
+ if ( null !== err ) {
49
+ onSameLine(`${logSymbols.error} ${messages.failed}`)
50
+ return next(true)
51
+ }
52
+
53
+ onSameLine(`${logSymbols.success} ${messages.updated}`)
54
+ next()
55
+ })
56
+ })
57
+ }