@platformatic/node 3.1.0 → 3.2.1

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/generator.js CHANGED
@@ -3,11 +3,27 @@
3
3
  import { BaseGenerator } from '@platformatic/generators'
4
4
  import { basename, dirname, sep } from 'node:path'
5
5
 
6
- const indexFile = `
6
+ const indexFileJS = `
7
7
  import { createServer } from 'node:http'
8
8
 
9
9
  export function create() {
10
- return createServer((req, res) => {
10
+ return createServer((_, res) => {
11
+ globalThis.platformatic.logger.debug('Serving request.')
12
+ res.writeHead(200, { 'content-type': 'application/json', connection: 'close' })
13
+ res.end(JSON.stringify({ hello: 'world' }))
14
+ })
15
+ }
16
+ `
17
+
18
+ const indexFileTS = `
19
+ import { getGlobal } from '@platformatic/globals'
20
+ import { createServer, type IncomingMessage, type ServerResponse } from 'node:http'
21
+
22
+ export function create() {
23
+ const platformatic = getGlobal()
24
+
25
+ return createServer((_: IncomingMessage, res: ServerResponse) => {
26
+ platformatic.logger.debug('Serving request.')
11
27
  res.writeHead(200, { 'content-type': 'application/json', connection: 'close' })
12
28
  res.end(JSON.stringify({ hello: 'world' }))
13
29
  })
@@ -22,12 +38,31 @@ export class Generator extends BaseGenerator {
22
38
  })
23
39
  }
24
40
 
41
+ async prepareQuestions () {
42
+ await super.prepareQuestions()
43
+
44
+ if (!this.config.skipTypescript) {
45
+ this.questions.push({
46
+ type: 'list',
47
+ name: 'typescript',
48
+ message: 'Do you want to use TypeScript?',
49
+ default: false,
50
+ choices: [
51
+ { name: 'yes', value: true },
52
+ { name: 'no', value: false }
53
+ ]
54
+ })
55
+ }
56
+ }
57
+
25
58
  async prepare () {
59
+ await this.getPlatformaticVersion()
60
+
26
61
  if (this.config.isUpdating) {
27
62
  return
28
63
  }
29
64
 
30
- const main = this.config.main || 'index.js'
65
+ const main = this.config.main || (this.config.typescript ? 'index.ts' : 'index.js')
31
66
  let indexPath = ''
32
67
  let indexName = main
33
68
 
@@ -36,9 +71,22 @@ export class Generator extends BaseGenerator {
36
71
  indexName = basename(main)
37
72
  }
38
73
 
39
- await this.getPlatformaticVersion()
74
+ let indexTemplate = indexFileJS
75
+ const dependencies = {
76
+ '@platformatic/node': `^${this.platformaticVersion}`
77
+ }
78
+
79
+ const devDependencies = {}
40
80
 
41
- this.addFile({ path: indexPath, file: indexName, contents: indexFile.trim() + '\n' })
81
+ if (this.config.typescript) {
82
+ indexTemplate = indexFileTS
83
+
84
+ dependencies['@platformatic/globals'] = `^${this.platformaticVersion}`
85
+ devDependencies['@platformatic/tsconfig'] = '^0.1.0'
86
+ devDependencies['@types/node'] = '^22.0.0'
87
+ }
88
+
89
+ this.addFile({ path: indexPath, file: indexName, contents: indexTemplate.trim() + '\n' })
42
90
 
43
91
  this.addFile({
44
92
  path: '',
@@ -48,18 +96,22 @@ export class Generator extends BaseGenerator {
48
96
  name: `${this.config.applicationName}`,
49
97
  main,
50
98
  type: 'module',
51
- scripts: {
52
- start: 'start-platformatic-node'
53
- },
54
- dependencies: {
55
- '@platformatic/node': `^${this.platformaticVersion}`
56
- }
99
+ dependencies,
100
+ devDependencies
57
101
  },
58
102
  null,
59
103
  2
60
104
  )
61
105
  })
62
106
 
107
+ if (this.config.typescript) {
108
+ this.addFile({
109
+ path: '',
110
+ file: 'tsconfig.json',
111
+ contents: JSON.stringify({ extends: '@platformatic/tsconfig' }, null, 2)
112
+ })
113
+ }
114
+
63
115
  this.addFile({
64
116
  path: '',
65
117
  file: 'watt.json',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/node",
3
- "version": "3.1.0",
3
+ "version": "3.2.1",
4
4
  "description": "Platformatic Node.js Capability",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -17,9 +17,9 @@
17
17
  "dependencies": {
18
18
  "json5": "^2.2.3",
19
19
  "light-my-request": "^6.0.0",
20
- "@platformatic/foundation": "3.1.0",
21
- "@platformatic/generators": "3.1.0",
22
- "@platformatic/basic": "3.1.0"
20
+ "@platformatic/basic": "3.2.1",
21
+ "@platformatic/foundation": "3.2.1",
22
+ "@platformatic/generators": "3.2.1"
23
23
  },
24
24
  "devDependencies": {
25
25
  "cleaner-spec-reporter": "^0.5.0",
@@ -31,8 +31,8 @@
31
31
  "neostandard": "^0.12.0",
32
32
  "tsx": "^4.19.0",
33
33
  "typescript": "^5.5.4",
34
- "@platformatic/service": "3.1.0",
35
- "@platformatic/gateway": "3.1.0"
34
+ "@platformatic/gateway": "3.2.1",
35
+ "@platformatic/service": "3.2.1"
36
36
  },
37
37
  "engines": {
38
38
  "node": ">=22.19.0"
package/schema.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://schemas.platformatic.dev/@platformatic/node/3.1.0.json",
2
+ "$id": "https://schemas.platformatic.dev/@platformatic/node/3.2.1.json",
3
3
  "$schema": "http://json-schema.org/draft-07/schema#",
4
4
  "title": "Platformatic Node.js Config",
5
5
  "type": "object",