create-ampless 0.2.0-alpha.21 → 0.2.0-alpha.22
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 +74 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1761,6 +1761,14 @@ import { join as join3, relative, extname as extname2, dirname } from "path";
|
|
|
1761
1761
|
import { log as log3, outro } from "@clack/prompts";
|
|
1762
1762
|
import pc3 from "picocolors";
|
|
1763
1763
|
import { execa as execa4 } from "execa";
|
|
1764
|
+
var AMPLESS_MANAGED_APP_PATHS = [
|
|
1765
|
+
"app/(admin)/admin",
|
|
1766
|
+
"app/api/admin",
|
|
1767
|
+
"app/api/media",
|
|
1768
|
+
"app/api/mcp",
|
|
1769
|
+
"app/login",
|
|
1770
|
+
"app/site"
|
|
1771
|
+
];
|
|
1764
1772
|
var AMPLESS_PACKAGES = /* @__PURE__ */ new Set([
|
|
1765
1773
|
"ampless",
|
|
1766
1774
|
"@ampless/admin",
|
|
@@ -1882,6 +1890,63 @@ async function walkDir(dir, base, out) {
|
|
|
1882
1890
|
}
|
|
1883
1891
|
}
|
|
1884
1892
|
}
|
|
1893
|
+
async function listFilesRecursive(root) {
|
|
1894
|
+
const out = [];
|
|
1895
|
+
async function walk(current, relPrefix) {
|
|
1896
|
+
const entries = await readdir3(current, { withFileTypes: true });
|
|
1897
|
+
for (const entry of entries) {
|
|
1898
|
+
const rel = relPrefix ? `${relPrefix}/${entry.name}` : entry.name;
|
|
1899
|
+
if (entry.isDirectory()) {
|
|
1900
|
+
await walk(join3(current, entry.name), rel);
|
|
1901
|
+
} else if (entry.isFile()) {
|
|
1902
|
+
out.push(rel);
|
|
1903
|
+
}
|
|
1904
|
+
}
|
|
1905
|
+
}
|
|
1906
|
+
if (!existsSync5(root)) return out;
|
|
1907
|
+
await walk(root, "");
|
|
1908
|
+
return out;
|
|
1909
|
+
}
|
|
1910
|
+
async function pruneEmptyDirs(root) {
|
|
1911
|
+
if (!existsSync5(root)) return;
|
|
1912
|
+
const entries = await readdir3(root, { withFileTypes: true });
|
|
1913
|
+
for (const entry of entries) {
|
|
1914
|
+
if (entry.isDirectory()) {
|
|
1915
|
+
await pruneEmptyDirs(join3(root, entry.name));
|
|
1916
|
+
}
|
|
1917
|
+
}
|
|
1918
|
+
const remaining = await readdir3(root);
|
|
1919
|
+
if (remaining.length === 0) {
|
|
1920
|
+
await rm2(root, { recursive: true, force: true });
|
|
1921
|
+
}
|
|
1922
|
+
}
|
|
1923
|
+
async function findObsoleteAppFiles(destDir, sharedDir) {
|
|
1924
|
+
const obsolete = [];
|
|
1925
|
+
for (const managedPath of AMPLESS_MANAGED_APP_PATHS) {
|
|
1926
|
+
const userPath = join3(destDir, managedPath);
|
|
1927
|
+
if (!existsSync5(userPath)) continue;
|
|
1928
|
+
const templatePath2 = join3(sharedDir, managedPath);
|
|
1929
|
+
const templateFiles = new Set(await listFilesRecursive(templatePath2));
|
|
1930
|
+
const userFiles = await listFilesRecursive(userPath);
|
|
1931
|
+
for (const f of userFiles) {
|
|
1932
|
+
if (!templateFiles.has(f)) {
|
|
1933
|
+
obsolete.push(`${managedPath}/${f}`);
|
|
1934
|
+
}
|
|
1935
|
+
}
|
|
1936
|
+
}
|
|
1937
|
+
return obsolete;
|
|
1938
|
+
}
|
|
1939
|
+
async function removeObsoleteAppFiles(destDir, paths) {
|
|
1940
|
+
for (const rel of paths) {
|
|
1941
|
+
const abs = join3(destDir, rel);
|
|
1942
|
+
if (existsSync5(abs)) {
|
|
1943
|
+
await rm2(abs, { force: true });
|
|
1944
|
+
}
|
|
1945
|
+
}
|
|
1946
|
+
for (const managedPath of AMPLESS_MANAGED_APP_PATHS) {
|
|
1947
|
+
await pruneEmptyDirs(join3(destDir, managedPath));
|
|
1948
|
+
}
|
|
1949
|
+
}
|
|
1885
1950
|
function substituteVars(content, vars) {
|
|
1886
1951
|
return content.replace(/\{\{(\w+)\}\}/g, (_, key) => vars[key] ?? `{{${key}}}`);
|
|
1887
1952
|
}
|
|
@@ -1935,6 +2000,7 @@ async function runUpgradeIn(destDir, sharedDir, opts = {}) {
|
|
|
1935
2000
|
const shippedThemes = themeSyncEnabled ? await listShippedThemes(templatesRoot) : [];
|
|
1936
2001
|
const existingThemes = themeSyncEnabled ? await discoverInstalledThemes(destDir) : [];
|
|
1937
2002
|
const preservedThemes = existingThemes.filter((t) => !shippedThemes.includes(t));
|
|
2003
|
+
const obsoleteFiles = await findObsoleteAppFiles(destDir, sharedDir);
|
|
1938
2004
|
log3.info(
|
|
1939
2005
|
`replace: ${pc3.green(`\u8FFD\u52A0 ${replaceNew.length}`)} / ${pc3.yellow(`\u66F4\u65B0 ${replaceUpdate.length}`)}`
|
|
1940
2006
|
);
|
|
@@ -1949,6 +2015,9 @@ async function runUpgradeIn(destDir, sharedDir, opts = {}) {
|
|
|
1949
2015
|
`themes: ${pc3.cyan(`\u30C7\u30D5\u30A9\u30EB\u30C8\u30C6\u30FC\u30DE\u3092\u540C\u671F: ${shippedThemes.length}`)} / ${pc3.dim(`\u30AB\u30B9\u30BF\u30E0\u30C6\u30FC\u30DE (my-*) \u3092\u4FDD\u6301: ${preservedThemes.length}`)}`
|
|
1950
2016
|
);
|
|
1951
2017
|
}
|
|
2018
|
+
if (obsoleteFiles.length > 0) {
|
|
2019
|
+
log3.info(`cleanup: ${pc3.yellow(`\u524A\u9664 ${obsoleteFiles.length}`)} (ampless-managed app/ \u914D\u4E0B\u3067\u30C6\u30F3\u30D7\u30EC\u306B\u7121\u3044\u30D5\u30A1\u30A4\u30EB)`);
|
|
2020
|
+
}
|
|
1952
2021
|
log3.info(`protected: ${pc3.dim(`\u30C6\u30F3\u30D7\u30EC\u306B\u5B58\u5728\u3059\u308B\u304C\u89E6\u3089\u306A\u3044: ${classification.protected.length} \u500B`)}`);
|
|
1953
2022
|
if (opts.dryRun) {
|
|
1954
2023
|
return {
|
|
@@ -1958,7 +2027,8 @@ async function runUpgradeIn(destDir, sharedDir, opts = {}) {
|
|
|
1958
2027
|
protected: classification.protected,
|
|
1959
2028
|
themesSynced: shippedThemes,
|
|
1960
2029
|
themesPreserved: preservedThemes,
|
|
1961
|
-
packageJsonMerged: false
|
|
2030
|
+
packageJsonMerged: false,
|
|
2031
|
+
obsoleteRemoved: obsoleteFiles
|
|
1962
2032
|
};
|
|
1963
2033
|
}
|
|
1964
2034
|
for (const rel of classification.replace) {
|
|
@@ -1972,6 +2042,7 @@ async function runUpgradeIn(destDir, sharedDir, opts = {}) {
|
|
|
1972
2042
|
await copyWithSubstitution(src, dst, vars);
|
|
1973
2043
|
}
|
|
1974
2044
|
const themeResult = themeSyncEnabled ? await syncThemes(destDir, templatesRoot) : { synced: [], preserved: [] };
|
|
2045
|
+
await removeObsoleteAppFiles(destDir, obsoleteFiles);
|
|
1975
2046
|
const templatePkgRaw = await readFile3(join3(sharedDir, "package.json"), "utf-8");
|
|
1976
2047
|
const templatePkg = JSON.parse(templatePkgRaw);
|
|
1977
2048
|
const indent = detectIndent(projectPkgRaw);
|
|
@@ -2011,7 +2082,8 @@ async function runUpgradeIn(destDir, sharedDir, opts = {}) {
|
|
|
2011
2082
|
protected: classification.protected,
|
|
2012
2083
|
themesSynced: themeResult.synced,
|
|
2013
2084
|
themesPreserved: themeResult.preserved,
|
|
2014
|
-
packageJsonMerged: true
|
|
2085
|
+
packageJsonMerged: true,
|
|
2086
|
+
obsoleteRemoved: obsoleteFiles
|
|
2015
2087
|
};
|
|
2016
2088
|
}
|
|
2017
2089
|
async function runUpgrade(args) {
|