create-platformatic 0.13.1 → 0.15.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-platformatic",
3
- "version": "0.13.1",
3
+ "version": "0.15.0",
4
4
  "description": "Create platformatic-db interactive tool",
5
5
  "repository": {
6
6
  "type": "git",
@@ -18,7 +18,7 @@
18
18
  "commist": "^3.2.0",
19
19
  "desm": "^1.3.0",
20
20
  "es-main": "^1.2.0",
21
- "execa": "^6.1.0",
21
+ "execa": "^7.0.0",
22
22
  "fastify": "^4.10.2",
23
23
  "help-me": "^4.2.0",
24
24
  "inquirer": "^9.1.4",
@@ -42,6 +42,7 @@
42
42
  "yaml": "^2.1.3"
43
43
  },
44
44
  "scripts": {
45
- "test": "standard | snazzy && NODE_OPTIONS=--loader=esmock c8 --100 tap --no-coverage test/*test.mjs test/*/*test.mjs"
45
+ "test": "standard | snazzy && NODE_OPTIONS=--loader=esmock c8 --100 tap --no-coverage test/*test.mjs test/*/*test.mjs",
46
+ "lint": "standard | snazzy"
46
47
  }
47
48
  }
@@ -24,6 +24,12 @@ lerna-debug.log*
24
24
 
25
25
  # Dependency directories
26
26
  node_modules/
27
+
28
+ # ctags
29
+ tags
30
+
31
+ # clinicjs
32
+ .clinic/
27
33
  `
28
34
 
29
35
  export const createGitignore = async (logger, dir = '.') => {
package/src/ghaction.mjs CHANGED
@@ -19,6 +19,9 @@ on:
19
19
 
20
20
  jobs:
21
21
  build_and_deploy:
22
+ permissions:
23
+ contents: read
24
+ pull-requests: write
22
25
  runs-on: ubuntu-latest
23
26
  steps:
24
27
  - name: Checkout application project repository
package/src/index.mjs CHANGED
@@ -5,7 +5,7 @@ import inquirer from 'inquirer'
5
5
  import createPlatformaticDB from './db/create-db-cli.mjs'
6
6
  import createPlatformaticService from './service/create-service-cli.mjs'
7
7
  import commist from 'commist'
8
- import { getUsername, getVersion, getSupportedNodeVersions, isCurrentVersionSupported } from './utils.mjs'
8
+ import { getUsername, getVersion, minimumSupportedNodeVersions, isCurrentVersionSupported } from './utils.mjs'
9
9
 
10
10
  const createPlatformatic = async (argv) => {
11
11
  const help = helpMe({
@@ -33,7 +33,7 @@ const createPlatformatic = async (argv) => {
33
33
  const currentVersion = process.versions.node
34
34
  const supported = isCurrentVersionSupported(currentVersion)
35
35
  if (!supported) {
36
- const supportedVersions = getSupportedNodeVersions().join(' or >= ')
36
+ const supportedVersions = minimumSupportedNodeVersions.join(' or >= ')
37
37
  await say(`Platformatic is not supported on Node.js v${currentVersion}.`)
38
38
  await say(`Please use one of the following Node.js versions >= ${supportedVersions}.`)
39
39
  }
package/src/utils.mjs CHANGED
@@ -71,10 +71,7 @@ export const validatePath = async projectPath => {
71
71
  // if the folder does not exist, check if the parent folder exists:
72
72
  const parentDir = dirname(projectDir)
73
73
  const canAccessParent = await isDirectoryWriteable(parentDir)
74
- if (canAccessParent) {
75
- return true
76
- }
77
- return false
74
+ return canAccessParent
78
75
  }
79
76
 
80
77
  const findConfigFile = async (directory, type) => {
@@ -102,18 +99,14 @@ export const getDependencyVersion = async (dependencyName) => {
102
99
  return packageJson.version
103
100
  }
104
101
 
105
- export const getSupportedNodeVersions = () => {
106
- return ['16.17.0', '18.8.0', '19.0.0']
107
- }
102
+ export const minimumSupportedNodeVersions = ['16.17.0', '18.8.0', '19.0.0']
108
103
 
109
104
  export const isCurrentVersionSupported = (currentVersion) => {
110
- const supportedVersions = getSupportedNodeVersions()
111
- for (const version of supportedVersions) {
112
- if (semver.gt(currentVersion, version)) { continue }
113
- if (semver.lt(currentVersion, version)) {
114
- return false
105
+ // TODO: add try/catch if some unsupported node version is passed
106
+ for (const version of minimumSupportedNodeVersions) {
107
+ if (semver.major(currentVersion) === semver.major(version) && semver.gte(currentVersion, version)) {
108
+ return true
115
109
  }
116
- break
117
110
  }
118
- return true
111
+ return false
119
112
  }
@@ -37,13 +37,16 @@ test('creates gh action', async ({ end, equal }) => {
37
37
  equal(accessible, true)
38
38
  const ghFile = await readFile(join(tmpDir, '.github/workflows/platformatic-deploy.yml'), 'utf8')
39
39
  const ghAction = parse(ghFile)
40
- const steps = ghAction.jobs.build_and_deploy.steps
40
+ const { steps, permissions } = ghAction.jobs.build_and_deploy
41
41
  equal(steps.length, 3)
42
42
  equal(steps[0].name, 'Checkout application project repository')
43
43
  equal(steps[1].name, 'npm install --omit=dev')
44
44
  equal(steps[2].name, 'Deploy project')
45
45
  equal(steps[2].env.DATABASE_URL, 'mydbconnectionstring')
46
46
  equal(steps[2].env.PLT_SERVER_LOGGER_LEVEL, 'info')
47
+
48
+ equal(permissions.contents, 'read')
49
+ equal(permissions['pull-requests'], 'write')
47
50
  })
48
51
 
49
52
  test('creates gh action with TS build step', async ({ end, equal }) => {
@@ -53,7 +56,7 @@ test('creates gh action with TS build step', async ({ end, equal }) => {
53
56
  equal(accessible, true)
54
57
  const ghFile = await readFile(join(tmpDir, '.github/workflows/platformatic-deploy.yml'), 'utf8')
55
58
  const ghAction = parse(ghFile)
56
- const steps = ghAction.jobs.build_and_deploy.steps
59
+ const { steps, permissions } = ghAction.jobs.build_and_deploy
57
60
  equal(steps.length, 4)
58
61
  equal(steps[0].name, 'Checkout application project repository')
59
62
  equal(steps[1].name, 'npm install --omit=dev')
@@ -61,6 +64,9 @@ test('creates gh action with TS build step', async ({ end, equal }) => {
61
64
  equal(steps[3].name, 'Deploy project')
62
65
  equal(steps[3].env.DATABASE_URL, 'mydbconnectionstring')
63
66
  equal(steps[3].env.PLT_SERVER_LOGGER_LEVEL, 'info')
67
+
68
+ equal(permissions.contents, 'read')
69
+ equal(permissions['pull-requests'], 'write')
64
70
  })
65
71
 
66
72
  test('do not create gitignore file because already present', async ({ end, equal }) => {
@@ -1,6 +1,6 @@
1
1
  import { test, beforeEach } from 'tap'
2
2
  import { MockAgent, setGlobalDispatcher } from 'undici'
3
- import { getVersion, randomBetween, sleep, validatePath, getDependencyVersion, findDBConfigFile, findServiceConfigFile, isFileAccessible, isCurrentVersionSupported, getSupportedNodeVersions } from '../src/utils.mjs'
3
+ import { getVersion, randomBetween, sleep, validatePath, getDependencyVersion, findDBConfigFile, findServiceConfigFile, isFileAccessible, isCurrentVersionSupported, minimumSupportedNodeVersions } from '../src/utils.mjs'
4
4
  import { mkdtempSync, rmSync, writeFileSync } from 'fs'
5
5
  import { tmpdir } from 'os'
6
6
  import { join } from 'path'
@@ -220,28 +220,62 @@ test('isFileAccessible', async ({ end, equal, mock }) => {
220
220
  rmSync(tmpDir1, { recursive: true, force: true })
221
221
  })
222
222
 
223
- test('getSupportedNodeVersions', async ({ equal, not }) => {
224
- const supportedVersions = getSupportedNodeVersions()
225
- equal(Array.isArray(supportedVersions), true)
226
- not(supportedVersions.length, 0)
223
+ test('minimumSupportedNodeVersions', async ({ equal, not }) => {
224
+ equal(Array.isArray(minimumSupportedNodeVersions), true)
225
+ not(minimumSupportedNodeVersions.length, 0)
227
226
  })
228
227
 
229
228
  test('isCurrentVersionSupported', async ({ equal }) => {
230
- const supportedVersions = getSupportedNodeVersions()
231
- const { major, minor, patch } = semver.minVersion(supportedVersions[0])
229
+ const { major, minor, patch } = semver.minVersion(minimumSupportedNodeVersions[0])
232
230
  {
233
- // major not supported
231
+ // v15 major not supported
234
232
  const nodeVersion = `${major - 1}.${minor}.${patch}`
235
233
  const supported = isCurrentVersionSupported(nodeVersion)
236
234
  equal(supported, false)
237
235
  }
238
236
  {
239
- // minor not supported
237
+ // v17 major not supported
238
+ const nodeVersion = `${major + 1}.${minor}.${patch}`
239
+ const supported = isCurrentVersionSupported(nodeVersion)
240
+ equal(supported, false)
241
+ }
242
+ {
243
+ // v16 minor not supported
240
244
  const nodeVersion = `${major}.${minor - 1}.${patch}`
241
245
  const supported = isCurrentVersionSupported(nodeVersion)
242
246
  equal(supported, false)
243
247
  }
244
- for (const version of supportedVersions) {
248
+ {
249
+ // v16 more than minimum is supported
250
+ const supported = isCurrentVersionSupported(`${major}.${minor + 2}.${patch}`)
251
+ equal(supported, true)
252
+ }
253
+ // node version 18 test, to check greater and lesser major version
254
+ const { major: major18, minor: minor18, patch: patch18 } = semver.minVersion(minimumSupportedNodeVersions[1])
255
+ {
256
+ // v17 major not supported
257
+ const nodeVersion = `${major18 - 1}.${minor18}.${patch18}`
258
+ const supported = isCurrentVersionSupported(nodeVersion)
259
+ equal(supported, false)
260
+ }
261
+ {
262
+ // v19 is supported
263
+ const nodeVersion = `${major18 + 1}.${minor18}.${patch18}`
264
+ const supported = isCurrentVersionSupported(nodeVersion)
265
+ equal(supported, true)
266
+ }
267
+ {
268
+ // v18 minor not supported
269
+ const nodeVersion = `${major18}.${minor18 - 2}.${patch18}`
270
+ const supported = isCurrentVersionSupported(nodeVersion)
271
+ equal(supported, false)
272
+ }
273
+ {
274
+ // v18 supported
275
+ const supported = isCurrentVersionSupported(`${major18}.${minor18 + 1}.${patch18}`)
276
+ equal(supported, true)
277
+ }
278
+ for (const version of minimumSupportedNodeVersions) {
245
279
  const supported = isCurrentVersionSupported(version)
246
280
  equal(supported, true)
247
281
  }