wattpm 2.63.4 → 2.64.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/lib/utils.js CHANGED
@@ -1,8 +1,5 @@
1
1
  import {
2
- ConfigManager,
3
- getParser,
4
- getStringifier,
5
- matchKnownSchema,
2
+ findConfigurationFile as findRawConfigurationFile,
6
3
  loadConfig as pltConfigLoadConfig,
7
4
  Store
8
5
  } from '@platformatic/config'
@@ -10,8 +7,7 @@ import { errors } from '@platformatic/control'
10
7
  import { platformaticRuntime, buildRuntime as pltBuildRuntime } from '@platformatic/runtime'
11
8
  import { bgGreen, black, bold } from 'colorette'
12
9
  import { existsSync } from 'node:fs'
13
- import { readFile, writeFile } from 'node:fs/promises'
14
- import { dirname, resolve } from 'node:path'
10
+ import { resolve } from 'node:path'
15
11
  import { parseArgs as nodeParseArgs } from 'node:util'
16
12
  import { pino } from 'pino'
17
13
  import pinoPretty from 'pino-pretty'
@@ -31,22 +27,21 @@ export function createLogger (level) {
31
27
  }
32
28
  },
33
29
  pinoPretty({
34
- colorize: true,
30
+ colorize: process.env.NO_COLOR !== 'true',
35
31
  customPrettifiers: {
36
32
  level (logLevel, _u1, _u2, { label, labelColorized, colors }) {
37
33
  return logLevel === 35 ? bgGreen(black(label)) : labelColorized
38
34
  }
39
- }
35
+ },
36
+ sync: true
40
37
  })
41
38
  )
42
39
  }
43
40
 
44
- export function overrideFatal (logger) {
45
- const originalFatal = logger.fatal.bind(logger)
46
- logger.fatal = function (...args) {
47
- originalFatal(...args)
48
- process.exit(1)
49
- }
41
+ export function logFatalError (logger, ...args) {
42
+ process.exitCode = 1
43
+ logger.fatal(...args)
44
+ return false
50
45
  }
51
46
 
52
47
  export function parseArgs (args, options, stopAtFirstPositional = true) {
@@ -162,42 +157,18 @@ export function serviceToEnvVariable (service) {
162
157
  }
163
158
 
164
159
  export async function findConfigurationFile (logger, root, configurationFile) {
165
- let current = root
166
-
167
- while (!configurationFile) {
168
- // Find a wattpm.json or watt.json file
169
- configurationFile = await ConfigManager.findConfigFile(current, true)
170
-
171
- // If a file is found, verify it actually represents a watt or runtime configuration
172
- if (configurationFile) {
173
- const configuration = await loadRawConfigurationFile(logger, resolve(current, configurationFile))
174
-
175
- if (matchKnownSchema(configuration.$schema) !== 'runtime') {
176
- configurationFile = null
177
- }
178
- }
179
-
180
- if (!configurationFile) {
181
- const newCurrent = dirname(current)
182
-
183
- if (newCurrent === current) {
184
- break
185
- }
186
-
187
- current = newCurrent
188
- }
189
- }
190
-
191
- if (typeof configurationFile !== 'string') {
192
- logger.fatal(
193
- `Cannot find a supported Watt configuration file (like ${bold(
194
- 'watt.json'
195
- )}, a ${bold('wattpm.json')} or a ${bold('platformatic.json')}) in ${bold(root)}.`
160
+ const configFile = await findRawConfigurationFile(root, configurationFile, 'runtime')
161
+
162
+ if (!configFile) {
163
+ return logFatalError(
164
+ logger,
165
+ `Cannot find a supported Watt configuration file (like ${bold('watt.json')}, a ${bold('wattpm.json')} or a ${bold(
166
+ 'platformatic.json'
167
+ )}) in ${bold(root)}.`
196
168
  )
197
169
  }
198
170
 
199
- const resolved = resolve(current, configurationFile)
200
- return resolved
171
+ return configFile
201
172
  }
202
173
 
203
174
  export async function loadConfigurationFile (logger, configurationFile) {
@@ -221,18 +192,6 @@ export async function loadConfigurationFile (logger, configurationFile) {
221
192
  return configManager.current
222
193
  }
223
194
 
224
- export async function loadRawConfigurationFile (_, configurationFile) {
225
- const parseConfig = getParser(configurationFile)
226
-
227
- return parseConfig(await readFile(configurationFile, 'utf-8'))
228
- }
229
-
230
- export function saveConfigurationFile (logger, configurationFile, config) {
231
- const stringifyConfig = getStringifier(configurationFile)
232
-
233
- return writeFile(configurationFile, stringifyConfig(config), 'utf-8')
234
- }
235
-
236
195
  export async function buildRuntime (logger, configurationFile) {
237
196
  const store = new Store()
238
197
  store.add(platformaticRuntime)
@@ -243,7 +202,7 @@ export async function buildRuntime (logger, configurationFile) {
243
202
  const runtimeConfig = config.configManager
244
203
  try {
245
204
  return await pltBuildRuntime(runtimeConfig)
246
- /* c8 ignore next 3 */
205
+ /* c8 ignore next 3 - Hard to test */
247
206
  } catch (e) {
248
207
  process.exit(1)
249
208
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wattpm",
3
- "version": "2.63.4",
3
+ "version": "2.64.0",
4
4
  "description": "The Node.js Application Server",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -36,11 +36,12 @@
36
36
  "semver": "^7.7.0",
37
37
  "split2": "^4.2.0",
38
38
  "table": "^6.8.2",
39
- "@platformatic/basic": "2.63.4",
40
- "@platformatic/config": "2.63.4",
41
- "@platformatic/runtime": "2.63.4",
42
- "@platformatic/utils": "2.63.4",
43
- "@platformatic/control": "2.63.4"
39
+ "@platformatic/basic": "2.64.0",
40
+ "@platformatic/config": "2.64.0",
41
+ "@platformatic/runtime": "2.64.0",
42
+ "@platformatic/control": "2.64.0",
43
+ "@platformatic/utils": "2.64.0",
44
+ "create-platformatic": "2.64.0"
44
45
  },
45
46
  "devDependencies": {
46
47
  "borp": "^0.20.0",
@@ -50,7 +51,7 @@
50
51
  "neostandard": "^0.12.0",
51
52
  "typescript": "^5.5.4",
52
53
  "undici": "^7.0.0",
53
- "@platformatic/node": "2.63.4"
54
+ "@platformatic/node": "2.64.0"
54
55
  },
55
56
  "scripts": {
56
57
  "test": "npm run lint && borp --concurrency=1 --timeout=300000",
package/schema.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://schemas.platformatic.dev/wattpm/2.63.4.json",
2
+ "$id": "https://schemas.platformatic.dev/wattpm/2.64.0.json",
3
3
  "$schema": "http://json-schema.org/draft-07/schema#",
4
4
  "type": "object",
5
5
  "properties": {
@@ -1,119 +0,0 @@
1
- import { ensureLoggableError } from '@platformatic/utils'
2
- import { bold } from 'colorette'
3
- import { existsSync } from 'node:fs'
4
- import { mkdir, stat, writeFile } from 'node:fs/promises'
5
- import { basename, resolve } from 'node:path'
6
- import { defaultConfiguration, defaultPackageJson, defaultEnv } from '../defaults.js'
7
- import { gitignore } from '../gitignore.js'
8
- import { schema, version } from '../schema.js'
9
- import { getRoot, parseArgs, saveConfigurationFile, verbose } from '../utils.js'
10
-
11
- export async function initCommand (logger, args) {
12
- const {
13
- values: { 'package-manager': packageManager },
14
- positionals
15
- } = parseArgs(
16
- args,
17
- {
18
- 'package-manager': {
19
- type: 'string',
20
- short: 'p',
21
- default: 'npm'
22
- }
23
- },
24
- false
25
- )
26
-
27
- /* c8 ignore next */
28
- const root = getRoot(positionals)
29
- const web = resolve(root, 'web')
30
- const configurationFile = resolve(root, 'watt.json')
31
-
32
- // Check that the none of the files to be created already exist
33
- if (existsSync(root)) {
34
- const statObject = await stat(root)
35
-
36
- if (!statObject.isDirectory()) {
37
- logger.fatal(`Path ${bold(root)} exists but it is not a directory.`)
38
- }
39
-
40
- const webFolder = resolve(root, 'web')
41
-
42
- if (existsSync(webFolder)) {
43
- const statObject = await stat(webFolder)
44
-
45
- if (!statObject.isDirectory()) {
46
- logger.fatal(`Path ${bold(webFolder)} exists but it is not a directory.`)
47
- }
48
- }
49
-
50
- for (const file of ['watt.json', 'package.json', '.gitignore']) {
51
- if (existsSync(resolve(root, file))) {
52
- logger.fatal(`Path ${bold(resolve(root, file))} already exists.`)
53
- }
54
- }
55
- }
56
-
57
- // Create the web folder, will implicitly create the root
58
- try {
59
- await mkdir(web, { recursive: true })
60
- /* c8 ignore next 6 */
61
- } catch (error) {
62
- logger.fatal(
63
- verbose ? { error: ensureLoggableError(error) } : undefined,
64
- `Cannot create folder ${web}: ${error.message}`
65
- )
66
- }
67
-
68
- await saveConfigurationFile(logger, configurationFile, {
69
- $schema: schema.$id,
70
- ...defaultConfiguration,
71
- entrypoint: positionals[1] ?? undefined
72
- })
73
-
74
- await writeFile(resolve(root, '.env.sample'), defaultEnv, 'utf-8')
75
- await writeFile(resolve(root, '.env'), defaultEnv, 'utf-8')
76
-
77
- const packageJson = {
78
- name: basename(root),
79
- ...defaultPackageJson,
80
- dependencies: { wattpm: `^${version}` }
81
- }
82
-
83
- if (packageManager === 'npm') {
84
- packageJson.workspaces = ['web/*', 'external/*']
85
- } else if (packageManager === 'pnpm') {
86
- await saveConfigurationFile(logger, resolve(root, 'pnpm-workspace.yaml'), { packages: ['web/*', 'external/*'] })
87
- }
88
-
89
- // Write the package.json file
90
- await saveConfigurationFile(logger, resolve(root, 'package.json'), packageJson)
91
-
92
- // Write the .gitignore file
93
- await writeFile(resolve(root, '.gitignore'), gitignore, 'utf-8')
94
-
95
- logger.done(`Created a watt application in ${bold(root)}.`)
96
- }
97
-
98
- export const help = {
99
- init: {
100
- usage: 'init [root] [entrypoint]',
101
- description: 'Creates a new application',
102
- args: [
103
- {
104
- name: 'root',
105
- description: 'The directory where to create the application (the default is the current directory)'
106
- },
107
- {
108
- name: 'entrypoint',
109
- description: 'The name of the entrypoint service'
110
- }
111
- ],
112
- options: [
113
- {
114
- usage: 'p, --package-manager <executable>',
115
- description: 'Use an alternative package manager'
116
- }
117
- ]
118
- }
119
- }
package/lib/defaults.js DELETED
@@ -1,29 +0,0 @@
1
- export const defaultConfiguration = {
2
- server: {
3
- hostname: '{HOSTNAME}',
4
- port: '{PORT}',
5
- },
6
- logger: {
7
- level: 'info'
8
- },
9
- autoload: {
10
- path: 'web'
11
- }
12
- }
13
-
14
- export const defaultPackageJson = {
15
- private: true,
16
- scripts: {
17
- dev: 'wattpm dev',
18
- build: 'wattpm build',
19
- start: 'wattpm start'
20
- },
21
- dependencies: {}
22
- }
23
-
24
- export const defaultServiceJson = {}
25
-
26
- export const defaultEnv = `
27
- PORT=3042
28
- HOSTNAME=127.0.0.1
29
- `