@mnci/cli 4.26.0 → 4.27.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/dist/cli.js +105 -0
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -3970,6 +3970,105 @@ function addGoInternalLib(workspaceRoot, name) {
|
|
|
3970
3970
|
|
|
3971
3971
|
// src/project-scaffolding/node.use-case.ts
|
|
3972
3972
|
var import_node_path12 = require("path");
|
|
3973
|
+
|
|
3974
|
+
// src/project-scaffolding/node-app-example.algorithm.ts
|
|
3975
|
+
var GREET_USE_CASE = `import type { Greeting } from './greeting.contract'
|
|
3976
|
+
|
|
3977
|
+
export function greet (name: string): Greeting {
|
|
3978
|
+
return { message: 'Hello, ' + name + '!' }
|
|
3979
|
+
}
|
|
3980
|
+
`;
|
|
3981
|
+
var GREETING_CONTRACT = `/** What greeting someone returns. */
|
|
3982
|
+
export interface Greeting {
|
|
3983
|
+
readonly message: string
|
|
3984
|
+
}
|
|
3985
|
+
`;
|
|
3986
|
+
var GREET_SPEC = `import { greet } from './greet.use-case'
|
|
3987
|
+
|
|
3988
|
+
describe('greet', () => {
|
|
3989
|
+
it('greets a name', () => {
|
|
3990
|
+
expect(greet('world')).toEqual({ message: 'Hello, world!' })
|
|
3991
|
+
})
|
|
3992
|
+
})
|
|
3993
|
+
`;
|
|
3994
|
+
var SLICE = {
|
|
3995
|
+
"hello/greet.use-case.ts": GREET_USE_CASE,
|
|
3996
|
+
"hello/greeting.contract.ts": GREETING_CONTRACT,
|
|
3997
|
+
"hello/greet.use-case.spec.ts": GREET_SPEC
|
|
3998
|
+
};
|
|
3999
|
+
function nodeAppExampleFiles(framework) {
|
|
4000
|
+
switch (framework) {
|
|
4001
|
+
case "none": {
|
|
4002
|
+
return {
|
|
4003
|
+
...SLICE,
|
|
4004
|
+
"hello/index.ts": "export * from './greeting.contract'\nexport * from './greet.use-case'\n",
|
|
4005
|
+
"main.ts": "import { greet } from './hello'\n\nconsole.log(greet('world').message)\n"
|
|
4006
|
+
};
|
|
4007
|
+
}
|
|
4008
|
+
case "express": {
|
|
4009
|
+
return {
|
|
4010
|
+
...SLICE,
|
|
4011
|
+
"hello/hello.handler.ts": `import type { Request, Response } from 'express'
|
|
4012
|
+
import { greet } from './greet.use-case'
|
|
4013
|
+
|
|
4014
|
+
export function helloHandler (request: Request, response: Response): void {
|
|
4015
|
+
const name = typeof request.query.name === 'string' ? request.query.name : 'world'
|
|
4016
|
+
response.send(greet(name))
|
|
4017
|
+
}
|
|
4018
|
+
`,
|
|
4019
|
+
"hello/index.ts": "export * from './greeting.contract'\nexport * from './greet.use-case'\nexport * from './hello.handler'\n",
|
|
4020
|
+
"main.ts": `import express from 'express'
|
|
4021
|
+
import { helloHandler } from './hello'
|
|
4022
|
+
|
|
4023
|
+
const host = process.env.HOST ?? 'localhost'
|
|
4024
|
+
const port = process.env.PORT ? Number(process.env.PORT) : 3000
|
|
4025
|
+
|
|
4026
|
+
const app = express()
|
|
4027
|
+
|
|
4028
|
+
app.get('/', helloHandler)
|
|
4029
|
+
|
|
4030
|
+
app.listen(port, host, () => {
|
|
4031
|
+
console.log('[ ready ] http://' + host + ':' + String(port))
|
|
4032
|
+
})
|
|
4033
|
+
`
|
|
4034
|
+
};
|
|
4035
|
+
}
|
|
4036
|
+
case "koa": {
|
|
4037
|
+
return {
|
|
4038
|
+
...SLICE,
|
|
4039
|
+
"hello/hello.handler.ts": `import type { Context } from 'koa'
|
|
4040
|
+
import { greet } from './greet.use-case'
|
|
4041
|
+
|
|
4042
|
+
export function helloHandler (context: Context): void {
|
|
4043
|
+
const name = typeof context.query.name === 'string' ? context.query.name : 'world'
|
|
4044
|
+
context.body = greet(name)
|
|
4045
|
+
}
|
|
4046
|
+
`,
|
|
4047
|
+
"hello/index.ts": "export * from './greeting.contract'\nexport * from './greet.use-case'\nexport * from './hello.handler'\n",
|
|
4048
|
+
"main.ts": `import Koa from 'koa'
|
|
4049
|
+
import { helloHandler } from './hello'
|
|
4050
|
+
|
|
4051
|
+
const host = process.env.HOST ?? 'localhost'
|
|
4052
|
+
const port = process.env.PORT ? Number(process.env.PORT) : 3000
|
|
4053
|
+
|
|
4054
|
+
const app = new Koa()
|
|
4055
|
+
|
|
4056
|
+
app.use(helloHandler)
|
|
4057
|
+
|
|
4058
|
+
app.listen(port, host, () => {
|
|
4059
|
+
console.log('[ ready ] http://' + host + ':' + String(port))
|
|
4060
|
+
})
|
|
4061
|
+
`
|
|
4062
|
+
};
|
|
4063
|
+
}
|
|
4064
|
+
case "fastify":
|
|
4065
|
+
case "nest": {
|
|
4066
|
+
return null;
|
|
4067
|
+
}
|
|
4068
|
+
}
|
|
4069
|
+
}
|
|
4070
|
+
|
|
4071
|
+
// src/project-scaffolding/node.use-case.ts
|
|
3973
4072
|
function ensurePlugin2(workspaceRoot, packageName) {
|
|
3974
4073
|
if (hasPlugin(workspaceRoot, packageName)) {
|
|
3975
4074
|
return;
|
|
@@ -4046,6 +4145,12 @@ function nodeAppPackageTarget(name) {
|
|
|
4046
4145
|
}
|
|
4047
4146
|
function addNodeApp(workspaceRoot, name, stack, framework = "none") {
|
|
4048
4147
|
runNodeApp(workspaceRoot, name, stack, framework);
|
|
4148
|
+
const example = nodeAppExampleFiles(framework);
|
|
4149
|
+
if (example !== null) {
|
|
4150
|
+
for (const [relative, contents] of Object.entries(example)) {
|
|
4151
|
+
writeFileEnsured((0, import_node_path12.join)(workspaceRoot, "apps", name, "src", relative), contents);
|
|
4152
|
+
}
|
|
4153
|
+
}
|
|
4049
4154
|
ensureAdmZip(workspaceRoot);
|
|
4050
4155
|
addNxTargets((0, import_node_path12.join)(workspaceRoot, "apps", name, "package.json"), {
|
|
4051
4156
|
package: nodeAppPackageTarget(name)
|