create-wattpm 3.72.0 → 4.0.0-alpha.1
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/lib/index.js +50 -35
- package/lib/utils.js +3 -14
- package/package.json +12 -12
- package/.npmignore +0 -2
package/lib/index.js
CHANGED
|
@@ -3,13 +3,15 @@ import {
|
|
|
3
3
|
defaultPackageManager,
|
|
4
4
|
detectApplicationType,
|
|
5
5
|
findConfigurationFileRecursive,
|
|
6
|
+
findRuntimeConfigurationFile,
|
|
6
7
|
generateDashedName,
|
|
7
8
|
getPackageManager,
|
|
8
9
|
getPkgManager,
|
|
9
10
|
loadConfigurationFile,
|
|
10
11
|
searchJavascriptFiles
|
|
11
12
|
} from '@platformatic/foundation'
|
|
12
|
-
import {
|
|
13
|
+
import { isLegacyConfigurationFileName } from '@platformatic/foundation/loader'
|
|
14
|
+
import { findAnyConfigurationFile, ImportGenerator } from '@platformatic/generators'
|
|
13
15
|
import { execa } from 'execa'
|
|
14
16
|
import defaultInquirer from 'inquirer'
|
|
15
17
|
import parseArgs from 'minimist'
|
|
@@ -183,7 +185,7 @@ export async function wrapApplication (
|
|
|
183
185
|
...generator.config,
|
|
184
186
|
...additionalGeneratorConfig,
|
|
185
187
|
targetDirectory: projectDir,
|
|
186
|
-
typescript:
|
|
188
|
+
typescript: true
|
|
187
189
|
})
|
|
188
190
|
|
|
189
191
|
await generator.ask()
|
|
@@ -227,8 +229,7 @@ export async function createPlatformatic (argv) {
|
|
|
227
229
|
const pkgManager = getPkgManager()
|
|
228
230
|
const modules = Array.isArray(args.module) ? args.module : [args.module]
|
|
229
231
|
await createApplication(logger, pkgManager, modules, args['install'], {
|
|
230
|
-
|
|
231
|
-
applicationsFolder: 'web'
|
|
232
|
+
applicationsFolder: 'applications'
|
|
232
233
|
})
|
|
233
234
|
}
|
|
234
235
|
|
|
@@ -248,7 +249,44 @@ export async function createApplication (
|
|
|
248
249
|
// Check in the directory and its parents if there is a config file
|
|
249
250
|
let shouldChooseProjectDir = true
|
|
250
251
|
let projectDir = process.cwd()
|
|
251
|
-
|
|
252
|
+
/*
|
|
253
|
+
The legacy lookup first, because it is the one whose search shape the flows below were written
|
|
254
|
+
against, then the current-format one -- which is what finds a project this wizard scaffolded,
|
|
255
|
+
since a `watt.config.*` is invisible to the other.
|
|
256
|
+
*/
|
|
257
|
+
/*
|
|
258
|
+
The legacy lookup first, because it is the search shape the flows below were written against,
|
|
259
|
+
then the current-format one -- which is what finds a project this wizard scaffolded, since a
|
|
260
|
+
`watt.config.*` is invisible to the other.
|
|
261
|
+
*/
|
|
262
|
+
/*
|
|
263
|
+
Wrapping an application leaves a configuration in the application's own directory. There is no
|
|
264
|
+
`runtime` block to nest those settings inside -- they are the root's own -- so the signal is a
|
|
265
|
+
configuration sitting beside the sources, which has to be read before the runtime lookup below
|
|
266
|
+
claims the directory as an ordinary project.
|
|
267
|
+
*/
|
|
268
|
+
const wrapped = await findAnyConfigurationFile(projectDir)
|
|
269
|
+
|
|
270
|
+
if (wrapped && !isLegacyConfigurationFileName(wrapped) && (await findApplicationRoot(projectDir))) {
|
|
271
|
+
/*
|
|
272
|
+
The singular `application` shorthand is what wrapping writes, and what distinguishes a wrapped
|
|
273
|
+
application from a runtime whose own directory happens to hold sources. Read from the source
|
|
274
|
+
rather than evaluated: evaluating a root expands its topology, which reaches every
|
|
275
|
+
application's configuration and so needs the dependencies this command has not installed yet.
|
|
276
|
+
*/
|
|
277
|
+
const source = await readFile(resolve(projectDir, wrapped), 'utf-8')
|
|
278
|
+
|
|
279
|
+
if (/\bapplication:\s*\{/.test(source)) {
|
|
280
|
+
const { label } = await detectApplicationType(projectDir)
|
|
281
|
+
|
|
282
|
+
await say(`The ${label} application has already been wrapped into Watt.`)
|
|
283
|
+
return
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
const runtimeConfigFile =
|
|
288
|
+
(await findConfigurationFileRecursive(projectDir, null, '@platformatic/runtime')) ??
|
|
289
|
+
(await findRuntimeConfigurationFile(logger, projectDir, null, false, false))
|
|
252
290
|
|
|
253
291
|
if (runtimeConfigFile) {
|
|
254
292
|
shouldChooseProjectDir = false
|
|
@@ -264,10 +302,11 @@ export async function createApplication (
|
|
|
264
302
|
|
|
265
303
|
// Check if the file belongs to a Watt application, this can happen for instance if we executed watt create
|
|
266
304
|
// in the applications folder
|
|
267
|
-
const existingRuntime =
|
|
305
|
+
const existingRuntime =
|
|
306
|
+
(await findConfigurationFileRecursive(applicationRoot, null, '@platformatic/runtime')) ??
|
|
307
|
+
(await findRuntimeConfigurationFile(logger, applicationRoot, null, false, false))
|
|
268
308
|
|
|
269
309
|
if (!existingRuntime) {
|
|
270
|
-
// If there is a watt.json file with a runtime property, we assume we already executed watt create and we exit.
|
|
271
310
|
const existingApplication = await findGatewayConfigFile(projectDir)
|
|
272
311
|
|
|
273
312
|
if (existingApplication) {
|
|
@@ -459,32 +498,8 @@ export async function createApplication (
|
|
|
459
498
|
}
|
|
460
499
|
}
|
|
461
500
|
|
|
462
|
-
let entrypoint = ''
|
|
463
|
-
const chooseEntrypoint = names.length > 1 && (!generator.existingConfigRaw || !generator.existingConfigRaw.entrypoint)
|
|
464
|
-
|
|
465
|
-
if (chooseEntrypoint) {
|
|
466
|
-
const results = await inquirer.prompt([
|
|
467
|
-
{
|
|
468
|
-
type: 'select',
|
|
469
|
-
name: 'entrypoint',
|
|
470
|
-
message: 'Which application should be exposed?',
|
|
471
|
-
choices: names.map(name => ({ name, value: name }))
|
|
472
|
-
}
|
|
473
|
-
])
|
|
474
|
-
entrypoint = results.entrypoint
|
|
475
|
-
} else {
|
|
476
|
-
entrypoint = names[0]
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
generator.setEntryPoint(entrypoint)
|
|
480
|
-
|
|
481
501
|
await generator.ask()
|
|
482
502
|
await generator.prepare()
|
|
483
|
-
|
|
484
|
-
if (chooseEntrypoint) {
|
|
485
|
-
await generator.updateConfigEntryPoint(entrypoint)
|
|
486
|
-
}
|
|
487
|
-
|
|
488
503
|
await generator.writeFiles()
|
|
489
504
|
|
|
490
505
|
// Create project here
|
|
@@ -509,9 +524,7 @@ export async function createApplication (
|
|
|
509
524
|
if (packageManager === 'pnpm' && !existsSync(pnpmWorkspacePath)) {
|
|
510
525
|
// add pnpm-workspace.yaml file if needed
|
|
511
526
|
let content = `packages:
|
|
512
|
-
- 'applications/*'
|
|
513
|
-
- 'services/*'
|
|
514
|
-
- 'web/*'`
|
|
527
|
+
- 'applications/*'`
|
|
515
528
|
|
|
516
529
|
// Add imported applications
|
|
517
530
|
for (const { application } of generator.applications) {
|
|
@@ -528,7 +541,9 @@ export async function createApplication (
|
|
|
528
541
|
}
|
|
529
542
|
|
|
530
543
|
if (typeof install === 'function') {
|
|
531
|
-
|
|
544
|
+
// The file the generator actually wrote. `runtimeConfig` still names a legacy candidate, and an
|
|
545
|
+
// install hook that opened it would open nothing.
|
|
546
|
+
await install(projectDir, generator.configurationFileName(), packageManager)
|
|
532
547
|
} else if (install) {
|
|
533
548
|
const spinner = ora('Installing dependencies...').start()
|
|
534
549
|
await execa(packageManager, ['install'], { cwd: projectDir })
|
package/lib/utils.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { findConfigurationFile } from '@platformatic/foundation'
|
|
2
2
|
import { execa } from 'execa'
|
|
3
3
|
import { access, constants, readFile } from 'node:fs/promises'
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { findPackageJSON } from 'node:module'
|
|
5
|
+
import { join, resolve } from 'node:path'
|
|
6
6
|
|
|
7
7
|
export const sleep = ms => new Promise(resolve => setTimeout(resolve, ms))
|
|
8
8
|
export const randomBetween = (min, max) => Math.floor(Math.random() * (max - min + 1) + min)
|
|
@@ -101,18 +101,7 @@ export async function getDependencyVersion (dependencyName) {
|
|
|
101
101
|
}
|
|
102
102
|
|
|
103
103
|
async function resolveWorkspaceDependency (dependencyName) {
|
|
104
|
-
const
|
|
105
|
-
let dependencyPath = dirname(require.resolve(dependencyName))
|
|
106
|
-
// some deps are resolved not at their root level
|
|
107
|
-
// for instance 'typescript' will be risolved in its own ./lib directory
|
|
108
|
-
// next loop is to find the nearest parent directory that contains a package.json file
|
|
109
|
-
while (!(await isFileAccessible(join(dependencyPath, 'package.json')))) {
|
|
110
|
-
dependencyPath = join(dependencyPath, '..')
|
|
111
|
-
if (dependencyPath === '/') {
|
|
112
|
-
throw new Error(`Cannot find package.json for ${dependencyName}`)
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
const pathToPackageJson = join(dependencyPath, 'package.json')
|
|
104
|
+
const pathToPackageJson = findPackageJSON(dependencyName, import.meta.url)
|
|
116
105
|
const packageJsonFile = await readFile(pathToPackageJson, 'utf-8')
|
|
117
106
|
const packageJson = JSON.parse(packageJsonFile)
|
|
118
107
|
return packageJson.version
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-wattpm",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0-alpha.1",
|
|
4
4
|
"description": "Create platformatic application interactive tool",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -14,8 +14,6 @@
|
|
|
14
14
|
"license": "Apache-2.0",
|
|
15
15
|
"author": "Platformatic Inc. <oss@platformatic.dev> (https://platformatic.dev)",
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@platformatic/foundation": "3.72.0",
|
|
18
|
-
"@platformatic/generators": "3.72.0",
|
|
19
17
|
"columnify": "^1.6.0",
|
|
20
18
|
"execa": "^9.0.0",
|
|
21
19
|
"inquirer": "^13.0.0",
|
|
@@ -24,15 +22,13 @@
|
|
|
24
22
|
"pino": "^9.9.0",
|
|
25
23
|
"pino-pretty": "^13.0.0",
|
|
26
24
|
"resolve": "^1.22.8",
|
|
27
|
-
"undici": "^
|
|
28
|
-
"which": "^3.0.1"
|
|
25
|
+
"undici": "^8.5.0",
|
|
26
|
+
"which": "^3.0.1",
|
|
27
|
+
"@platformatic/foundation": "4.0.0-alpha.1",
|
|
28
|
+
"@platformatic/generators": "4.0.0-alpha.1"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@
|
|
32
|
-
"@platformatic/gateway": "3.72.0",
|
|
33
|
-
"@platformatic/runtime": "3.72.0",
|
|
34
|
-
"@platformatic/service": "3.72.0",
|
|
35
|
-
"@types/node": "^22.5.0",
|
|
31
|
+
"@types/node": "^24.0.0",
|
|
36
32
|
"c8": "^11.0.0",
|
|
37
33
|
"cleaner-spec-reporter": "^0.5.0",
|
|
38
34
|
"cross-env": "^7.0.3",
|
|
@@ -42,10 +38,14 @@
|
|
|
42
38
|
"neostandard": "^0.12.0",
|
|
43
39
|
"semver": "^7.6.0",
|
|
44
40
|
"typescript": "~6.0.3",
|
|
45
|
-
"yaml": "^2.4.1"
|
|
41
|
+
"yaml": "^2.4.1",
|
|
42
|
+
"@platformatic/gateway": "4.0.0-alpha.1",
|
|
43
|
+
"@platformatic/runtime": "4.0.0-alpha.1",
|
|
44
|
+
"@platformatic/service": "4.0.0-alpha.1",
|
|
45
|
+
"@platformatic/db": "4.0.0-alpha.1"
|
|
46
46
|
},
|
|
47
47
|
"engines": {
|
|
48
|
-
"node": ">=
|
|
48
|
+
"node": ">=24.20.0"
|
|
49
49
|
},
|
|
50
50
|
"scripts": {
|
|
51
51
|
"test": "npm run test:unit && npm run test:cli",
|
package/.npmignore
DELETED