wp-advads 1.0.39 → 1.0.40

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 CHANGED
@@ -51,6 +51,14 @@ Bumps the version, changelog, translations, build, and git (explicit file list,
51
51
  npx wp-advads release
52
52
  ```
53
53
 
54
+ #### `changelog`
55
+
56
+ Prints pending `.changelog` entries to the console. Does not write `changelog.txt` or `readme.txt`.
57
+
58
+ ```bash
59
+ npx wp-advads changelog
60
+ ```
61
+
54
62
  #### `class <classname> [options]`
55
63
 
56
64
  Writes a PHP class under `paths.php`. Combine `--heading` with a template flag (`-i` / `-g` / `-r` / `-s`).
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "wp-advads",
4
- "version": "1.0.39",
4
+ "version": "1.0.40",
5
5
  "description": "Create an Advanced Ads WordPress plugin ecosystem.",
6
6
  "author": {
7
7
  "name": "Shakeeb Ahmed",
package/src/app.js CHANGED
@@ -68,6 +68,12 @@ const app = async () => {
68
68
  .description('Create a new release for the plugin')
69
69
  .action(commands.release);
70
70
 
71
+ // Command: changelog
72
+ program
73
+ .command('changelog')
74
+ .description('Print pending .changelog entries to the console')
75
+ .action(commands.changelog);
76
+
71
77
  // Command: class
72
78
  program
73
79
  .command('class')
@@ -0,0 +1,94 @@
1
+ /**
2
+ * External Dependencies
3
+ */
4
+ import fs from 'fs'
5
+ import logSymbols from 'log-symbols'
6
+
7
+ /**
8
+ * Internal Dependencies
9
+ */
10
+ import { heading, onSameLine, write } from '../utilities/index.js'
11
+
12
+ const LABELS = {
13
+ fix: 'Fix',
14
+ feature: 'Feature',
15
+ improvement: 'Improvement',
16
+ }
17
+
18
+ /**
19
+ * Collect formatted changelog lines from `.changelog` (read-only).
20
+ *
21
+ * @param {string} dir Directory with pending changelog entry files
22
+ * @returns {string[]|null} Formatted lines, empty array if none, null if missing
23
+ */
24
+ export function collectChangelogLines( dir = './.changelog' ) {
25
+ if ( ! fs.existsSync( dir ) ) {
26
+ return null
27
+ }
28
+
29
+ const changes = {
30
+ fix: [],
31
+ feature: [],
32
+ improvement: [],
33
+ }
34
+ const allowed = Object.keys( LABELS )
35
+
36
+ for ( const fileName of fs.readdirSync( dir ).sort() ) {
37
+ const type = fileName.split( '-' )[ 0 ]
38
+
39
+ if ( ! allowed.includes( type ) ) {
40
+ continue
41
+ }
42
+
43
+ const content = fs.readFileSync( `${ dir }/${ fileName }`, 'utf8' ).trim()
44
+ if ( content ) {
45
+ changes[ type ].push( `- ${ LABELS[ type ] }: ${ content }` )
46
+ }
47
+ }
48
+
49
+ const entries = [
50
+ ...changes.feature,
51
+ ...changes.improvement,
52
+ ...changes.fix,
53
+ ]
54
+
55
+ if ( entries.length === 0 ) {
56
+ return []
57
+ }
58
+
59
+ const date = new Date().toLocaleDateString( 'en', {
60
+ year: 'numeric',
61
+ month: 'long',
62
+ day: 'numeric',
63
+ } )
64
+
65
+ return [
66
+ `= Unreleased (${ date }) =`,
67
+ '',
68
+ ...entries,
69
+ ]
70
+ }
71
+
72
+ /**
73
+ * Print pending changelog entries to the console. Writes no files.
74
+ */
75
+ export default function changelog() {
76
+ heading( 'Changelog preview' )
77
+ write( 'Reading .changelog...' )
78
+
79
+ const lines = collectChangelogLines()
80
+
81
+ if ( null === lines ) {
82
+ onSameLine( `${ logSymbols.error } Unable to find .changelog directory` )
83
+ return
84
+ }
85
+
86
+ if ( 0 === lines.length ) {
87
+ onSameLine( `${ logSymbols.warning } No pending changelog entries` )
88
+ return
89
+ }
90
+
91
+ onSameLine( `${ logSymbols.success } Pending changelog entries` )
92
+ console.log( '' )
93
+ console.log( lines.join( '\n' ) )
94
+ }
@@ -1,4 +1,5 @@
1
1
  export { default as build } from './build.js'
2
+ export { default as changelog } from './changelog.js'
2
3
  export { default as css } from './css.js'
3
4
  export { default as classFile } from './class.js'
4
5
  export { default as init } from './init.js'
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Standalone changelog command: print pending entries to console, write nothing.
3
+ */
4
+ import assert from 'node:assert/strict'
5
+ import { existsSync } from 'node:fs'
6
+ import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises'
7
+ import { tmpdir } from 'node:os'
8
+ import { join } from 'node:path'
9
+ import { test } from 'node:test'
10
+ import { collectChangelogLines } from '../src/commands/changelog.js'
11
+
12
+ test( 'collectChangelogLines formats .changelog entries and does not write files', async () => {
13
+ const dir = await mkdtemp( join( tmpdir(), 'wp-advads-changelog-preview-' ) )
14
+ const cwd = process.cwd()
15
+ process.chdir( dir )
16
+
17
+ try {
18
+ await mkdir( join( dir, '.changelog' ) )
19
+ await writeFile( join( dir, '.changelog', 'feature-1' ), 'add widgets\n' )
20
+ await writeFile( join( dir, '.changelog', 'fix-2' ), 'crash on save\n' )
21
+ await writeFile( join( dir, '.changelog', 'improvement-3' ), 'faster load\n' )
22
+ await writeFile( join( dir, '.changelog', 'notes' ), 'ignored\n' )
23
+
24
+ const lines = collectChangelogLines()
25
+
26
+ assert.ok( lines.some( ( line ) => line.startsWith( '= Unreleased (' ) ) )
27
+ assert.ok( lines.includes( '- Feature: add widgets' ) )
28
+ assert.ok( lines.includes( '- Improvement: faster load' ) )
29
+ assert.ok( lines.includes( '- Fix: crash on save' ) )
30
+ assert.equal( lines.indexOf( '- Feature: add widgets' ) < lines.indexOf( '- Improvement: faster load' ), true )
31
+ assert.equal( lines.indexOf( '- Improvement: faster load' ) < lines.indexOf( '- Fix: crash on save' ), true )
32
+ assert.equal( existsSync( join( dir, 'changelog.txt' ) ), false )
33
+ assert.equal( existsSync( join( dir, 'readme.txt' ) ), false )
34
+ } finally {
35
+ process.chdir( cwd )
36
+ await rm( dir, { recursive: true, force: true } )
37
+ }
38
+ } )
39
+
40
+ test( 'collectChangelogLines returns null when .changelog is missing', async () => {
41
+ const dir = await mkdtemp( join( tmpdir(), 'wp-advads-changelog-missing-' ) )
42
+ const cwd = process.cwd()
43
+ process.chdir( dir )
44
+
45
+ try {
46
+ assert.equal( collectChangelogLines(), null )
47
+ } finally {
48
+ process.chdir( cwd )
49
+ await rm( dir, { recursive: true, force: true } )
50
+ }
51
+ } )