create-platformatic 0.12.1 → 0.13.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/package.json +3 -3
- package/src/create-gitignore.mjs +4 -0
- package/src/index.mjs +9 -1
- package/src/utils.mjs +28 -4
- package/test/utils.test.mjs +67 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-platformatic",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.1",
|
|
4
4
|
"description": "Create platformatic-db interactive tool",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -24,18 +24,18 @@
|
|
|
24
24
|
"inquirer": "^9.1.4",
|
|
25
25
|
"log-update": "^5.0.1",
|
|
26
26
|
"minimist": "^1.2.7",
|
|
27
|
-
"mkdirp": "^
|
|
27
|
+
"mkdirp": "^2.0.0",
|
|
28
28
|
"ora": "^6.1.2",
|
|
29
29
|
"pino": "^8.8.0",
|
|
30
30
|
"pino-pretty": "^9.1.1",
|
|
31
31
|
"pupa": "^3.1.0",
|
|
32
|
+
"semver": "^7.3.8",
|
|
32
33
|
"undici": "^5.14.0"
|
|
33
34
|
},
|
|
34
35
|
"devDependencies": {
|
|
35
36
|
"c8": "^7.12.0",
|
|
36
37
|
"dotenv": "^16.0.3",
|
|
37
38
|
"esmock": "^2.1.0",
|
|
38
|
-
"semver": "^7.3.8",
|
|
39
39
|
"snazzy": "^9.0.0",
|
|
40
40
|
"standard": "^17.0.0",
|
|
41
41
|
"tap": "^16.3.2",
|
package/src/create-gitignore.mjs
CHANGED
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 } from './utils.mjs'
|
|
8
|
+
import { getUsername, getVersion, getSupportedNodeVersions, isCurrentVersionSupported } from './utils.mjs'
|
|
9
9
|
|
|
10
10
|
const createPlatformatic = async (argv) => {
|
|
11
11
|
const help = helpMe({
|
|
@@ -30,6 +30,14 @@ const createPlatformatic = async (argv) => {
|
|
|
30
30
|
await say(`${greeting} welcome to ${version ? `Platformatic ${version}!` : 'Platformatic!'}`)
|
|
31
31
|
await say('Let\'s start by creating a new project.')
|
|
32
32
|
|
|
33
|
+
const currentVersion = process.versions.node
|
|
34
|
+
const supported = isCurrentVersionSupported(currentVersion)
|
|
35
|
+
if (!supported) {
|
|
36
|
+
const supportedVersions = getSupportedNodeVersions().join(' or >= ')
|
|
37
|
+
await say(`Platformatic is not supported on Node.js v${currentVersion}.`)
|
|
38
|
+
await say(`Please use one of the following Node.js versions >= ${supportedVersions}.`)
|
|
39
|
+
}
|
|
40
|
+
|
|
33
41
|
const options = await inquirer.prompt({
|
|
34
42
|
type: 'list',
|
|
35
43
|
name: 'type',
|
package/src/utils.mjs
CHANGED
|
@@ -3,6 +3,7 @@ import { request } from 'undici'
|
|
|
3
3
|
import { access, constants, readFile } from 'fs/promises'
|
|
4
4
|
import { resolve, join, dirname } from 'path'
|
|
5
5
|
import { createRequire } from 'module'
|
|
6
|
+
import semver from 'semver'
|
|
6
7
|
|
|
7
8
|
export const sleep = ms => new Promise((resolve) => setTimeout(resolve, ms))
|
|
8
9
|
export const randomBetween = (min, max) => Math.floor(Math.random() * (max - min + 1) + min)
|
|
@@ -18,16 +19,23 @@ export async function isFileAccessible (filename, directory) {
|
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
export const getUsername = async () => {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
try {
|
|
23
|
+
const { stdout } = await execa('git', ['config', 'user.name'])
|
|
24
|
+
if (stdout?.trim()) {
|
|
25
|
+
return stdout.trim()
|
|
26
|
+
}
|
|
27
|
+
} catch (err) {
|
|
28
|
+
// ignore: git failed
|
|
24
29
|
}
|
|
25
|
-
{
|
|
30
|
+
try {
|
|
26
31
|
const { stdout } = await execa('whoami')
|
|
27
32
|
if (stdout?.trim()) {
|
|
28
33
|
return stdout.trim()
|
|
29
34
|
}
|
|
35
|
+
} catch (err) {
|
|
36
|
+
// ignore: whoami failed
|
|
30
37
|
}
|
|
38
|
+
|
|
31
39
|
return null
|
|
32
40
|
}
|
|
33
41
|
|
|
@@ -93,3 +101,19 @@ export const getDependencyVersion = async (dependencyName) => {
|
|
|
93
101
|
const packageJson = JSON.parse(packageJsonFile)
|
|
94
102
|
return packageJson.version
|
|
95
103
|
}
|
|
104
|
+
|
|
105
|
+
export const getSupportedNodeVersions = () => {
|
|
106
|
+
return ['16.17.0', '18.8.0', '19.0.0']
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
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
|
|
115
|
+
}
|
|
116
|
+
break
|
|
117
|
+
}
|
|
118
|
+
return true
|
|
119
|
+
}
|
package/test/utils.test.mjs
CHANGED
|
@@ -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 } from '../src/utils.mjs'
|
|
3
|
+
import { getVersion, randomBetween, sleep, validatePath, getDependencyVersion, findDBConfigFile, findServiceConfigFile, isFileAccessible, isCurrentVersionSupported, getSupportedNodeVersions } from '../src/utils.mjs'
|
|
4
4
|
import { mkdtempSync, rmSync, writeFileSync } from 'fs'
|
|
5
5
|
import { tmpdir } from 'os'
|
|
6
6
|
import { join } from 'path'
|
|
@@ -47,6 +47,45 @@ test('getUsername from whoami', async ({ end, equal }) => {
|
|
|
47
47
|
equal(username, name)
|
|
48
48
|
})
|
|
49
49
|
|
|
50
|
+
test('if getUsername from git failed, it tries whoim', async ({ end, equal }) => {
|
|
51
|
+
const name = 'lukeskywalker'
|
|
52
|
+
|
|
53
|
+
const { getUsername } = await esmock.strict('../src/utils.mjs', {
|
|
54
|
+
execa: {
|
|
55
|
+
execa: (command) => {
|
|
56
|
+
if (command === 'git') {
|
|
57
|
+
throw new Error('git failed')
|
|
58
|
+
}
|
|
59
|
+
if (command === 'whoami') {
|
|
60
|
+
return { stdout: name }
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return ''
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
})
|
|
67
|
+
const username = await getUsername()
|
|
68
|
+
equal(username, name)
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
test('if both git usern.ame and whoami fail, no username is set', async ({ end, equal }) => {
|
|
72
|
+
const { getUsername } = await esmock.strict('../src/utils.mjs', {
|
|
73
|
+
execa: {
|
|
74
|
+
execa: (command) => {
|
|
75
|
+
if (command === 'git') {
|
|
76
|
+
throw new Error('git failed')
|
|
77
|
+
}
|
|
78
|
+
if (command === 'whoami') {
|
|
79
|
+
throw new Error('whoami failed')
|
|
80
|
+
}
|
|
81
|
+
return ''
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
})
|
|
85
|
+
const username = await getUsername()
|
|
86
|
+
equal(username, null)
|
|
87
|
+
})
|
|
88
|
+
|
|
50
89
|
test('getUsername - no username found', async ({ end, equal }) => {
|
|
51
90
|
const { getUsername } = await esmock.strict('../src/utils.mjs', {
|
|
52
91
|
execa: {
|
|
@@ -180,3 +219,30 @@ test('isFileAccessible', async ({ end, equal, mock }) => {
|
|
|
180
219
|
equal(await isFileAccessible(config2), false)
|
|
181
220
|
rmSync(tmpDir1, { recursive: true, force: true })
|
|
182
221
|
})
|
|
222
|
+
|
|
223
|
+
test('getSupportedNodeVersions', async ({ equal, not }) => {
|
|
224
|
+
const supportedVersions = getSupportedNodeVersions()
|
|
225
|
+
equal(Array.isArray(supportedVersions), true)
|
|
226
|
+
not(supportedVersions.length, 0)
|
|
227
|
+
})
|
|
228
|
+
|
|
229
|
+
test('isCurrentVersionSupported', async ({ equal }) => {
|
|
230
|
+
const supportedVersions = getSupportedNodeVersions()
|
|
231
|
+
const { major, minor, patch } = semver.minVersion(supportedVersions[0])
|
|
232
|
+
{
|
|
233
|
+
// major not supported
|
|
234
|
+
const nodeVersion = `${major - 1}.${minor}.${patch}`
|
|
235
|
+
const supported = isCurrentVersionSupported(nodeVersion)
|
|
236
|
+
equal(supported, false)
|
|
237
|
+
}
|
|
238
|
+
{
|
|
239
|
+
// minor not supported
|
|
240
|
+
const nodeVersion = `${major}.${minor - 1}.${patch}`
|
|
241
|
+
const supported = isCurrentVersionSupported(nodeVersion)
|
|
242
|
+
equal(supported, false)
|
|
243
|
+
}
|
|
244
|
+
for (const version of supportedVersions) {
|
|
245
|
+
const supported = isCurrentVersionSupported(version)
|
|
246
|
+
equal(supported, true)
|
|
247
|
+
}
|
|
248
|
+
})
|