wattpm-utils 3.39.0 → 3.41.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/bin/cli.js CHANGED
@@ -1,11 +1,10 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import { checkNodeVersionForApplications, setExecutableId, setExecutableName } from '@platformatic/foundation'
3
+ import { checkNodeVersionForApplications } from '@platformatic/foundation'
4
+ import { createCLIContext } from '@platformatic/foundation/lib/cli.js'
4
5
 
5
6
  checkNodeVersionForApplications()
6
- setExecutableId('wattpm-utils')
7
- setExecutableName('Watt')
8
7
 
9
8
  // Use await import here so that we can throw a proper error on unsupported Node.js version
10
9
  const { main } = await import('../index.js')
11
- await main()
10
+ await main.call(createCLIContext('wattpm-utils', 'Watt'))
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { createCliLogger, getExecutableId, logFatalError, parseArgs, setVerbose } from '@platformatic/foundation'
1
+ import { createCliLogger, logFatalError, parseArgs } from '@platformatic/foundation'
2
2
  import { bold } from 'colorette'
3
3
  import { createCommand } from './lib/commands/create.js'
4
4
  import { installCommand, updateCommand } from './lib/commands/dependencies.js'
@@ -8,7 +8,7 @@ import { patchConfigCommand } from './lib/commands/patch-config.js'
8
8
  import { version } from './lib/version.js'
9
9
 
10
10
  export async function main () {
11
- globalThis.platformatic = { executable: getExecutableId() }
11
+ globalThis.platformatic = { executable: this.executableId }
12
12
 
13
13
  const options = {
14
14
  'no-pretty': {
@@ -31,6 +31,7 @@ export async function main () {
31
31
 
32
32
  const { values, unparsed } = parseArgs(process.argv.slice(2), options)
33
33
  const logger = createCliLogger('info', values['no-pretty'])
34
+ this.logger = logger
34
35
 
35
36
  if (values.version || unparsed[0] === 'version') {
36
37
  console.log(version)
@@ -38,16 +39,16 @@ export async function main () {
38
39
  }
39
40
 
40
41
  if (values.help) {
41
- helpCommand(logger, [])
42
+ helpCommand.call(this, logger, [])
42
43
  return
43
44
  } else if (unparsed.includes('-h') || unparsed.includes('--help')) {
44
- helpCommand(logger, unparsed)
45
+ helpCommand.call(this, logger, unparsed)
45
46
  return
46
47
  }
47
48
 
48
49
  /* c8 ignore next 3 */
49
50
  if (values.verbose) {
50
- setVerbose(true)
51
+ this.verbose = true
51
52
  }
52
53
 
53
54
  let command
@@ -82,11 +83,11 @@ export async function main () {
82
83
  if (!command) {
83
84
  logFatalError(
84
85
  logger,
85
- `Unknown command ${bold(requestedCommand)}. Please run ${bold(`"${getExecutableId()} help"`)} to see available commands.`
86
+ `Unknown command ${bold(requestedCommand)}. Please run ${bold(`"${this.executableId} help"`)} to see available commands.`
86
87
  )
87
88
 
88
89
  return
89
90
  }
90
91
 
91
- await command(logger, unparsed.slice(1))
92
+ await command.call(this, logger, unparsed.slice(1))
92
93
  }
@@ -1,4 +1,4 @@
1
- import { getExecutableName, getPackageManager, parseArgs } from '@platformatic/foundation'
1
+ import { getPackageManager, parseArgs } from '@platformatic/foundation'
2
2
  import { createApplication, getUsername, getVersion, say } from 'create-wattpm'
3
3
  import { resolve } from 'node:path'
4
4
  import { installDependencies } from './dependencies.js'
@@ -41,7 +41,7 @@ export async function createCommand (logger, args) {
41
41
  const version = await getVersion()
42
42
 
43
43
  /* c8 ignore next 3 - Ignoring else branches */
44
- const executableName = getExecutableName()
44
+ const executableName = this.executableName
45
45
  const greeting = username ? `Hello ${username},` : 'Hello,'
46
46
  await say(`${greeting} welcome to ${version ? `${executableName} ${version}!` : `${executableName}!`}`)
47
47
 
@@ -68,7 +68,7 @@ export async function createCommand (logger, args) {
68
68
 
69
69
  const createHelp = {
70
70
  description () {
71
- return `Creates a new ${getExecutableName()} project`
71
+ return `Creates a new ${this.executableName} project`
72
72
  },
73
73
  options: [
74
74
  {
@@ -207,7 +207,15 @@ export async function installCommand (logger, args) {
207
207
  )
208
208
 
209
209
  const root = getRoot(positionals)
210
- const configurationFile = await findRuntimeConfigurationFile(logger, root, config)
210
+ const configurationFile = await findRuntimeConfigurationFile(
211
+ logger,
212
+ root,
213
+ config,
214
+ true,
215
+ true,
216
+ true,
217
+ this.executableName
218
+ )
211
219
 
212
220
  /* c8 ignore next 3 - Hard to test */
213
221
  if (!configurationFile) {
@@ -241,7 +249,15 @@ export async function updateCommand (logger, args) {
241
249
  )
242
250
 
243
251
  const root = getRoot(positionals)
244
- const configurationFile = await findRuntimeConfigurationFile(logger, root, config)
252
+ const configurationFile = await findRuntimeConfigurationFile(
253
+ logger,
254
+ root,
255
+ config,
256
+ true,
257
+ true,
258
+ true,
259
+ this.executableName
260
+ )
245
261
 
246
262
  /* c8 ignore next 3 - Hard to test */
247
263
  if (!configurationFile) {
@@ -5,7 +5,6 @@ import {
5
5
  ensureLoggableError,
6
6
  findConfigurationFile,
7
7
  findRuntimeConfigurationFile,
8
- getExecutableId,
9
8
  getRoot,
10
9
  loadConfigurationFile as loadRawConfigurationFile,
11
10
  logFatalError,
@@ -94,8 +93,16 @@ export async function appendEnvVariable (envFile, key, value) {
94
93
  return writeFile(envFile, contents, 'utf-8')
95
94
  }
96
95
 
97
- async function fixConfiguration (logger, root, configOption, skipDependencies, packageManager) {
98
- const configurationFile = await findRuntimeConfigurationFile(logger, root, configOption, true, true, false)
96
+ async function fixConfiguration (context, logger, root, configOption, skipDependencies, packageManager) {
97
+ const configurationFile = await findRuntimeConfigurationFile(
98
+ logger,
99
+ root,
100
+ configOption,
101
+ true,
102
+ true,
103
+ false,
104
+ context.executableName
105
+ )
99
106
 
100
107
  /* c8 ignore next 3 - Hard to test */
101
108
  if (!configurationFile) {
@@ -533,7 +540,7 @@ export async function importCommand (logger, args) {
533
540
  Two arguments = root and URL
534
541
  */
535
542
  if (positionals.length === 0) {
536
- return fixConfiguration(logger, '', config, skipDependencies, packageManager)
543
+ return fixConfiguration(this, logger, '', config, skipDependencies, packageManager)
537
544
  } else if (positionals.length === 1) {
538
545
  root = getRoot()
539
546
  rawUrl = positionals[0]
@@ -542,7 +549,15 @@ export async function importCommand (logger, args) {
542
549
  rawUrl = positionals[1]
543
550
  }
544
551
 
545
- const configurationFile = await findRuntimeConfigurationFile(logger, root, config)
552
+ const configurationFile = await findRuntimeConfigurationFile(
553
+ logger,
554
+ root,
555
+ config,
556
+ true,
557
+ true,
558
+ true,
559
+ this.executableName
560
+ )
546
561
 
547
562
  /* c8 ignore next 3 - Hard to test */
548
563
  if (!configurationFile) {
@@ -597,7 +612,15 @@ export async function resolveCommand (logger, args) {
597
612
  )
598
613
 
599
614
  const root = getRoot(positionals)
600
- const configurationFile = await findRuntimeConfigurationFile(logger, root, config)
615
+ const configurationFile = await findRuntimeConfigurationFile(
616
+ logger,
617
+ root,
618
+ config,
619
+ true,
620
+ true,
621
+ true,
622
+ this.executableName
623
+ )
601
624
 
602
625
  /* c8 ignore next 3 - Hard to test */
603
626
  if (!configurationFile) {
@@ -693,7 +716,7 @@ export const help = {
693
716
  ],
694
717
  footer () {
695
718
  return `
696
- ${getExecutableId()} resolve command resolves runtime applications that have the \`url\` in their configuration.
719
+ ${this.executableId} resolve command resolves runtime applications that have the \`url\` in their configuration.
697
720
  To change the directory where an application is cloned, you can set the \`path\` property in the application configuration.
698
721
 
699
722
  After cloning the application, the resolve command will set the relative path to the application in the Platformatic configuration file.
@@ -1,9 +1,9 @@
1
- import { getExecutableId, getExecutableName, logFatalError, logo } from '@platformatic/foundation'
1
+ import { logFatalError, logo } from '@platformatic/foundation'
2
2
  import { loadApplicationsCommands } from '@platformatic/runtime'
3
3
  import { bold } from 'colorette'
4
4
 
5
- function sanitizeHelp (raw) {
6
- return (typeof raw === 'function' ? raw() : raw).trim()
5
+ function sanitizeHelp (context, raw) {
6
+ return (typeof raw === 'function' ? raw.call(context) : raw).trim()
7
7
  }
8
8
 
9
9
  async function loadCommands () {
@@ -19,14 +19,14 @@ async function loadCommands () {
19
19
  return commands
20
20
  }
21
21
 
22
- export async function showGeneralHelp (logger) {
22
+ export async function showGeneralHelp (context, logger) {
23
23
  if (typeof logger !== 'function') {
24
24
  logger = console.log
25
25
  }
26
26
 
27
- const executableId = getExecutableId()
27
+ const executableId = context.executableId
28
28
  const commands = Object.values(await loadCommands())
29
- const applicationsCommands = Object.values((await loadApplicationsCommands()).help)
29
+ const applicationsCommands = Object.values((await loadApplicationsCommands(context.executableName)).help)
30
30
 
31
31
  const options = [
32
32
  { usage: '-V, --version', description: `Show ${executableId} version` },
@@ -34,7 +34,7 @@ export async function showGeneralHelp (logger) {
34
34
  { usage: '--help', description: 'Show this help' }
35
35
  ]
36
36
 
37
- logger(logo())
37
+ logger(logo.call(context))
38
38
  logger(`\nUsage: ${executableId} [options] [command]\n`)
39
39
 
40
40
  // Compute the maximum length of options or commands
@@ -48,24 +48,26 @@ export async function showGeneralHelp (logger) {
48
48
  // Print all options
49
49
  logger('Options:\n')
50
50
  for (const { usage, description } of options) {
51
- logger(` ${usage.padEnd(maximumLength, ' ')} ${sanitizeHelp(description)}`)
51
+ logger(` ${usage.padEnd(maximumLength, ' ')} ${sanitizeHelp(context, description)}`)
52
52
  }
53
53
  logger('')
54
54
 
55
55
  // Print all commands
56
56
  logger('Commands:\n')
57
57
  for (const { usage, description } of commands) {
58
- logger(` ${usage.padEnd(maximumLength, ' ')} ${sanitizeHelp(description)}`)
58
+ logger(` ${usage.padEnd(maximumLength, ' ')} ${sanitizeHelp(context, description)}`)
59
59
  }
60
60
  logger('')
61
61
  }
62
62
 
63
- export function showHelp (command, logger) {
63
+ export function showHelp (context, command, logger) {
64
64
  if (typeof logger !== 'function') {
65
65
  logger = console.log
66
66
  }
67
67
 
68
- logger(`\nUsage: ${getExecutableId()} ${sanitizeHelp(command.usage)}\n\n${sanitizeHelp(command.description)}.\n`)
68
+ logger(
69
+ `\nUsage: ${context.executableId} ${sanitizeHelp(context, command.usage)}\n\n${sanitizeHelp(context, command.description)}.\n`
70
+ )
69
71
 
70
72
  let { options, args } = command
71
73
  options ??= []
@@ -78,7 +80,7 @@ export function showHelp (command, logger) {
78
80
  if (options.length) {
79
81
  logger('Options:\n')
80
82
  for (const { usage, description } of options) {
81
- logger(` ${usage.padEnd(maximumLength, ' ')} ${sanitizeHelp(description)}`)
83
+ logger(` ${usage.padEnd(maximumLength, ' ')} ${sanitizeHelp(context, description)}`)
82
84
  }
83
85
  logger('')
84
86
  }
@@ -87,13 +89,13 @@ export function showHelp (command, logger) {
87
89
  if (args.length) {
88
90
  logger('Arguments:\n')
89
91
  for (const { name, description } of args) {
90
- logger(` ${name.padEnd(maximumLength, ' ')} ${sanitizeHelp(description)}`)
92
+ logger(` ${name.padEnd(maximumLength, ' ')} ${sanitizeHelp(context, description)}`)
91
93
  }
92
94
  logger('')
93
95
  }
94
96
 
95
97
  if (command.footer) {
96
- logger(sanitizeHelp(command.footer) + '\n')
98
+ logger(sanitizeHelp(context, command.footer) + '\n')
97
99
  }
98
100
  }
99
101
 
@@ -101,31 +103,31 @@ export async function helpCommand (logger, args) {
101
103
  const command = args?.[0]
102
104
 
103
105
  if (!command) {
104
- return showGeneralHelp()
106
+ return showGeneralHelp(this)
105
107
  }
106
108
 
107
109
  const commands = await loadCommands()
108
110
  if (!commands[command]) {
109
111
  return logFatalError(
110
112
  logger,
111
- `Unknown command ${bold(command)}. Please run ${bold(`"${getExecutableId()} help"`)} to see available commands.`
113
+ `Unknown command ${bold(command)}. Please run ${bold(`"${this.executableId} help"`)} to see available commands.`
112
114
  )
113
115
  }
114
116
 
115
- showHelp(commands[command])
117
+ showHelp(this, commands[command])
116
118
  }
117
119
 
118
120
  export const help = {
119
121
  help: {
120
122
  usage: 'help [command]',
121
123
  description () {
122
- return `Show help about ${getExecutableName()} or one of its commands`
124
+ return `Show help about ${this.executableName} or one of its commands`
123
125
  }
124
126
  },
125
127
  version: {
126
128
  usage: 'version',
127
129
  description () {
128
- return `Show current ${getExecutableName()} version`
130
+ return `Show current ${this.executableName} version`
129
131
  }
130
132
  }
131
133
  }
@@ -69,7 +69,9 @@ export async function patchConfig (logger, configurationFile, patchPath) {
69
69
  applications: {}
70
70
  }
71
71
 
72
- const applications = Object.fromEntries(loaded.runtime.applications.map(application => [application.id, application]))
72
+ const applications = Object.fromEntries(
73
+ loaded.runtime.applications.map(application => [application.id, application])
74
+ )
73
75
 
74
76
  // Load configuration for all applications
75
77
  for (const application of loaded.runtime.applications) {
@@ -165,7 +167,15 @@ export async function patchConfigCommand (logger, args) {
165
167
  patch = positionals[1]
166
168
  }
167
169
 
168
- const configurationFile = await findRuntimeConfigurationFile(logger, root, config)
170
+ const configurationFile = await findRuntimeConfigurationFile(
171
+ logger,
172
+ root,
173
+ config,
174
+ true,
175
+ true,
176
+ true,
177
+ this.executableName
178
+ )
169
179
 
170
180
  /* c8 ignore next 3 */
171
181
  if (!configurationFile) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wattpm-utils",
3
- "version": "3.39.0",
3
+ "version": "3.41.0",
4
4
  "description": "The Node.js Application Server Utilities Commands",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -29,9 +29,9 @@
29
29
  "execa": "^9.4.0",
30
30
  "semver": "^7.7.0",
31
31
  "tar": "^7.5.7",
32
- "@platformatic/foundation": "3.39.0",
33
- "@platformatic/runtime": "3.39.0",
34
- "create-wattpm": "3.39.0"
32
+ "@platformatic/foundation": "3.41.0",
33
+ "create-wattpm": "3.41.0",
34
+ "@platformatic/runtime": "3.41.0"
35
35
  },
36
36
  "devDependencies": {
37
37
  "cleaner-spec-reporter": "^0.5.0",
@@ -41,7 +41,7 @@
41
41
  "neostandard": "^0.12.0",
42
42
  "typescript": "^5.5.4",
43
43
  "undici": "^7.0.0",
44
- "@platformatic/node": "3.39.0"
44
+ "@platformatic/node": "3.41.0"
45
45
  },
46
46
  "engines": {
47
47
  "node": ">=22.19.0"