wp-advads 1.0.31 → 1.0.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. package/.github/workflows/test.yml +17 -0
  2. package/CHANGELOG.md +23 -1
  3. package/LICENSE +15 -0
  4. package/README.md +8 -7
  5. package/package.json +9 -7
  6. package/src/app.js +17 -11
  7. package/src/commands/build.js +72 -59
  8. package/src/commands/class.js +34 -40
  9. package/src/commands/css.js +13 -19
  10. package/src/commands/init.js +4 -1
  11. package/src/commands/javascript.js +13 -19
  12. package/src/commands/release/change-version.js +14 -17
  13. package/src/commands/release/changelog.js +23 -31
  14. package/src/commands/release/git.js +25 -13
  15. package/src/commands/release/github.js +63 -12
  16. package/src/commands/release/semver.js +22 -25
  17. package/src/commands/release/translations.js +17 -23
  18. package/src/commands/release.js +3 -4
  19. package/src/commands/updates.js +20 -17
  20. package/src/commands/views.js +16 -18
  21. package/src/commands/wp-glotpress.js +125 -126
  22. package/src/commands/wp-pot.js +17 -9
  23. package/src/utilities/filesystem.js +57 -36
  24. package/src/utilities/flow.js +21 -0
  25. package/src/utilities/formatting.js +13 -4
  26. package/src/utilities/index.js +1 -1
  27. package/src/utilities/misc.js +1 -6
  28. package/src/utilities/settings.js +34 -14
  29. package/src/utilities/shell.js +60 -8
  30. package/template/files/class-singleton.php +5 -0
  31. package/template/files/javascript.js +0 -2
  32. package/template/files/view.php +2 -0
  33. package/test/build.test.js +168 -0
  34. package/test/changelog-locales.test.js +49 -0
  35. package/test/class.test.js +47 -0
  36. package/test/compile-templates.test.js +70 -0
  37. package/test/deps-hygiene.test.js +46 -0
  38. package/test/engines.test.js +11 -0
  39. package/test/get-latest-tag.test.js +51 -0
  40. package/test/git-precheck.test.js +44 -0
  41. package/test/github-final.test.js +93 -0
  42. package/test/glotpress-download.test.js +176 -0
  43. package/test/nested-path.test.js +39 -0
  44. package/test/no-fs-extra.test.js +11 -0
  45. package/test/package-identity.test.js +19 -0
  46. package/test/path-confine.test.js +42 -0
  47. package/test/pot-docs.test.js +27 -0
  48. package/test/pot-headers.test.js +49 -0
  49. package/test/project-root.test.js +26 -0
  50. package/test/release-waterfall.test.js +62 -0
  51. package/test/semver.test.js +25 -0
  52. package/test/settings-clone.test.js +34 -0
  53. package/test/settings-path.test.js +31 -0
  54. package/test/shell.test.js +100 -0
  55. package/test/singleton.test.js +14 -0
  56. package/test/stable-tag.test.js +13 -0
  57. package/test/stub-security.test.js +37 -0
  58. package/test/template-folder.test.js +19 -0
  59. package/test/translations.test.js +51 -0
  60. package/test/update-file-content.test.js +38 -0
  61. package/test/updates.test.js +39 -0
  62. package/test/version.test.js +22 -0
  63. package/test/view-escape.test.js +17 -0
  64. package/test/view.test.js +33 -0
  65. package/test/write-force.test.js +47 -0
  66. package/src/utilities/semver.js +0 -45
  67. package/template/.github/pull_request_template.md +0 -52
  68. package/template/configs/.editorconfig +0 -27
  69. package/template/configs/.eslintignore +0 -13
  70. package/template/configs/.eslintrc.js +0 -13
  71. package/template/configs/.phpcs.xml.dist +0 -87
  72. package/template/configs/.prettierignore +0 -49
  73. package/template/configs/.prettierrc.js +0 -3
  74. package/template/configs/.stylelintrc +0 -44
  75. package/template/configs/composer.json +0 -51
  76. package/template/configs/gitattributes +0 -34
  77. package/template/configs/gitignore +0 -43
  78. package/template/configs/package.json +0 -66
  79. package/template/configs/postcss.config.js +0 -6
  80. package/template/configs/tailwind.config.js +0 -8
  81. package/template/configs/webpack.mix.js +0 -65
  82. package/template/configs/webpack.mix.local.js +0 -3
  83. package/template/includes/index.php +0 -2
  84. package/template/index.js +0 -0
  85. package/template/index.php +0 -4
  86. package/template/plugin/assets/scss/app.scss +0 -0
  87. package/template/plugin/assets/src/app.js +0 -0
  88. package/template/tools/laravel-mix/wp-pot.js +0 -57
  89. package/template/tools/wp-glotpress.js +0 -162
@@ -4,19 +4,18 @@
4
4
  import fs from 'fs'
5
5
  import path from 'path'
6
6
  import logSymbols from 'log-symbols'
7
- import { forEach, waterfall } from 'async'
8
-
9
- /**
10
- * Internal Dependencies
11
- */
12
7
  import { pluginData } from '../release.js'
13
- import { getSetting, heading, onSameLine, saveConfig, updateFileContent, write } from "../../utilities/index.js"
8
+ import { getSetting, heading, onSameLine, runSteps, saveConfig, updateFileContent, write } from "../../utilities/index.js"
14
9
 
15
10
  /**
16
11
  * Update version in readme.txt file
17
12
  *
18
13
  * @example Stable tag: {version}
19
14
  */
15
+ export function applyStableTag( content, version ) {
16
+ return content.replace( /^(Stable tag:)[ \t]*.*$/mi, `$1 ${version}` )
17
+ }
18
+
20
19
  function updateReadme(next) {
21
20
  updateFileContent(
22
21
  './readme.txt',
@@ -27,16 +26,12 @@ function updateReadme(next) {
27
26
  },
28
27
  next,
29
28
  (content) => {
30
- let regex = new RegExp('^(?<prefix>Stable tag:\\h*)(?<version>(.*))$', 'mi')
31
- regex = regex.exec(content)
32
-
33
- if (null !== regex) {
34
- regex = regex.groups
35
- content = content.replace(`${regex.prefix}${regex.version}`, `${regex.prefix} ${pluginData.semver.getNextVersionString()}`)
29
+ const updated = applyStableTag( content, pluginData.semver.getNextVersionString() )
30
+ if ( updated !== content ) {
36
31
  pluginData.commitMessages.push('update version in readme.txt')
37
32
  }
38
33
 
39
- return content
34
+ return updated
40
35
  }
41
36
  )
42
37
  }
@@ -65,7 +60,7 @@ function updatePluginFiles(next) {
65
60
  return next(true)
66
61
  }
67
62
 
68
- forEach(phpFiles, (fileName, nextFile) => {
63
+ const steps = phpFiles.map( ( fileName ) => ( nextFile ) => {
69
64
  updateFileContent(
70
65
  fileName,
71
66
  {
@@ -104,7 +99,9 @@ function updatePluginFiles(next) {
104
99
  return content
105
100
  }
106
101
  )
107
- }, () => next())
102
+ } )
103
+
104
+ runSteps( steps, () => next() )
108
105
  })
109
106
  }
110
107
 
@@ -134,8 +131,8 @@ export default function updateVersionNumber(next) {
134
131
 
135
132
  flow.push(updatePluginFiles)
136
133
 
137
- waterfall(
134
+ runSteps(
138
135
  flow,
139
- () => next()
136
+ ( err ) => next( err )
140
137
  )
141
138
  }
@@ -2,15 +2,9 @@
2
2
  * External Dependencies
3
3
  */
4
4
  import fs from 'fs'
5
- import path from 'path'
6
5
  import logSymbols from 'log-symbols'
7
- import { forEach, waterfall } from 'async'
8
-
9
- /**
10
- * Internal Dependencies
11
- */
12
6
  import { pluginData } from '../release.js';
13
- import { heading, execCommand, onSameLine, updateFileContent, write } from "../../utilities/index.js"
7
+ import { heading, execCommand, getSetting, onSameLine, runSteps, updateFileContent, write } from "../../utilities/index.js"
14
8
 
15
9
  const LOCALES_CHANGELOG = {
16
10
  updated: {
@@ -92,11 +86,11 @@ function writeLocalesChangelog(type, changes) {
92
86
  * Update changelog for locales
93
87
  */
94
88
  function updateLocalesChangelog(next) {
95
- const { glotpress = {} } = pluginData
89
+ const destination = getSetting('glotpress.destination') || './languages/'
96
90
 
97
91
  write('Generating translations changelog...')
98
92
 
99
- execCommand('git ls-files ' + glotpress.destination, function(result) {
93
+ execCommand( [ 'git', 'ls-files', '--', destination ], function(result) {
100
94
  const files = result.split('\n').slice(0,-1)
101
95
  const changes = loopLocales(pluginData.locales, files)
102
96
 
@@ -133,7 +127,7 @@ function generateEntries(next) {
133
127
  return next(true)
134
128
  }
135
129
 
136
- forEach(files.sort(), (fileName, nextFile) => {
130
+ for ( const fileName of files.sort() ) {
137
131
  const parts = fileName.split('-')
138
132
 
139
133
  if (allowed.includes(parts[0])) {
@@ -143,27 +137,25 @@ function generateEntries(next) {
143
137
  `- ${labels[parts[0]]}: ${content.toString().trim()}`
144
138
  )
145
139
  }
140
+ }
146
141
 
147
- nextFile()
148
- }, () => {
149
- const currentDate = new Date();
150
- const options = { year: 'numeric', month: 'long', day: 'numeric' };
151
- pluginData.changelogChanges = [
152
- ...changes['feature'],
153
- ...changes['improvement'],
154
- ...changes['fix'],
155
- ]
156
-
157
- pluginData.changelogChanges = pluginData.changelogChanges.length > 0
158
- ? [
159
- `= ${pluginData.semver.getNextVersionString()} (${currentDate.toLocaleDateString('en', options)}) =`,
160
- '',
161
- ...pluginData.changelogChanges
162
- ] : false
163
-
164
- onSameLine(`${logSymbols.success} Changelog entries generated successfully`)
165
- next()
166
- })
142
+ const currentDate = new Date();
143
+ const options = { year: 'numeric', month: 'long', day: 'numeric' };
144
+ pluginData.changelogChanges = [
145
+ ...changes['feature'],
146
+ ...changes['improvement'],
147
+ ...changes['fix'],
148
+ ]
149
+
150
+ pluginData.changelogChanges = pluginData.changelogChanges.length > 0
151
+ ? [
152
+ `= ${pluginData.semver.getNextVersionString()} (${currentDate.toLocaleDateString('en', options)}) =`,
153
+ '',
154
+ ...pluginData.changelogChanges
155
+ ] : false
156
+
157
+ onSameLine(`${logSymbols.success} Changelog entries generated successfully`)
158
+ next()
167
159
  })
168
160
  }
169
161
 
@@ -257,5 +249,5 @@ export default function updateChangelog(next) {
257
249
  flow.push(cleanChangelogDirectory)
258
250
  }
259
251
 
260
- waterfall( flow, () => next() )
252
+ runSteps( flow, ( err ) => next( err ) )
261
253
  }
@@ -14,20 +14,32 @@ import { execCommand, onSameLine, getSetting, write } from "../../utilities/inde
14
14
  */
15
15
  export function getLatestTag() {
16
16
  return new Promise((resolve, reject) => {
17
- try {
18
- execCommand('git rev-list --tags --max-count=1', function(tags) {
19
- execCommand( 'git describe --tags ' + tags.trim(), function(version) {
20
- version = version.trim()
21
- resolve( '' !== version ? version : getSetting( 'wp.version', '0.0.0' ) )
22
- } )
23
- })
24
- }
25
- catch (err) {
26
- reject(err)
27
- }
17
+ execCommand( 'git describe --tags --abbrev=0', function(version, error, stderr) {
18
+ if ( error ) {
19
+ const text = String( stderr || error.message || '' )
20
+ if ( /No names found/i.test( text ) ) {
21
+ resolve( getSetting( 'wp.version', '0.0.0' ) )
22
+ return
23
+ }
24
+
25
+ reject( error )
26
+ return
27
+ }
28
+
29
+ version = String( version || '' ).trim().replace(/^v/, '')
30
+ resolve( '' !== version ? version : getSetting( 'wp.version', '0.0.0' ) )
31
+ } )
28
32
  })
29
33
  }
30
34
 
35
+ function gitRemoteFailed( error, stderr ) {
36
+ if ( error ) {
37
+ return true
38
+ }
39
+
40
+ return typeof stderr === 'string' && ( stderr.includes( 'error:' ) || stderr.includes( 'fatal:' ) )
41
+ }
42
+
31
43
  /**
32
44
  * Check if user has permission to write to repo
33
45
  */
@@ -37,7 +49,7 @@ export function hasPermission(next) {
37
49
  write(`${message}....`)
38
50
 
39
51
  execCommand('git push --dry-run', function(result, error, stderr) {
40
- if (stderr.includes('error:') || stderr.includes('fatal:')) {
52
+ if ( gitRemoteFailed( error, stderr ) ) {
41
53
  onSameLine(`${logSymbols.error} ${message}`)
42
54
  return next(true)
43
55
  }
@@ -56,7 +68,7 @@ export function gitFetch(next) {
56
68
  write(`${message}....`)
57
69
 
58
70
  execCommand('git fetch', function(result, error, stderr) {
59
- if (stderr.includes('error:') || stderr.includes('fatal:')) {
71
+ if ( gitRemoteFailed( error, stderr ) ) {
60
72
  onSameLine(`${logSymbols.error} ${message}`)
61
73
  return next(true)
62
74
  }
@@ -1,14 +1,14 @@
1
1
  /**
2
2
  * External Dependencies
3
3
  */
4
- import { waterfall } from 'async'
4
+ import fs from 'fs'
5
5
  import logSymbols from 'log-symbols'
6
6
 
7
7
  /**
8
8
  * Internal Dependencies
9
9
  */
10
10
  import { pluginData } from '../release.js'
11
- import { execCommand, heading, onSameLine, write } from "../../utilities/index.js"
11
+ import { execCommand, heading, onSameLine, runSteps, write } from "../../utilities/index.js"
12
12
  import {
13
13
  hasPermission,
14
14
  gitFetch,
@@ -22,14 +22,14 @@ import {
22
22
  export function githubPreTasks(next) {
23
23
  heading('Github operations')
24
24
 
25
- waterfall(
25
+ runSteps(
26
26
  [
27
27
  hasPermission,
28
28
  gitFetch,
29
29
  verifyNextVersion,
30
30
  getCurrentBranchName,
31
31
  ],
32
- ( err, results ) => {
32
+ ( err ) => {
33
33
  if(err) {
34
34
  return next(true)
35
35
  }
@@ -48,13 +48,64 @@ export function githubFinalTasks(next) {
48
48
 
49
49
  const version = pluginData.semver.getNextVersionString()
50
50
  const message = pluginData.commitMessages.join('\n')
51
+ const files = releasePaths()
51
52
 
52
- execCommand('git add .', function() {
53
- execCommand(`git commit --no-verify -m 'bump version to ${version}' -m '${message}'`, function(result, err, stderr) {
54
- execCommand('git push', function() {
55
- onSameLine(`${logSymbols.success} Git commit successful`)
56
- next()
57
- })
58
- })
59
- })
53
+ if ( files.length < 1 ) {
54
+ onSameLine(`${logSymbols.error} No release files to commit`)
55
+ return next( new Error( 'No release files to commit' ) )
56
+ }
57
+
58
+ runSteps(
59
+ [
60
+ ( done ) => git( [ 'add', '--', ...files ], done ),
61
+ ( done ) => git(
62
+ [
63
+ 'commit',
64
+ '-m',
65
+ `bump version to ${version}`,
66
+ '-m',
67
+ message,
68
+ ],
69
+ done
70
+ ),
71
+ ( done ) => git( [ 'push' ], done ),
72
+ ],
73
+ ( error ) => {
74
+ if ( error ) {
75
+ return next( error )
76
+ }
77
+
78
+ onSameLine(`${logSymbols.success} Git commit successful`)
79
+ next()
80
+ }
81
+ )
82
+ }
83
+
84
+ function releasePaths() {
85
+ let phpFiles = []
86
+ try {
87
+ phpFiles = fs.readdirSync( '.' ).filter( ( file ) => {
88
+ return file.toLowerCase().endsWith( '.php' ) && file.toLowerCase() !== 'index.php'
89
+ } )
90
+ } catch ( _ ) {}
91
+
92
+ return [
93
+ 'readme.txt',
94
+ 'changelog.txt',
95
+ 'wp.advads',
96
+ 'languages',
97
+ '.changelog',
98
+ ...phpFiles,
99
+ ].filter( ( file ) => fs.existsSync( file ) )
100
+ }
101
+
102
+ function git( args, done ) {
103
+ execCommand( [ 'git', ...args ], ( stdout, error, stderr ) => {
104
+ if ( error ) {
105
+ onSameLine(`${logSymbols.error} ${stderr || error.message}`)
106
+ return done( error )
107
+ }
108
+
109
+ done()
110
+ } )
60
111
  }
@@ -17,7 +17,7 @@ const PRE_RELEASE_NAMES = [ 'alpha', 'beta', 'rc' ]
17
17
  /**
18
18
  * Semantic version generator
19
19
  */
20
- class SemVer {
20
+ export class SemVer {
21
21
  constructor(baseVersion, increment, preRelease) {
22
22
  this.baseVersion = baseVersion
23
23
  this.increment = increment
@@ -40,14 +40,21 @@ class SemVer {
40
40
  }
41
41
 
42
42
  parseVersion() {
43
- const regex = new RegExp('(?<major>\\d+)\\.(?<minor>\\d+)\\.(?<patch>\\d+)(?:-(?<pre>alpha|beta|rc))?(?:\\.(?<pre_count>\\d+))?', 'gm')
44
- this.baseVersion = { ...regex.exec(this.baseVersion).groups }
43
+ const regex = new RegExp('(?<major>\\d+)\\.(?<minor>\\d+)\\.(?<patch>\\d+)(?:-(?<pre>alpha|beta|rc))?(?:\\.(?<pre_count>\\d+))?', 'm')
44
+ const match = regex.exec(this.baseVersion)
45
+
46
+ if ( ! match || ! match.groups ) {
47
+ console.log(`${logSymbols.error} ${chalk.bold.red(`Failed!`)} Invalid version: ${this.baseVersion}`)
48
+ throw new Error('failed')
49
+ }
50
+
51
+ this.baseVersion = { ...match.groups }
45
52
 
46
53
  this.baseVersion.major = parseInt(this.baseVersion.major)
47
54
  this.baseVersion.minor = parseInt(this.baseVersion.minor)
48
55
  this.baseVersion.patch = parseInt(this.baseVersion.patch)
49
56
  this.baseVersion.pre = undefined === this.baseVersion.pre ? false : this.baseVersion.pre
50
- this.baseVersion.pre_count = undefined === this.baseVersion.pre_count ? false : this.baseVersion.pre_count
57
+ this.baseVersion.pre_count = undefined === this.baseVersion.pre_count ? false : parseInt(this.baseVersion.pre_count)
51
58
  }
52
59
 
53
60
  getNextVersion() {
@@ -68,17 +75,6 @@ class SemVer {
68
75
  return this.versionString;
69
76
  }
70
77
 
71
- getLatestMinor() {
72
- if (this.nextVersion.patch === 0) {
73
- return this.getNextVersionString();
74
- }
75
-
76
- const latestMinor = {...this.nextVersion}
77
- latestMinor.patch = 0
78
-
79
- return `${this.nextVersion.major}.${this.nextVersion.minor}.${this.nextVersion.patch}`
80
- }
81
-
82
78
  setupNextVersion() {
83
79
  this.nextVersion = { ...this.baseVersion }
84
80
 
@@ -116,6 +112,13 @@ class SemVer {
116
112
  }
117
113
 
118
114
  createPreReleaseFromPreRelease() {
115
+ if (this.baseVersion.pre === this.preRelease) {
116
+ this.nextVersion.pre_count = this.baseVersion.pre_count
117
+ ? this.baseVersion.pre_count + 1
118
+ : 1
119
+ return
120
+ }
121
+
119
122
  let increment = 'patch'
120
123
  if (this.baseVersion.patch === 0) {
121
124
  increment = this.baseVersion.minor ? 'major' : 'minor'
@@ -125,14 +128,8 @@ class SemVer {
125
128
  this.incrementVersion()
126
129
  }
127
130
 
128
- if (this.baseVersion.pre === this.preRelease) {
129
- this.nextVersion.pre_count = this.baseVersion.pre_count
130
- ? 2
131
- : this.baseVersion.pre_count + 1
132
- } else {
133
- this.nextVersion.pre = this.preRelease
134
- this.nextVersion.pre_count = 1
135
- }
131
+ this.nextVersion.pre = this.preRelease
132
+ this.nextVersion.pre_count = 1
136
133
 
137
134
  this.checkPreReleaseLogic()
138
135
  }
@@ -161,7 +158,7 @@ class SemVer {
161
158
  */
162
159
  checkPreReleaseLogic() {
163
160
  if (
164
- isset(this.baseVersion.pre)
161
+ this.baseVersion.pre
165
162
  && (
166
163
  this.nextVersion[this.increment] !== this.baseVersion[this.increment]
167
164
  || this.nextVersion[this.increment] === 0
@@ -194,5 +191,5 @@ export default function getSemVer(next) {
194
191
  catch (err) {
195
192
  return next(true)
196
193
  }
197
- })
194
+ }).catch( () => next(true) )
198
195
  }
@@ -7,38 +7,32 @@ import logSymbols from 'log-symbols'
7
7
  * Internal Dependencies
8
8
  */
9
9
  import { pluginData } from '../release.js'
10
- import { heading, execCommand, getSetting } from "../../utilities/index.js"
10
+ import { heading } from "../../utilities/index.js"
11
+ import { downloadTranslations } from '../wp-glotpress.js'
11
12
 
12
13
  /**
13
14
  * Execute routine to download translations from GlotPress
14
15
  */
15
- export default function updateTranslations( next ) {
16
+ export default async function updateTranslations( next ) {
16
17
  heading('Downloading translations from glotpress')
17
18
 
18
- const glotpress = getSetting('wp.glotpress')
19
+ try {
20
+ const { files, locales } = await downloadTranslations()
21
+ console.log( logSymbols.success + ` Downloaded ${files.length} files successfully` )
19
22
 
20
- if (!glotpress) {
21
- console.log( logSymbols.warning + ' No glotpress project found' )
22
- next()
23
- return;
24
- }
25
-
26
- execCommand( 'npx wp-advads translations', function(locales) {
27
- locales = locales.split('\n').slice(4).slice(0,-1)
28
- console.log( logSymbols.success + ` Downloaded ${locales.length} files successfully` )
29
-
30
- if (locales.length > 0) {
23
+ if (files.length > 0) {
31
24
  pluginData.commitMessages.push('add: Download translation from GlotPress')
32
25
  }
33
26
 
34
- const newLocales = {}
35
- locales.map((locale) => {
36
- const data = locale.split('=')
37
- newLocales[ data[0] ] = data[1]
38
- })
39
-
40
- pluginData.locales = newLocales
41
-
27
+ pluginData.locales = locales
42
28
  next()
43
- })
29
+ } catch (err) {
30
+ if ( err && err.message === 'No glotpress project found' ) {
31
+ console.log( logSymbols.warning + ' No glotpress project found' )
32
+ next()
33
+ return
34
+ }
35
+
36
+ next(err)
37
+ }
44
38
  }
@@ -2,13 +2,12 @@
2
2
  * External Dependencies
3
3
  */
4
4
  import chalk from 'chalk'
5
- import { waterfall } from 'async'
6
5
  import logSymbols from 'log-symbols'
7
6
 
8
7
  /**
9
8
  * Node dependencies
10
9
  */
11
- import { heading } from '../utilities/index.js'
10
+ import { heading, runSteps } from '../utilities/index.js'
12
11
 
13
12
  /**
14
13
  * Internal Dependencies
@@ -31,13 +30,13 @@ export default async () => {
31
30
  heading('Releasing the plugin...')
32
31
  console.log('------------------------------------------------');
33
32
 
34
- waterfall(
33
+ runSteps(
35
34
  [
36
35
  prompts,
37
36
  getSemVer,
38
37
  githubPreTasks,
39
38
  updateTranslations,
40
- wpBuild,
39
+ ( next ) => wpBuild( next, pluginData.commitMessages ),
41
40
  updateVersionNumber,
42
41
  updateChangelog,
43
42
  githubFinalTasks
@@ -2,30 +2,33 @@
2
2
  * Node Dependencies
3
3
  */
4
4
  import path from 'path';
5
- import fs from 'fs-extra';
6
5
 
7
6
  /**
8
7
  * Internal Dependencies
9
8
  */
10
- import { getSetting, writeFile, heading, getProjectRoot, msgErrorTitle, getTemplateFile, compileTemplate } from "../utilities/index.js";
9
+ import { getSetting, heading, getProjectRoot, writeFromTemplate } from "../utilities/index.js";
11
10
 
12
- export default (version) => {
11
+ export default (version, options = {}) => {
13
12
  heading('Creating update file...')
14
13
 
15
- try {
16
- const filename = `upgrade-${version}.php`;
17
- const folder = path.join(getProjectRoot(), getSetting('paths.updates'));
18
-
19
- // Data
20
- const data = getSetting();
21
- data.heading = `Update routine for version ${version}`;
22
- data.version = version.replaceAll('.', '_');
23
-
24
- const content = compileTemplate(getTemplateFile('files/update.php'), data);
25
- writeFile(folder,filename, content)
14
+ const settings = getSetting()
15
+ const data = {
16
+ ...settings,
17
+ heading: `Update routine for version ${version}`,
18
+ description: `Update routine for version ${version}`,
19
+ prefix: settings.misc?.prefix,
20
+ version: version.replaceAll('.', '_'),
26
21
  }
27
- catch (err) {
28
- msgErrorTitle('We failed!!!');
29
- throw err;
22
+
23
+ if ( ! data.prefix ) {
24
+ throw new Error( 'misc.prefix is required' );
30
25
  }
26
+
27
+ writeFromTemplate(
28
+ path.join(getProjectRoot(), getSetting('paths.updates')),
29
+ `upgrade-${version}.php`,
30
+ 'files/update.php',
31
+ data,
32
+ options.force
33
+ )
31
34
  }
@@ -1,4 +1,3 @@
1
-
2
1
  /**
3
2
  * Node Dependencies
4
3
  */
@@ -7,25 +6,24 @@ import path from 'path';
7
6
  /**
8
7
  * Internal Dependencies
9
8
  */
10
- import { getSetting, writeFile, heading, filenameToHeading, getProjectRoot, msgErrorTitle, getTemplateFile, compileTemplate } from "../utilities/index.js";
9
+ import { getSetting, heading, filenameToHeading, getProjectRoot, writeFromTemplate } from "../utilities/index.js";
11
10
 
12
- export default (name, header) => {
11
+ export default (name, header, options = {}) => {
13
12
  heading('Creating view file...')
14
13
 
15
- try {
16
- const paths = name.toLowerCase().split('/')
17
- const filename = paths.pop() + '.php';
18
- const folder = path.join(getProjectRoot(), getSetting('paths.views'), paths.join('/'));
19
-
20
- // Data
21
- const data = getSetting();
22
- data.heading = header || filenameToHeading(filename) + ' template file';
14
+ const dest = path.join( getProjectRoot(), getSetting( 'paths.views' ), name.toLowerCase().replaceAll( '\\', '/' ) ) + '.php'
15
+ const filename = path.basename( dest )
16
+ const headingText = header || filenameToHeading(filename) + ' template file'
23
17
 
24
- const content = compileTemplate(getTemplateFile('files/view.php'), data);
25
- writeFile(folder, filename, content);
26
- }
27
- catch (err) {
28
- msgErrorTitle('We failed!!!');
29
- throw err;
30
- }
18
+ writeFromTemplate(
19
+ path.dirname( dest ),
20
+ filename,
21
+ 'files/view.php',
22
+ {
23
+ ...getSetting(),
24
+ heading: headingText,
25
+ description: headingText,
26
+ },
27
+ options.force
28
+ )
31
29
  }