@platformatic/generators 4.0.0-new-config.6 → 4.0.0-new-config.8

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.
@@ -5,14 +5,23 @@ import { readFile, readdir, stat } from 'node:fs/promises'
5
5
  import { dirname, isAbsolute, join, relative, resolve, sep } from 'node:path'
6
6
  import { BaseGenerator } from './base-generator.js'
7
7
 
8
- export function importedConfiguration (pkg) {
8
+ export function importedConfiguration (pkg, { entrypoint = false } = {}) {
9
9
  const factory = capabilityFactories[pkg]
10
10
 
11
+ // The sole application of a runtime is its entrypoint, and a framework capability -- like the node
12
+ // capability -- writes no port of its own, so in production it would bind nothing and be reachable
13
+ // from nowhere. When it is the only application it takes the default port. The value is written
14
+ // directly here rather than through the env-scoped placeholder the generators use, because the
15
+ // import path writes this file itself, outside that machinery.
16
+ const server = entrypoint ? '{\n server: { port: Number(process.env.PORT || 3042) }\n}' : '{}'
17
+
11
18
  if (factory) {
12
- return `import { ${factory} } from '${pkg}'\n\nexport default ${factory}({})\n`
19
+ return `import { ${factory} } from '${pkg}'\n\nexport default ${factory}(${server})\n`
13
20
  }
14
21
 
15
- return `export default {\n module: '${pkg}'\n}\n`
22
+ return entrypoint
23
+ ? `export default {\n module: '${pkg}',\n server: { port: Number(process.env.PORT || 3042) }\n}\n`
24
+ : `export default {\n module: '${pkg}'\n}\n`
16
25
  }
17
26
 
18
27
  export class ImportGenerator extends BaseGenerator {
@@ -153,7 +162,7 @@ export class ImportGenerator extends BaseGenerator {
153
162
  this.addFile({
154
163
  path: '',
155
164
  file: join(updatedPath, 'watt.config.mjs'),
156
- contents: importedConfiguration(pkg)
165
+ contents: importedConfiguration(pkg, { entrypoint: this.config.entrypoint })
157
166
  })
158
167
  }
159
168
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/generators",
3
- "version": "4.0.0-new-config.6",
3
+ "version": "4.0.0-new-config.8",
4
4
  "description": "Main classes and utils for generators.",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -24,7 +24,7 @@
24
24
  "magicast": "^0.5.4",
25
25
  "pino": "^9.9.0",
26
26
  "undici": "^8.5.0",
27
- "@platformatic/foundation": "4.0.0-new-config.6"
27
+ "@platformatic/foundation": "4.0.0-new-config.8"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@types/inquirer": "^9.0.7",