create-platformatic 1.1.1 → 1.3.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/create-platformatic.mjs +1 -1
- package/package.json +7 -5
- package/src/cli-options.mjs +10 -0
- package/src/composer/create-composer-cli.mjs +13 -4
- package/src/composer/create-composer.mjs +50 -15
- package/src/create-git-repository.mjs +105 -0
- package/src/db/create-db-cli.mjs +7 -4
- package/src/db/create-db.mjs +12 -10
- package/src/index.mjs +2 -0
- package/src/runtime/create-runtime-cli.mjs +7 -3
- package/src/runtime/create-runtime.mjs +7 -2
- package/src/service/create-service-cli.mjs +8 -3
- package/src/service/create-service.mjs +6 -2
package/create-platformatic.mjs
CHANGED
|
@@ -37,5 +37,5 @@ export {
|
|
|
37
37
|
createDynamicWorkspaceGHAction
|
|
38
38
|
} from './src/ghaction.mjs'
|
|
39
39
|
|
|
40
|
-
export { createGitignore, createPackageJson, getDependencyVersion, getVersion } from './src/index.mjs'
|
|
40
|
+
export { createGitignore, createGitRepository, createPackageJson, getDependencyVersion, getVersion } from './src/index.mjs'
|
|
41
41
|
export { default as createService } from './src/service/create-service.mjs'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-platformatic",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Create platformatic-db interactive tool",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -32,9 +32,10 @@
|
|
|
32
32
|
"pino-pretty": "^10.2.0",
|
|
33
33
|
"pupa": "^3.1.0",
|
|
34
34
|
"semver": "^7.5.4",
|
|
35
|
+
"strip-ansi": "^7.1.0",
|
|
35
36
|
"undici": "^5.25.4",
|
|
36
37
|
"which": "^3.0.1",
|
|
37
|
-
"@platformatic/config": "1.
|
|
38
|
+
"@platformatic/config": "1.3.0"
|
|
38
39
|
},
|
|
39
40
|
"devDependencies": {
|
|
40
41
|
"ajv": "^8.12.0",
|
|
@@ -47,11 +48,12 @@
|
|
|
47
48
|
"tap": "^16.3.9",
|
|
48
49
|
"typescript": "~5.2.2",
|
|
49
50
|
"yaml": "^2.3.2",
|
|
50
|
-
"@platformatic/db": "1.
|
|
51
|
-
"@platformatic/service": "1.
|
|
51
|
+
"@platformatic/db": "1.3.0",
|
|
52
|
+
"@platformatic/service": "1.3.0"
|
|
52
53
|
},
|
|
53
54
|
"scripts": {
|
|
54
|
-
"test": "
|
|
55
|
+
"test:cli": "tap --no-coverage test/cli/*test.mjs -t120",
|
|
56
|
+
"test": "standard | snazzy && cross-env NODE_OPTIONS=\"--loader=esmock --no-warnings\" c8 tap --no-coverage test/*test.mjs test/*[!cli]/*test.mjs && npm run test:cli",
|
|
55
57
|
"lint": "standard | snazzy"
|
|
56
58
|
}
|
|
57
59
|
}
|
package/src/cli-options.mjs
CHANGED
|
@@ -19,6 +19,16 @@ export const getUseTypescript = typescript => {
|
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
export const getInitGitRepository = () => {
|
|
23
|
+
return {
|
|
24
|
+
type: 'list',
|
|
25
|
+
name: 'initGitRepository',
|
|
26
|
+
message: 'Do you want to init the git repository?',
|
|
27
|
+
default: false,
|
|
28
|
+
choices: [{ name: 'yes', value: true }, { name: 'no', value: false }]
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
22
32
|
let port = 3042
|
|
23
33
|
export const getPort = (nextPort) => {
|
|
24
34
|
if (nextPort === undefined) {
|
|
@@ -11,7 +11,7 @@ import { execa } from 'execa'
|
|
|
11
11
|
import ora from 'ora'
|
|
12
12
|
import createComposer from './create-composer.mjs'
|
|
13
13
|
import askDir from '../ask-dir.mjs'
|
|
14
|
-
import { getRunPackageManagerInstall, getPort } from '../cli-options.mjs'
|
|
14
|
+
import { getRunPackageManagerInstall, getPort, getUseTypescript, getInitGitRepository } from '../cli-options.mjs'
|
|
15
15
|
import { createReadme } from '../create-readme.mjs'
|
|
16
16
|
import { stat } from 'node:fs/promises'
|
|
17
17
|
import { join } from 'path'
|
|
@@ -61,6 +61,7 @@ const createPlatformaticComposer = async (_args, opts) => {
|
|
|
61
61
|
const portQuestion = getPort(args.port)
|
|
62
62
|
portQuestion.when = !isRuntimeContext
|
|
63
63
|
toAsk.push(portQuestion)
|
|
64
|
+
toAsk.push(getUseTypescript(args.typescript))
|
|
64
65
|
|
|
65
66
|
if (isRuntimeContext) {
|
|
66
67
|
const servicesNames = opts.runtimeContext.servicesNames.filter(
|
|
@@ -90,12 +91,18 @@ const createPlatformaticComposer = async (_args, opts) => {
|
|
|
90
91
|
choices: [{ name: 'yes', value: true }, { name: 'no', value: false }]
|
|
91
92
|
})
|
|
92
93
|
}
|
|
94
|
+
|
|
95
|
+
if (!opts.skipGitRepository) {
|
|
96
|
+
toAsk.push(getInitGitRepository())
|
|
97
|
+
}
|
|
93
98
|
const {
|
|
94
99
|
runPackageManagerInstall,
|
|
95
100
|
servicesToCompose,
|
|
96
101
|
port,
|
|
97
102
|
staticWorkspaceGitHubAction,
|
|
98
|
-
dynamicWorkspaceGitHubAction
|
|
103
|
+
dynamicWorkspaceGitHubAction,
|
|
104
|
+
useTypescript,
|
|
105
|
+
initGitRepository
|
|
99
106
|
} = await inquirer.prompt(toAsk)
|
|
100
107
|
|
|
101
108
|
// Create the project directory
|
|
@@ -108,7 +115,9 @@ const createPlatformaticComposer = async (_args, opts) => {
|
|
|
108
115
|
servicesToCompose,
|
|
109
116
|
staticWorkspaceGitHubAction,
|
|
110
117
|
dynamicWorkspaceGitHubAction,
|
|
111
|
-
runtimeContext: opts.runtimeContext
|
|
118
|
+
runtimeContext: opts.runtimeContext,
|
|
119
|
+
typescript: useTypescript,
|
|
120
|
+
initGitRepository
|
|
112
121
|
}
|
|
113
122
|
|
|
114
123
|
await createComposer(
|
|
@@ -123,7 +132,7 @@ const createPlatformaticComposer = async (_args, opts) => {
|
|
|
123
132
|
// Create the package.json, notes that we don't have the option for TS (yet) so we don't generate
|
|
124
133
|
// the package.json with the TS build
|
|
125
134
|
if (!opts.skipPackageJson) {
|
|
126
|
-
await createPackageJson(version, fastifyVersion, logger, projectDir,
|
|
135
|
+
await createPackageJson(version, fastifyVersion, logger, projectDir, useTypescript)
|
|
127
136
|
}
|
|
128
137
|
if (!opts.skipGitignore) {
|
|
129
138
|
await createGitignore(logger, projectDir)
|
|
@@ -4,8 +4,12 @@ import { join } from 'path'
|
|
|
4
4
|
import * as desm from 'desm'
|
|
5
5
|
import { generatePlugins, generateRouteWithTypesSupport } from '../create-plugins.mjs'
|
|
6
6
|
import { createDynamicWorkspaceGHAction, createStaticWorkspaceGHAction } from '../ghaction.mjs'
|
|
7
|
+
import { getTsConfig } from '../get-tsconfig.mjs'
|
|
8
|
+
import { createGitRepository } from '../create-git-repository.mjs'
|
|
7
9
|
|
|
8
|
-
|
|
10
|
+
const TS_OUT_DIR = 'dist'
|
|
11
|
+
|
|
12
|
+
function generateConfig (isRuntimeContext, version, servicesToCompose, typescript, envPrefix) {
|
|
9
13
|
const config = {
|
|
10
14
|
$schema: `https://platformatic.dev/schemas/v${version}/composer`,
|
|
11
15
|
composer: {
|
|
@@ -35,9 +39,7 @@ function generateConfig (isRuntimeContext, version, servicesToCompose, envPrefix
|
|
|
35
39
|
level: '{PLT_SERVER_LOGGER_LEVEL}'
|
|
36
40
|
}
|
|
37
41
|
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (isRuntimeContext) {
|
|
42
|
+
} else {
|
|
41
43
|
config.composer.services = servicesToCompose.map((serviceName) => {
|
|
42
44
|
return {
|
|
43
45
|
id: serviceName,
|
|
@@ -49,10 +51,14 @@ function generateConfig (isRuntimeContext, version, servicesToCompose, envPrefix
|
|
|
49
51
|
})
|
|
50
52
|
}
|
|
51
53
|
|
|
54
|
+
if (typescript === true && config.plugins) {
|
|
55
|
+
config.plugins.typescript = `{PLT_${envPrefix}TYPESCRIPT}`
|
|
56
|
+
}
|
|
57
|
+
|
|
52
58
|
return config
|
|
53
59
|
}
|
|
54
60
|
|
|
55
|
-
function generateEnv (isRuntimeContext, hostname, port, envPrefix) {
|
|
61
|
+
function generateEnv (isRuntimeContext, hostname, port, typescript, envPrefix) {
|
|
56
62
|
let env = ''
|
|
57
63
|
|
|
58
64
|
if (!isRuntimeContext) {
|
|
@@ -64,6 +70,13 @@ PLT_SERVER_LOGGER_LEVEL=info`
|
|
|
64
70
|
env += `
|
|
65
71
|
PLT_${envPrefix}EXAMPLE_ORIGIN=
|
|
66
72
|
`
|
|
73
|
+
if (typescript === true) {
|
|
74
|
+
env += `\
|
|
75
|
+
# Set to false to disable automatic typescript compilation.
|
|
76
|
+
# Changing this setting is needed for production
|
|
77
|
+
PLT_${envPrefix}TYPESCRIPT=true
|
|
78
|
+
`
|
|
79
|
+
}
|
|
67
80
|
return env
|
|
68
81
|
}
|
|
69
82
|
|
|
@@ -71,11 +84,19 @@ async function createComposer (
|
|
|
71
84
|
params,
|
|
72
85
|
logger,
|
|
73
86
|
currentDir = process.cwd(),
|
|
74
|
-
version
|
|
75
|
-
staticWorkspaceGitHubAction,
|
|
76
|
-
dynamicWorkspaceGitHubAction
|
|
87
|
+
version
|
|
77
88
|
) {
|
|
78
|
-
const {
|
|
89
|
+
const {
|
|
90
|
+
isRuntimeContext,
|
|
91
|
+
hostname,
|
|
92
|
+
port,
|
|
93
|
+
servicesToCompose = [],
|
|
94
|
+
runtimeContext,
|
|
95
|
+
typescript,
|
|
96
|
+
staticWorkspaceGitHubAction,
|
|
97
|
+
dynamicWorkspaceGitHubAction,
|
|
98
|
+
initGitRepository
|
|
99
|
+
} = params
|
|
79
100
|
|
|
80
101
|
const composerEnv = {
|
|
81
102
|
PLT_SERVER_LOGGER_LEVEL: 'info',
|
|
@@ -91,11 +112,11 @@ async function createComposer (
|
|
|
91
112
|
if (accessibleConfigFilename === undefined) {
|
|
92
113
|
const envPrefix = runtimeContext !== undefined ? `${runtimeContext.envPrefix}_` : ''
|
|
93
114
|
|
|
94
|
-
const config = generateConfig(isRuntimeContext, version, servicesToCompose, envPrefix)
|
|
115
|
+
const config = generateConfig(isRuntimeContext, version, servicesToCompose, typescript, envPrefix)
|
|
95
116
|
await writeFile(join(currentDir, 'platformatic.composer.json'), JSON.stringify(config, null, 2))
|
|
96
117
|
logger.info('Configuration file platformatic.composer.json successfully created.')
|
|
97
118
|
|
|
98
|
-
const env = generateEnv(isRuntimeContext, hostname, port, envPrefix)
|
|
119
|
+
const env = generateEnv(isRuntimeContext, hostname, port, typescript, envPrefix)
|
|
99
120
|
const envFileExists = await isFileAccessible('.env', currentDir)
|
|
100
121
|
await appendFile(join(currentDir, '.env'), env)
|
|
101
122
|
await writeFile(join(currentDir, '.env.sample'), env)
|
|
@@ -108,14 +129,28 @@ async function createComposer (
|
|
|
108
129
|
} else {
|
|
109
130
|
logger.info(`Configuration file ${accessibleConfigFilename} found, skipping creation of configuration file.`)
|
|
110
131
|
}
|
|
111
|
-
await generatePlugins(logger, currentDir,
|
|
112
|
-
await generateRouteWithTypesSupport(logger, currentDir,
|
|
132
|
+
await generatePlugins(logger, currentDir, typescript, 'composer')
|
|
133
|
+
await generateRouteWithTypesSupport(logger, currentDir, true)
|
|
134
|
+
|
|
135
|
+
if (typescript === true) {
|
|
136
|
+
const tsConfigFileName = join(currentDir, 'tsconfig.json')
|
|
137
|
+
const tsConfig = getTsConfig(TS_OUT_DIR)
|
|
138
|
+
await writeFile(tsConfigFileName, JSON.stringify(tsConfig, null, 2))
|
|
139
|
+
logger.info(`Typescript configuration file ${tsConfigFileName} successfully created.`)
|
|
140
|
+
|
|
141
|
+
// TODO: global.d.ts is needed to compile the project. Still need to populate it
|
|
142
|
+
await writeFile(join(currentDir, 'global.d.ts'), '')
|
|
143
|
+
}
|
|
113
144
|
|
|
114
145
|
if (staticWorkspaceGitHubAction) {
|
|
115
|
-
await createStaticWorkspaceGHAction(logger, composerEnv, './platformatic.service.json', currentDir,
|
|
146
|
+
await createStaticWorkspaceGHAction(logger, composerEnv, './platformatic.service.json', currentDir, typescript)
|
|
116
147
|
}
|
|
117
148
|
if (dynamicWorkspaceGitHubAction) {
|
|
118
|
-
await createDynamicWorkspaceGHAction(logger, composerEnv, './platformatic.service.json', currentDir,
|
|
149
|
+
await createDynamicWorkspaceGHAction(logger, composerEnv, './platformatic.service.json', currentDir, typescript)
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (initGitRepository) {
|
|
153
|
+
await createGitRepository(logger, currentDir)
|
|
119
154
|
}
|
|
120
155
|
|
|
121
156
|
return composerEnv
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { execa } from 'execa'
|
|
2
|
+
|
|
3
|
+
export const GIT_FIRST_COMMIT_MESSAGE = 'Platformatic project started! 🚀'
|
|
4
|
+
export const GIT_MAIN_BRANCH = 'main'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Creates a Git repository and performs the initial commit if it doesn't already exist.
|
|
8
|
+
*
|
|
9
|
+
* This function checks if Git is installed, initializes a Git repository in the specified
|
|
10
|
+
* directory if it's not already a Git repository, and performs the initial commit.
|
|
11
|
+
*
|
|
12
|
+
* @param {import('pino.').BaseLogger} logger - The logger interface for logging messages.
|
|
13
|
+
* @param {string} [dir='.'] - The target directory where the Git repository should be created.
|
|
14
|
+
*/
|
|
15
|
+
export async function createGitRepository (logger, dir = '.') {
|
|
16
|
+
if (!await isGitInstalled()) {
|
|
17
|
+
logger.error('Git is not installed')
|
|
18
|
+
return
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (!await gitInit(logger, dir)) {
|
|
22
|
+
return
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (!await gitCommit(logger, dir)) {
|
|
26
|
+
return
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
logger.info('Git repository initialized.')
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Checks if Git is installed on the system.
|
|
34
|
+
*
|
|
35
|
+
* @async
|
|
36
|
+
* @returns {Promise<boolean>} A Promise that resolves to true if Git is installed, false otherwise.
|
|
37
|
+
*/
|
|
38
|
+
async function isGitInstalled () {
|
|
39
|
+
try {
|
|
40
|
+
await execa('git', ['--version'])
|
|
41
|
+
return true
|
|
42
|
+
} catch (err) {
|
|
43
|
+
return false
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Checks if a Git repository exists in the specified directory.
|
|
49
|
+
*
|
|
50
|
+
* @async
|
|
51
|
+
* @param {string} dir - The directory to check for a Git repository.
|
|
52
|
+
* @returns {Promise<boolean>} A Promise that resolves to true if a Git repository exists in the directory, false otherwise.
|
|
53
|
+
*/
|
|
54
|
+
async function doesGitRepositoryExist (dir) {
|
|
55
|
+
try {
|
|
56
|
+
await execa('git', ['rev-parse', '--is-inside-work-tree'], { cwd: dir })
|
|
57
|
+
return true
|
|
58
|
+
} catch (e) {
|
|
59
|
+
return false
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Initializes a Git repository in the specified directory if it doesn't already exist.
|
|
65
|
+
*
|
|
66
|
+
* @async
|
|
67
|
+
* @param {import('pino.').BaseLogger} - The logger object for logging messages.
|
|
68
|
+
* @param {string} dir - The directory where the Git repository should be initialized.
|
|
69
|
+
* @returns {Promise<boolean>} A Promise that resolves to true if the Git repository is successfully initialized, false otherwise.
|
|
70
|
+
*/
|
|
71
|
+
async function gitInit (logger, dir) {
|
|
72
|
+
try {
|
|
73
|
+
if (await doesGitRepositoryExist(dir)) {
|
|
74
|
+
logger.info('Git repository already exists.')
|
|
75
|
+
return false
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
await execa('git', ['init', '-b', GIT_MAIN_BRANCH], { cwd: dir })
|
|
79
|
+
logger.debug('Git repository initialized.')
|
|
80
|
+
return true
|
|
81
|
+
} catch (err) {
|
|
82
|
+
logger.error('Git repository init failed.', err)
|
|
83
|
+
return false
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Commits changes in a Git repository located in the specified directory.
|
|
89
|
+
*
|
|
90
|
+
* @async
|
|
91
|
+
* @param {import('pino.').BaseLogger} - The logger object for logging messages.
|
|
92
|
+
* @param {string} dir - The directory of the Git repository where changes should be committed.
|
|
93
|
+
* @returns {Promise<boolean>} A Promise that resolves to true if the Git commit is successful, false otherwise.
|
|
94
|
+
*/
|
|
95
|
+
async function gitCommit (logger, dir) {
|
|
96
|
+
try {
|
|
97
|
+
await execa('git', ['add', '-A'], { cwd: dir })
|
|
98
|
+
await execa('git', ['commit', '-m', GIT_FIRST_COMMIT_MESSAGE], { cwd: dir })
|
|
99
|
+
logger.debug('Git commit done.')
|
|
100
|
+
return true
|
|
101
|
+
} catch (err) {
|
|
102
|
+
logger.error('Git commit failed.', err)
|
|
103
|
+
return false
|
|
104
|
+
}
|
|
105
|
+
}
|
package/src/db/create-db-cli.mjs
CHANGED
|
@@ -12,7 +12,7 @@ import { execa } from 'execa'
|
|
|
12
12
|
import ora from 'ora'
|
|
13
13
|
import { getConnectionString, createDB } from './create-db.mjs'
|
|
14
14
|
import askDir from '../ask-dir.mjs'
|
|
15
|
-
import { getRunPackageManagerInstall, getUseTypescript, getPort } from '../cli-options.mjs'
|
|
15
|
+
import { getRunPackageManagerInstall, getUseTypescript, getPort, getInitGitRepository } from '../cli-options.mjs'
|
|
16
16
|
import { createReadme } from '../create-readme.mjs'
|
|
17
17
|
import { join } from 'node:path'
|
|
18
18
|
|
|
@@ -169,8 +169,10 @@ const createPlatformaticDB = async (_args, opts) => {
|
|
|
169
169
|
when: !opts.skipGitHubActions,
|
|
170
170
|
choices: [{ name: 'yes', value: true }, { name: 'no', value: false }]
|
|
171
171
|
})
|
|
172
|
-
|
|
173
|
-
|
|
172
|
+
if (!opts.skipGitRepository) {
|
|
173
|
+
toAsk.push(getInitGitRepository())
|
|
174
|
+
}
|
|
175
|
+
// Prompt for questions
|
|
174
176
|
const wizardOptions = await inquirer.prompt(toAsk)
|
|
175
177
|
|
|
176
178
|
await mkdir(projectDir, { recursive: true })
|
|
@@ -191,7 +193,8 @@ const createPlatformaticDB = async (_args, opts) => {
|
|
|
191
193
|
typescript: useTypescript,
|
|
192
194
|
staticWorkspaceGitHubAction: wizardOptions.staticWorkspaceGitHubAction,
|
|
193
195
|
dynamicWorkspaceGitHubAction: wizardOptions.dynamicWorkspaceGitHubAction,
|
|
194
|
-
runtimeContext: opts.runtimeContext
|
|
196
|
+
runtimeContext: opts.runtimeContext,
|
|
197
|
+
initGitRepository: wizardOptions.initGitRepository
|
|
195
198
|
}
|
|
196
199
|
|
|
197
200
|
await createDB(params, logger, projectDir, version)
|
package/src/db/create-db.mjs
CHANGED
|
@@ -4,6 +4,7 @@ import { addPrefixToEnv, findDBConfigFile, isFileAccessible } from '../utils.mjs
|
|
|
4
4
|
import { getTsConfig } from '../get-tsconfig.mjs'
|
|
5
5
|
import { generatePlugins } from '../create-plugins.mjs'
|
|
6
6
|
import { createDynamicWorkspaceGHAction, createStaticWorkspaceGHAction } from '../ghaction.mjs'
|
|
7
|
+
import { createGitRepository } from '../create-git-repository.mjs'
|
|
7
8
|
|
|
8
9
|
const connectionStrings = {
|
|
9
10
|
postgres: 'postgres://postgres:postgres@127.0.0.1:5432/postgres',
|
|
@@ -298,7 +299,7 @@ function generateConfig (isRuntimeContext, migrations, plugin, types, typescript
|
|
|
298
299
|
}
|
|
299
300
|
}
|
|
300
301
|
|
|
301
|
-
if (typescript === true) {
|
|
302
|
+
if (typescript === true && config.plugins) {
|
|
302
303
|
config.plugins.typescript = `{PLT_${envPrefix}TYPESCRIPT}`
|
|
303
304
|
}
|
|
304
305
|
|
|
@@ -349,7 +350,8 @@ export async function createDB (params, logger, currentDir, version) {
|
|
|
349
350
|
connectionString,
|
|
350
351
|
staticWorkspaceGitHubAction,
|
|
351
352
|
dynamicWorkspaceGitHubAction,
|
|
352
|
-
runtimeContext
|
|
353
|
+
runtimeContext,
|
|
354
|
+
initGitRepository
|
|
353
355
|
} = params
|
|
354
356
|
|
|
355
357
|
const dbEnv = {
|
|
@@ -418,14 +420,9 @@ export async function createDB (params, logger, currentDir, version) {
|
|
|
418
420
|
|
|
419
421
|
if (typescript === true) {
|
|
420
422
|
const tsConfigFileName = join(currentDir, 'tsconfig.json')
|
|
421
|
-
const
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
await writeFile(tsConfigFileName, JSON.stringify(tsConfig, null, 2))
|
|
425
|
-
logger.info(`Typescript configuration file ${tsConfigFileName} successfully created.`)
|
|
426
|
-
} else {
|
|
427
|
-
logger.info(`Typescript configuration file ${tsConfigFileName} found, skipping creation of typescript configuration file.`)
|
|
428
|
-
}
|
|
423
|
+
const tsConfig = getTsConfig(TS_OUT_DIR)
|
|
424
|
+
await writeFile(tsConfigFileName, JSON.stringify(tsConfig, null, 2))
|
|
425
|
+
logger.info(`Typescript configuration file ${tsConfigFileName} successfully created.`)
|
|
429
426
|
}
|
|
430
427
|
|
|
431
428
|
if (plugin) {
|
|
@@ -462,9 +459,14 @@ export async function createDB (params, logger, currentDir, version) {
|
|
|
462
459
|
await createDynamicWorkspaceGHAction(logger, dbEnv, './platformatic.db.json', currentDir, typescript)
|
|
463
460
|
}
|
|
464
461
|
|
|
462
|
+
if (initGitRepository) {
|
|
463
|
+
await createGitRepository(logger, currentDir)
|
|
464
|
+
}
|
|
465
|
+
|
|
465
466
|
if (isRuntimeContext) {
|
|
466
467
|
return addPrefixToEnv(isRuntimeContext)
|
|
467
468
|
}
|
|
469
|
+
|
|
468
470
|
return dbEnv
|
|
469
471
|
}
|
|
470
472
|
|
package/src/index.mjs
CHANGED
|
@@ -11,6 +11,7 @@ import commist from 'commist'
|
|
|
11
11
|
import { getUsername, getVersion, minimumSupportedNodeVersions, isCurrentVersionSupported, findRuntimeConfigFile, getDependencyVersion } from './utils.mjs'
|
|
12
12
|
import { createPackageJson } from './create-package-json.mjs'
|
|
13
13
|
import { createGitignore } from './create-gitignore.mjs'
|
|
14
|
+
import { createGitRepository } from './create-git-repository.mjs'
|
|
14
15
|
|
|
15
16
|
export async function chooseKind (argv, opts = {}) {
|
|
16
17
|
const skip = opts.skip
|
|
@@ -107,6 +108,7 @@ export default createPlatformatic
|
|
|
107
108
|
export {
|
|
108
109
|
createPackageJson,
|
|
109
110
|
createGitignore,
|
|
111
|
+
createGitRepository,
|
|
110
112
|
getVersion,
|
|
111
113
|
getDependencyVersion
|
|
112
114
|
}
|
|
@@ -11,7 +11,7 @@ import { execa } from 'execa'
|
|
|
11
11
|
import ora from 'ora'
|
|
12
12
|
import createRuntime from './create-runtime.mjs'
|
|
13
13
|
import askDir from '../ask-dir.mjs'
|
|
14
|
-
import { getPort, getRunPackageManagerInstall } from '../cli-options.mjs'
|
|
14
|
+
import { getInitGitRepository, getPort, getRunPackageManagerInstall } from '../cli-options.mjs'
|
|
15
15
|
import generateName from 'boring-name-generator'
|
|
16
16
|
import { chooseKind } from '../index.mjs'
|
|
17
17
|
import { createReadme } from '../create-readme.mjs'
|
|
@@ -67,10 +67,12 @@ export async function createPlatformaticRuntime (_args) {
|
|
|
67
67
|
choices: [{ name: 'yes', value: true }, { name: 'no', value: false }]
|
|
68
68
|
})
|
|
69
69
|
|
|
70
|
+
toAsk.push(getInitGitRepository())
|
|
70
71
|
const {
|
|
71
72
|
runPackageManagerInstall,
|
|
72
73
|
staticWorkspaceGitHubAction,
|
|
73
|
-
dynamicWorkspaceGitHubAction
|
|
74
|
+
dynamicWorkspaceGitHubAction,
|
|
75
|
+
initGitRepository
|
|
74
76
|
} = await inquirer.prompt(toAsk)
|
|
75
77
|
|
|
76
78
|
await mkdir(servicesDir, { recursive: true })
|
|
@@ -130,7 +132,8 @@ export async function createPlatformaticRuntime (_args) {
|
|
|
130
132
|
entrypointPort,
|
|
131
133
|
staticWorkspaceGitHubAction,
|
|
132
134
|
dynamicWorkspaceGitHubAction,
|
|
133
|
-
serviceNames: names
|
|
135
|
+
serviceNames: names,
|
|
136
|
+
initGitRepository
|
|
134
137
|
}
|
|
135
138
|
|
|
136
139
|
await createRuntime(params, logger, projectDir, version)
|
|
@@ -180,6 +183,7 @@ export async function createRuntimeService ({ servicesDir, names, logger }) {
|
|
|
180
183
|
skipGitHubActions: true,
|
|
181
184
|
skipPackageJson: true,
|
|
182
185
|
skipGitignore: true,
|
|
186
|
+
skipGitRepository: true,
|
|
183
187
|
port: '0',
|
|
184
188
|
isRuntimeContext: true,
|
|
185
189
|
runtimeContext: {
|
|
@@ -3,6 +3,7 @@ import { findRuntimeConfigFile } from '../utils.mjs'
|
|
|
3
3
|
import { join, relative, isAbsolute } from 'path'
|
|
4
4
|
import * as desm from 'desm'
|
|
5
5
|
import { createDynamicWorkspaceGHAction, createStaticWorkspaceGHAction } from '../ghaction.mjs'
|
|
6
|
+
import { createGitRepository } from '../create-git-repository.mjs'
|
|
6
7
|
|
|
7
8
|
function generateConfig (version, path, entrypoint) {
|
|
8
9
|
const config = {
|
|
@@ -25,9 +26,10 @@ async function createRuntime (params, logger, currentDir = process.cwd(), versio
|
|
|
25
26
|
entrypoint,
|
|
26
27
|
entrypointPort,
|
|
27
28
|
staticWorkspaceGitHubAction,
|
|
28
|
-
dynamicWorkspaceGitHubAction
|
|
29
|
+
dynamicWorkspaceGitHubAction,
|
|
30
|
+
initGitRepository
|
|
29
31
|
} = params
|
|
30
|
-
|
|
32
|
+
console.log('@@@@@@@@@@@@@@@@', params)
|
|
31
33
|
if (!version) {
|
|
32
34
|
const pkg = await readFile(desm.join(import.meta.url, '..', '..', 'package.json'))
|
|
33
35
|
version = JSON.parse(pkg).version
|
|
@@ -59,6 +61,9 @@ async function createRuntime (params, logger, currentDir = process.cwd(), versio
|
|
|
59
61
|
await createDynamicWorkspaceGHAction(logger, runtimeEnv, './platformatic.runtime.json', currentDir, false)
|
|
60
62
|
}
|
|
61
63
|
|
|
64
|
+
if (initGitRepository) {
|
|
65
|
+
await createGitRepository(logger, currentDir)
|
|
66
|
+
}
|
|
62
67
|
return {}
|
|
63
68
|
}
|
|
64
69
|
/**
|
|
@@ -12,7 +12,7 @@ import { execa } from 'execa'
|
|
|
12
12
|
import ora from 'ora'
|
|
13
13
|
import createService from './create-service.mjs'
|
|
14
14
|
import askDir from '../ask-dir.mjs'
|
|
15
|
-
import { getRunPackageManagerInstall, getUseTypescript, getPort } from '../cli-options.mjs'
|
|
15
|
+
import { getRunPackageManagerInstall, getUseTypescript, getPort, getInitGitRepository } from '../cli-options.mjs'
|
|
16
16
|
import { createReadme } from '../create-readme.mjs'
|
|
17
17
|
|
|
18
18
|
const createPlatformaticService = async (_args, opts = {}) => {
|
|
@@ -71,12 +71,16 @@ const createPlatformaticService = async (_args, opts = {}) => {
|
|
|
71
71
|
choices: [{ name: 'yes', value: true }, { name: 'no', value: false }]
|
|
72
72
|
})
|
|
73
73
|
}
|
|
74
|
+
if (!opts.skipGitRepository) {
|
|
75
|
+
toAsk.push(getInitGitRepository())
|
|
76
|
+
}
|
|
74
77
|
const {
|
|
75
78
|
runPackageManagerInstall,
|
|
76
79
|
useTypescript,
|
|
77
80
|
port,
|
|
78
81
|
staticWorkspaceGitHubAction,
|
|
79
|
-
dynamicWorkspaceGitHubAction
|
|
82
|
+
dynamicWorkspaceGitHubAction,
|
|
83
|
+
initGitRepository
|
|
80
84
|
} = await inquirer.prompt(toAsk)
|
|
81
85
|
|
|
82
86
|
// Create the project directory
|
|
@@ -89,7 +93,8 @@ const createPlatformaticService = async (_args, opts = {}) => {
|
|
|
89
93
|
typescript: useTypescript,
|
|
90
94
|
staticWorkspaceGitHubAction,
|
|
91
95
|
dynamicWorkspaceGitHubAction,
|
|
92
|
-
runtimeContext: opts.runtimeContext
|
|
96
|
+
runtimeContext: opts.runtimeContext,
|
|
97
|
+
initGitRepository
|
|
93
98
|
}
|
|
94
99
|
|
|
95
100
|
await createService(params, logger, projectDir, version)
|
|
@@ -5,6 +5,7 @@ import { addPrefixToEnv, findServiceConfigFile, isFileAccessible } from '../util
|
|
|
5
5
|
import { getTsConfig } from '../get-tsconfig.mjs'
|
|
6
6
|
import { generatePlugins } from '../create-plugins.mjs'
|
|
7
7
|
import { createDynamicWorkspaceGHAction, createStaticWorkspaceGHAction } from '../ghaction.mjs'
|
|
8
|
+
import { createGitRepository } from '../create-git-repository.mjs'
|
|
8
9
|
|
|
9
10
|
const TS_OUT_DIR = 'dist'
|
|
10
11
|
|
|
@@ -72,7 +73,8 @@ async function createService (params, logger, currentDir = process.cwd(), versio
|
|
|
72
73
|
typescript = false,
|
|
73
74
|
staticWorkspaceGitHubAction,
|
|
74
75
|
dynamicWorkspaceGitHubAction,
|
|
75
|
-
runtimeContext
|
|
76
|
+
runtimeContext,
|
|
77
|
+
initGitRepository
|
|
76
78
|
} = params
|
|
77
79
|
|
|
78
80
|
const serviceEnv = {
|
|
@@ -139,7 +141,9 @@ async function createService (params, logger, currentDir = process.cwd(), versio
|
|
|
139
141
|
if (isRuntimeContext) {
|
|
140
142
|
return addPrefixToEnv(serviceEnv, runtimeContext.envPrefix)
|
|
141
143
|
}
|
|
142
|
-
|
|
144
|
+
if (initGitRepository) {
|
|
145
|
+
await createGitRepository(logger, currentDir)
|
|
146
|
+
}
|
|
143
147
|
return serviceEnv
|
|
144
148
|
}
|
|
145
149
|
|