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.
@@ -1,8 +1,9 @@
1
- import { writeFile, mkdir, readFile, appendFile } from 'fs/promises'
1
+ import { writeFile, readFile, appendFile } from 'fs/promises'
2
2
  import { join } from 'path'
3
3
  import * as desm from 'desm'
4
4
  import { findServiceConfigFile, isFileAccessible } from '../utils.mjs'
5
5
  import { getTsConfig } from '../get-tsconfig.mjs'
6
+ import { generatePlugins } from '../create-plugins.mjs'
6
7
 
7
8
  const TS_OUT_DIR = 'dist'
8
9
 
@@ -55,76 +56,6 @@ PLT_TYPESCRIPT=true
55
56
  return env
56
57
  }
57
58
 
58
- const JS_PLUGIN_WITH_TYPES_SUPPORT = `\
59
- /// <reference path="../global.d.ts" />
60
- 'use strict'
61
- /** @param {import('fastify').FastifyInstance} fastify */
62
- module.exports = async function (fastify, opts) {
63
- fastify.decorate('example', 'foobar')
64
- }
65
- `
66
-
67
- const TS_PLUGIN_WITH_TYPES_SUPPORT = `\
68
- /// <reference path="../global.d.ts" />
69
- import { FastifyInstance, FastifyPluginOptions } from 'fastify'
70
-
71
- export default async function (fastify: FastifyInstance, opts: FastifyPluginOptions) {
72
- fastify.decorate('example', 'foobar')
73
- }
74
- `
75
-
76
- const JS_ROUTES_WITH_TYPES_SUPPORT = `\
77
- /// <reference path="../global.d.ts" />
78
- 'use strict'
79
- /** @param {import('fastify').FastifyInstance} fastify */
80
- module.exports = async function (fastify, opts) {
81
- fastify.get('/', async (request, reply) => {
82
- return { hello: fastify.example }
83
- })
84
- }
85
- `
86
-
87
- const TS_ROUTES_WITH_TYPES_SUPPORT = `\
88
- /// <reference path="../global.d.ts" />
89
- import { FastifyInstance, FastifyPluginOptions } from 'fastify'
90
-
91
- declare module 'fastify' {
92
- interface FastifyInstance {
93
- example: string
94
- }
95
- }
96
-
97
- export default async function (fastify: FastifyInstance, opts: FastifyPluginOptions) {
98
- fastify.get('/', async (request, reply) => {
99
- return { hello: fastify.example }
100
- })
101
- }
102
- `
103
-
104
- async function generatePluginWithTypesSupport (logger, currentDir, isTypescript) {
105
- await mkdir(join(currentDir, 'plugins'))
106
- const pluginTemplate = isTypescript
107
- ? TS_PLUGIN_WITH_TYPES_SUPPORT
108
- : JS_PLUGIN_WITH_TYPES_SUPPORT
109
- const pluginName = isTypescript
110
- ? 'example.ts'
111
- : 'example.js'
112
- await writeFile(join(currentDir, 'plugins', pluginName), pluginTemplate)
113
- logger.info('Plugins folder "plugins" successfully created.')
114
- }
115
-
116
- async function generateRouteWithTypesSupport (logger, currentDir, isTypescript) {
117
- await mkdir(join(currentDir, 'routes'))
118
- const routesTemplate = isTypescript
119
- ? TS_ROUTES_WITH_TYPES_SUPPORT
120
- : JS_ROUTES_WITH_TYPES_SUPPORT
121
- const routesName = isTypescript
122
- ? 'root.ts'
123
- : 'root.js'
124
- await writeFile(join(currentDir, 'routes', routesName), routesTemplate)
125
- logger.info('Routes folder "routes" successfully created.')
126
- }
127
-
128
59
  async function createService ({ hostname, port, typescript = false }, logger, currentDir = process.cwd(), version) {
129
60
  if (!version) {
130
61
  const pkg = await readFile(desm.join(import.meta.url, '..', '..', 'package.json'))
@@ -167,19 +98,7 @@ async function createService ({ hostname, port, typescript = false }, logger, cu
167
98
  }
168
99
  }
169
100
 
170
- const pluginFolderExists = await isFileAccessible('plugins', currentDir)
171
- if (!pluginFolderExists) {
172
- await generatePluginWithTypesSupport(logger, currentDir, typescript)
173
- } else {
174
- logger.info('Plugins folder "plugins" found, skipping creation of plugins folder.')
175
- }
176
-
177
- const routeFolderExists = await isFileAccessible('routes', currentDir)
178
- if (!routeFolderExists) {
179
- await generateRouteWithTypesSupport(logger, currentDir, typescript)
180
- } else {
181
- logger.info('Routes folder "routes" found, skipping creation of routes folder.')
182
- }
101
+ await generatePlugins(logger, currentDir, typescript, 'service')
183
102
 
184
103
  const output = {
185
104
  PLT_SERVER_LOGGER_LEVEL: 'info',
@@ -1,84 +0,0 @@
1
- import { test } from 'tap'
2
- import { getRunPackageManagerInstall, getUseTypescript, getPort, getOverwriteReadme } from '../src/cli-options.mjs'
3
-
4
- test('getRunPackageManagerInstall', async ({ same }) => {
5
- same(
6
- getRunPackageManagerInstall('npm'),
7
- {
8
- type: 'list',
9
- name: 'runPackageManagerInstall',
10
- message: 'Do you want to run npm install?',
11
- default: true,
12
- choices: [{ name: 'yes', value: true }, { name: 'no', value: false }]
13
- }
14
- )
15
- })
16
-
17
- test('getUseTypescript', async ({ same }) => {
18
- same(
19
- getUseTypescript(true),
20
- {
21
- type: 'list',
22
- when: false,
23
- name: 'useTypescript',
24
- message: 'Do you want to use TypeScript?',
25
- default: true,
26
- choices: [{ name: 'yes', value: true }, { name: 'no', value: false }]
27
- }
28
- )
29
- })
30
-
31
- test('getOverwriteReadme', async ({ same }) => {
32
- same(
33
- getOverwriteReadme(),
34
- {
35
- type: 'list',
36
- name: 'shouldReplace',
37
- message: 'Do you want to overwrite the existing README.md?',
38
- default: true,
39
- choices: [{ name: 'yes', value: true }, { name: 'no', value: false }]
40
- }
41
- )
42
- })
43
-
44
- test('getPort', async ({ same }) => {
45
- same(
46
- getPort(undefined),
47
- {
48
- type: 'input',
49
- name: 'port',
50
- message: 'What port do you want to use?',
51
- default: 3042
52
- }
53
- )
54
-
55
- same(
56
- getPort(undefined),
57
- {
58
- type: 'input',
59
- name: 'port',
60
- message: 'What port do you want to use?',
61
- default: 3043
62
- }
63
- )
64
-
65
- same(
66
- getPort(1234),
67
- {
68
- type: 'input',
69
- name: 'port',
70
- message: 'What port do you want to use?',
71
- default: 1234
72
- }
73
- )
74
-
75
- same(
76
- getPort(undefined),
77
- {
78
- type: 'input',
79
- name: 'port',
80
- message: 'What port do you want to use?',
81
- default: 3044
82
- }
83
- )
84
- })
@@ -1,75 +0,0 @@
1
- import createComposer from '../../src/composer/create-composer.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
- import dotenv from 'dotenv'
7
-
8
- const base = tmpdir()
9
- let tmpDir
10
- let log = []
11
- beforeEach(() => {
12
- tmpDir = mkdtempSync(join(base, 'test-create-platformatic-'))
13
- })
14
-
15
- afterEach(() => {
16
- log = []
17
- rmSync(tmpDir, { recursive: true, force: true })
18
- process.env = {}
19
- })
20
-
21
- const fakeLogger = {
22
- debug: msg => log.push(msg),
23
- info: msg => log.push(msg)
24
- }
25
-
26
- test('creates composer', async ({ equal, same, ok }) => {
27
- const params = {
28
- hostname: 'myhost',
29
- port: 6666,
30
- typescript: false
31
- }
32
-
33
- await createComposer(params, fakeLogger, tmpDir)
34
-
35
- const pathToComposerConfigFile = join(tmpDir, 'platformatic.composer.json')
36
- const composerConfigFile = readFileSync(pathToComposerConfigFile, 'utf8')
37
- const composerConfig = JSON.parse(composerConfigFile)
38
- const { server, composer } = composerConfig
39
-
40
- equal(server.hostname, '{PLT_SERVER_HOSTNAME}')
41
- equal(server.port, '{PORT}')
42
-
43
- const pathToDbEnvFile = join(tmpDir, '.env')
44
- dotenv.config({ path: pathToDbEnvFile })
45
- equal(process.env.PLT_SERVER_HOSTNAME, 'myhost')
46
- equal(process.env.PORT, '6666')
47
- process.env = {}
48
-
49
- const pathToDbEnvSampleFile = join(tmpDir, '.env.sample')
50
- dotenv.config({ path: pathToDbEnvSampleFile })
51
- equal(process.env.PLT_SERVER_HOSTNAME, 'myhost')
52
- equal(process.env.PORT, '6666')
53
-
54
- same(composer, {
55
- services: [{
56
- id: 'example',
57
- origin: '{PLT_EXAMPLE_ORIGIN}',
58
- openapi: {
59
- url: '/documentation/json'
60
- }
61
- }],
62
- refreshTimeout: 1000
63
- })
64
- })
65
-
66
- test('creates project with configuration already present', async ({ ok }) => {
67
- const pathToComposerConfigFileOld = join(tmpDir, 'platformatic.composer.json')
68
- writeFileSync(pathToComposerConfigFileOld, JSON.stringify({ test: 'test' }))
69
- const params = {
70
- hostname: 'myhost',
71
- port: 6666
72
- }
73
- await createComposer(params, fakeLogger, tmpDir)
74
- ok(log.includes('Configuration file platformatic.composer.json found, skipping creation of configuration file.'))
75
- })
@@ -1,35 +0,0 @@
1
- import { test, beforeEach, afterEach } from 'tap'
2
- import { tmpdir } from 'os'
3
- import { isFileAccessible } from '../src/utils.mjs'
4
- import { createGitignore } from '../src/create-gitignore.mjs'
5
- import { mkdtempSync, rmSync, writeFileSync } from 'fs'
6
- import { join } from 'path'
7
-
8
- let log = ''
9
- const fakeLogger = {
10
- debug: msg => { log = msg }
11
- }
12
-
13
- let tmpDir
14
- beforeEach(() => {
15
- log = ''
16
- tmpDir = mkdtempSync(join(tmpdir(), 'test-create-platformatic-'))
17
- })
18
-
19
- afterEach(() => {
20
- rmSync(tmpDir, { recursive: true, force: true })
21
- })
22
-
23
- test('creates gitignore file', async ({ end, equal }) => {
24
- await createGitignore(fakeLogger, tmpDir)
25
- equal(log, `Gitignore file ${join(tmpDir, '.gitignore')} successfully created.`)
26
- const accessible = await isFileAccessible(join(tmpDir, '.gitignore'))
27
- equal(accessible, true)
28
- })
29
-
30
- test('do not create gitignore file because already present', async ({ end, equal }) => {
31
- const gitignore = join(tmpDir, '.gitignore')
32
- writeFileSync(gitignore, 'TEST')
33
- await createGitignore(fakeLogger, tmpDir)
34
- equal(log, `Gitignore file ${join(tmpDir, '.gitignore')} found, skipping creation of gitignore file.`)
35
- })
@@ -1,81 +0,0 @@
1
- import { test, beforeEach, afterEach } from 'tap'
2
- import { tmpdir } from 'os'
3
- import { isFileAccessible } from '../src/utils.mjs'
4
- import { createPackageJson } from '../src/create-package-json.mjs'
5
- import { mkdtempSync, rmSync, writeFileSync, readFileSync } from 'fs'
6
- import { join } from 'path'
7
-
8
- let log = ''
9
- const fakeLogger = {
10
- debug: msg => { log = msg }
11
- }
12
-
13
- let tmpDir
14
- beforeEach(() => {
15
- log = ''
16
- tmpDir = mkdtempSync(join(tmpdir(), 'test-create-platformatic-'))
17
- })
18
-
19
- afterEach(() => {
20
- rmSync(tmpDir, { recursive: true, force: true })
21
- })
22
-
23
- test('creates package.json file for db project', async ({ equal }) => {
24
- const version = '1.2.3'
25
- const fastifyVersion = '4.5.6'
26
- const addTSBuild = false
27
- const scripts = {}
28
- const dependencies = {
29
- '@platformatic/db': `^${version}`
30
- }
31
- await createPackageJson(version, fastifyVersion, fakeLogger, tmpDir, addTSBuild, scripts, dependencies)
32
- equal(log, `${join(tmpDir, 'package.json')} successfully created.`)
33
- const accessible = await isFileAccessible(join(tmpDir, 'package.json'))
34
- equal(accessible, true)
35
- const packageJson = JSON.parse(readFileSync(join(tmpDir, 'package.json')))
36
- equal(packageJson.scripts.start, 'platformatic start')
37
- equal(packageJson.scripts.build, undefined)
38
- equal(packageJson.dependencies.platformatic, `^${version}`)
39
- equal(packageJson.dependencies['@platformatic/db'], `^${version}`)
40
- equal(packageJson.devDependencies.fastify, `^${fastifyVersion}`)
41
- })
42
-
43
- test('creates package.json file for service project', async ({ equal }) => {
44
- const version = '1.2.3'
45
- const fastifyVersion = '4.5.6'
46
- const addTSBuild = false
47
- await createPackageJson(version, fastifyVersion, fakeLogger, tmpDir, addTSBuild)
48
- equal(log, `${join(tmpDir, 'package.json')} successfully created.`)
49
- const accessible = await isFileAccessible(join(tmpDir, 'package.json'))
50
- equal(accessible, true)
51
- const packageJson = JSON.parse(readFileSync(join(tmpDir, 'package.json')))
52
- equal(packageJson.scripts.start, 'platformatic start')
53
- equal(packageJson.dependencies.platformatic, `^${version}`)
54
- equal(packageJson.devDependencies.fastify, `^${fastifyVersion}`)
55
- })
56
-
57
- test('do not create package.json file because already present', async ({ equal }) => {
58
- const version = '1.2.3'
59
- const fastifyVersion = '4.5.6'
60
- const addTSBuild = false
61
- const packagejson = join(tmpDir, 'package.json')
62
- writeFileSync(packagejson, 'TEST')
63
- await createPackageJson(version, fastifyVersion, fakeLogger, tmpDir, addTSBuild)
64
- equal(log, `${join(tmpDir, 'package.json')} found, skipping creation of package.json file.`)
65
- })
66
-
67
- test('creates package.json file with TS build', async ({ equal }) => {
68
- const version = '1.2.3'
69
- const fastifyVersion = '4.5.6'
70
- const addTSBuild = true
71
- await createPackageJson(version, fastifyVersion, fakeLogger, tmpDir, addTSBuild)
72
- equal(log, `${join(tmpDir, 'package.json')} successfully created.`)
73
- const accessible = await isFileAccessible(join(tmpDir, 'package.json'))
74
- equal(accessible, true)
75
- const packageJson = JSON.parse(readFileSync(join(tmpDir, 'package.json')))
76
- equal(packageJson.scripts.start, 'platformatic start')
77
- equal(packageJson.scripts.clean, 'rm -fr ./dist')
78
- equal(packageJson.scripts.build, 'platformatic compile')
79
- equal(packageJson.dependencies.platformatic, `^${version}`)
80
- equal(packageJson.devDependencies.fastify, `^${fastifyVersion}`)
81
- })
@@ -1,295 +0,0 @@
1
- import createDB from '../../src/db/create-db.mjs'
2
- import { test, beforeEach, afterEach } from 'tap'
3
- import { isFileAccessible } from '../../src/utils.mjs'
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 { schema } from '@platformatic/db'
9
- import Ajv from 'ajv'
10
-
11
- const moviesMigrationDo = `
12
- -- Add SQL in this file to create the database tables for your API
13
- CREATE TABLE IF NOT EXISTS movies (
14
- id INTEGER PRIMARY KEY,
15
- title TEXT NOT NULL
16
- );
17
- `
18
-
19
- const moviesMigrationUndo = `
20
- -- Add SQL in this file to drop the database tables
21
- DROP TABLE movies;
22
- `
23
-
24
- const base = tmpdir()
25
- let tmpDir
26
- let log = []
27
- beforeEach(() => {
28
- tmpDir = mkdtempSync(join(base, 'test-create-platformatic-'))
29
- })
30
-
31
- afterEach(() => {
32
- log = []
33
- rmSync(tmpDir, { recursive: true, force: true })
34
- process.env = {}
35
- })
36
-
37
- const fakeLogger = {
38
- debug: msg => log.push(msg),
39
- info: msg => log.push(msg)
40
- }
41
-
42
- test('creates project with no typescript', async ({ equal }) => {
43
- const params = {
44
- hostname: 'myhost',
45
- port: 6666,
46
- plugin: true
47
- }
48
-
49
- await createDB(params, fakeLogger, tmpDir)
50
-
51
- const pathToDbConfigFile = join(tmpDir, 'platformatic.db.json')
52
- const pathToMigrationFolder = join(tmpDir, 'migrations')
53
- const pathToMigrationFileDo = join(pathToMigrationFolder, '001.do.sql')
54
- const pathToMigrationFileUndo = join(pathToMigrationFolder, '001.undo.sql')
55
-
56
- const dbConfigFile = readFileSync(pathToDbConfigFile, 'utf8')
57
- const dbConfig = JSON.parse(dbConfigFile)
58
- const { server, db, migrations } = dbConfig
59
- const ajv = new Ajv({ strict: false })
60
- ajv.addKeyword('relativePath')
61
- const validate = ajv.compile(schema)
62
- equal(validate(dbConfig), true)
63
-
64
- equal(server.hostname, '{PLT_SERVER_HOSTNAME}')
65
- equal(server.port, '{PORT}')
66
- equal(db.connectionString, '{DATABASE_URL}')
67
- equal(db.schemalock, true)
68
-
69
- const pathToDbEnvFile = join(tmpDir, '.env')
70
- dotenv.config({ path: pathToDbEnvFile })
71
- equal(process.env.PLT_SERVER_HOSTNAME, 'myhost')
72
- equal(process.env.PORT, '6666')
73
- equal(process.env.DATABASE_URL, 'sqlite://./db.sqlite')
74
- process.env = {}
75
-
76
- const pathToDbEnvSampleFile = join(tmpDir, '.env.sample')
77
- dotenv.config({ path: pathToDbEnvSampleFile })
78
- equal(process.env.PLT_SERVER_HOSTNAME, 'myhost')
79
- equal(process.env.PORT, '6666')
80
- equal(process.env.DATABASE_URL, 'sqlite://./db.sqlite')
81
-
82
- equal(db.graphql, true)
83
- equal(db.openapi, true)
84
- equal(migrations.dir, 'migrations')
85
-
86
- const migrationFileDo = readFileSync(pathToMigrationFileDo, 'utf8')
87
- equal(migrationFileDo, moviesMigrationDo)
88
- const migrationFileUndo = readFileSync(pathToMigrationFileUndo, 'utf8')
89
- equal(migrationFileUndo, moviesMigrationUndo)
90
-
91
- equal(await isFileAccessible(join(tmpDir, 'plugin.js')), true)
92
- })
93
-
94
- test('creates project with no typescript and no plugin', async ({ equal }) => {
95
- const params = {
96
- hostname: 'myhost',
97
- port: 6666,
98
- plugin: false,
99
- connectionString: 'sqlite://./custom/path/to/db.sqlite'
100
- }
101
-
102
- await createDB(params, fakeLogger, tmpDir)
103
-
104
- const pathToDbConfigFile = join(tmpDir, 'platformatic.db.json')
105
- const pathToMigrationFolder = join(tmpDir, 'migrations')
106
- const pathToMigrationFileDo = join(pathToMigrationFolder, '001.do.sql')
107
- const pathToMigrationFileUndo = join(pathToMigrationFolder, '001.undo.sql')
108
-
109
- const dbConfigFile = readFileSync(pathToDbConfigFile, 'utf8')
110
- const dbConfig = JSON.parse(dbConfigFile)
111
- const { server, db, migrations } = dbConfig
112
-
113
- equal(server.hostname, '{PLT_SERVER_HOSTNAME}')
114
- equal(server.port, '{PORT}')
115
- equal(db.connectionString, '{DATABASE_URL}')
116
-
117
- const pathToDbEnvFile = join(tmpDir, '.env')
118
- dotenv.config({ path: pathToDbEnvFile })
119
- equal(process.env.PLT_SERVER_HOSTNAME, 'myhost')
120
- equal(process.env.PORT, '6666')
121
- equal(process.env.DATABASE_URL, 'sqlite://./custom/path/to/db.sqlite')
122
- process.env = {}
123
-
124
- const pathToDbEnvSampleFile = join(tmpDir, '.env.sample')
125
- dotenv.config({ path: pathToDbEnvSampleFile })
126
- equal(process.env.PLT_SERVER_HOSTNAME, 'myhost')
127
- equal(process.env.PORT, '6666')
128
- equal(process.env.DATABASE_URL, 'sqlite://./db.sqlite')
129
-
130
- equal(db.graphql, true)
131
- equal(db.openapi, true)
132
- equal(migrations.dir, 'migrations')
133
-
134
- const migrationFileDo = readFileSync(pathToMigrationFileDo, 'utf8')
135
- equal(migrationFileDo, moviesMigrationDo)
136
- const migrationFileUndo = readFileSync(pathToMigrationFileUndo, 'utf8')
137
- equal(migrationFileUndo, moviesMigrationUndo)
138
-
139
- equal(await isFileAccessible(join(tmpDir, 'plugin.js')), false)
140
- })
141
-
142
- test('creates project with no migrations', async ({ equal }) => {
143
- const params = {
144
- hostname: 'myhost',
145
- port: 6666,
146
- migrations: ''
147
- }
148
-
149
- await createDB(params, fakeLogger, tmpDir)
150
-
151
- const pathToDbConfigFile = join(tmpDir, 'platformatic.db.json')
152
- const dbConfigFile = readFileSync(pathToDbConfigFile, 'utf8')
153
- const dbConfig = JSON.parse(dbConfigFile)
154
- const { migrations } = dbConfig
155
-
156
- equal(migrations, undefined)
157
- })
158
-
159
- test('creates project with typescript', async ({ equal, same }) => {
160
- const params = {
161
- hostname: 'myhost',
162
- port: 6666,
163
- typescript: true
164
- }
165
-
166
- await createDB(params, fakeLogger, tmpDir)
167
-
168
- const pathToDbConfigFile = join(tmpDir, 'platformatic.db.json')
169
- const pathToMigrationFolder = join(tmpDir, 'migrations')
170
- const pathToMigrationFileDo = join(pathToMigrationFolder, '001.do.sql')
171
- const pathToMigrationFileUndo = join(pathToMigrationFolder, '001.undo.sql')
172
-
173
- const dbConfigFile = readFileSync(pathToDbConfigFile, 'utf8')
174
- const dbConfig = JSON.parse(dbConfigFile)
175
- const { server, db, migrations, plugins } = dbConfig
176
-
177
- equal(server.hostname, '{PLT_SERVER_HOSTNAME}')
178
- equal(server.port, '{PORT}')
179
- equal(db.connectionString, '{DATABASE_URL}')
180
-
181
- const pathToDbEnvFile = join(tmpDir, '.env')
182
- dotenv.config({ path: pathToDbEnvFile })
183
- equal(process.env.PLT_SERVER_HOSTNAME, 'myhost')
184
- equal(process.env.PORT, '6666')
185
- equal(process.env.DATABASE_URL, 'sqlite://./db.sqlite')
186
- equal(process.env.PLT_TYPESCRIPT, 'true')
187
- process.env = {}
188
-
189
- const pathToDbEnvSampleFile = join(tmpDir, '.env.sample')
190
- dotenv.config({ path: pathToDbEnvSampleFile })
191
- equal(process.env.PLT_SERVER_HOSTNAME, 'myhost')
192
- equal(process.env.PORT, '6666')
193
- equal(process.env.DATABASE_URL, 'sqlite://./db.sqlite')
194
- equal(process.env.PLT_TYPESCRIPT, 'true')
195
-
196
- equal(db.graphql, true)
197
- equal(db.openapi, true)
198
- equal(migrations.dir, 'migrations')
199
-
200
- const migrationFileDo = readFileSync(pathToMigrationFileDo, 'utf8')
201
- equal(migrationFileDo, moviesMigrationDo)
202
- const migrationFileUndo = readFileSync(pathToMigrationFileUndo, 'utf8')
203
- equal(migrationFileUndo, moviesMigrationUndo)
204
-
205
- same(plugins.paths, ['plugin.ts'])
206
- equal(plugins.typescript, '{PLT_TYPESCRIPT}')
207
- equal(await isFileAccessible(join(tmpDir, 'plugin.ts')), true)
208
- equal(await isFileAccessible(join(tmpDir, 'tsconfig.json')), true)
209
- })
210
-
211
- test('creates project with configuration already present', async ({ ok }) => {
212
- const pathToDbConfigFileOld = join(tmpDir, 'platformatic.db.json')
213
- writeFileSync(pathToDbConfigFileOld, JSON.stringify({ test: 'test' }))
214
- const params = {
215
- hostname: 'myhost',
216
- port: 6666
217
- }
218
- await createDB(params, fakeLogger, tmpDir)
219
- ok(log.includes('Configuration file platformatic.db.json found, skipping creation of configuration file.'))
220
- })
221
-
222
- test('creates project with migration folder already present', async ({ equal }) => {
223
- const pathToMigrationsOld = join(tmpDir, 'migrations')
224
- mkdirSync(pathToMigrationsOld)
225
- const params = {
226
- hostname: 'myhost',
227
- port: 6666
228
- }
229
- await createDB(params, fakeLogger, tmpDir)
230
- equal(log.includes('Migrations folder migrations found, skipping creation of migrations folder.'), true)
231
- })
232
-
233
- test('creates project with "do" migration already present', async ({ ok }) => {
234
- const pathToMigrationsOld = join(tmpDir, 'migrations')
235
- mkdirSync(pathToMigrationsOld)
236
- const pathToMigrationFileDo = join(pathToMigrationsOld, '001.do.sql')
237
- writeFileSync(pathToMigrationFileDo, 'test')
238
- const params = {
239
- hostname: 'myhost',
240
- port: 6666
241
- }
242
- await createDB(params, fakeLogger, tmpDir)
243
- ok(log.includes('Migration file 001.do.sql found, skipping creation of migration file.'))
244
- })
245
-
246
- test('creates project with tsconfig already present', async ({ ok }) => {
247
- const pathToTsConfig = join(tmpDir, 'tsconfig.json')
248
- writeFileSync(pathToTsConfig, 'test')
249
- const params = {
250
- hostname: 'myhost',
251
- port: 6666,
252
- typescript: true
253
- }
254
- await createDB(params, fakeLogger, tmpDir)
255
- ok(log.includes(`Typescript configuration file ${pathToTsConfig} found, skipping creation of typescript configuration file.`))
256
- })
257
-
258
- test('creates project with plugin already present', async ({ ok }) => {
259
- const pathToPlugin = join(tmpDir, 'plugin.js')
260
- writeFileSync(pathToPlugin, 'test')
261
- const params = {
262
- hostname: 'myhost',
263
- port: 6666,
264
- plugin: true,
265
- types: true
266
- }
267
- await createDB(params, fakeLogger, tmpDir)
268
- ok(log.includes(`Plugin file ${pathToPlugin} found, skipping creation of plugin file.`))
269
- })
270
-
271
- test('creates project with no default migrations', async ({ notOk }) => {
272
- const params = {
273
- hostname: 'myhost',
274
- port: 6666,
275
- plugin: false,
276
- migrations: ''
277
- }
278
- await createDB(params, fakeLogger, tmpDir)
279
- notOk(log.includes('Migrations folder migrations successfully created.'))
280
- notOk(log.includes('Migration file 001.do.sql successfully created.'))
281
- notOk(log.includes('Migration file 001.undo.sql successfully created.'))
282
- })
283
-
284
- test('creates project with default migrations', async ({ ok }) => {
285
- const params = {
286
- hostname: 'myhost',
287
- port: 6666,
288
- plugin: false,
289
- migrations: 'migrations'
290
- }
291
- await createDB(params, fakeLogger, tmpDir)
292
- ok(log.includes('Migrations folder migrations successfully created.'))
293
- ok(log.includes('Migration file 001.do.sql successfully created.'))
294
- ok(log.includes('Migration file 001.undo.sql successfully created.'))
295
- })
@@ -1,8 +0,0 @@
1
- import { test } from 'tap'
2
- import * as funcs from '../create-platformatic.mjs'
3
- test('Should export functions', async ({ ok }) => {
4
- ok(funcs.createPackageJson)
5
- ok(funcs.createGitignore)
6
- ok(funcs.getDependencyVersion)
7
- ok(funcs.getVersion)
8
- })