create-platformatic 0.15.0 → 0.16.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
|
@@ -6,10 +6,11 @@ import { join } from 'node:path'
|
|
|
6
6
|
const packageJsonTemplate = (addTSBuild = false) => (`\
|
|
7
7
|
{
|
|
8
8
|
"scripts": {
|
|
9
|
-
|
|
10
|
-
?
|
|
9
|
+
${addTSBuild
|
|
10
|
+
? ` "start": "yarn clean && platformatic {type} start",
|
|
11
|
+
"clean": "rm -fr ./dist",
|
|
11
12
|
"build": "npx tsc"`
|
|
12
|
-
: ''}
|
|
13
|
+
: '"start": "platformatic {type} start"'}
|
|
13
14
|
},
|
|
14
15
|
"devDependencies": {
|
|
15
16
|
"fastify": "^{fastifyVersion}"
|
package/src/db/create-db-cli.mjs
CHANGED
|
@@ -8,7 +8,7 @@ import inquirer from 'inquirer'
|
|
|
8
8
|
import { readFile, writeFile } from 'fs/promises'
|
|
9
9
|
import pino from 'pino'
|
|
10
10
|
import pretty from 'pino-pretty'
|
|
11
|
-
import { execa
|
|
11
|
+
import { execa } from 'execa'
|
|
12
12
|
import ora from 'ora'
|
|
13
13
|
import createDB from './create-db.mjs'
|
|
14
14
|
import askProjectDir from '../ask-project-dir.mjs'
|
|
@@ -95,7 +95,7 @@ const createPlatformaticDB = async (_args) => {
|
|
|
95
95
|
hostname: args.hostname,
|
|
96
96
|
port: args.port,
|
|
97
97
|
database: args.database,
|
|
98
|
-
migrations: args.migrations,
|
|
98
|
+
migrations: wizardOptions.defaultMigrations ? args.migrations : '',
|
|
99
99
|
plugin: generatePlugin,
|
|
100
100
|
types: useTypes,
|
|
101
101
|
typescript: useTypescript
|
|
@@ -125,10 +125,10 @@ const createPlatformaticDB = async (_args) => {
|
|
|
125
125
|
}
|
|
126
126
|
|
|
127
127
|
if (runPackageManagerInstall) {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
128
|
+
// We applied package manager install, so we can:
|
|
129
|
+
// - run the migrations
|
|
130
|
+
// - generate types
|
|
131
|
+
// if we don't generate migrations, we don't ask to apply them (the folder might not exist)
|
|
132
132
|
if (wizardOptions.defaultMigrations) {
|
|
133
133
|
const { applyMigrations } = await inquirer.prompt([{
|
|
134
134
|
type: 'list',
|
|
@@ -141,7 +141,7 @@ const createPlatformaticDB = async (_args) => {
|
|
|
141
141
|
if (applyMigrations) {
|
|
142
142
|
const spinner = ora('Applying migrations...').start()
|
|
143
143
|
// We need to apply migrations using the platformatic installed in the project
|
|
144
|
-
await
|
|
144
|
+
await execa(pkgManager, ['exec', 'platformatic', 'db', 'migrations', 'apply'], { cwd: projectDir })
|
|
145
145
|
spinner.succeed('...done!')
|
|
146
146
|
}
|
|
147
147
|
}
|
|
@@ -156,14 +156,14 @@ const createPlatformaticDB = async (_args) => {
|
|
|
156
156
|
|
|
157
157
|
if (generateTypes) {
|
|
158
158
|
const spinner = ora('Generating types...').start()
|
|
159
|
-
await
|
|
159
|
+
await execa(pkgManager, ['exec', 'platformatic', 'db', 'types'], { cwd: projectDir })
|
|
160
160
|
spinner.succeed('...done!')
|
|
161
161
|
}
|
|
162
162
|
}
|
|
163
|
-
await
|
|
163
|
+
await execa(pkgManager, ['exec', 'platformatic', 'db', 'schema', 'config'], { cwd: projectDir })
|
|
164
164
|
logger.info('Configuration schema successfully created.')
|
|
165
165
|
}
|
|
166
|
-
await askCreateGHAction(logger, env, 'db', useTypescript)
|
|
166
|
+
await askCreateGHAction(logger, env, 'db', useTypescript, projectDir)
|
|
167
167
|
|
|
168
168
|
if (!runPackageManagerInstall) {
|
|
169
169
|
logger.warn(`You must run the following commands in the project folder to complete the setup:
|
|
@@ -97,7 +97,7 @@ const createPlatformaticService = async (_args) => {
|
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
// We don't have the option for TS (yet) so we don't run build on TS
|
|
100
|
-
await askCreateGHAction(logger, env, 'service', false)
|
|
100
|
+
await askCreateGHAction(logger, env, 'service', false, projectDir)
|
|
101
101
|
}
|
|
102
102
|
|
|
103
103
|
export default createPlatformaticService
|
|
@@ -20,7 +20,7 @@ afterEach(() => {
|
|
|
20
20
|
rmSync(tmpDir, { recursive: true, force: true })
|
|
21
21
|
})
|
|
22
22
|
|
|
23
|
-
test('creates package.json file for db project', async ({
|
|
23
|
+
test('creates package.json file for db project', async ({ equal }) => {
|
|
24
24
|
const version = '1.2.3'
|
|
25
25
|
const fastifyVersion = '4.5.6'
|
|
26
26
|
await createPackageJson('db', version, fastifyVersion, fakeLogger, tmpDir, false)
|
|
@@ -34,7 +34,7 @@ test('creates package.json file for db project', async ({ end, equal }) => {
|
|
|
34
34
|
equal(packageJson.devDependencies.fastify, `^${fastifyVersion}`)
|
|
35
35
|
})
|
|
36
36
|
|
|
37
|
-
test('creates package.json file for service project', async ({
|
|
37
|
+
test('creates package.json file for service project', async ({ equal }) => {
|
|
38
38
|
const version = '1.2.3'
|
|
39
39
|
const fastifyVersion = '4.5.6'
|
|
40
40
|
await createPackageJson('service', version, fastifyVersion, fakeLogger, tmpDir, false)
|
|
@@ -47,7 +47,7 @@ test('creates package.json file for service project', async ({ end, equal }) =>
|
|
|
47
47
|
equal(packageJson.devDependencies.fastify, `^${fastifyVersion}`)
|
|
48
48
|
})
|
|
49
49
|
|
|
50
|
-
test('do not create package.json file because already present', async ({
|
|
50
|
+
test('do not create package.json file because already present', async ({ equal }) => {
|
|
51
51
|
const version = '1.2.3'
|
|
52
52
|
const fastifyVersion = '4.5.6'
|
|
53
53
|
const packagejson = join(tmpDir, 'package.json')
|
|
@@ -56,7 +56,7 @@ test('do not create package.json file because already present', async ({ end, eq
|
|
|
56
56
|
equal(log, `${tmpDir}/package.json found, skipping creation of package.json file.`)
|
|
57
57
|
})
|
|
58
58
|
|
|
59
|
-
test('creates package.json file with
|
|
59
|
+
test('creates package.json file with TS build', async ({ equal }) => {
|
|
60
60
|
const version = '1.2.3'
|
|
61
61
|
const fastifyVersion = '4.5.6'
|
|
62
62
|
await createPackageJson('db', version, fastifyVersion, fakeLogger, tmpDir, true)
|
|
@@ -64,7 +64,8 @@ test('creates package.json file with TD build', async ({ end, equal }) => {
|
|
|
64
64
|
const accessible = await isFileAccessible(join(tmpDir, 'package.json'))
|
|
65
65
|
equal(accessible, true)
|
|
66
66
|
const packageJson = JSON.parse(readFileSync(join(tmpDir, 'package.json')))
|
|
67
|
-
equal(packageJson.scripts.start, 'platformatic db start')
|
|
67
|
+
equal(packageJson.scripts.start, 'yarn clean && platformatic db start')
|
|
68
|
+
equal(packageJson.scripts.clean, 'rm -fr ./dist')
|
|
68
69
|
equal(packageJson.scripts.build, 'npx tsc')
|
|
69
70
|
equal(packageJson.dependencies.platformatic, `^${version}`)
|
|
70
71
|
equal(packageJson.devDependencies.fastify, `^${fastifyVersion}`)
|
|
@@ -36,7 +36,7 @@ const fakeLogger = {
|
|
|
36
36
|
info: msg => log.push(msg)
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
test('creates project with no typescript', async ({
|
|
39
|
+
test('creates project with no typescript', async ({ equal }) => {
|
|
40
40
|
const params = {
|
|
41
41
|
hostname: 'myhost',
|
|
42
42
|
port: 6666,
|
|
@@ -75,15 +75,15 @@ test('creates project with no typescript', async ({ end, equal }) => {
|
|
|
75
75
|
equal(core.openapi, true)
|
|
76
76
|
equal(migrations.dir, 'migrations')
|
|
77
77
|
|
|
78
|
-
const migrationFileDo =
|
|
78
|
+
const migrationFileDo = readFileSync(pathToMigrationFileDo, 'utf8')
|
|
79
79
|
equal(migrationFileDo, moviesMigrationDo)
|
|
80
|
-
const migrationFileUndo =
|
|
80
|
+
const migrationFileUndo = readFileSync(pathToMigrationFileUndo, 'utf8')
|
|
81
81
|
equal(migrationFileUndo, moviesMigrationUndo)
|
|
82
82
|
|
|
83
83
|
equal(await isFileAccessible(join(tmpDir, 'plugin.js')), true)
|
|
84
84
|
})
|
|
85
85
|
|
|
86
|
-
test('creates project with no typescript and no plugin', async ({
|
|
86
|
+
test('creates project with no typescript and no plugin', async ({ equal }) => {
|
|
87
87
|
const params = {
|
|
88
88
|
hostname: 'myhost',
|
|
89
89
|
port: 6666,
|
|
@@ -122,15 +122,15 @@ test('creates project with no typescript and no plugin', async ({ end, equal })
|
|
|
122
122
|
equal(core.openapi, true)
|
|
123
123
|
equal(migrations.dir, 'migrations')
|
|
124
124
|
|
|
125
|
-
const migrationFileDo =
|
|
125
|
+
const migrationFileDo = readFileSync(pathToMigrationFileDo, 'utf8')
|
|
126
126
|
equal(migrationFileDo, moviesMigrationDo)
|
|
127
|
-
const migrationFileUndo =
|
|
127
|
+
const migrationFileUndo = readFileSync(pathToMigrationFileUndo, 'utf8')
|
|
128
128
|
equal(migrationFileUndo, moviesMigrationUndo)
|
|
129
129
|
|
|
130
130
|
equal(await isFileAccessible(join(tmpDir, 'plugin.js')), false)
|
|
131
131
|
})
|
|
132
132
|
|
|
133
|
-
test('creates project with typescript', async ({
|
|
133
|
+
test('creates project with typescript', async ({ equal }) => {
|
|
134
134
|
const params = {
|
|
135
135
|
hostname: 'myhost',
|
|
136
136
|
port: 6666,
|
|
@@ -169,9 +169,9 @@ test('creates project with typescript', async ({ end, equal }) => {
|
|
|
169
169
|
equal(core.openapi, true)
|
|
170
170
|
equal(migrations.dir, 'migrations')
|
|
171
171
|
|
|
172
|
-
const migrationFileDo =
|
|
172
|
+
const migrationFileDo = readFileSync(pathToMigrationFileDo, 'utf8')
|
|
173
173
|
equal(migrationFileDo, moviesMigrationDo)
|
|
174
|
-
const migrationFileUndo =
|
|
174
|
+
const migrationFileUndo = readFileSync(pathToMigrationFileUndo, 'utf8')
|
|
175
175
|
equal(migrationFileUndo, moviesMigrationUndo)
|
|
176
176
|
|
|
177
177
|
equal(plugin.path, 'plugin.ts')
|
|
@@ -180,7 +180,7 @@ test('creates project with typescript', async ({ end, equal }) => {
|
|
|
180
180
|
equal(await isFileAccessible(join(tmpDir, 'tsconfig.json')), true)
|
|
181
181
|
})
|
|
182
182
|
|
|
183
|
-
test('creates project with configuration already present', async ({
|
|
183
|
+
test('creates project with configuration already present', async ({ ok }) => {
|
|
184
184
|
const pathToDbConfigFileOld = join(tmpDir, 'platformatic.db.json')
|
|
185
185
|
writeFileSync(pathToDbConfigFileOld, JSON.stringify({ test: 'test' }))
|
|
186
186
|
const params = {
|
|
@@ -191,7 +191,7 @@ test('creates project with configuration already present', async ({ end, equal,
|
|
|
191
191
|
ok(log.includes('Configuration file platformatic.db.json found, skipping creation of configuration file.'))
|
|
192
192
|
})
|
|
193
193
|
|
|
194
|
-
test('creates project with migration folder already present', async ({
|
|
194
|
+
test('creates project with migration folder already present', async ({ equal }) => {
|
|
195
195
|
const pathToMigrationsOld = join(tmpDir, 'migrations')
|
|
196
196
|
mkdirSync(pathToMigrationsOld)
|
|
197
197
|
const params = {
|
|
@@ -202,7 +202,7 @@ test('creates project with migration folder already present', async ({ end, equa
|
|
|
202
202
|
equal(log.includes('Migrations folder migrations found, skipping creation of migrations folder.'), true)
|
|
203
203
|
})
|
|
204
204
|
|
|
205
|
-
test('creates project with "do" migration already present', async ({
|
|
205
|
+
test('creates project with "do" migration already present', async ({ ok }) => {
|
|
206
206
|
const pathToMigrationsOld = join(tmpDir, 'migrations')
|
|
207
207
|
mkdirSync(pathToMigrationsOld)
|
|
208
208
|
const pathToMigrationFileDo = join(pathToMigrationsOld, '001.do.sql')
|
|
@@ -215,7 +215,7 @@ test('creates project with "do" migration already present', async ({ end, equal,
|
|
|
215
215
|
ok(log.includes('Migration file 001.do.sql found, skipping creation of migration file.'))
|
|
216
216
|
})
|
|
217
217
|
|
|
218
|
-
test('creates project with tsconfig already present', async ({
|
|
218
|
+
test('creates project with tsconfig already present', async ({ ok }) => {
|
|
219
219
|
const pathToTsConfig = join(tmpDir, 'tsconfig.json')
|
|
220
220
|
writeFileSync(pathToTsConfig, 'test')
|
|
221
221
|
const params = {
|
|
@@ -227,7 +227,7 @@ test('creates project with tsconfig already present', async ({ end, equal, ok })
|
|
|
227
227
|
ok(log.includes(`Typescript configuration file ${pathToTsConfig} found, skipping creation of typescript configuration file.`))
|
|
228
228
|
})
|
|
229
229
|
|
|
230
|
-
test('creates project with plugin already present', async ({
|
|
230
|
+
test('creates project with plugin already present', async ({ ok }) => {
|
|
231
231
|
const pathToPlugin = join(tmpDir, 'plugin.js')
|
|
232
232
|
writeFileSync(pathToPlugin, 'test')
|
|
233
233
|
const params = {
|
|
@@ -239,3 +239,29 @@ test('creates project with plugin already present', async ({ end, equal, ok }) =
|
|
|
239
239
|
await createDB(params, fakeLogger, tmpDir)
|
|
240
240
|
ok(log.includes(`Plugin file ${pathToPlugin} found, skipping creation of plugin file.`))
|
|
241
241
|
})
|
|
242
|
+
|
|
243
|
+
test('creates project with no default migrations', async ({ notOk }) => {
|
|
244
|
+
const params = {
|
|
245
|
+
hostname: 'myhost',
|
|
246
|
+
port: 6666,
|
|
247
|
+
plugin: false,
|
|
248
|
+
migrations: ''
|
|
249
|
+
}
|
|
250
|
+
await createDB(params, fakeLogger, tmpDir)
|
|
251
|
+
notOk(log.includes('Migrations folder migrations successfully created.'))
|
|
252
|
+
notOk(log.includes('Migration file 001.do.sql successfully created.'))
|
|
253
|
+
notOk(log.includes('Migration file 001.undo.sql successfully created.'))
|
|
254
|
+
})
|
|
255
|
+
|
|
256
|
+
test('creates project with default migrations', async ({ ok }) => {
|
|
257
|
+
const params = {
|
|
258
|
+
hostname: 'myhost',
|
|
259
|
+
port: 6666,
|
|
260
|
+
plugin: false,
|
|
261
|
+
migrations: 'migrations'
|
|
262
|
+
}
|
|
263
|
+
await createDB(params, fakeLogger, tmpDir)
|
|
264
|
+
ok(log.includes('Migrations folder migrations successfully created.'))
|
|
265
|
+
ok(log.includes('Migration file 001.do.sql successfully created.'))
|
|
266
|
+
ok(log.includes('Migration file 001.undo.sql successfully created.'))
|
|
267
|
+
})
|