@mnci/cli 4.25.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/README.md +1 -1
- package/dist/cli.js +139 -17
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1336,7 +1336,7 @@ already use:
|
|
|
1336
1336
|
- **`node-function-app` overlay**: `@azure/functions` is installed for real
|
|
1337
1337
|
(a plain `@nx/node:application` app has no Azure dependency by default,
|
|
1338
1338
|
unlike a plugin-generated one), an HTTP-triggered `app.http(...)` sample
|
|
1339
|
-
(v4 programming model) is written as a `src/hello/` slice (`hello.handler.ts`
|
|
1339
|
+
(v4 programming model) is written as a `src/hello/` slice (`hello.handler.ts` adapting the transport, `greet.use-case.ts` and its spec, `greeting.contract.ts`, behind an `index.ts`; `--empty` skips the slice), `host.json` is
|
|
1340
1340
|
added, and the manifest is repaired — `main: 'main.js'` (the dist shim) and
|
|
1341
1341
|
`@azure/functions` added to `dependencies` for Azure's deploy-time install
|
|
1342
1342
|
to find.
|
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)
|
|
@@ -4066,6 +4171,10 @@ var NODE_FUNCTION_APP_MAIN = `// esbuild only includes what is reachable from he
|
|
|
4066
4171
|
// function slice you create under src/ (through its index).
|
|
4067
4172
|
import './hello'
|
|
4068
4173
|
`;
|
|
4174
|
+
var NODE_FUNCTION_APP_MAIN_EMPTY = `// esbuild only includes what is reachable from here, so import each function slice
|
|
4175
|
+
// you create under src/ (through its index).
|
|
4176
|
+
export {}
|
|
4177
|
+
`;
|
|
4069
4178
|
var NODE_FUNCTION_APP_HOST_JSON = `{
|
|
4070
4179
|
"version": "2.0",
|
|
4071
4180
|
"extensionBundle": {
|
|
@@ -4076,11 +4185,11 @@ var NODE_FUNCTION_APP_HOST_JSON = `{
|
|
|
4076
4185
|
`;
|
|
4077
4186
|
var NODE_FUNCTION_APP_HELLO = `import { app } from '@azure/functions'
|
|
4078
4187
|
import type { HttpRequest, HttpResponseInit } from '@azure/functions'
|
|
4079
|
-
import {
|
|
4188
|
+
import { greet } from './greet.use-case'
|
|
4080
4189
|
|
|
4081
4190
|
async function hello(request: HttpRequest): Promise<HttpResponseInit> {
|
|
4082
4191
|
const name = request.query.get('name') ?? 'world'
|
|
4083
|
-
return { body:
|
|
4192
|
+
return { body: greet(name).message }
|
|
4084
4193
|
}
|
|
4085
4194
|
|
|
4086
4195
|
app.http('hello', {
|
|
@@ -4092,15 +4201,22 @@ app.http('hello', {
|
|
|
4092
4201
|
`;
|
|
4093
4202
|
var NODE_FUNCTION_APP_HELLO_BARREL = `export * from './hello.handler'
|
|
4094
4203
|
`;
|
|
4095
|
-
var
|
|
4096
|
-
|
|
4204
|
+
var NODE_FUNCTION_APP_GREETING_CONTRACT = `/** What greeting someone returns. */
|
|
4205
|
+
export interface Greeting {
|
|
4206
|
+
readonly message: string
|
|
4207
|
+
}
|
|
4208
|
+
`;
|
|
4209
|
+
var NODE_FUNCTION_APP_GREET_USE_CASE = `import type { Greeting } from './greeting.contract'
|
|
4210
|
+
|
|
4211
|
+
export function greet (name: string): Greeting {
|
|
4212
|
+
return { message: 'Hello, ' + name + '!' }
|
|
4097
4213
|
}
|
|
4098
4214
|
`;
|
|
4099
|
-
var
|
|
4215
|
+
var NODE_FUNCTION_APP_GREET_SPEC = `import { greet } from './greet.use-case'
|
|
4100
4216
|
|
|
4101
|
-
describe('
|
|
4217
|
+
describe('greet', () => {
|
|
4102
4218
|
it('greets a name', () => {
|
|
4103
|
-
expect(
|
|
4219
|
+
expect(greet('world')).toEqual({ message: 'Hello, world!' })
|
|
4104
4220
|
})
|
|
4105
4221
|
})
|
|
4106
4222
|
`;
|
|
@@ -4148,22 +4264,28 @@ function nodeFunctionAppStartTarget(name) {
|
|
|
4148
4264
|
options: { command: "func start", cwd: `apps/${name}` }
|
|
4149
4265
|
};
|
|
4150
4266
|
}
|
|
4151
|
-
function addNodeFunctionApp(workspaceRoot, name, stack) {
|
|
4267
|
+
function addNodeFunctionApp(workspaceRoot, name, stack, empty = false) {
|
|
4152
4268
|
runNodeApp(workspaceRoot, name, stack, "none");
|
|
4153
4269
|
ensureAzureFunctionsPackage(workspaceRoot);
|
|
4154
4270
|
const nodeFunctionAppRoot = (0, import_node_path12.join)(workspaceRoot, "apps", name);
|
|
4155
|
-
writeFileEnsured((0, import_node_path12.join)(nodeFunctionAppRoot, "src/main.ts"), NODE_FUNCTION_APP_MAIN);
|
|
4156
|
-
|
|
4157
|
-
|
|
4158
|
-
|
|
4159
|
-
|
|
4271
|
+
writeFileEnsured((0, import_node_path12.join)(nodeFunctionAppRoot, "src/main.ts"), empty ? NODE_FUNCTION_APP_MAIN_EMPTY : NODE_FUNCTION_APP_MAIN);
|
|
4272
|
+
if (!empty) {
|
|
4273
|
+
const slice = (0, import_node_path12.join)(nodeFunctionAppRoot, "src/hello");
|
|
4274
|
+
writeFileEnsured((0, import_node_path12.join)(slice, "hello.handler.ts"), NODE_FUNCTION_APP_HELLO);
|
|
4275
|
+
writeFileEnsured((0, import_node_path12.join)(slice, "greet.use-case.ts"), NODE_FUNCTION_APP_GREET_USE_CASE);
|
|
4276
|
+
writeFileEnsured((0, import_node_path12.join)(slice, "greet.use-case.spec.ts"), NODE_FUNCTION_APP_GREET_SPEC);
|
|
4277
|
+
writeFileEnsured((0, import_node_path12.join)(slice, "greeting.contract.ts"), NODE_FUNCTION_APP_GREETING_CONTRACT);
|
|
4278
|
+
writeFileEnsured((0, import_node_path12.join)(slice, "index.ts"), NODE_FUNCTION_APP_HELLO_BARREL);
|
|
4279
|
+
}
|
|
4160
4280
|
writeFileEnsured((0, import_node_path12.join)(nodeFunctionAppRoot, "host.json"), NODE_FUNCTION_APP_HOST_JSON);
|
|
4161
4281
|
repairNodeFunctionAppManifest(nodeFunctionAppRoot, workspaceRoot);
|
|
4162
4282
|
ensureAdmZip(workspaceRoot);
|
|
4163
4283
|
addNxTargets((0, import_node_path12.join)(nodeFunctionAppRoot, "package.json"), {
|
|
4164
4284
|
package: nodeFunctionAppPackageTarget(name),
|
|
4165
4285
|
prune: nodeFunctionAppPruneTarget(name),
|
|
4166
|
-
start: nodeFunctionAppStartTarget(name)
|
|
4286
|
+
start: nodeFunctionAppStartTarget(name),
|
|
4287
|
+
// With no spec the runner exits non-zero; an empty scaffold must still pass `nx test`.
|
|
4288
|
+
...empty && { test: { options: { passWithNoTests: true } } }
|
|
4167
4289
|
});
|
|
4168
4290
|
removeGeneratedEslintConfig(workspaceRoot, `apps/${name}`);
|
|
4169
4291
|
registerProjectCommands(workspaceRoot, name, { build: true, start: `nx run ${name}:start` });
|
|
@@ -6542,7 +6664,7 @@ var PROJECT_KINDS = [
|
|
|
6542
6664
|
"csharp-internal-lib",
|
|
6543
6665
|
"vscode-extension"
|
|
6544
6666
|
];
|
|
6545
|
-
var EMPTY_KINDS = /* @__PURE__ */ new Set(["npm-lib", "internal-lib", "react-lib", "react-internal-lib"]);
|
|
6667
|
+
var EMPTY_KINDS = /* @__PURE__ */ new Set(["npm-lib", "internal-lib", "react-lib", "react-internal-lib", "node-function-app"]);
|
|
6546
6668
|
async function runAdd(kind, name, options) {
|
|
6547
6669
|
const workspaceRoot = process.cwd();
|
|
6548
6670
|
if (!fileExists((0, import_node_path25.join)(workspaceRoot, "nx.json"))) {
|
|
@@ -6588,7 +6710,7 @@ async function runAdd(kind, name, options) {
|
|
|
6588
6710
|
break;
|
|
6589
6711
|
}
|
|
6590
6712
|
case "node-function-app": {
|
|
6591
|
-
addNodeFunctionApp(workspaceRoot, resolvedName, stack);
|
|
6713
|
+
addNodeFunctionApp(workspaceRoot, resolvedName, stack, options.empty === true);
|
|
6592
6714
|
break;
|
|
6593
6715
|
}
|
|
6594
6716
|
case "npm-lib": {
|
|
@@ -7706,7 +7828,7 @@ function buildProgram(cliVersion) {
|
|
|
7706
7828
|
"node-app only: express | fastify | koa | nest | none (default: none)"
|
|
7707
7829
|
).option(
|
|
7708
7830
|
"--empty",
|
|
7709
|
-
"npm-lib, internal-lib, react-lib, react-internal-lib: scaffold the slice skeleton only, with no sample code or spec"
|
|
7831
|
+
"npm-lib, internal-lib, react-lib, react-internal-lib, node-function-app: scaffold the slice skeleton only, with no sample code or spec"
|
|
7710
7832
|
).option(
|
|
7711
7833
|
"--lib <name>",
|
|
7712
7834
|
"python-vendor only: the internal Python library (libs/<name>) to vendor into <name>"
|