@mnci/cli 4.29.2 → 4.31.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 +119 -24
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -2563,6 +2563,19 @@ function csharpConsoleProgram(identity) {
|
|
|
2563
2563
|
Console.WriteLine(GreetUseCase.Greet("world").Message);
|
|
2564
2564
|
`;
|
|
2565
2565
|
}
|
|
2566
|
+
function csharpExampleTest(identity) {
|
|
2567
|
+
return `using ${identity};
|
|
2568
|
+
|
|
2569
|
+
public class GreetUseCaseTests
|
|
2570
|
+
{
|
|
2571
|
+
[Fact]
|
|
2572
|
+
public void GreetsAName()
|
|
2573
|
+
{
|
|
2574
|
+
Assert.Equal("Hello, world!", GreetUseCase.Greet("world").Message);
|
|
2575
|
+
}
|
|
2576
|
+
}
|
|
2577
|
+
`;
|
|
2578
|
+
}
|
|
2566
2579
|
|
|
2567
2580
|
// src/project-scaffolding/post-generation.use-case.ts
|
|
2568
2581
|
var import_node_fs5 = require("fs");
|
|
@@ -2970,6 +2983,21 @@ function writeCsharpExample(absoluteRoot, identity, kind) {
|
|
|
2970
2983
|
writeFileEnsured((0, import_node_path6.join)(absoluteRoot, "Program.cs"), csharpConsoleProgram(identity));
|
|
2971
2984
|
}
|
|
2972
2985
|
}
|
|
2986
|
+
function addCsharpTestProject(workspaceRoot, projectRoot, identity) {
|
|
2987
|
+
const name = (0, import_node_path6.basename)(projectRoot);
|
|
2988
|
+
const testRoot = `tests/${name}`;
|
|
2989
|
+
scaffoldDotnetProject(workspaceRoot, testRoot, `${identity}.Tests`, "xunit");
|
|
2990
|
+
(0, import_node_fs6.rmSync)((0, import_node_path6.join)(workspaceRoot, testRoot, "UnitTest1.cs"), { force: true });
|
|
2991
|
+
writeFileEnsured((0, import_node_path6.join)(workspaceRoot, testRoot, "GreetUseCaseTests.cs"), csharpExampleTest(identity));
|
|
2992
|
+
writeFileEnsured(
|
|
2993
|
+
(0, import_node_path6.join)(workspaceRoot, testRoot, "project.json"),
|
|
2994
|
+
toJson({ name: `${name}-tests`, tags: ["type:csharp-test"] })
|
|
2995
|
+
);
|
|
2996
|
+
const reference = (0, import_node_path6.join)(workspaceRoot, projectRoot, `${identity}.csproj`);
|
|
2997
|
+
if (runShell("dotnet", ["add", (0, import_node_path6.join)(workspaceRoot, testRoot), "reference", reference], workspaceRoot) !== 0) {
|
|
2998
|
+
throw new Error(`dotnet add reference failed for ${testRoot}`);
|
|
2999
|
+
}
|
|
3000
|
+
}
|
|
2973
3001
|
function csharpAppPackageTarget(tag, projectRoot, name) {
|
|
2974
3002
|
const outDir = `dist/apps/${name}`;
|
|
2975
3003
|
const zip = `dist/drop/${tag}-${name}.zip`;
|
|
@@ -2994,6 +3022,7 @@ function addCsharpApp(workspaceRoot, name, template = "console") {
|
|
|
2994
3022
|
const projectRoot = `apps/${name}`;
|
|
2995
3023
|
scaffoldDotnetProject(workspaceRoot, projectRoot, pascalCase(name), template);
|
|
2996
3024
|
writeCsharpExample((0, import_node_path6.join)(workspaceRoot, projectRoot), pascalCase(name), template);
|
|
3025
|
+
addCsharpTestProject(workspaceRoot, projectRoot, pascalCase(name));
|
|
2997
3026
|
addProjectJsonTargets((0, import_node_path6.join)(workspaceRoot, projectRoot, "project.json"), {
|
|
2998
3027
|
package: csharpAppPackageTarget("csharp-app", projectRoot, name),
|
|
2999
3028
|
start: csharpAppStartTarget(projectRoot)
|
|
@@ -3118,6 +3147,7 @@ async function addCsharpLib(workspaceRoot, name, options, kindProvided) {
|
|
|
3118
3147
|
const identity = `${pascalScope(scope)}.${pascalCase(name)}`;
|
|
3119
3148
|
scaffoldDotnetProject(workspaceRoot, projectRoot, identity, "classlib");
|
|
3120
3149
|
writeCsharpExample((0, import_node_path6.join)(workspaceRoot, projectRoot), identity, "classlib");
|
|
3150
|
+
addCsharpTestProject(workspaceRoot, projectRoot, identity);
|
|
3121
3151
|
addInitialVersion((0, import_node_path6.join)(workspaceRoot, projectRoot, `${identity}.csproj`));
|
|
3122
3152
|
writeCsharpVersionActions(workspaceRoot);
|
|
3123
3153
|
addProjectJsonReleaseVersionActions((0, import_node_path6.join)(workspaceRoot, projectRoot, "project.json"));
|
|
@@ -3135,6 +3165,7 @@ function addCsharpInternalLib(workspaceRoot, name) {
|
|
|
3135
3165
|
const identity = pascalCase(name);
|
|
3136
3166
|
scaffoldDotnetProject(workspaceRoot, projectRoot, identity, "classlib");
|
|
3137
3167
|
writeCsharpExample((0, import_node_path6.join)(workspaceRoot, projectRoot), identity, "classlib");
|
|
3168
|
+
addCsharpTestProject(workspaceRoot, projectRoot, identity);
|
|
3138
3169
|
registerProjectCommands(workspaceRoot, name, { build: false });
|
|
3139
3170
|
logger.step(
|
|
3140
3171
|
`Reference it from a consumer with: dotnet add <consumer>.csproj reference ${projectRoot}/${identity}.csproj`
|
|
@@ -3214,6 +3245,7 @@ function addCsharpFunctionApp(workspaceRoot, name) {
|
|
|
3214
3245
|
if (runShell("dotnet", ["restore", projectRoot], workspaceRoot) !== 0) {
|
|
3215
3246
|
throw new Error(`dotnet restore failed for ${projectRoot}`);
|
|
3216
3247
|
}
|
|
3248
|
+
addCsharpTestProject(workspaceRoot, projectRoot, identity);
|
|
3217
3249
|
addProjectJsonTargets((0, import_node_path6.join)(absoluteRoot, "project.json"), {
|
|
3218
3250
|
package: csharpAppPackageTarget("csharp-function-app", projectRoot, name),
|
|
3219
3251
|
start: csharpFunctionAppStartTarget(projectRoot)
|
|
@@ -3278,6 +3310,72 @@ function addFlutterInternalLib(workspaceRoot, name) {
|
|
|
3278
3310
|
var import_node_fs10 = require("fs");
|
|
3279
3311
|
var import_node_path11 = require("path");
|
|
3280
3312
|
|
|
3313
|
+
// src/project-scaffolding/go-example.algorithm.ts
|
|
3314
|
+
function greetingContract(packageName) {
|
|
3315
|
+
return [
|
|
3316
|
+
`package ${packageName}`,
|
|
3317
|
+
"",
|
|
3318
|
+
"// Greeting is what greeting someone returns.",
|
|
3319
|
+
"type Greeting struct {",
|
|
3320
|
+
" Message string",
|
|
3321
|
+
"}",
|
|
3322
|
+
""
|
|
3323
|
+
].join("\n");
|
|
3324
|
+
}
|
|
3325
|
+
function greetUseCase(packageName) {
|
|
3326
|
+
return [
|
|
3327
|
+
`package ${packageName}`,
|
|
3328
|
+
"",
|
|
3329
|
+
"// Greet greets someone by name: a worked example of a use case. Replace it with your own.",
|
|
3330
|
+
"func Greet(name string) Greeting {",
|
|
3331
|
+
' return Greeting{Message: "Hello, " + name + "!"}',
|
|
3332
|
+
"}",
|
|
3333
|
+
""
|
|
3334
|
+
].join("\n");
|
|
3335
|
+
}
|
|
3336
|
+
function greetUseCaseTest(packageName) {
|
|
3337
|
+
return [
|
|
3338
|
+
`package ${packageName}`,
|
|
3339
|
+
"",
|
|
3340
|
+
'import "testing"',
|
|
3341
|
+
"",
|
|
3342
|
+
"func TestGreet(t *testing.T) {",
|
|
3343
|
+
' if got := Greet("world").Message; got != "Hello, world!" {',
|
|
3344
|
+
' t.Fatalf("got %q", got)',
|
|
3345
|
+
" }",
|
|
3346
|
+
"}",
|
|
3347
|
+
""
|
|
3348
|
+
].join("\n");
|
|
3349
|
+
}
|
|
3350
|
+
function goLibraryExampleFiles(packageName, fileStem) {
|
|
3351
|
+
return {
|
|
3352
|
+
"greeting_contract.go": greetingContract(packageName),
|
|
3353
|
+
[`${fileStem}_use_case.go`]: greetUseCase(packageName),
|
|
3354
|
+
[`${fileStem}_use_case_test.go`]: greetUseCaseTest(packageName)
|
|
3355
|
+
};
|
|
3356
|
+
}
|
|
3357
|
+
function goAppExampleFiles(modulePath) {
|
|
3358
|
+
return {
|
|
3359
|
+
"main.go": [
|
|
3360
|
+
"package main",
|
|
3361
|
+
"",
|
|
3362
|
+
"import (",
|
|
3363
|
+
' "fmt"',
|
|
3364
|
+
"",
|
|
3365
|
+
` "${modulePath}/hello"`,
|
|
3366
|
+
")",
|
|
3367
|
+
"",
|
|
3368
|
+
"func main() {",
|
|
3369
|
+
' fmt.Println(hello.Greet("world").Message)',
|
|
3370
|
+
"}",
|
|
3371
|
+
""
|
|
3372
|
+
].join("\n"),
|
|
3373
|
+
"hello/greeting_contract.go": greetingContract("hello"),
|
|
3374
|
+
"hello/greet_use_case.go": greetUseCase("hello"),
|
|
3375
|
+
"hello/greet_use_case_test.go": greetUseCaseTest("hello")
|
|
3376
|
+
};
|
|
3377
|
+
}
|
|
3378
|
+
|
|
3281
3379
|
// src/go-workspace/go-plugin.use-case.ts
|
|
3282
3380
|
var import_node_fs7 = require("fs");
|
|
3283
3381
|
var import_node_path8 = require("path");
|
|
@@ -3715,6 +3813,18 @@ function setGoModulePath(workspaceRoot, projectDir) {
|
|
|
3715
3813
|
const rewritten = (0, import_node_fs10.readFileSync)(goModPath, "utf8").replace(/^module\s+\S+/m, () => `module ${prefix}/${projectDir}`);
|
|
3716
3814
|
writeFileEnsured(goModPath, rewritten);
|
|
3717
3815
|
}
|
|
3816
|
+
function writeGoAppExample(workspaceRoot, projectDir) {
|
|
3817
|
+
const goModPath = (0, import_node_path11.join)(workspaceRoot, projectDir, "go.mod");
|
|
3818
|
+
const modulePath = fileExists(goModPath) ? /^module\s+(\S+)/m.exec((0, import_node_fs10.readFileSync)(goModPath, "utf8"))?.[1] : void 0;
|
|
3819
|
+
if (modulePath === void 0) {
|
|
3820
|
+
return;
|
|
3821
|
+
}
|
|
3822
|
+
(0, import_node_fs10.rmSync)((0, import_node_path11.join)(workspaceRoot, projectDir, "main_test.go"), { force: true });
|
|
3823
|
+
const example = goAppExampleFiles(modulePath);
|
|
3824
|
+
for (const [relative, contents] of Object.entries(example)) {
|
|
3825
|
+
writeFileEnsured((0, import_node_path11.join)(workspaceRoot, projectDir, relative), contents);
|
|
3826
|
+
}
|
|
3827
|
+
}
|
|
3718
3828
|
function goTestTarget() {
|
|
3719
3829
|
return { executor: "@nx-go/nx-go:test" };
|
|
3720
3830
|
}
|
|
@@ -3834,7 +3944,7 @@ function goLibraryIdentifiers(projectName) {
|
|
|
3834
3944
|
};
|
|
3835
3945
|
}
|
|
3836
3946
|
function reshapeGoLibraryScaffold(projectRoot, projectName) {
|
|
3837
|
-
const { packageName,
|
|
3947
|
+
const { packageName, fileStem } = goLibraryIdentifiers(projectName);
|
|
3838
3948
|
(0, import_node_fs10.rmSync)((0, import_node_path11.join)(projectRoot, `${projectName}.go`), { force: true });
|
|
3839
3949
|
(0, import_node_fs10.rmSync)((0, import_node_path11.join)(projectRoot, `${projectName}_test.go`), { force: true });
|
|
3840
3950
|
const files = [
|
|
@@ -3852,29 +3962,10 @@ package ${packageName}
|
|
|
3852
3962
|
package ${packageName}
|
|
3853
3963
|
`
|
|
3854
3964
|
],
|
|
3855
|
-
|
|
3856
|
-
|
|
3857
|
-
|
|
3858
|
-
|
|
3859
|
-
// ${functionName} is the generator's sample behaviour, kept so the slice builds and tests.
|
|
3860
|
-
func ${functionName}(name string) string {
|
|
3861
|
-
return "${functionName} " + name
|
|
3862
|
-
}
|
|
3863
|
-
`
|
|
3864
|
-
],
|
|
3865
|
-
[
|
|
3866
|
-
(0, import_node_path11.join)(packageName, `${fileStem}_use_case_test.go`),
|
|
3867
|
-
`package ${packageName}
|
|
3868
|
-
|
|
3869
|
-
import "testing"
|
|
3870
|
-
|
|
3871
|
-
func Test${functionName}(t *testing.T) {
|
|
3872
|
-
if got := ${functionName}("works"); got != "${functionName} works" {
|
|
3873
|
-
t.Fatalf("got %q", got)
|
|
3874
|
-
}
|
|
3875
|
-
}
|
|
3876
|
-
`
|
|
3877
|
-
]
|
|
3965
|
+
// The starter slice: a contract, a use case and its test (see goLibraryExampleFiles).
|
|
3966
|
+
...Object.entries(goLibraryExampleFiles(packageName, fileStem)).map(
|
|
3967
|
+
([name, content]) => [(0, import_node_path11.join)(packageName, name), content]
|
|
3968
|
+
)
|
|
3878
3969
|
];
|
|
3879
3970
|
for (const [relativePath, content] of files) {
|
|
3880
3971
|
const path = (0, import_node_path11.join)(projectRoot, relativePath);
|
|
@@ -3912,6 +4003,9 @@ function addGoApp(workspaceRoot, name, options = {}) {
|
|
|
3912
4003
|
workspaceRoot
|
|
3913
4004
|
);
|
|
3914
4005
|
setGoModulePath(workspaceRoot, `apps/${name}`);
|
|
4006
|
+
if (options.web === void 0) {
|
|
4007
|
+
writeGoAppExample(workspaceRoot, `apps/${name}`);
|
|
4008
|
+
}
|
|
3915
4009
|
addProjectJsonTargets((0, import_node_path11.join)(workspaceRoot, "apps", name, "project.json"), {
|
|
3916
4010
|
build: goBuildTarget(name),
|
|
3917
4011
|
test: goTestTarget(),
|
|
@@ -3951,6 +4045,7 @@ function addGoFunctionApp(workspaceRoot, name) {
|
|
|
3951
4045
|
workspaceRoot
|
|
3952
4046
|
);
|
|
3953
4047
|
setGoModulePath(workspaceRoot, `apps/${name}`);
|
|
4048
|
+
writeGoAppExample(workspaceRoot, `apps/${name}`);
|
|
3954
4049
|
addProjectJsonTargets((0, import_node_path11.join)(workspaceRoot, "apps", name, "project.json"), {
|
|
3955
4050
|
"build": goBuildTarget(name),
|
|
3956
4051
|
"test": goTestTarget(),
|