create-platformatic 0.47.2 → 0.47.3
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.47.
|
|
3
|
+
"version": "0.47.3",
|
|
4
4
|
"description": "Create platformatic-db interactive tool",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"semver": "^7.5.1",
|
|
35
35
|
"undici": "^5.22.1",
|
|
36
36
|
"which": "^3.0.1",
|
|
37
|
-
"@platformatic/config": "0.47.
|
|
37
|
+
"@platformatic/config": "0.47.3"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"ajv": "^8.12.0",
|
|
@@ -47,8 +47,8 @@
|
|
|
47
47
|
"tap": "^16.3.6",
|
|
48
48
|
"typescript": "~5.2.0",
|
|
49
49
|
"yaml": "^2.3.1",
|
|
50
|
-
"@platformatic/db": "0.47.
|
|
51
|
-
"@platformatic/service": "0.47.
|
|
50
|
+
"@platformatic/db": "0.47.3",
|
|
51
|
+
"@platformatic/service": "0.47.3"
|
|
52
52
|
},
|
|
53
53
|
"scripts": {
|
|
54
54
|
"test": "standard | snazzy && cross-env NODE_OPTIONS=\"--loader=esmock --no-warnings\" c8 tap --no-coverage test/*test.mjs test/*/*test.mjs",
|
package/src/db/create-db-cli.mjs
CHANGED
|
@@ -158,7 +158,8 @@ const createPlatformaticDB = async (_args, opts) => {
|
|
|
158
158
|
migrations: wizardOptions.defaultMigrations ? args.migrations : '',
|
|
159
159
|
plugin: generatePlugin,
|
|
160
160
|
types: useTypes,
|
|
161
|
-
typescript: useTypescript
|
|
161
|
+
typescript: useTypescript,
|
|
162
|
+
isRuntime: opts.isRuntime
|
|
162
163
|
}
|
|
163
164
|
|
|
164
165
|
const env = await createDB(params, logger, projectDir, version)
|
package/src/db/create-db.mjs
CHANGED
|
@@ -332,7 +332,6 @@ export async function createDB ({ hostname, database = 'sqlite', port, migration
|
|
|
332
332
|
const config = generateConfig(migrations, plugin, types, typescript, version)
|
|
333
333
|
await writeFile(join(currentDir, 'platformatic.db.json'), JSON.stringify(config, null, 2))
|
|
334
334
|
logger.info('Configuration file platformatic.db.json successfully created.')
|
|
335
|
-
|
|
336
335
|
const env = generateEnv(hostname, port, connectionString, typescript)
|
|
337
336
|
const envFileExists = await isFileAccessible('.env', currentDir)
|
|
338
337
|
await appendFile(join(currentDir, '.env'), env)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { readFile, writeFile } from 'fs/promises'
|
|
1
|
+
import { readFile, readdir, stat, unlink, writeFile } from 'fs/promises'
|
|
2
2
|
import { findRuntimeConfigFile } from '../utils.mjs'
|
|
3
3
|
import { join, relative, isAbsolute } from 'path'
|
|
4
4
|
import * as desm from 'desm'
|
|
@@ -33,8 +33,83 @@ async function createRuntime (logger, currentDir = process.cwd(), version, servi
|
|
|
33
33
|
} else {
|
|
34
34
|
logger.info(`Configuration file ${accessibleConfigFilename} found, skipping creation of configuration file.`)
|
|
35
35
|
}
|
|
36
|
+
if (servicesDir) {
|
|
37
|
+
const servicesDirFullPath = join(currentDir, servicesDir)
|
|
38
|
+
|
|
39
|
+
try {
|
|
40
|
+
await stat(servicesDirFullPath)
|
|
41
|
+
await cleanServicesConfig(logger, servicesDirFullPath, entrypoint)
|
|
42
|
+
await manageServicesEnvFiles(servicesDirFullPath, currentDir, entrypoint)
|
|
43
|
+
} catch (err) {
|
|
44
|
+
// do nothing. There are no services to manage, somehow.
|
|
45
|
+
}
|
|
46
|
+
}
|
|
36
47
|
|
|
37
48
|
return {}
|
|
38
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
*
|
|
52
|
+
* @param {string} servicesDir the services dir
|
|
53
|
+
* @param {string | null} entrypoint the entrypoint. If specified the function will filter it out
|
|
54
|
+
* @returns {Promise}
|
|
55
|
+
*/
|
|
56
|
+
async function getAllServices (servicesDir, entrypoint = null) {
|
|
57
|
+
const services = (await readdir(servicesDir))
|
|
58
|
+
if (entrypoint) {
|
|
59
|
+
return services.filter(dir => dir !== entrypoint)
|
|
60
|
+
}
|
|
61
|
+
return services
|
|
62
|
+
}
|
|
63
|
+
async function cleanServicesConfig (logger, servicesDir, entrypoint) {
|
|
64
|
+
const services = await getAllServices(servicesDir, entrypoint)
|
|
65
|
+
for (const svc of services) {
|
|
66
|
+
const serviceDir = join(servicesDir, svc)
|
|
67
|
+
const configFile = await findConfigFile(serviceDir)
|
|
68
|
+
if (!configFile) {
|
|
69
|
+
logger.warn(`Cannot find config file in ${serviceDir}`)
|
|
70
|
+
} else {
|
|
71
|
+
console.log(`Found config file ${configFile}`)
|
|
72
|
+
const configFilePath = join(serviceDir, configFile)
|
|
73
|
+
const config = JSON.parse(await readFile(configFilePath, 'utf8'))
|
|
74
|
+
delete config.server
|
|
75
|
+
await writeFile(configFilePath, JSON.stringify(config, null, 2))
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async function manageServicesEnvFiles (servicesDir, runtimeDir, entrypoint) {
|
|
81
|
+
let mainEnvFile = ''
|
|
82
|
+
const services = await getAllServices(servicesDir)
|
|
83
|
+
for (const svc of services) {
|
|
84
|
+
const envFile = await readFile(join(servicesDir, svc, '.env'), 'utf8')
|
|
85
|
+
if (svc === entrypoint) {
|
|
86
|
+
// copy the whole file
|
|
87
|
+
mainEnvFile += `\n${envFile}`
|
|
88
|
+
} else {
|
|
89
|
+
// read .env file
|
|
90
|
+
const lines = envFile.split('\n')
|
|
91
|
+
lines.forEach((line) => {
|
|
92
|
+
// copy to main env file only if line _doesn't_ match
|
|
93
|
+
// i.e any other config or comments
|
|
94
|
+
if (!line.match(/(PLT_LOGGER_LEVEL|PORT|PLT_SERVER_HOSTNAME)=/)) {
|
|
95
|
+
mainEnvFile += `\n${line}`
|
|
96
|
+
}
|
|
97
|
+
})
|
|
98
|
+
}
|
|
99
|
+
try {
|
|
100
|
+
await unlink(join(servicesDir, svc, '.env.sample'))
|
|
101
|
+
} catch (err) {
|
|
102
|
+
// do nothing
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
await writeFile(join(runtimeDir, '.env'), mainEnvFile)
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
async function findConfigFile (dir) {
|
|
109
|
+
const allFiles = await readdir(dir)
|
|
110
|
+
return allFiles.find((file) => {
|
|
111
|
+
return file.match(/platformatic\.(.*)\.json/)
|
|
112
|
+
})
|
|
113
|
+
}
|
|
39
114
|
|
|
40
115
|
export default createRuntime
|
|
@@ -70,7 +70,8 @@ const createPlatformaticService = async (_args, opts = {}) => {
|
|
|
70
70
|
const params = {
|
|
71
71
|
hostname: args.hostname,
|
|
72
72
|
port,
|
|
73
|
-
typescript: useTypescript
|
|
73
|
+
typescript: useTypescript,
|
|
74
|
+
isRuntime: opts.isRuntime
|
|
74
75
|
}
|
|
75
76
|
|
|
76
77
|
const env = await createService(params, logger, projectDir, version)
|