create-platformatic 0.45.1 → 0.46.2
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 +4 -4
- package/src/composer/create-composer-cli.mjs +1 -1
- package/src/create-plugins.mjs +232 -0
- package/src/db/create-db-cli.mjs +3 -2
- package/src/db/create-db.mjs +246 -36
- package/src/ghaction.mjs +1 -1
- package/src/runtime/create-runtime-cli.mjs +1 -1
- package/src/service/create-service-cli.mjs +6 -3
- package/src/service/create-service.mjs +3 -84
- package/test/cli-options.test.mjs +0 -84
- package/test/composer/create-composer.test.mjs +0 -75
- package/test/create-gitignore.test.mjs +0 -35
- package/test/create-package-json.test.mjs +0 -81
- package/test/db/create-db.test.mjs +0 -295
- package/test/exports.test.mjs +0 -8
- package/test/get-pkg-manager.test.mjs +0 -36
- package/test/ghaction-dynamic.test.mjs +0 -98
- package/test/ghaction-static.test.mjs +0 -97
- package/test/runtime/create-runtime.test.mjs +0 -70
- package/test/service/create-service.test.mjs +0 -147
- package/test/utils.test.mjs +0 -261
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { test, beforeEach } from 'tap'
|
|
2
|
-
import { getPkgManager } from '../src/get-pkg-manager.mjs'
|
|
3
|
-
|
|
4
|
-
beforeEach(() => {
|
|
5
|
-
delete process.env.npm_config_user_agent
|
|
6
|
-
})
|
|
7
|
-
|
|
8
|
-
test('detects npm', async ({ end, equal }) => {
|
|
9
|
-
process.env.npm_config_user_agent = 'npm/7.18.1 node/v16.4.2 darwin x64'
|
|
10
|
-
equal(getPkgManager(), 'npm')
|
|
11
|
-
})
|
|
12
|
-
|
|
13
|
-
test('detects yarn', async ({ end, equal }) => {
|
|
14
|
-
process.env.npm_config_user_agent = 'yarn/1.22.10 npm/? node/v16.4.2 darwin x64'
|
|
15
|
-
equal(getPkgManager(), 'yarn')
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
test('detects pnpm', async ({ end, equal }) => {
|
|
19
|
-
process.env.npm_config_user_agent = 'pnpm/6.14.1 npm/? node/v16.4.2 darwin x64'
|
|
20
|
-
equal(getPkgManager(), 'pnpm')
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
test('detects cnpm', async ({ end, equal }) => {
|
|
24
|
-
process.env.npm_config_user_agent = 'cnpm/7.0.0 npminsall/1.0.0 node/v16.4.2 darwin x64'
|
|
25
|
-
equal(getPkgManager(), 'cnpm')
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
test('defaults to npm if the user agent is unknown', async ({ end, equal }) => {
|
|
29
|
-
process.env.npm_config_user_agent = 'xxxxxxxxxxxxxxxxxx'
|
|
30
|
-
equal(getPkgManager(), 'npm')
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
test('defaults to npm if the user agent is not set', async ({ end, equal }) => {
|
|
34
|
-
delete process.env.npm_config_user_agent
|
|
35
|
-
equal(getPkgManager(), 'npm')
|
|
36
|
-
})
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
import { test, beforeEach, afterEach } from 'tap'
|
|
4
|
-
import { mkdtemp, rmdir, writeFile, readFile, mkdir } from 'fs/promises'
|
|
5
|
-
import { join } from 'path'
|
|
6
|
-
import { tmpdir } from 'os'
|
|
7
|
-
import { isFileAccessible } from '../src/utils.mjs'
|
|
8
|
-
import { createDynamicWorkspaceGHAction } from '../src/ghaction.mjs'
|
|
9
|
-
import { parse } from 'yaml'
|
|
10
|
-
|
|
11
|
-
let log = []
|
|
12
|
-
let tmpDir
|
|
13
|
-
const fakeLogger = {
|
|
14
|
-
info: msg => { log.push(msg) },
|
|
15
|
-
warn: msg => { log.push(msg) }
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
beforeEach(async () => {
|
|
19
|
-
log = []
|
|
20
|
-
tmpDir = await mkdtemp(join(tmpdir(), 'test-create-platformatic-'))
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
afterEach(async () => {
|
|
24
|
-
await rmdir(tmpDir, { recursive: true, force: true })
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
const env = {
|
|
28
|
-
DATABASE_URL: 'mydbconnectionstring',
|
|
29
|
-
PLT_SERVER_LOGGER_LEVEL: 'info'
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
test('creates gh action', async ({ equal, match }) => {
|
|
33
|
-
await createDynamicWorkspaceGHAction(fakeLogger, env, 'db', tmpDir, false)
|
|
34
|
-
equal(log[0], 'PR Previews are enabled for your app and the Github action was successfully created, please add the following secrets as repository secrets: ')
|
|
35
|
-
const accessible = await isFileAccessible(join(tmpDir, '.github/workflows/platformatic-dynamic-workspace-deploy.yml'))
|
|
36
|
-
equal(accessible, true)
|
|
37
|
-
const ghFile = await readFile(join(tmpDir, '.github/workflows/platformatic-dynamic-workspace-deploy.yml'), 'utf8')
|
|
38
|
-
const ghAction = parse(ghFile)
|
|
39
|
-
const { steps, permissions, env: jobEnv } = ghAction.jobs.build_and_deploy
|
|
40
|
-
equal(steps.length, 3)
|
|
41
|
-
equal(steps[0].name, 'Checkout application project repository')
|
|
42
|
-
equal(steps[1].name, 'npm install --omit=dev')
|
|
43
|
-
equal(steps[2].name, 'Deploy project')
|
|
44
|
-
match(jobEnv.DATABASE_URL, /\$\{\{ secrets.DATABASE_URL \}\}/)
|
|
45
|
-
equal(jobEnv.PLT_SERVER_LOGGER_LEVEL, 'info')
|
|
46
|
-
|
|
47
|
-
equal(permissions.contents, 'read')
|
|
48
|
-
equal(permissions['pull-requests'], 'write')
|
|
49
|
-
})
|
|
50
|
-
|
|
51
|
-
test('creates gh action with TS build step', async ({ equal, match }) => {
|
|
52
|
-
await createDynamicWorkspaceGHAction(fakeLogger, env, 'db', tmpDir, true)
|
|
53
|
-
equal(log[0], 'PR Previews are enabled for your app and the Github action was successfully created, please add the following secrets as repository secrets: ')
|
|
54
|
-
const accessible = await isFileAccessible(join(tmpDir, '.github/workflows/platformatic-dynamic-workspace-deploy.yml'))
|
|
55
|
-
equal(accessible, true)
|
|
56
|
-
const ghFile = await readFile(join(tmpDir, '.github/workflows/platformatic-dynamic-workspace-deploy.yml'), 'utf8')
|
|
57
|
-
const ghAction = parse(ghFile)
|
|
58
|
-
const { steps, permissions, env: jobEnv } = ghAction.jobs.build_and_deploy
|
|
59
|
-
equal(steps.length, 4)
|
|
60
|
-
equal(steps[0].name, 'Checkout application project repository')
|
|
61
|
-
equal(steps[1].name, 'npm install --omit=dev')
|
|
62
|
-
equal(steps[2].name, 'Build project')
|
|
63
|
-
equal(steps[3].name, 'Deploy project')
|
|
64
|
-
match(jobEnv.DATABASE_URL, /\$\{\{ secrets.DATABASE_URL \}\}/)
|
|
65
|
-
equal(jobEnv.PLT_SERVER_LOGGER_LEVEL, 'info')
|
|
66
|
-
|
|
67
|
-
equal(permissions.contents, 'read')
|
|
68
|
-
equal(permissions['pull-requests'], 'write')
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
test('do not create gitignore file because already present', async ({ end, equal }) => {
|
|
72
|
-
await mkdir(join(tmpDir, '.github', 'workflows'), { recursive: true })
|
|
73
|
-
const ghaction = join(tmpDir, '.github', 'workflows', 'platformatic-dynamic-workspace-deploy.yml')
|
|
74
|
-
await writeFile(ghaction, 'TEST')
|
|
75
|
-
await createDynamicWorkspaceGHAction(fakeLogger, env, 'db', tmpDir)
|
|
76
|
-
equal(log[0], `Github action file ${join(tmpDir, '.github', 'workflows', 'platformatic-dynamic-workspace-deploy.yml')} found, skipping creation of github action file.`)
|
|
77
|
-
})
|
|
78
|
-
|
|
79
|
-
test('creates gh action with a warn if a .git folder is not present', async ({ end, equal }) => {
|
|
80
|
-
await createDynamicWorkspaceGHAction(fakeLogger, env, 'db', tmpDir)
|
|
81
|
-
equal(log[0], 'PR Previews are enabled for your app and the Github action was successfully created, please add the following secrets as repository secrets: ')
|
|
82
|
-
const accessible = await isFileAccessible(join(tmpDir, '.github/workflows/platformatic-dynamic-workspace-deploy.yml'))
|
|
83
|
-
equal(accessible, true)
|
|
84
|
-
const secretsLogLine = log[1].split('\n')
|
|
85
|
-
equal(secretsLogLine[1].trim(), 'PLATFORMATIC_DYNAMIC_WORKSPACE_ID: your workspace id')
|
|
86
|
-
equal(secretsLogLine[2].trim(), 'PLATFORMATIC_DYNAMIC_WORKSPACE_API_KEY: your workspace API key')
|
|
87
|
-
equal(secretsLogLine[3].trim(), 'DATABASE_URL: mydbconnectionstring')
|
|
88
|
-
equal(log[2], 'No git repository found. The Github action won\'t be triggered.')
|
|
89
|
-
})
|
|
90
|
-
|
|
91
|
-
test('creates gh action without a warn if a .git folder is present', async ({ end, equal }) => {
|
|
92
|
-
await mkdir(join(tmpDir, '.git'), { recursive: true })
|
|
93
|
-
await createDynamicWorkspaceGHAction(fakeLogger, env, 'db', tmpDir)
|
|
94
|
-
equal(log[0], 'PR Previews are enabled for your app and the Github action was successfully created, please add the following secrets as repository secrets: ')
|
|
95
|
-
const accessible = await isFileAccessible(join(tmpDir, '.github/workflows/platformatic-dynamic-workspace-deploy.yml'))
|
|
96
|
-
equal(accessible, true)
|
|
97
|
-
equal(log.length, 2)
|
|
98
|
-
})
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
import { test, beforeEach, afterEach } from 'tap'
|
|
4
|
-
import { mkdtemp, rmdir, writeFile, readFile, mkdir } from 'fs/promises'
|
|
5
|
-
import { join } from 'path'
|
|
6
|
-
import { tmpdir } from 'os'
|
|
7
|
-
import { isFileAccessible } from '../src/utils.mjs'
|
|
8
|
-
import { createStaticWorkspaceGHAction } from '../src/ghaction.mjs'
|
|
9
|
-
import { parse } from 'yaml'
|
|
10
|
-
|
|
11
|
-
let log = []
|
|
12
|
-
let tmpDir
|
|
13
|
-
const fakeLogger = {
|
|
14
|
-
info: msg => { log.push(msg) },
|
|
15
|
-
warn: msg => { log.push(msg) }
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
beforeEach(async () => {
|
|
19
|
-
log = []
|
|
20
|
-
tmpDir = await mkdtemp(join(tmpdir(), 'test-create-platformatic-'))
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
afterEach(async () => {
|
|
24
|
-
await rmdir(tmpDir, { recursive: true, force: true })
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
const env = {
|
|
28
|
-
DATABASE_URL: 'mydbconnectionstring',
|
|
29
|
-
PLT_SERVER_LOGGER_LEVEL: 'info'
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
test('creates gh action', async ({ equal, match }) => {
|
|
33
|
-
await createStaticWorkspaceGHAction(fakeLogger, env, 'db', tmpDir, false)
|
|
34
|
-
equal(log[0], 'Github action successfully created, please add the following secrets as repository secrets: ')
|
|
35
|
-
const accessible = await isFileAccessible(join(tmpDir, '.github/workflows/platformatic-static-workspace-deploy.yml'))
|
|
36
|
-
equal(accessible, true)
|
|
37
|
-
const ghFile = await readFile(join(tmpDir, '.github/workflows/platformatic-static-workspace-deploy.yml'), 'utf8')
|
|
38
|
-
const ghAction = parse(ghFile)
|
|
39
|
-
const { steps, permissions, env: jobEnv } = ghAction.jobs.build_and_deploy
|
|
40
|
-
|
|
41
|
-
equal(steps.length, 3)
|
|
42
|
-
equal(steps[0].name, 'Checkout application project repository')
|
|
43
|
-
equal(steps[1].name, 'npm install --omit=dev')
|
|
44
|
-
equal(steps[2].name, 'Deploy project')
|
|
45
|
-
match(jobEnv.DATABASE_URL, /\$\{\{ secrets.DATABASE_URL \}\}/)
|
|
46
|
-
equal(jobEnv.PLT_SERVER_LOGGER_LEVEL, 'info')
|
|
47
|
-
|
|
48
|
-
equal(permissions.contents, 'read')
|
|
49
|
-
})
|
|
50
|
-
|
|
51
|
-
test('creates gh action with TS build step', async ({ equal, match }) => {
|
|
52
|
-
await createStaticWorkspaceGHAction(fakeLogger, env, 'db', tmpDir, true)
|
|
53
|
-
equal(log[0], 'Github action successfully created, please add the following secrets as repository secrets: ')
|
|
54
|
-
const accessible = await isFileAccessible(join(tmpDir, '.github/workflows/platformatic-static-workspace-deploy.yml'))
|
|
55
|
-
equal(accessible, true)
|
|
56
|
-
const ghFile = await readFile(join(tmpDir, '.github/workflows/platformatic-static-workspace-deploy.yml'), 'utf8')
|
|
57
|
-
const ghAction = parse(ghFile)
|
|
58
|
-
const { steps, permissions, env: jobEnv } = ghAction.jobs.build_and_deploy
|
|
59
|
-
equal(steps.length, 4)
|
|
60
|
-
equal(steps[0].name, 'Checkout application project repository')
|
|
61
|
-
equal(steps[1].name, 'npm install --omit=dev')
|
|
62
|
-
equal(steps[2].name, 'Build project')
|
|
63
|
-
equal(steps[3].name, 'Deploy project')
|
|
64
|
-
match(jobEnv.DATABASE_URL, /\$\{\{ secrets.DATABASE_URL \}\}/)
|
|
65
|
-
equal(jobEnv.PLT_SERVER_LOGGER_LEVEL, 'info')
|
|
66
|
-
|
|
67
|
-
equal(permissions.contents, 'read')
|
|
68
|
-
})
|
|
69
|
-
|
|
70
|
-
test('do not create gitignore file because already present', async ({ end, equal }) => {
|
|
71
|
-
await mkdir(join(tmpDir, '.github', 'workflows'), { recursive: true })
|
|
72
|
-
const ghaction = join(tmpDir, '.github', 'workflows', 'platformatic-static-workspace-deploy.yml')
|
|
73
|
-
await writeFile(ghaction, 'TEST')
|
|
74
|
-
await createStaticWorkspaceGHAction(fakeLogger, env, 'db', tmpDir)
|
|
75
|
-
equal(log[0], `Github action file ${join(tmpDir, '.github', 'workflows', 'platformatic-static-workspace-deploy.yml')} found, skipping creation of github action file.`)
|
|
76
|
-
})
|
|
77
|
-
|
|
78
|
-
test('creates gh action with a warn if a .git folder is not present', async ({ end, equal }) => {
|
|
79
|
-
await createStaticWorkspaceGHAction(fakeLogger, env, 'db', tmpDir)
|
|
80
|
-
equal(log[0], 'Github action successfully created, please add the following secrets as repository secrets: ')
|
|
81
|
-
const accessible = await isFileAccessible(join(tmpDir, '.github/workflows/platformatic-static-workspace-deploy.yml'))
|
|
82
|
-
equal(accessible, true)
|
|
83
|
-
const secretsLogLine = log[1].split('\n')
|
|
84
|
-
equal(secretsLogLine[1].trim(), 'PLATFORMATIC_STATIC_WORKSPACE_ID: your workspace id')
|
|
85
|
-
equal(secretsLogLine[2].trim(), 'PLATFORMATIC_STATIC_WORKSPACE_API_KEY: your workspace API key')
|
|
86
|
-
equal(secretsLogLine[3].trim(), 'DATABASE_URL: mydbconnectionstring')
|
|
87
|
-
equal(log[2], 'No git repository found. The Github action won\'t be triggered.')
|
|
88
|
-
})
|
|
89
|
-
|
|
90
|
-
test('creates gh action without a warn if a .git folder is present', async ({ end, equal }) => {
|
|
91
|
-
await mkdir(join(tmpDir, '.git'), { recursive: true })
|
|
92
|
-
await createStaticWorkspaceGHAction(fakeLogger, env, 'db', tmpDir)
|
|
93
|
-
equal(log[0], 'Github action successfully created, please add the following secrets as repository secrets: ')
|
|
94
|
-
const accessible = await isFileAccessible(join(tmpDir, '.github/workflows/platformatic-static-workspace-deploy.yml'))
|
|
95
|
-
equal(accessible, true)
|
|
96
|
-
equal(log.length, 2)
|
|
97
|
-
})
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import createRuntime from '../../src/runtime/create-runtime.mjs'
|
|
2
|
-
import { test, beforeEach, afterEach } from 'tap'
|
|
3
|
-
import { tmpdir } from 'os'
|
|
4
|
-
import { mkdtempSync, rmSync, readFileSync, writeFileSync } from 'fs'
|
|
5
|
-
import { join } from 'path'
|
|
6
|
-
|
|
7
|
-
const base = tmpdir()
|
|
8
|
-
let tmpDir
|
|
9
|
-
let log = []
|
|
10
|
-
beforeEach(() => {
|
|
11
|
-
tmpDir = mkdtempSync(join(base, 'test-create-platformatic-'))
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
afterEach(() => {
|
|
15
|
-
log = []
|
|
16
|
-
rmSync(tmpDir, { recursive: true, force: true })
|
|
17
|
-
process.env = {}
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
const fakeLogger = {
|
|
21
|
-
debug: msg => log.push(msg),
|
|
22
|
-
info: msg => log.push(msg)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
test('creates runtime', async ({ equal, same, ok }) => {
|
|
26
|
-
await createRuntime(fakeLogger, tmpDir, undefined, 'library-app/services', 'foobar')
|
|
27
|
-
|
|
28
|
-
const pathToRuntimeConfigFile = join(tmpDir, 'platformatic.runtime.json')
|
|
29
|
-
const runtimeConfigFile = readFileSync(pathToRuntimeConfigFile, 'utf8')
|
|
30
|
-
const runtimeConfig = JSON.parse(runtimeConfigFile)
|
|
31
|
-
|
|
32
|
-
delete runtimeConfig.$schema
|
|
33
|
-
|
|
34
|
-
same(runtimeConfig, {
|
|
35
|
-
entrypoint: 'foobar',
|
|
36
|
-
allowCycles: false,
|
|
37
|
-
hotReload: true,
|
|
38
|
-
autoload: {
|
|
39
|
-
path: 'library-app/services',
|
|
40
|
-
exclude: ['docs']
|
|
41
|
-
}
|
|
42
|
-
})
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
test('with a full path for autoload', async ({ equal, same, ok }) => {
|
|
46
|
-
await createRuntime(fakeLogger, tmpDir, undefined, join(tmpDir, 'services'), 'foobar')
|
|
47
|
-
|
|
48
|
-
const pathToRuntimeConfigFile = join(tmpDir, 'platformatic.runtime.json')
|
|
49
|
-
const runtimeConfigFile = readFileSync(pathToRuntimeConfigFile, 'utf8')
|
|
50
|
-
const runtimeConfig = JSON.parse(runtimeConfigFile)
|
|
51
|
-
|
|
52
|
-
delete runtimeConfig.$schema
|
|
53
|
-
|
|
54
|
-
same(runtimeConfig, {
|
|
55
|
-
entrypoint: 'foobar',
|
|
56
|
-
allowCycles: false,
|
|
57
|
-
hotReload: true,
|
|
58
|
-
autoload: {
|
|
59
|
-
path: 'services',
|
|
60
|
-
exclude: ['docs']
|
|
61
|
-
}
|
|
62
|
-
})
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
test('creates project with configuration already present', async ({ ok }) => {
|
|
66
|
-
const pathToRuntimeConfigFileOld = join(tmpDir, 'platformatic.runtime.json')
|
|
67
|
-
writeFileSync(pathToRuntimeConfigFileOld, JSON.stringify({ test: 'test' }))
|
|
68
|
-
await createRuntime(fakeLogger, tmpDir, 'foobar')
|
|
69
|
-
ok(log.includes('Configuration file platformatic.runtime.json found, skipping creation of configuration file.'))
|
|
70
|
-
})
|
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
import createService from '../../src/service/create-service.mjs'
|
|
2
|
-
import { isFileAccessible } from '../../src/utils.mjs'
|
|
3
|
-
import { test, beforeEach, afterEach } from 'tap'
|
|
4
|
-
import { tmpdir } from 'os'
|
|
5
|
-
import { mkdtempSync, rmSync, readFileSync, writeFileSync, mkdirSync } from 'fs'
|
|
6
|
-
import { join } from 'path'
|
|
7
|
-
import dotenv from 'dotenv'
|
|
8
|
-
import Ajv from 'ajv'
|
|
9
|
-
import { schema } from '@platformatic/service'
|
|
10
|
-
|
|
11
|
-
const base = tmpdir()
|
|
12
|
-
let tmpDir
|
|
13
|
-
let log = []
|
|
14
|
-
beforeEach(() => {
|
|
15
|
-
tmpDir = mkdtempSync(join(base, 'test-create-platformatic-'))
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
afterEach(() => {
|
|
19
|
-
log = []
|
|
20
|
-
rmSync(tmpDir, { recursive: true, force: true })
|
|
21
|
-
process.env = {}
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
const fakeLogger = {
|
|
25
|
-
debug: msg => log.push(msg),
|
|
26
|
-
info: msg => log.push(msg)
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
test('creates service with typescript', async ({ equal, same, ok }) => {
|
|
30
|
-
const params = {
|
|
31
|
-
hostname: 'myhost',
|
|
32
|
-
port: 6666,
|
|
33
|
-
typescript: true
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
await createService(params, fakeLogger, tmpDir)
|
|
37
|
-
|
|
38
|
-
const pathToServiceConfigFile = join(tmpDir, 'platformatic.service.json')
|
|
39
|
-
const serviceConfigFile = readFileSync(pathToServiceConfigFile, 'utf8')
|
|
40
|
-
const serviceConfig = JSON.parse(serviceConfigFile)
|
|
41
|
-
const ajv = new Ajv()
|
|
42
|
-
ajv.addKeyword('resolvePath')
|
|
43
|
-
const validate = ajv.compile(schema.schema)
|
|
44
|
-
const isValid = validate(serviceConfig)
|
|
45
|
-
equal(isValid, true)
|
|
46
|
-
const { server, plugins } = serviceConfig
|
|
47
|
-
|
|
48
|
-
equal(server.hostname, '{PLT_SERVER_HOSTNAME}')
|
|
49
|
-
equal(server.port, '{PORT}')
|
|
50
|
-
|
|
51
|
-
const pathToDbEnvFile = join(tmpDir, '.env')
|
|
52
|
-
dotenv.config({ path: pathToDbEnvFile })
|
|
53
|
-
equal(process.env.PLT_SERVER_HOSTNAME, 'myhost')
|
|
54
|
-
equal(process.env.PORT, '6666')
|
|
55
|
-
equal(process.env.PLT_TYPESCRIPT, 'true')
|
|
56
|
-
|
|
57
|
-
process.env = {}
|
|
58
|
-
|
|
59
|
-
const pathToDbEnvSampleFile = join(tmpDir, '.env.sample')
|
|
60
|
-
dotenv.config({ path: pathToDbEnvSampleFile })
|
|
61
|
-
equal(process.env.PLT_SERVER_HOSTNAME, 'myhost')
|
|
62
|
-
equal(process.env.PORT, '6666')
|
|
63
|
-
equal(process.env.PLT_TYPESCRIPT, 'true')
|
|
64
|
-
|
|
65
|
-
same(plugins.paths, [{ path: './plugins', encapsulate: false }, './routes'])
|
|
66
|
-
equal(plugins.typescript, '{PLT_TYPESCRIPT}')
|
|
67
|
-
|
|
68
|
-
ok(await isFileAccessible(join(tmpDir, 'tsconfig.json')))
|
|
69
|
-
ok(await isFileAccessible(join(tmpDir, 'plugins', 'example.ts')))
|
|
70
|
-
ok(await isFileAccessible(join(tmpDir, 'routes', 'root.ts')))
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
test('creates service with javascript', async ({ equal, same, ok }) => {
|
|
74
|
-
const params = {
|
|
75
|
-
hostname: 'myhost',
|
|
76
|
-
port: 6666,
|
|
77
|
-
typescript: false
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
await createService(params, fakeLogger, tmpDir)
|
|
81
|
-
|
|
82
|
-
const pathToServiceConfigFile = join(tmpDir, 'platformatic.service.json')
|
|
83
|
-
const serviceConfigFile = readFileSync(pathToServiceConfigFile, 'utf8')
|
|
84
|
-
const serviceConfig = JSON.parse(serviceConfigFile)
|
|
85
|
-
const { server, plugins } = serviceConfig
|
|
86
|
-
|
|
87
|
-
equal(server.hostname, '{PLT_SERVER_HOSTNAME}')
|
|
88
|
-
equal(server.port, '{PORT}')
|
|
89
|
-
|
|
90
|
-
const pathToDbEnvFile = join(tmpDir, '.env')
|
|
91
|
-
dotenv.config({ path: pathToDbEnvFile })
|
|
92
|
-
equal(process.env.PLT_SERVER_HOSTNAME, 'myhost')
|
|
93
|
-
equal(process.env.PORT, '6666')
|
|
94
|
-
process.env = {}
|
|
95
|
-
|
|
96
|
-
const pathToDbEnvSampleFile = join(tmpDir, '.env.sample')
|
|
97
|
-
dotenv.config({ path: pathToDbEnvSampleFile })
|
|
98
|
-
equal(process.env.PLT_SERVER_HOSTNAME, 'myhost')
|
|
99
|
-
equal(process.env.PORT, '6666')
|
|
100
|
-
|
|
101
|
-
same(plugins, { paths: [{ path: './plugins', encapsulate: false }, './routes'] })
|
|
102
|
-
ok(await isFileAccessible(join(tmpDir, 'plugins', 'example.js')))
|
|
103
|
-
ok(await isFileAccessible(join(tmpDir, 'routes', 'root.js')))
|
|
104
|
-
})
|
|
105
|
-
|
|
106
|
-
test('creates project with configuration already present', async ({ ok }) => {
|
|
107
|
-
const pathToServiceConfigFileOld = join(tmpDir, 'platformatic.service.json')
|
|
108
|
-
writeFileSync(pathToServiceConfigFileOld, JSON.stringify({ test: 'test' }))
|
|
109
|
-
const params = {
|
|
110
|
-
hostname: 'myhost',
|
|
111
|
-
port: 6666
|
|
112
|
-
}
|
|
113
|
-
await createService(params, fakeLogger, tmpDir)
|
|
114
|
-
ok(log.includes('Configuration file platformatic.service.json found, skipping creation of configuration file.'))
|
|
115
|
-
})
|
|
116
|
-
|
|
117
|
-
test('creates project with tsconfig already present', async ({ ok }) => {
|
|
118
|
-
const pathToTsConfig = join(tmpDir, 'tsconfig.json')
|
|
119
|
-
writeFileSync(pathToTsConfig, 'test')
|
|
120
|
-
const params = {
|
|
121
|
-
hostname: 'myhost',
|
|
122
|
-
port: 6666,
|
|
123
|
-
typescript: true
|
|
124
|
-
}
|
|
125
|
-
await createService(params, fakeLogger, tmpDir)
|
|
126
|
-
ok(log.includes(`Typescript configuration file ${pathToTsConfig} found, skipping creation of typescript configuration file.`))
|
|
127
|
-
})
|
|
128
|
-
|
|
129
|
-
test('creates project with plugins already present', async ({ ok }) => {
|
|
130
|
-
const pathToPlugins = join(tmpDir, 'plugins')
|
|
131
|
-
mkdirSync(pathToPlugins)
|
|
132
|
-
const params = {
|
|
133
|
-
hostname: 'myhost'
|
|
134
|
-
}
|
|
135
|
-
await createService(params, fakeLogger, tmpDir)
|
|
136
|
-
ok(log.includes('Plugins folder "plugins" found, skipping creation of plugins folder.'))
|
|
137
|
-
})
|
|
138
|
-
|
|
139
|
-
test('creates project with routes already present', async ({ ok }) => {
|
|
140
|
-
const pathToPlugins = join(tmpDir, 'routes')
|
|
141
|
-
mkdirSync(pathToPlugins)
|
|
142
|
-
const params = {
|
|
143
|
-
hostname: 'myhost'
|
|
144
|
-
}
|
|
145
|
-
await createService(params, fakeLogger, tmpDir)
|
|
146
|
-
ok(log.includes('Routes folder "routes" found, skipping creation of routes folder.'))
|
|
147
|
-
})
|