@amaster.ai/cli 1.1.30 → 1.1.31
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 +22 -2
- package/dist/cli.cjs +96 -39
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +97 -40
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -3,7 +3,7 @@ import { readFileSync, existsSync, writeFileSync, readdirSync, statSync, rmSync,
|
|
|
3
3
|
import { createInterface } from 'readline/promises';
|
|
4
4
|
import { stdin, stdout } from 'process';
|
|
5
5
|
import { Command, Option } from 'commander';
|
|
6
|
-
import { readFile, mkdtemp, stat, rm, writeFile, readdir, unlink, copyFile, mkdir
|
|
6
|
+
import { readFile, mkdtemp, stat, rm, writeFile, readdir, access, unlink, copyFile, mkdir } from 'fs/promises';
|
|
7
7
|
import { join, resolve, basename, dirname, relative, parse, extname } from 'path';
|
|
8
8
|
import { randomBytes, createHash, randomUUID } from 'crypto';
|
|
9
9
|
import { tmpdir, homedir } from 'os';
|
|
@@ -537,6 +537,7 @@ async function loadAddonManifestFromDirectory(directory) {
|
|
|
537
537
|
const manifestText = await readFile(manifestPath, "utf8");
|
|
538
538
|
const manifest = JSON.parse(manifestText);
|
|
539
539
|
validateAddonManifest(manifest);
|
|
540
|
+
await assertDisplayAssetPathsExist(directory, manifest);
|
|
540
541
|
return manifest;
|
|
541
542
|
}
|
|
542
543
|
function validateAddonManifest(manifest) {
|
|
@@ -555,9 +556,40 @@ function validateAddonManifest(manifest) {
|
|
|
555
556
|
if (!Array.isArray(manifest.members)) {
|
|
556
557
|
throw new Error("addon.json missing members");
|
|
557
558
|
}
|
|
559
|
+
validateDisplayAssets(manifest);
|
|
558
560
|
validateInstallRequirements(manifest);
|
|
559
561
|
validateInstallNpm(manifest);
|
|
560
562
|
}
|
|
563
|
+
function validateDisplayAssets(manifest) {
|
|
564
|
+
const image = manifest.display.image;
|
|
565
|
+
if (image !== void 0) {
|
|
566
|
+
if (typeof image !== "string") {
|
|
567
|
+
throw new Error("addon.json display.image must be a string");
|
|
568
|
+
}
|
|
569
|
+
normalizeRelativePath(image, "display.image");
|
|
570
|
+
}
|
|
571
|
+
const screenshots = manifest.display.screenshots;
|
|
572
|
+
if (screenshots !== void 0) {
|
|
573
|
+
if (!Array.isArray(screenshots)) {
|
|
574
|
+
throw new Error("addon.json display.screenshots must be an array");
|
|
575
|
+
}
|
|
576
|
+
screenshots.forEach((item, index) => {
|
|
577
|
+
if (typeof item !== "string") {
|
|
578
|
+
throw new Error(`addon.json display.screenshots[${index}] must be a string`);
|
|
579
|
+
}
|
|
580
|
+
normalizeRelativePath(item, `display.screenshots[${index}]`);
|
|
581
|
+
});
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
async function assertDisplayAssetPathsExist(directory, manifest) {
|
|
585
|
+
const paths = [
|
|
586
|
+
...manifest.display.image ? [manifest.display.image] : [],
|
|
587
|
+
...manifest.display.screenshots ?? []
|
|
588
|
+
];
|
|
589
|
+
for (const assetPath of paths) {
|
|
590
|
+
await assertPathExists(directory, normalizeRelativePath(assetPath, "display asset path"));
|
|
591
|
+
}
|
|
592
|
+
}
|
|
561
593
|
function validateInstallRequirements(manifest) {
|
|
562
594
|
const requirements = manifest.install?.requirements;
|
|
563
595
|
if (!requirements) {
|
|
@@ -624,21 +656,21 @@ function validateInstallNpm(manifest) {
|
|
|
624
656
|
function resolveMemberSourcePath(member) {
|
|
625
657
|
const sourcePath = member.source?.path;
|
|
626
658
|
if (typeof sourcePath === "string" && sourcePath.trim()) {
|
|
627
|
-
return normalizeRelativePath(sourcePath);
|
|
659
|
+
return normalizeRelativePath(sourcePath, "member source path");
|
|
628
660
|
}
|
|
629
661
|
const fallbackKeys = ["entry", "path", "contentPath"];
|
|
630
662
|
for (const key of fallbackKeys) {
|
|
631
663
|
const value = member[key];
|
|
632
664
|
if (typeof value === "string" && value.trim()) {
|
|
633
|
-
return normalizeRelativePath(value);
|
|
665
|
+
return normalizeRelativePath(value, "member source path");
|
|
634
666
|
}
|
|
635
667
|
}
|
|
636
668
|
return null;
|
|
637
669
|
}
|
|
638
|
-
function normalizeRelativePath(value) {
|
|
670
|
+
function normalizeRelativePath(value, fieldName = "path") {
|
|
639
671
|
const normalized = value.replace(/^\.?\//, "").replace(/\\/g, "/");
|
|
640
672
|
if (!normalized || normalized.startsWith("../") || normalized.includes("/../")) {
|
|
641
|
-
throw new Error(`Invalid
|
|
673
|
+
throw new Error(`Invalid addon.json ${fieldName}: ${value}`);
|
|
642
674
|
}
|
|
643
675
|
return normalized;
|
|
644
676
|
}
|
|
@@ -706,6 +738,14 @@ async function tryDetectNearestApplicationType(startDir = process.cwd()) {
|
|
|
706
738
|
|
|
707
739
|
// src/marketplace/install.ts
|
|
708
740
|
var execFileAsync = promisify(execFile);
|
|
741
|
+
var ADDON_ROUTES_FILE = "src/routes-addon.ts";
|
|
742
|
+
var ADDON_ROUTES_IMPORT = 'import { addonRoutes } from "./routes-addon";';
|
|
743
|
+
var LEGACY_ADDON_ROUTES_IMPORT = 'import { addonRoutes } from "./amaster/registry/addon-routes.generated";';
|
|
744
|
+
var LEGACY_ADDON_ROUTES_FILE = "src/amaster/registry/addon-routes.generated.ts";
|
|
745
|
+
var ADDON_PAGES_FILE = "src/app-addon.config.ts";
|
|
746
|
+
var ADDON_PAGES_IMPORT = 'import { addonPages, addonTabBarItems } from "./app-addon.config";';
|
|
747
|
+
var LEGACY_ADDON_PAGES_IMPORT = 'import { addonPages, addonTabBarItems } from "./amaster/registry/addon-pages.generated";';
|
|
748
|
+
var LEGACY_ADDON_PAGES_FILE = "src/amaster/registry/addon-pages.generated.ts";
|
|
709
749
|
var AddonInstallConflictError = class extends Error {
|
|
710
750
|
constructor(input) {
|
|
711
751
|
super(`Addon ${input.operation} has ${input.conflicts.length} conflict(s)`);
|
|
@@ -1614,10 +1654,14 @@ async function ensureWebRoutesPatched(targetDir) {
|
|
|
1614
1654
|
const routesFile = join(targetDir, "src", "routes.tsx");
|
|
1615
1655
|
const original = await readFile(routesFile, "utf8");
|
|
1616
1656
|
let next = original;
|
|
1617
|
-
if (
|
|
1657
|
+
if (next.includes(LEGACY_ADDON_ROUTES_IMPORT)) {
|
|
1658
|
+
next = next.replace(LEGACY_ADDON_ROUTES_IMPORT, ADDON_ROUTES_IMPORT);
|
|
1659
|
+
}
|
|
1660
|
+
if (!next.includes(ADDON_ROUTES_IMPORT)) {
|
|
1618
1661
|
next = next.replace(
|
|
1619
1662
|
'import type { ComponentType } from "react";',
|
|
1620
|
-
|
|
1663
|
+
`import type { ComponentType } from "react";
|
|
1664
|
+
${ADDON_ROUTES_IMPORT}`
|
|
1621
1665
|
);
|
|
1622
1666
|
}
|
|
1623
1667
|
if (!next.includes("...addonRoutes")) {
|
|
@@ -1641,8 +1685,11 @@ async function ensureMiniAppConfigPatched(targetDir, needsTabBarItems) {
|
|
|
1641
1685
|
const configFile = join(targetDir, "src", "app.config.ts");
|
|
1642
1686
|
const original = await readFile(configFile, "utf8");
|
|
1643
1687
|
let next = original;
|
|
1644
|
-
if (
|
|
1645
|
-
next =
|
|
1688
|
+
if (next.includes(LEGACY_ADDON_PAGES_IMPORT)) {
|
|
1689
|
+
next = next.replace(LEGACY_ADDON_PAGES_IMPORT, ADDON_PAGES_IMPORT);
|
|
1690
|
+
}
|
|
1691
|
+
if (!next.includes(ADDON_PAGES_IMPORT)) {
|
|
1692
|
+
next = `${ADDON_PAGES_IMPORT}
|
|
1646
1693
|
${next}`;
|
|
1647
1694
|
}
|
|
1648
1695
|
if (!next.includes("...addonPages")) {
|
|
@@ -1667,8 +1714,6 @@ ${next}`;
|
|
|
1667
1714
|
}
|
|
1668
1715
|
}
|
|
1669
1716
|
async function rebuildRegistryFiles(targetDir, applicationType, metas) {
|
|
1670
|
-
const registryDir = join(targetDir, "src", "amaster", "registry");
|
|
1671
|
-
await mkdir(registryDir, { recursive: true });
|
|
1672
1717
|
if (applicationType === "web") {
|
|
1673
1718
|
const pageMembers2 = metas.flatMap(
|
|
1674
1719
|
(meta) => meta.members.filter((member) => member.type === "page" && member.page?.web).map((member) => ({ addonName: meta.name, member }))
|
|
@@ -1678,32 +1723,38 @@ async function rebuildRegistryFiles(targetDir, applicationType, metas) {
|
|
|
1678
1723
|
const entry = member.page.web.entry;
|
|
1679
1724
|
return {
|
|
1680
1725
|
identifier,
|
|
1681
|
-
importPath:
|
|
1726
|
+
importPath: `./${removeFileExtension(entry).replace(/\\/g, "/")}`,
|
|
1682
1727
|
route: member.page.web.route,
|
|
1683
1728
|
visible: member.page.web.visible,
|
|
1684
1729
|
name: member.name
|
|
1685
1730
|
};
|
|
1686
1731
|
});
|
|
1687
|
-
const
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1732
|
+
const routesFile = join(targetDir, "src", "routes.tsx");
|
|
1733
|
+
const routesContent = existsSync(routesFile) ? await readFile(routesFile, "utf8") : "";
|
|
1734
|
+
const alreadyPatched2 = routesContent.includes(ADDON_ROUTES_IMPORT) || routesContent.includes(LEGACY_ADDON_ROUTES_IMPORT) || routesContent.includes("...addonRoutes");
|
|
1735
|
+
await unlink(join(targetDir, LEGACY_ADDON_ROUTES_FILE)).catch(() => void 0);
|
|
1736
|
+
if (imports.length > 0 || alreadyPatched2) {
|
|
1737
|
+
const fileContent = [
|
|
1738
|
+
'import type { ComponentType } from "react";',
|
|
1739
|
+
...imports.map((item) => `import ${item.identifier} from "${item.importPath}";`),
|
|
1740
|
+
"",
|
|
1741
|
+
"type AddonRouteConfig = {",
|
|
1742
|
+
" name: string;",
|
|
1743
|
+
" path: string;",
|
|
1744
|
+
" Component: ComponentType<Record<string, unknown>>;",
|
|
1745
|
+
" visible?: boolean;",
|
|
1746
|
+
"};",
|
|
1747
|
+
"",
|
|
1748
|
+
"export const addonRoutes: AddonRouteConfig[] = [",
|
|
1749
|
+
...imports.map(
|
|
1750
|
+
(item) => ` { name: ${JSON.stringify(item.name)}, path: ${JSON.stringify(item.route)}, Component: ${item.identifier},${item.visible === void 0 ? "" : ` visible: ${item.visible},`} },`
|
|
1751
|
+
),
|
|
1752
|
+
"];",
|
|
1753
|
+
""
|
|
1754
|
+
].join("\n");
|
|
1755
|
+
await writeFile(join(targetDir, ADDON_ROUTES_FILE), fileContent);
|
|
1756
|
+
await ensureWebRoutesPatched(targetDir);
|
|
1757
|
+
}
|
|
1707
1758
|
return;
|
|
1708
1759
|
}
|
|
1709
1760
|
const pageMembers = metas.flatMap(
|
|
@@ -1714,14 +1765,20 @@ async function rebuildRegistryFiles(targetDir, applicationType, metas) {
|
|
|
1714
1765
|
pagePath: page.pagePath,
|
|
1715
1766
|
...page.tabBar
|
|
1716
1767
|
}));
|
|
1717
|
-
const
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1768
|
+
const appConfigFile = join(targetDir, "src", "app.config.ts");
|
|
1769
|
+
const appConfigContent = existsSync(appConfigFile) ? await readFile(appConfigFile, "utf8") : "";
|
|
1770
|
+
const alreadyPatched = appConfigContent.includes(ADDON_PAGES_IMPORT) || appConfigContent.includes(LEGACY_ADDON_PAGES_IMPORT) || appConfigContent.includes("...addonPages") || appConfigContent.includes("...addonTabBarItems");
|
|
1771
|
+
await unlink(join(targetDir, LEGACY_ADDON_PAGES_FILE)).catch(() => void 0);
|
|
1772
|
+
if (addonPages.length > 0 || alreadyPatched) {
|
|
1773
|
+
const fileContent = [
|
|
1774
|
+
`export const addonPages = ${JSON.stringify(addonPages, null, 2)};`,
|
|
1775
|
+
"",
|
|
1776
|
+
`export const addonTabBarItems = ${JSON.stringify(addonTabBarItems, null, 2)};`,
|
|
1777
|
+
""
|
|
1778
|
+
].join("\n");
|
|
1779
|
+
await writeFile(join(targetDir, ADDON_PAGES_FILE), fileContent);
|
|
1780
|
+
await ensureMiniAppConfigPatched(targetDir, addonTabBarItems.length > 0);
|
|
1781
|
+
}
|
|
1725
1782
|
}
|
|
1726
1783
|
async function materializeAddon(options) {
|
|
1727
1784
|
const targetDir = resolve(options.targetDir);
|