@bluealba/platform-cli 0.2.0 → 0.2.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/dist/index.js +92 -42
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -125,8 +125,8 @@ function Spinner({ label }) {
|
|
|
125
125
|
import { Fzf } from "fzf";
|
|
126
126
|
|
|
127
127
|
// src/commands/create-application/create-application.command.ts
|
|
128
|
-
import { join as
|
|
129
|
-
import { cwd } from "process";
|
|
128
|
+
import { join as join10 } from "path";
|
|
129
|
+
import { cwd as cwd2 } from "process";
|
|
130
130
|
import { mkdir as mkdir2 } from "fs/promises";
|
|
131
131
|
|
|
132
132
|
// src/commands/create-application/scaffold-application-monorepo.ts
|
|
@@ -465,6 +465,20 @@ function formatError(err) {
|
|
|
465
465
|
return err instanceof Error ? err.message : String(err);
|
|
466
466
|
}
|
|
467
467
|
|
|
468
|
+
// src/utils/platform-check.ts
|
|
469
|
+
import { access } from "fs/promises";
|
|
470
|
+
import { join as join9 } from "path";
|
|
471
|
+
import { cwd } from "process";
|
|
472
|
+
async function isPlatformInitialized() {
|
|
473
|
+
try {
|
|
474
|
+
await access(join9(cwd(), "core"));
|
|
475
|
+
await access(join9(cwd(), "local"));
|
|
476
|
+
return true;
|
|
477
|
+
} catch {
|
|
478
|
+
return false;
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
|
|
468
482
|
// src/commands/create-application/create-application.command.ts
|
|
469
483
|
var CREATE_APPLICATION_COMMAND_NAME = "create-application";
|
|
470
484
|
var createApplicationCommand = {
|
|
@@ -481,10 +495,14 @@ async function createApplication(params, logger) {
|
|
|
481
495
|
hasUserInterface,
|
|
482
496
|
hasBackendService
|
|
483
497
|
} = params;
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
498
|
+
if (!await isPlatformInitialized()) {
|
|
499
|
+
logger.log("Error: Cannot create an application \u2014 no platform initialized in this directory.");
|
|
500
|
+
return;
|
|
501
|
+
}
|
|
502
|
+
const rootDir = cwd2();
|
|
503
|
+
const applicationDir = join10(rootDir, applicationName);
|
|
504
|
+
const bootstrapServiceDir = join10(applicationDir, "services", `${applicationName}-bootstrap-service`);
|
|
505
|
+
const localDir = join10(rootDir, "local");
|
|
488
506
|
logger.log(`Creating application monorepo "${applicationName}"...`);
|
|
489
507
|
try {
|
|
490
508
|
await scaffoldApplicationMonorepo(applicationDir, organizationName, platformName, applicationName, logger);
|
|
@@ -492,8 +510,8 @@ async function createApplication(params, logger) {
|
|
|
492
510
|
logger.log(`Error: Could not scaffold application monorepo \u2014 ${formatError(err)}`);
|
|
493
511
|
return;
|
|
494
512
|
}
|
|
495
|
-
await mkdir2(
|
|
496
|
-
await mkdir2(
|
|
513
|
+
await mkdir2(join10(applicationDir, "services"), { recursive: true });
|
|
514
|
+
await mkdir2(join10(applicationDir, "ui"), { recursive: true });
|
|
497
515
|
logger.log(`Creating bootstrap service "${applicationName}-bootstrap-service"...`);
|
|
498
516
|
const bootstrapServiceDir_var = `${applicationName}/services`;
|
|
499
517
|
try {
|
|
@@ -526,7 +544,7 @@ async function createApplication(params, logger) {
|
|
|
526
544
|
);
|
|
527
545
|
}
|
|
528
546
|
if (hasUserInterface) {
|
|
529
|
-
const uiDir =
|
|
547
|
+
const uiDir = join10(applicationDir, "ui", `${applicationName}-ui`);
|
|
530
548
|
const uiBaseDir = `${applicationName}/ui`;
|
|
531
549
|
try {
|
|
532
550
|
await scaffoldUiModule(uiDir, organizationName, platformName, applicationName, applicationDisplayName, uiBaseDir, logger);
|
|
@@ -536,7 +554,7 @@ async function createApplication(params, logger) {
|
|
|
536
554
|
}
|
|
537
555
|
}
|
|
538
556
|
if (hasBackendService) {
|
|
539
|
-
const serviceDir =
|
|
557
|
+
const serviceDir = join10(applicationDir, "services", `${applicationName}-service`);
|
|
540
558
|
const serviceBaseDir = `${applicationName}/services`;
|
|
541
559
|
try {
|
|
542
560
|
await scaffoldNestjsService(serviceDir, organizationName, applicationName, applicationDisplayName, serviceBaseDir, logger);
|
|
@@ -545,7 +563,7 @@ async function createApplication(params, logger) {
|
|
|
545
563
|
return;
|
|
546
564
|
}
|
|
547
565
|
}
|
|
548
|
-
const dockerComposePath =
|
|
566
|
+
const dockerComposePath = join10(localDir, `${applicationName}-docker-compose.yml`);
|
|
549
567
|
const basePort = await getNextAvailablePort(localDir);
|
|
550
568
|
const uiPort = hasUserInterface ? basePort : 0;
|
|
551
569
|
const servicePort = hasBackendService ? hasUserInterface ? basePort + 1 : basePort : 0;
|
|
@@ -558,14 +576,14 @@ async function createApplication(params, logger) {
|
|
|
558
576
|
servicePort,
|
|
559
577
|
logger
|
|
560
578
|
);
|
|
561
|
-
const rootDockerComposePath =
|
|
579
|
+
const rootDockerComposePath = join10(localDir, "docker-compose.yml");
|
|
562
580
|
await updateRootDockerCompose(rootDockerComposePath, applicationName, logger);
|
|
563
581
|
logger.log(`Done! Application "${applicationName}" created at ${applicationDir}`);
|
|
564
582
|
}
|
|
565
583
|
|
|
566
584
|
// src/commands/init/init.command.ts
|
|
567
|
-
import { join as
|
|
568
|
-
import { cwd as
|
|
585
|
+
import { join as join16 } from "path";
|
|
586
|
+
import { cwd as cwd3 } from "process";
|
|
569
587
|
|
|
570
588
|
// src/utils/string.ts
|
|
571
589
|
function camelize(name) {
|
|
@@ -574,8 +592,8 @@ function camelize(name) {
|
|
|
574
592
|
|
|
575
593
|
// src/commands/init/scaffold-platform.ts
|
|
576
594
|
import { fileURLToPath as fileURLToPath6 } from "url";
|
|
577
|
-
import { join as
|
|
578
|
-
var templateDir =
|
|
595
|
+
import { join as join11, dirname as dirname7 } from "path";
|
|
596
|
+
var templateDir = join11(
|
|
579
597
|
dirname7(fileURLToPath6(import.meta.url)),
|
|
580
598
|
"..",
|
|
581
599
|
"templates",
|
|
@@ -587,8 +605,8 @@ async function scaffoldPlatform(outputDir, variables, logger) {
|
|
|
587
605
|
|
|
588
606
|
// src/commands/init/scaffold-platform-bootstrap.ts
|
|
589
607
|
import { fileURLToPath as fileURLToPath7 } from "url";
|
|
590
|
-
import { join as
|
|
591
|
-
var templateDir2 =
|
|
608
|
+
import { join as join12, dirname as dirname8 } from "path";
|
|
609
|
+
var templateDir2 = join12(
|
|
592
610
|
dirname8(fileURLToPath7(import.meta.url)),
|
|
593
611
|
"..",
|
|
594
612
|
"templates",
|
|
@@ -600,8 +618,8 @@ async function scaffoldPlatformBootstrap(outputDir, variables, logger) {
|
|
|
600
618
|
|
|
601
619
|
// src/commands/init/scaffold-customization-ui.ts
|
|
602
620
|
import { fileURLToPath as fileURLToPath8 } from "url";
|
|
603
|
-
import { join as
|
|
604
|
-
var templateDir3 =
|
|
621
|
+
import { join as join13, dirname as dirname9 } from "path";
|
|
622
|
+
var templateDir3 = join13(
|
|
605
623
|
dirname9(fileURLToPath8(import.meta.url)),
|
|
606
624
|
"..",
|
|
607
625
|
"templates",
|
|
@@ -612,10 +630,10 @@ async function scaffoldCustomizationUi(outputDir, variables, logger) {
|
|
|
612
630
|
}
|
|
613
631
|
|
|
614
632
|
// src/commands/init/register-customization-module.ts
|
|
615
|
-
import { join as
|
|
633
|
+
import { join as join14 } from "path";
|
|
616
634
|
import { readFile as readFile5, writeFile as writeFile5 } from "fs/promises";
|
|
617
635
|
async function registerCustomizationModule(bootstrapServiceDir, organizationName, logger) {
|
|
618
|
-
const modulesJsonPath =
|
|
636
|
+
const modulesJsonPath = join14(bootstrapServiceDir, "src", "data", "platform", "modules.json");
|
|
619
637
|
const entry = {
|
|
620
638
|
name: `@${organizationName}/platform-customization-ui`,
|
|
621
639
|
displayName: "Platform Customization UI",
|
|
@@ -638,7 +656,7 @@ async function registerCustomizationModule(bootstrapServiceDir, organizationName
|
|
|
638
656
|
|
|
639
657
|
// src/commands/init/generate-local-env.ts
|
|
640
658
|
import { readFile as readFile6, writeFile as writeFile6 } from "fs/promises";
|
|
641
|
-
import { join as
|
|
659
|
+
import { join as join15 } from "path";
|
|
642
660
|
|
|
643
661
|
// src/utils/random.ts
|
|
644
662
|
import { randomBytes } from "crypto";
|
|
@@ -648,8 +666,8 @@ function generateRandomSecret() {
|
|
|
648
666
|
|
|
649
667
|
// src/commands/init/generate-local-env.ts
|
|
650
668
|
async function generateLocalEnv(outputDir, logger) {
|
|
651
|
-
const examplePath =
|
|
652
|
-
const envPath =
|
|
669
|
+
const examplePath = join15(outputDir, "local", ".env.example");
|
|
670
|
+
const envPath = join15(outputDir, "local", ".env");
|
|
653
671
|
logger.log("Generating local/.env with random secrets...");
|
|
654
672
|
const content = await readFile6(examplePath, "utf-8");
|
|
655
673
|
const result = content.replace(/^(PAE_AUTH_JWT_SECRET|PAE_GATEWAY_SERVICE_ACCESS_SECRET|PAE_DB_PASSWORD)=$/gm, (_, key) => {
|
|
@@ -665,9 +683,13 @@ var initCommand = {
|
|
|
665
683
|
description: "Initialize a new platform"
|
|
666
684
|
};
|
|
667
685
|
async function init(params, logger) {
|
|
686
|
+
if (await isPlatformInitialized()) {
|
|
687
|
+
logger.log("Error: Cannot initialize a new platform \u2014 a platform is already initialized in this directory.");
|
|
688
|
+
return;
|
|
689
|
+
}
|
|
668
690
|
const { organizationName, platformName, platformDisplayName } = params;
|
|
669
691
|
const platformTitle = camelize(platformName);
|
|
670
|
-
const outputDir =
|
|
692
|
+
const outputDir = cwd3();
|
|
671
693
|
logger.log(`Initializing ${platformTitle} platform for @${organizationName}...`);
|
|
672
694
|
const variables = {
|
|
673
695
|
organizationName,
|
|
@@ -691,7 +713,7 @@ async function init(params, logger) {
|
|
|
691
713
|
}
|
|
692
714
|
try {
|
|
693
715
|
await scaffoldPlatformBootstrap(
|
|
694
|
-
|
|
716
|
+
join16(outputDir, "core", "services", "platform-bootstrap-service"),
|
|
695
717
|
variables,
|
|
696
718
|
logger
|
|
697
719
|
);
|
|
@@ -701,7 +723,7 @@ async function init(params, logger) {
|
|
|
701
723
|
}
|
|
702
724
|
try {
|
|
703
725
|
await scaffoldCustomizationUi(
|
|
704
|
-
|
|
726
|
+
join16(outputDir, "core", "ui", "platform-customization-ui"),
|
|
705
727
|
variables,
|
|
706
728
|
logger
|
|
707
729
|
);
|
|
@@ -711,7 +733,7 @@ async function init(params, logger) {
|
|
|
711
733
|
}
|
|
712
734
|
try {
|
|
713
735
|
await registerCustomizationModule(
|
|
714
|
-
|
|
736
|
+
join16(outputDir, "core", "services", "platform-bootstrap-service"),
|
|
715
737
|
organizationName,
|
|
716
738
|
logger
|
|
717
739
|
);
|
|
@@ -723,8 +745,8 @@ async function init(params, logger) {
|
|
|
723
745
|
}
|
|
724
746
|
|
|
725
747
|
// src/commands/configure-idp/configure-idp.command.ts
|
|
726
|
-
import { join as
|
|
727
|
-
import { cwd as
|
|
748
|
+
import { join as join17 } from "path";
|
|
749
|
+
import { cwd as cwd4 } from "process";
|
|
728
750
|
import { fetch as undiciFetch, Agent } from "undici";
|
|
729
751
|
|
|
730
752
|
// src/utils/env-reader.ts
|
|
@@ -802,7 +824,11 @@ var configureIdpCommand = {
|
|
|
802
824
|
description: "Configure an Identity Provider (IDP) in the gateway"
|
|
803
825
|
};
|
|
804
826
|
async function configureIdp(params, logger) {
|
|
805
|
-
|
|
827
|
+
if (!await isPlatformInitialized()) {
|
|
828
|
+
logger.log("Error: Cannot configure an IDP \u2014 no platform initialized in this directory.");
|
|
829
|
+
return;
|
|
830
|
+
}
|
|
831
|
+
const envPath = join17(cwd4(), "local", ".env");
|
|
806
832
|
let env;
|
|
807
833
|
try {
|
|
808
834
|
env = await readEnvFile(envPath);
|
|
@@ -892,8 +918,8 @@ import { useState as useState2, useCallback, useRef } from "react";
|
|
|
892
918
|
|
|
893
919
|
// src/controllers/ui/create-application.ui-controller.ts
|
|
894
920
|
import { readFile as readFile8 } from "fs/promises";
|
|
895
|
-
import { join as
|
|
896
|
-
import { cwd as
|
|
921
|
+
import { join as join18 } from "path";
|
|
922
|
+
import { cwd as cwd5 } from "process";
|
|
897
923
|
|
|
898
924
|
// src/services/create-application.service.ts
|
|
899
925
|
async function createApplicationService(params, logger) {
|
|
@@ -902,11 +928,15 @@ async function createApplicationService(params, logger) {
|
|
|
902
928
|
|
|
903
929
|
// src/controllers/ui/create-application.ui-controller.ts
|
|
904
930
|
async function createApplicationUiController(ctx) {
|
|
931
|
+
if (!await isPlatformInitialized()) {
|
|
932
|
+
ctx.log("Error: Cannot create an application \u2014 no platform initialized in this directory.");
|
|
933
|
+
return;
|
|
934
|
+
}
|
|
905
935
|
let organizationName;
|
|
906
936
|
let platformName;
|
|
907
937
|
try {
|
|
908
938
|
const corePackageJson = JSON.parse(
|
|
909
|
-
await readFile8(
|
|
939
|
+
await readFile8(join18(cwd5(), "core", "package.json"), "utf-8")
|
|
910
940
|
);
|
|
911
941
|
const scopeMatch = corePackageJson.name.match(/^@([^/]+)\//);
|
|
912
942
|
organizationName = scopeMatch?.[1];
|
|
@@ -958,6 +988,10 @@ async function initService(params, logger) {
|
|
|
958
988
|
|
|
959
989
|
// src/controllers/ui/init.ui-controller.ts
|
|
960
990
|
async function initUiController(ctx) {
|
|
991
|
+
if (await isPlatformInitialized()) {
|
|
992
|
+
ctx.log("Error: Cannot initialize a new platform \u2014 a platform is already initialized in this directory.");
|
|
993
|
+
return;
|
|
994
|
+
}
|
|
961
995
|
const organizationName = await ctx.prompt("Organization name:");
|
|
962
996
|
const platformName = await ctx.prompt("Platform name:");
|
|
963
997
|
const platformDisplayName = await ctx.prompt("Platform display name:");
|
|
@@ -971,6 +1005,10 @@ async function configureIdpService(params, logger) {
|
|
|
971
1005
|
|
|
972
1006
|
// src/controllers/ui/configure-idp.ui-controller.ts
|
|
973
1007
|
async function configureIdpUiController(ctx) {
|
|
1008
|
+
if (!await isPlatformInitialized()) {
|
|
1009
|
+
ctx.log("Error: Cannot configure an IDP \u2014 no platform initialized in this directory.");
|
|
1010
|
+
return;
|
|
1011
|
+
}
|
|
974
1012
|
const providers = getAllProviders();
|
|
975
1013
|
const options = providers.map((p, i) => `${i + 1}: ${p.displayName}`).join(", ");
|
|
976
1014
|
const selectionInput = await ctx.prompt(`Select IDP type (${options}):`);
|
|
@@ -1203,9 +1241,13 @@ function App() {
|
|
|
1203
1241
|
|
|
1204
1242
|
// src/controllers/cli/create-application.cli-controller.ts
|
|
1205
1243
|
import { readFile as readFile9 } from "fs/promises";
|
|
1206
|
-
import { join as
|
|
1207
|
-
import { cwd as
|
|
1244
|
+
import { join as join19 } from "path";
|
|
1245
|
+
import { cwd as cwd6 } from "process";
|
|
1208
1246
|
async function createApplicationCliController(args2) {
|
|
1247
|
+
if (!await isPlatformInitialized()) {
|
|
1248
|
+
console.error("Error: Cannot create an application \u2014 no platform initialized in this directory.");
|
|
1249
|
+
process.exit(1);
|
|
1250
|
+
}
|
|
1209
1251
|
const {
|
|
1210
1252
|
applicationName,
|
|
1211
1253
|
applicationDisplayName,
|
|
@@ -1225,7 +1267,7 @@ async function createApplicationCliController(args2) {
|
|
|
1225
1267
|
let platformName;
|
|
1226
1268
|
try {
|
|
1227
1269
|
const corePackageJson = JSON.parse(
|
|
1228
|
-
await readFile9(
|
|
1270
|
+
await readFile9(join19(cwd6(), "core", "package.json"), "utf-8")
|
|
1229
1271
|
);
|
|
1230
1272
|
const scopeMatch = corePackageJson.name.match(/^@([^/]+)\//);
|
|
1231
1273
|
organizationName = scopeMatch?.[1];
|
|
@@ -1255,6 +1297,10 @@ async function createApplicationCliController(args2) {
|
|
|
1255
1297
|
|
|
1256
1298
|
// src/controllers/cli/init.cli-controller.ts
|
|
1257
1299
|
async function initCliController(args2) {
|
|
1300
|
+
if (await isPlatformInitialized()) {
|
|
1301
|
+
console.error("Error: Cannot initialize a new platform \u2014 a platform is already initialized in this directory.");
|
|
1302
|
+
process.exit(1);
|
|
1303
|
+
}
|
|
1258
1304
|
const { organizationName, platformName, platformDisplayName } = args2;
|
|
1259
1305
|
if (!organizationName || !platformName || !platformDisplayName) {
|
|
1260
1306
|
console.error("Error: organizationName, platformName, and platformDisplayName are required.");
|
|
@@ -1269,6 +1315,10 @@ async function initCliController(args2) {
|
|
|
1269
1315
|
// src/controllers/cli/configure-idp.cli-controller.ts
|
|
1270
1316
|
async function configureIdpCliController(args2) {
|
|
1271
1317
|
const logger = { log: console.log };
|
|
1318
|
+
if (!await isPlatformInitialized()) {
|
|
1319
|
+
console.error("Error: Cannot configure an IDP \u2014 no platform initialized in this directory.");
|
|
1320
|
+
process.exit(1);
|
|
1321
|
+
}
|
|
1272
1322
|
const { providerType, name, issuer, clientId, clientSecret } = args2;
|
|
1273
1323
|
if (!providerType || !name || !issuer || !clientId || !clientSecret) {
|
|
1274
1324
|
logger.log("Error: Missing required arguments: providerType, name, issuer, clientId, clientSecret");
|
|
@@ -1293,12 +1343,12 @@ async function configureIdpCliController(args2) {
|
|
|
1293
1343
|
|
|
1294
1344
|
// src/utils/run-npm-script.ts
|
|
1295
1345
|
import { spawn } from "child_process";
|
|
1296
|
-
import { access } from "fs/promises";
|
|
1297
|
-
import { join as
|
|
1346
|
+
import { access as access2 } from "fs/promises";
|
|
1347
|
+
import { join as join20 } from "path";
|
|
1298
1348
|
async function runNpmScript(scriptName, logger, signal) {
|
|
1299
|
-
const localDir =
|
|
1349
|
+
const localDir = join20(process.cwd(), "local");
|
|
1300
1350
|
try {
|
|
1301
|
-
await
|
|
1351
|
+
await access2(localDir);
|
|
1302
1352
|
} catch {
|
|
1303
1353
|
logger.log(`Error: "local/" directory not found. Run "platform init" first.`);
|
|
1304
1354
|
return;
|