@mnci/cli 4.29.2 → 4.30.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 +87 -24
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -3278,6 +3278,72 @@ function addFlutterInternalLib(workspaceRoot, name) {
|
|
|
3278
3278
|
var import_node_fs10 = require("fs");
|
|
3279
3279
|
var import_node_path11 = require("path");
|
|
3280
3280
|
|
|
3281
|
+
// src/project-scaffolding/go-example.algorithm.ts
|
|
3282
|
+
function greetingContract(packageName) {
|
|
3283
|
+
return [
|
|
3284
|
+
`package ${packageName}`,
|
|
3285
|
+
"",
|
|
3286
|
+
"// Greeting is what greeting someone returns.",
|
|
3287
|
+
"type Greeting struct {",
|
|
3288
|
+
" Message string",
|
|
3289
|
+
"}",
|
|
3290
|
+
""
|
|
3291
|
+
].join("\n");
|
|
3292
|
+
}
|
|
3293
|
+
function greetUseCase(packageName) {
|
|
3294
|
+
return [
|
|
3295
|
+
`package ${packageName}`,
|
|
3296
|
+
"",
|
|
3297
|
+
"// Greet greets someone by name: a worked example of a use case. Replace it with your own.",
|
|
3298
|
+
"func Greet(name string) Greeting {",
|
|
3299
|
+
' return Greeting{Message: "Hello, " + name + "!"}',
|
|
3300
|
+
"}",
|
|
3301
|
+
""
|
|
3302
|
+
].join("\n");
|
|
3303
|
+
}
|
|
3304
|
+
function greetUseCaseTest(packageName) {
|
|
3305
|
+
return [
|
|
3306
|
+
`package ${packageName}`,
|
|
3307
|
+
"",
|
|
3308
|
+
'import "testing"',
|
|
3309
|
+
"",
|
|
3310
|
+
"func TestGreet(t *testing.T) {",
|
|
3311
|
+
' if got := Greet("world").Message; got != "Hello, world!" {',
|
|
3312
|
+
' t.Fatalf("got %q", got)',
|
|
3313
|
+
" }",
|
|
3314
|
+
"}",
|
|
3315
|
+
""
|
|
3316
|
+
].join("\n");
|
|
3317
|
+
}
|
|
3318
|
+
function goLibraryExampleFiles(packageName, fileStem) {
|
|
3319
|
+
return {
|
|
3320
|
+
"greeting_contract.go": greetingContract(packageName),
|
|
3321
|
+
[`${fileStem}_use_case.go`]: greetUseCase(packageName),
|
|
3322
|
+
[`${fileStem}_use_case_test.go`]: greetUseCaseTest(packageName)
|
|
3323
|
+
};
|
|
3324
|
+
}
|
|
3325
|
+
function goAppExampleFiles(modulePath) {
|
|
3326
|
+
return {
|
|
3327
|
+
"main.go": [
|
|
3328
|
+
"package main",
|
|
3329
|
+
"",
|
|
3330
|
+
"import (",
|
|
3331
|
+
' "fmt"',
|
|
3332
|
+
"",
|
|
3333
|
+
` "${modulePath}/hello"`,
|
|
3334
|
+
")",
|
|
3335
|
+
"",
|
|
3336
|
+
"func main() {",
|
|
3337
|
+
' fmt.Println(hello.Greet("world").Message)',
|
|
3338
|
+
"}",
|
|
3339
|
+
""
|
|
3340
|
+
].join("\n"),
|
|
3341
|
+
"hello/greeting_contract.go": greetingContract("hello"),
|
|
3342
|
+
"hello/greet_use_case.go": greetUseCase("hello"),
|
|
3343
|
+
"hello/greet_use_case_test.go": greetUseCaseTest("hello")
|
|
3344
|
+
};
|
|
3345
|
+
}
|
|
3346
|
+
|
|
3281
3347
|
// src/go-workspace/go-plugin.use-case.ts
|
|
3282
3348
|
var import_node_fs7 = require("fs");
|
|
3283
3349
|
var import_node_path8 = require("path");
|
|
@@ -3715,6 +3781,18 @@ function setGoModulePath(workspaceRoot, projectDir) {
|
|
|
3715
3781
|
const rewritten = (0, import_node_fs10.readFileSync)(goModPath, "utf8").replace(/^module\s+\S+/m, () => `module ${prefix}/${projectDir}`);
|
|
3716
3782
|
writeFileEnsured(goModPath, rewritten);
|
|
3717
3783
|
}
|
|
3784
|
+
function writeGoAppExample(workspaceRoot, projectDir) {
|
|
3785
|
+
const goModPath = (0, import_node_path11.join)(workspaceRoot, projectDir, "go.mod");
|
|
3786
|
+
const modulePath = fileExists(goModPath) ? /^module\s+(\S+)/m.exec((0, import_node_fs10.readFileSync)(goModPath, "utf8"))?.[1] : void 0;
|
|
3787
|
+
if (modulePath === void 0) {
|
|
3788
|
+
return;
|
|
3789
|
+
}
|
|
3790
|
+
(0, import_node_fs10.rmSync)((0, import_node_path11.join)(workspaceRoot, projectDir, "main_test.go"), { force: true });
|
|
3791
|
+
const example = goAppExampleFiles(modulePath);
|
|
3792
|
+
for (const [relative, contents] of Object.entries(example)) {
|
|
3793
|
+
writeFileEnsured((0, import_node_path11.join)(workspaceRoot, projectDir, relative), contents);
|
|
3794
|
+
}
|
|
3795
|
+
}
|
|
3718
3796
|
function goTestTarget() {
|
|
3719
3797
|
return { executor: "@nx-go/nx-go:test" };
|
|
3720
3798
|
}
|
|
@@ -3834,7 +3912,7 @@ function goLibraryIdentifiers(projectName) {
|
|
|
3834
3912
|
};
|
|
3835
3913
|
}
|
|
3836
3914
|
function reshapeGoLibraryScaffold(projectRoot, projectName) {
|
|
3837
|
-
const { packageName,
|
|
3915
|
+
const { packageName, fileStem } = goLibraryIdentifiers(projectName);
|
|
3838
3916
|
(0, import_node_fs10.rmSync)((0, import_node_path11.join)(projectRoot, `${projectName}.go`), { force: true });
|
|
3839
3917
|
(0, import_node_fs10.rmSync)((0, import_node_path11.join)(projectRoot, `${projectName}_test.go`), { force: true });
|
|
3840
3918
|
const files = [
|
|
@@ -3852,29 +3930,10 @@ package ${packageName}
|
|
|
3852
3930
|
package ${packageName}
|
|
3853
3931
|
`
|
|
3854
3932
|
],
|
|
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
|
-
]
|
|
3933
|
+
// The starter slice: a contract, a use case and its test (see goLibraryExampleFiles).
|
|
3934
|
+
...Object.entries(goLibraryExampleFiles(packageName, fileStem)).map(
|
|
3935
|
+
([name, content]) => [(0, import_node_path11.join)(packageName, name), content]
|
|
3936
|
+
)
|
|
3878
3937
|
];
|
|
3879
3938
|
for (const [relativePath, content] of files) {
|
|
3880
3939
|
const path = (0, import_node_path11.join)(projectRoot, relativePath);
|
|
@@ -3912,6 +3971,9 @@ function addGoApp(workspaceRoot, name, options = {}) {
|
|
|
3912
3971
|
workspaceRoot
|
|
3913
3972
|
);
|
|
3914
3973
|
setGoModulePath(workspaceRoot, `apps/${name}`);
|
|
3974
|
+
if (options.web === void 0) {
|
|
3975
|
+
writeGoAppExample(workspaceRoot, `apps/${name}`);
|
|
3976
|
+
}
|
|
3915
3977
|
addProjectJsonTargets((0, import_node_path11.join)(workspaceRoot, "apps", name, "project.json"), {
|
|
3916
3978
|
build: goBuildTarget(name),
|
|
3917
3979
|
test: goTestTarget(),
|
|
@@ -3951,6 +4013,7 @@ function addGoFunctionApp(workspaceRoot, name) {
|
|
|
3951
4013
|
workspaceRoot
|
|
3952
4014
|
);
|
|
3953
4015
|
setGoModulePath(workspaceRoot, `apps/${name}`);
|
|
4016
|
+
writeGoAppExample(workspaceRoot, `apps/${name}`);
|
|
3954
4017
|
addProjectJsonTargets((0, import_node_path11.join)(workspaceRoot, "apps", name, "project.json"), {
|
|
3955
4018
|
"build": goBuildTarget(name),
|
|
3956
4019
|
"test": goTestTarget(),
|