create-platformatic 0.33.1 → 0.34.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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-platformatic",
3
- "version": "0.33.1",
3
+ "version": "0.34.0",
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.33.1"
37
+ "@platformatic/config": "0.34.0"
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.1.6",
49
49
  "yaml": "^2.3.1",
50
- "@platformatic/db": "0.33.1",
51
- "@platformatic/service": "0.33.1"
50
+ "@platformatic/db": "0.34.0",
51
+ "@platformatic/service": "0.34.0"
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",
@@ -3,8 +3,15 @@ import { writeFile, readFile } from 'fs/promises'
3
3
  import { join } from 'node:path'
4
4
  import { fileURLToPath } from 'node:url'
5
5
 
6
+ /**
7
+ * Creates a package.json template file
8
+ * @param {boolean} addTSBuild Whether to add TS Build or not
9
+ * @param {string} fastifyVersion Fastify Version
10
+ * @param {string} platVersion Platformatic Version
11
+ */
6
12
  const packageJsonTemplate = async (addTSBuild, fastifyVersion, platVersion) => {
7
13
  const __dirname = fileURLToPath(new URL('.', import.meta.url))
14
+
8
15
  const pkg = {
9
16
  scripts: {
10
17
  start: 'platformatic start'
@@ -38,13 +45,15 @@ const packageJsonTemplate = async (addTSBuild, fastifyVersion, platVersion) => {
38
45
  * @param {string} dir Target directory where to create the file
39
46
  * @param {boolean} addTSBuild Whether to add TS Build or not
40
47
  * @param {object} scripts Package.json scripts list
48
+ * @param {object} dependencies Package.json dependencies list
41
49
  */
42
- export const createPackageJson = async (platVersion, fastifyVersion, logger, dir, addTSBuild = false, scripts = {}) => {
50
+ export const createPackageJson = async (platVersion, fastifyVersion, logger, dir, addTSBuild = false, scripts = {}, dependencies = {}) => {
43
51
  const packageJsonFileName = join(dir, 'package.json')
44
52
  const isPackageJsonExists = await isFileAccessible(packageJsonFileName)
45
53
  if (!isPackageJsonExists) {
46
54
  const pkg = await packageJsonTemplate(addTSBuild, fastifyVersion, platVersion)
47
55
  Object.assign(pkg.scripts, scripts)
56
+ Object.assign(pkg.dependencies, dependencies)
48
57
  await writeFile(packageJsonFileName, JSON.stringify(pkg, null, 2))
49
58
  logger.debug(`${packageJsonFileName} successfully created.`)
50
59
  } else {
@@ -169,8 +169,12 @@ const createPlatformaticDB = async (_args, opts) => {
169
169
  migrate: 'platformatic db migrations apply'
170
170
  }
171
171
 
172
+ const dependencies = {
173
+ '@platformatic/db': `^${version}`
174
+ }
175
+
172
176
  // Create the package.json, .gitignore, readme
173
- await createPackageJson(version, fastifyVersion, logger, projectDir, useTypescript, scripts)
177
+ await createPackageJson(version, fastifyVersion, logger, projectDir, useTypescript, scripts, dependencies)
174
178
  await createGitignore(logger, projectDir)
175
179
  await createReadme(logger, projectDir)
176
180
 
@@ -203,12 +203,17 @@ export async function createDB ({ hostname, database = 'sqlite', port, migration
203
203
  await generatePluginWithTypesSupport(logger, currentDir, typescript)
204
204
  }
205
205
 
206
- return {
206
+ const output = {
207
207
  DATABASE_URL: connectionString,
208
208
  PLT_SERVER_LOGGER_LEVEL: 'info',
209
209
  PORT: port,
210
210
  PLT_SERVER_HOSTNAME: hostname
211
211
  }
212
+
213
+ if (typescript) {
214
+ output.PLT_TYPESCRIPT = true
215
+ }
216
+ return output
212
217
  }
213
218
 
214
219
  export default createDB
package/src/ghaction.mjs CHANGED
@@ -3,12 +3,13 @@ import inquirer from 'inquirer'
3
3
  import { isFileAccessible } from './utils.mjs'
4
4
  import { writeFile, mkdir } from 'fs/promises'
5
5
  import columnify from 'columnify'
6
- function envAsString (env) {
6
+ function envAsString (env, indent) {
7
+ const spaces = Array(indent * 2).join(' ')
7
8
  return Object.keys(env).reduce((acc, key) => {
8
9
  if (key === 'DATABASE_URL') {
9
- acc += ` ${key}: \${{ secrets.DATABASE_URL }}\n`
10
+ acc += `${spaces}${key}: \${{ secrets.DATABASE_URL }}\n`
10
11
  } else {
11
- acc += ` ${key}: ${env[key]} \n`
12
+ acc += `${spaces}${key}: ${env[key]} \n`
12
13
  }
13
14
 
14
15
  return acc
@@ -31,7 +32,7 @@ function formatSecretsToAdd (secrets) {
31
32
  return output
32
33
  }
33
34
  export const dynamicWorkspaceGHTemplate = (env, config, buildTS = false) => {
34
- const envString = envAsString(env)
35
+ const envString = envAsString(env, 3)
35
36
 
36
37
  return `name: Deploy Platformatic application to the cloud
37
38
  on:
@@ -46,6 +47,8 @@ jobs:
46
47
  contents: read
47
48
  pull-requests: write
48
49
  runs-on: ubuntu-latest
50
+ env:
51
+ ${envString}
49
52
  steps:
50
53
  - name: Checkout application project repository
51
54
  uses: actions/checkout@v3
@@ -62,13 +65,11 @@ jobs:
62
65
  platformatic_workspace_id: \${{ secrets.PLATFORMATIC_DYNAMIC_WORKSPACE_ID }}
63
66
  platformatic_workspace_key: \${{ secrets.PLATFORMATIC_DYNAMIC_WORKSPACE_API_KEY }}
64
67
  platformatic_config_path: ${config}
65
- env:
66
- ${envString}
67
68
  `
68
69
  }
69
70
 
70
71
  export const staticWorkspaceGHTemplate = (env, config, buildTS = false) => {
71
- const envString = envAsString(env)
72
+ const envString = envAsString(env, 3)
72
73
 
73
74
  return `name: Deploy Platformatic application to the cloud
74
75
  on:
@@ -84,6 +85,8 @@ jobs:
84
85
  permissions:
85
86
  contents: read
86
87
  runs-on: ubuntu-latest
88
+ env:
89
+ ${envString}
87
90
  steps:
88
91
  - name: Checkout application project repository
89
92
  uses: actions/checkout@v3
@@ -100,8 +103,6 @@ jobs:
100
103
  platformatic_workspace_id: \${{ secrets.PLATFORMATIC_STATIC_WORKSPACE_ID }}
101
104
  platformatic_workspace_key: \${{ secrets.PLATFORMATIC_STATIC_WORKSPACE_API_KEY }}
102
105
  platformatic_config_path: ${config}
103
- env:
104
- ${envString}
105
106
  `
106
107
  }
107
108
 
@@ -180,12 +180,15 @@ async function createService ({ hostname, port, typescript = false }, logger, cu
180
180
  } else {
181
181
  logger.info('Routes folder "routes" found, skipping creation of routes folder.')
182
182
  }
183
-
184
- return {
183
+ const output = {
185
184
  PLT_SERVER_LOGGER_LEVEL: 'info',
186
185
  PORT: port,
187
186
  PLT_SERVER_HOSTNAME: hostname
188
187
  }
188
+ if (typescript) {
189
+ output.PLT_TYPESCRIPT = true
190
+ }
191
+ return output
189
192
  }
190
193
 
191
194
  export default createService
@@ -23,7 +23,12 @@ afterEach(() => {
23
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
- await createPackageJson(version, fastifyVersion, fakeLogger, tmpDir, false)
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)
27
32
  equal(log, `${join(tmpDir, 'package.json')} successfully created.`)
28
33
  const accessible = await isFileAccessible(join(tmpDir, 'package.json'))
29
34
  equal(accessible, true)
@@ -31,13 +36,15 @@ test('creates package.json file for db project', async ({ equal }) => {
31
36
  equal(packageJson.scripts.start, 'platformatic start')
32
37
  equal(packageJson.scripts.build, undefined)
33
38
  equal(packageJson.dependencies.platformatic, `^${version}`)
39
+ equal(packageJson.dependencies['@platformatic/db'], `^${version}`)
34
40
  equal(packageJson.devDependencies.fastify, `^${fastifyVersion}`)
35
41
  })
36
42
 
37
43
  test('creates package.json file for service project', async ({ equal }) => {
38
44
  const version = '1.2.3'
39
45
  const fastifyVersion = '4.5.6'
40
- await createPackageJson(version, fastifyVersion, fakeLogger, tmpDir, false)
46
+ const addTSBuild = false
47
+ await createPackageJson(version, fastifyVersion, fakeLogger, tmpDir, addTSBuild)
41
48
  equal(log, `${join(tmpDir, 'package.json')} successfully created.`)
42
49
  const accessible = await isFileAccessible(join(tmpDir, 'package.json'))
43
50
  equal(accessible, true)
@@ -50,16 +57,18 @@ test('creates package.json file for service project', async ({ equal }) => {
50
57
  test('do not create package.json file because already present', async ({ equal }) => {
51
58
  const version = '1.2.3'
52
59
  const fastifyVersion = '4.5.6'
60
+ const addTSBuild = false
53
61
  const packagejson = join(tmpDir, 'package.json')
54
62
  writeFileSync(packagejson, 'TEST')
55
- await createPackageJson(version, fastifyVersion, fakeLogger, tmpDir, false)
63
+ await createPackageJson(version, fastifyVersion, fakeLogger, tmpDir, addTSBuild)
56
64
  equal(log, `${join(tmpDir, 'package.json')} found, skipping creation of package.json file.`)
57
65
  })
58
66
 
59
67
  test('creates package.json file with TS build', async ({ equal }) => {
60
68
  const version = '1.2.3'
61
69
  const fastifyVersion = '4.5.6'
62
- await createPackageJson(version, fastifyVersion, fakeLogger, tmpDir, true)
70
+ const addTSBuild = true
71
+ await createPackageJson(version, fastifyVersion, fakeLogger, tmpDir, addTSBuild)
63
72
  equal(log, `${join(tmpDir, 'package.json')} successfully created.`)
64
73
  const accessible = await isFileAccessible(join(tmpDir, 'package.json'))
65
74
  equal(accessible, true)
@@ -181,6 +181,7 @@ test('creates project with typescript', async ({ equal, same }) => {
181
181
  equal(process.env.PLT_SERVER_HOSTNAME, 'myhost')
182
182
  equal(process.env.PORT, '6666')
183
183
  equal(process.env.DATABASE_URL, 'sqlite://./db.sqlite')
184
+ equal(process.env.PLT_TYPESCRIPT, 'true')
184
185
  process.env = {}
185
186
 
186
187
  const pathToDbEnvSampleFile = join(tmpDir, '.env.sample')
@@ -36,13 +36,13 @@ test('creates gh action', async ({ equal, match }) => {
36
36
  equal(accessible, true)
37
37
  const ghFile = await readFile(join(tmpDir, '.github/workflows/platformatic-dynamic-workspace-deploy.yml'), 'utf8')
38
38
  const ghAction = parse(ghFile)
39
- const { steps, permissions } = ghAction.jobs.build_and_deploy
39
+ const { steps, permissions, env: jobEnv } = ghAction.jobs.build_and_deploy
40
40
  equal(steps.length, 3)
41
41
  equal(steps[0].name, 'Checkout application project repository')
42
42
  equal(steps[1].name, 'npm install --omit=dev')
43
43
  equal(steps[2].name, 'Deploy project')
44
- match(steps[2].env.DATABASE_URL, /\$\{\{ secrets.DATABASE_URL \}\}/)
45
- equal(steps[2].env.PLT_SERVER_LOGGER_LEVEL, 'info')
44
+ match(jobEnv.DATABASE_URL, /\$\{\{ secrets.DATABASE_URL \}\}/)
45
+ equal(jobEnv.PLT_SERVER_LOGGER_LEVEL, 'info')
46
46
 
47
47
  equal(permissions.contents, 'read')
48
48
  equal(permissions['pull-requests'], 'write')
@@ -55,14 +55,14 @@ test('creates gh action with TS build step', async ({ equal, match }) => {
55
55
  equal(accessible, true)
56
56
  const ghFile = await readFile(join(tmpDir, '.github/workflows/platformatic-dynamic-workspace-deploy.yml'), 'utf8')
57
57
  const ghAction = parse(ghFile)
58
- const { steps, permissions } = ghAction.jobs.build_and_deploy
58
+ const { steps, permissions, env: jobEnv } = ghAction.jobs.build_and_deploy
59
59
  equal(steps.length, 4)
60
60
  equal(steps[0].name, 'Checkout application project repository')
61
61
  equal(steps[1].name, 'npm install --omit=dev')
62
62
  equal(steps[2].name, 'Build project')
63
63
  equal(steps[3].name, 'Deploy project')
64
- match(steps[3].env.DATABASE_URL, /\$\{\{ secrets.DATABASE_URL \}\}/)
65
- equal(steps[3].env.PLT_SERVER_LOGGER_LEVEL, 'info')
64
+ match(jobEnv.DATABASE_URL, /\$\{\{ secrets.DATABASE_URL \}\}/)
65
+ equal(jobEnv.PLT_SERVER_LOGGER_LEVEL, 'info')
66
66
 
67
67
  equal(permissions.contents, 'read')
68
68
  equal(permissions['pull-requests'], 'write')
@@ -36,13 +36,14 @@ test('creates gh action', async ({ equal, match }) => {
36
36
  equal(accessible, true)
37
37
  const ghFile = await readFile(join(tmpDir, '.github/workflows/platformatic-static-workspace-deploy.yml'), 'utf8')
38
38
  const ghAction = parse(ghFile)
39
- const { steps, permissions } = ghAction.jobs.build_and_deploy
39
+ const { steps, permissions, env: jobEnv } = ghAction.jobs.build_and_deploy
40
+
40
41
  equal(steps.length, 3)
41
42
  equal(steps[0].name, 'Checkout application project repository')
42
43
  equal(steps[1].name, 'npm install --omit=dev')
43
44
  equal(steps[2].name, 'Deploy project')
44
- match(steps[2].env.DATABASE_URL, /\$\{\{ secrets.DATABASE_URL \}\}/)
45
- equal(steps[2].env.PLT_SERVER_LOGGER_LEVEL, 'info')
45
+ match(jobEnv.DATABASE_URL, /\$\{\{ secrets.DATABASE_URL \}\}/)
46
+ equal(jobEnv.PLT_SERVER_LOGGER_LEVEL, 'info')
46
47
 
47
48
  equal(permissions.contents, 'read')
48
49
  })
@@ -54,14 +55,14 @@ test('creates gh action with TS build step', async ({ equal, match }) => {
54
55
  equal(accessible, true)
55
56
  const ghFile = await readFile(join(tmpDir, '.github/workflows/platformatic-static-workspace-deploy.yml'), 'utf8')
56
57
  const ghAction = parse(ghFile)
57
- const { steps, permissions } = ghAction.jobs.build_and_deploy
58
+ const { steps, permissions, env: jobEnv } = ghAction.jobs.build_and_deploy
58
59
  equal(steps.length, 4)
59
60
  equal(steps[0].name, 'Checkout application project repository')
60
61
  equal(steps[1].name, 'npm install --omit=dev')
61
62
  equal(steps[2].name, 'Build project')
62
63
  equal(steps[3].name, 'Deploy project')
63
- match(steps[3].env.DATABASE_URL, /\$\{\{ secrets.DATABASE_URL \}\}/)
64
- equal(steps[3].env.PLT_SERVER_LOGGER_LEVEL, 'info')
64
+ match(jobEnv.DATABASE_URL, /\$\{\{ secrets.DATABASE_URL \}\}/)
65
+ equal(jobEnv.PLT_SERVER_LOGGER_LEVEL, 'info')
65
66
 
66
67
  equal(permissions.contents, 'read')
67
68
  })
@@ -52,12 +52,15 @@ test('creates service with typescript', async ({ equal, same, ok }) => {
52
52
  dotenv.config({ path: pathToDbEnvFile })
53
53
  equal(process.env.PLT_SERVER_HOSTNAME, 'myhost')
54
54
  equal(process.env.PORT, '6666')
55
+ equal(process.env.PLT_TYPESCRIPT, 'true')
56
+
55
57
  process.env = {}
56
58
 
57
59
  const pathToDbEnvSampleFile = join(tmpDir, '.env.sample')
58
60
  dotenv.config({ path: pathToDbEnvSampleFile })
59
61
  equal(process.env.PLT_SERVER_HOSTNAME, 'myhost')
60
62
  equal(process.env.PORT, '6666')
63
+ equal(process.env.PLT_TYPESCRIPT, 'true')
61
64
 
62
65
  same(plugins.paths, [{ path: './plugins', encapsulate: false }, './routes'])
63
66
  equal(plugins.typescript, '{PLT_TYPESCRIPT}')