@soroush.design/cli 0.2.0-alpha.5 → 0.3.0-alpha.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/bin.mjs +4 -4
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +1 -1
- package/dist/{io-CqI2BTaP.mjs → io-BFbf4S_u.mjs} +178 -124
- package/package.json +3 -3
- package/templates/astro/js/base/README.md +2 -5
- package/templates/astro/js/base/src/components/About.jsx +1 -4
- package/templates/astro/js/base/src/components/Header.jsx +64 -69
- package/templates/astro/js/base/src/components/SchemeSwitch.jsx +33 -0
- package/templates/astro/js/base/src/layouts/Layout.astro +24 -13
- package/templates/astro/ts/base/README.md +2 -5
- package/templates/astro/ts/base/src/components/About.tsx +1 -4
- package/templates/astro/ts/base/src/components/Header.tsx +65 -69
- package/templates/astro/ts/base/src/components/SchemeSwitch.tsx +41 -0
- package/templates/astro/ts/base/src/layouts/Layout.astro +24 -13
- package/templates/react-router/js/base/src/components/Header.jsx +59 -0
- package/templates/react-router/js/base/src/components/SchemeSwitch.jsx +31 -0
- package/templates/react-router/js/base/src/pages/Layout.jsx +8 -75
- package/templates/react-router/ts/base/src/components/Header.tsx +60 -0
- package/templates/react-router/ts/base/src/components/SchemeSwitch.tsx +39 -0
- package/templates/react-router/ts/base/src/pages/Layout.tsx +8 -75
- package/templates/vike/js/base/src/components/Header.jsx +59 -0
- package/templates/vike/js/base/src/components/SchemeSwitch.jsx +33 -0
- package/templates/vike/js/base/src/pages/+Layout.jsx +11 -106
- package/templates/vike/js/base/src/pages/+onRenderHtml.jsx +2 -2
- package/templates/vike/js/base/src/pages/PageShell.jsx +1 -1
- package/templates/vike/js/ssr/src/pages/+onRenderHtml.jsx +2 -2
- package/templates/vike/ts/base/src/components/Header.tsx +60 -0
- package/templates/vike/ts/base/src/components/SchemeSwitch.tsx +41 -0
- package/templates/vike/ts/base/src/pages/+Layout.tsx +11 -106
- package/templates/vike/ts/base/src/pages/+onRenderHtml.tsx +2 -2
- package/templates/vike/ts/base/src/pages/PageShell.tsx +1 -1
- package/templates/vike/ts/ssr/src/pages/+onRenderHtml.tsx +2 -2
package/dist/bin.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { n as main, t as createNodeIo } from "./io-
|
|
2
|
+
import { n as main, t as createNodeIo } from "./io-BFbf4S_u.mjs";
|
|
3
3
|
// ../design-system/package.json
|
|
4
4
|
var name = "@soroush.tech/design-system";
|
|
5
|
-
var version = "
|
|
5
|
+
var version = "3.0.0-alpha.0";
|
|
6
6
|
var peerDependencies = {
|
|
7
|
-
"react": "^
|
|
8
|
-
"react-dom": "^
|
|
7
|
+
"react": "^19.2.8",
|
|
8
|
+
"react-dom": "^19.2.8"
|
|
9
9
|
};
|
|
10
10
|
// src/bin.ts
|
|
11
11
|
process.exitCode = await main(process.argv.slice(2), createNodeIo(), {
|
package/dist/index.d.mts
CHANGED
|
@@ -100,7 +100,7 @@ interface CreateOptions {
|
|
|
100
100
|
packageManager: PackageManagerName | undefined;
|
|
101
101
|
/** How the repository holds the app: asked for, or a workspace, when missing. */
|
|
102
102
|
layout: Layout | undefined;
|
|
103
|
-
/** How the pages are rendered: asked for, or
|
|
103
|
+
/** How the pages are rendered: asked for, or the first the framework renders, when missing. */
|
|
104
104
|
rendering: Rendering | undefined;
|
|
105
105
|
/** The libraries to add: asked for, or none, when missing. */
|
|
106
106
|
libraries: readonly Library[] | undefined;
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as createNodeIo, n as default, r as readDesignSystemPackage } from "./io-
|
|
1
|
+
export { t as createNodeIo, n as default, r as readDesignSystemPackage } from "./io-BFbf4S_u.mjs";
|
|
@@ -997,6 +997,26 @@ function isConditionMet(expression, flags) {
|
|
|
997
997
|
if (position !== tokens.length) throw new Error(`The condition "${expression}" goes on after its end.`);
|
|
998
998
|
return value;
|
|
999
999
|
}
|
|
1000
|
+
/** Opens a block on an @if, switches its branch on an @elif or @else, and closes it on @endif. */
|
|
1001
|
+
function applyMarker(open, { word, expression }, flags, name) {
|
|
1002
|
+
if (word === "if") {
|
|
1003
|
+
const holds = isConditionMet(expression, flags);
|
|
1004
|
+
open.push({
|
|
1005
|
+
isKept: holds,
|
|
1006
|
+
isTaken: holds
|
|
1007
|
+
});
|
|
1008
|
+
return;
|
|
1009
|
+
}
|
|
1010
|
+
const block = open.at(-1);
|
|
1011
|
+
if (!block) throw new Error(`${name} has an @${word} with no @if.`);
|
|
1012
|
+
if (word === "elif") {
|
|
1013
|
+
block.isKept = !block.isTaken && isConditionMet(expression, flags);
|
|
1014
|
+
block.isTaken ||= block.isKept;
|
|
1015
|
+
} else if (word === "else") {
|
|
1016
|
+
block.isKept = !block.isTaken;
|
|
1017
|
+
block.isTaken = true;
|
|
1018
|
+
} else open.pop();
|
|
1019
|
+
}
|
|
1000
1020
|
/**
|
|
1001
1021
|
* A template's text for an app: the lines whose conditions hold, with each placeholder replaced by
|
|
1002
1022
|
* its value. Returns `undefined` when nothing is left, so the file is not written.
|
|
@@ -1007,26 +1027,8 @@ function renderTemplate(source, flags, values, name = "the template") {
|
|
|
1007
1027
|
const lines = [];
|
|
1008
1028
|
for (const line of source.split("\n")) {
|
|
1009
1029
|
const marker = readMarker(line);
|
|
1010
|
-
if (
|
|
1011
|
-
|
|
1012
|
-
continue;
|
|
1013
|
-
}
|
|
1014
|
-
const { word, expression } = marker;
|
|
1015
|
-
const block = open.at(-1);
|
|
1016
|
-
if (word === "if") {
|
|
1017
|
-
const holds = isConditionMet(expression, flags);
|
|
1018
|
-
open.push({
|
|
1019
|
-
isKept: holds,
|
|
1020
|
-
isTaken: holds
|
|
1021
|
-
});
|
|
1022
|
-
} else if (!block) throw new Error(`${name} has an @${word} with no @if.`);
|
|
1023
|
-
else if (word === "elif") {
|
|
1024
|
-
block.isKept = !block.isTaken && isConditionMet(expression, flags);
|
|
1025
|
-
block.isTaken ||= block.isKept;
|
|
1026
|
-
} else if (word === "else") {
|
|
1027
|
-
block.isKept = !block.isTaken;
|
|
1028
|
-
block.isTaken = true;
|
|
1029
|
-
} else open.pop();
|
|
1030
|
+
if (marker) applyMarker(open, marker, flags, name);
|
|
1031
|
+
else if (isKept()) lines.push(line);
|
|
1030
1032
|
}
|
|
1031
1033
|
if (open.length > 0) throw new Error(`${name} leaves an @if open.`);
|
|
1032
1034
|
let text = lines.join("\n");
|
|
@@ -1043,7 +1045,7 @@ const toOutputPath = (path) => {
|
|
|
1043
1045
|
return Object.hasOwn(RENAMES, name) ? `${path.slice(0, -name.length)}${RENAMES[name]}` : path;
|
|
1044
1046
|
};
|
|
1045
1047
|
/** Every file under `folder`, by its path from there, `/`-separated. */
|
|
1046
|
-
function readFolder(folder) {
|
|
1048
|
+
function readFolder$1(folder) {
|
|
1047
1049
|
const files = /* @__PURE__ */ new Map();
|
|
1048
1050
|
const visit = (directory) => {
|
|
1049
1051
|
for (const entry of readdirSync(directory, { withFileTypes: true })) {
|
|
@@ -1072,7 +1074,7 @@ function readLayers(root, layers) {
|
|
|
1072
1074
|
for (const layer of layers) {
|
|
1073
1075
|
const folder = join(root, layer);
|
|
1074
1076
|
if (!existsSync(folder)) continue;
|
|
1075
|
-
for (const [path, source] of readFolder(folder)) files.set(toOutputPath(path), source);
|
|
1077
|
+
for (const [path, source] of readFolder$1(folder)) files.set(toOutputPath(path), source);
|
|
1076
1078
|
}
|
|
1077
1079
|
return files;
|
|
1078
1080
|
}
|
|
@@ -1127,7 +1129,6 @@ const VERSIONS = {
|
|
|
1127
1129
|
"@astrojs/check": "^0.9.12",
|
|
1128
1130
|
"@astrojs/node": "^11.1.13",
|
|
1129
1131
|
"@astrojs/react": "^7.1.9",
|
|
1130
|
-
"@emotion/server": "^11.11.0",
|
|
1131
1132
|
"@hookform/resolvers": "^7.0.6",
|
|
1132
1133
|
"@reduxjs/toolkit": "^2.14.0",
|
|
1133
1134
|
"@soroush.tech/eslint-config": "workspace:*",
|
|
@@ -1137,6 +1138,7 @@ const VERSIONS = {
|
|
|
1137
1138
|
"@types/node": "^26.6.6",
|
|
1138
1139
|
"@types/react": "^19.3.0",
|
|
1139
1140
|
"@types/react-dom": "^19.3.0",
|
|
1141
|
+
"@umber-style/server": "0.3.0",
|
|
1140
1142
|
"@vitejs/plugin-react": "^6.3.0",
|
|
1141
1143
|
"@vitest/coverage-v8": "^5.1.0",
|
|
1142
1144
|
"astro": "^7.4.12",
|
|
@@ -1263,11 +1265,7 @@ function createFiles$2(facts) {
|
|
|
1263
1265
|
const astroStarter = {
|
|
1264
1266
|
title: "Astro",
|
|
1265
1267
|
label: "Astro: HTML pages, with React islands",
|
|
1266
|
-
renderings: [
|
|
1267
|
-
"isomorphic",
|
|
1268
|
-
"ssr",
|
|
1269
|
-
"ssg"
|
|
1270
|
-
],
|
|
1268
|
+
renderings: ["ssr", "ssg"],
|
|
1271
1269
|
hasLibraries: true,
|
|
1272
1270
|
createFiles: createFiles$2
|
|
1273
1271
|
};
|
|
@@ -1359,7 +1357,7 @@ function createPackageJson({ packageName, isTypeScript, rendering, libraries, ve
|
|
|
1359
1357
|
dependencies: {
|
|
1360
1358
|
"@soroush.tech/design-system": toRange(version),
|
|
1361
1359
|
...pickVersions([
|
|
1362
|
-
"@
|
|
1360
|
+
"@umber-style/server",
|
|
1363
1361
|
...libraryPackages,
|
|
1364
1362
|
"react",
|
|
1365
1363
|
"react-dom",
|
|
@@ -1473,7 +1471,11 @@ function createRootFiles(facts, scripts) {
|
|
|
1473
1471
|
},
|
|
1474
1472
|
...isPnpm ? [{
|
|
1475
1473
|
path: "pnpm-workspace.yaml",
|
|
1476
|
-
content:
|
|
1474
|
+
content: [
|
|
1475
|
+
"packages:",
|
|
1476
|
+
...WORKSPACES.map((glob) => ` - ${glob}`),
|
|
1477
|
+
""
|
|
1478
|
+
].join("\n")
|
|
1477
1479
|
}] : [],
|
|
1478
1480
|
{
|
|
1479
1481
|
path: ".gitignore",
|
|
@@ -1662,6 +1664,25 @@ async function askLibraries(io) {
|
|
|
1662
1664
|
async function askSampleData(io) {
|
|
1663
1665
|
return await io.select("Add sample data pages?", YES_OR_NO, 1) === "yes";
|
|
1664
1666
|
}
|
|
1667
|
+
/** A question's label, as the summary says what was picked: with no "(recommended)". */
|
|
1668
|
+
const toPicked = (label) => label.replace(" (recommended)", "");
|
|
1669
|
+
/** The summary of every choice, one a line, which create shows before the files it writes. */
|
|
1670
|
+
function formatChoices(choices) {
|
|
1671
|
+
const libraries = LIBRARIES.filter(({ name }) => choices.libraries.includes(name));
|
|
1672
|
+
const rows = [
|
|
1673
|
+
["Title", [choices.title]],
|
|
1674
|
+
["Framework", [toPicked(choices.starter.label)]],
|
|
1675
|
+
["Language", [choices.isTypeScript ? "TypeScript" : "JavaScript"]],
|
|
1676
|
+
["Package manager", [choices.packageManager.name]],
|
|
1677
|
+
["Repository", [toPicked(LAYOUT_LABELS[choices.layout])]],
|
|
1678
|
+
["Rendering", [toPicked(RENDERING_LABELS[choices.rendering])]],
|
|
1679
|
+
["Libraries", libraries.length ? libraries.map(({ label }) => label) : ["none"]],
|
|
1680
|
+
["Color scheme", [`${choices.scheme}, by default`]],
|
|
1681
|
+
["Sample data pages", [choices.hasSampleData ? "yes: /items and /items/<id>, from src/data/items" : "no"]]
|
|
1682
|
+
];
|
|
1683
|
+
const width = Math.max(...rows.map(([key]) => key.length)) + 2;
|
|
1684
|
+
return rows.flatMap(([key, values]) => values.map((value, index) => ` ${(index === 0 ? key : "").padEnd(width)}${value}`)).join("\n");
|
|
1685
|
+
}
|
|
1665
1686
|
/** Whether to create the app: never on a dry run or with no terminal, else on --yes or a yes. */
|
|
1666
1687
|
async function isApproved(options, isPreviewOnly, io) {
|
|
1667
1688
|
if (options.isDryRun) {
|
|
@@ -1716,76 +1737,119 @@ function writeAndInstall({ name, target, wasMissing, plan, packageManager }, opt
|
|
|
1716
1737
|
io.write(formatClosing(name, plan, packageManager));
|
|
1717
1738
|
return 0;
|
|
1718
1739
|
}
|
|
1719
|
-
/**
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
const canAsk = !isPreviewOnly && !options.isConfirmed;
|
|
1740
|
+
/** The answer given on the command line, else the person's when `isAsked`, else `fallback`. */
|
|
1741
|
+
async function choose(given, isAsked, ask, fallback) {
|
|
1742
|
+
if (given !== void 0) return given;
|
|
1743
|
+
return isAsked ? ask() : fallback;
|
|
1744
|
+
}
|
|
1745
|
+
/** Refuses a --framework create has no starter for, or a create with no starter at all. */
|
|
1746
|
+
function findStarterRefusal(starters, given) {
|
|
1727
1747
|
const frameworks = Object.keys(starters);
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
const
|
|
1735
|
-
const name = options.name ?? (canAsk ? await askName(io) : DEFAULT_NAME);
|
|
1748
|
+
if (frameworks.length > 0 && (given === void 0 || Object.hasOwn(starters, given))) return;
|
|
1749
|
+
const names = frameworks.join(", ") || "none yet";
|
|
1750
|
+
return `create has no starter for ${given ?? "any framework"}. It has: ${names}.`;
|
|
1751
|
+
}
|
|
1752
|
+
/** The app's folder, new or empty, and its title: asked for, or given. */
|
|
1753
|
+
async function readFolder(options, io, canAsk) {
|
|
1754
|
+
const name = await choose(options.name, canAsk, () => askName(io), DEFAULT_NAME);
|
|
1736
1755
|
const nameRefusal = findNameRefusal(name);
|
|
1737
|
-
if (nameRefusal) {
|
|
1738
|
-
io.write(`${nameRefusal}\n`);
|
|
1739
|
-
return 1;
|
|
1740
|
-
}
|
|
1756
|
+
if (nameRefusal) return { refusal: nameRefusal };
|
|
1741
1757
|
const target = join(realpathSync(io.cwd), name);
|
|
1742
1758
|
const folder = getFolderState(target, name);
|
|
1743
|
-
if (typeof folder === "object")
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
}
|
|
1752
|
-
|
|
1753
|
-
|
|
1759
|
+
if (typeof folder === "object") return folder;
|
|
1760
|
+
const title = (await choose(options.title, canAsk, () => askTitle(io, name), name)).trim() || name;
|
|
1761
|
+
if (isRefusedTitle(title)) return { refusal: `${title} is not a title create can use: it cannot hold \` $ { } < > or \\.` };
|
|
1762
|
+
return {
|
|
1763
|
+
name,
|
|
1764
|
+
target,
|
|
1765
|
+
wasMissing: folder === "missing",
|
|
1766
|
+
title
|
|
1767
|
+
};
|
|
1768
|
+
}
|
|
1769
|
+
/** Refuses a --render none of the starters in `pool` renders, naming the ones that do. */
|
|
1770
|
+
function findRenderingRefusal(rendering, offered, pool, starters) {
|
|
1771
|
+
if (rendering === void 0 || offered.includes(rendering)) return void 0;
|
|
1772
|
+
const titles = pool.map((framework) => starters[framework].title).join(" or ");
|
|
1773
|
+
const pointer = Object.keys(starters).filter((framework) => starters[framework].renderings.includes(rendering)).map((framework) => ` --framework ${framework} does.`).join("");
|
|
1774
|
+
return `${titles} does not render ${rendering}: it renders ${offered.join(" or ")}.${pointer}`;
|
|
1775
|
+
}
|
|
1776
|
+
/** Refuses --with for an app that takes no library, or libraries that do not go together. */
|
|
1777
|
+
function findLibraryRefusal(libraries, rendering, starter) {
|
|
1778
|
+
if (!libraries?.length) return void 0;
|
|
1779
|
+
if (rendering === "ssg") return "An SSG app has no JavaScript in the browser, so it takes no library: leave out --with.";
|
|
1780
|
+
if (!starter.hasLibraries) return `${starter.title} takes no library yet: leave out --with.`;
|
|
1781
|
+
return findLibraryConflict(libraries);
|
|
1782
|
+
}
|
|
1783
|
+
/** Every choice the app is made from: given, asked for when `canAsk`, or the default. */
|
|
1784
|
+
async function readChoices(options, io, starters, userAgent, canAsk) {
|
|
1785
|
+
const given = options.framework;
|
|
1786
|
+
const starterRefusal = findStarterRefusal(starters, given);
|
|
1787
|
+
if (starterRefusal) return { refusal: starterRefusal };
|
|
1788
|
+
const pool = given === void 0 ? Object.keys(starters) : [given];
|
|
1789
|
+
const folder = await readFolder(options, io, canAsk);
|
|
1790
|
+
if ("refusal" in folder) return folder;
|
|
1791
|
+
const isTypeScript = await choose(options.isTypeScript, canAsk, () => askLanguage(io), true);
|
|
1754
1792
|
const detected = readPackageManager(userAgent);
|
|
1755
|
-
const packageManager = resolvePackageManager(options.packageManager
|
|
1756
|
-
if ("refusal" in packageManager)
|
|
1757
|
-
|
|
1758
|
-
return 1;
|
|
1759
|
-
}
|
|
1760
|
-
const isWorkspace = (options.layout ?? (canAsk ? await askLayout(io) : LAYOUTS[0])) === "workspace";
|
|
1793
|
+
const packageManager = resolvePackageManager(await choose(options.packageManager, canAsk, () => askPackageManager(io, detected.name), detected.name), detected, io);
|
|
1794
|
+
if ("refusal" in packageManager) return packageManager;
|
|
1795
|
+
const layout = await choose(options.layout, canAsk, () => askLayout(io), LAYOUTS[0]);
|
|
1761
1796
|
const offered = RENDERINGS.filter((rendering) => pool.some((framework) => starters[framework].renderings.includes(rendering)));
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
io.write(`${titles} does not render ${options.rendering}: it renders ${offered.join(" or ")}.${pointer}\n`);
|
|
1766
|
-
return 1;
|
|
1767
|
-
}
|
|
1768
|
-
const rendering = options.rendering ?? (canAsk && offered.length > 1 ? await askRendering(io, offered) : offered[0]);
|
|
1797
|
+
const renderingRefusal = findRenderingRefusal(options.rendering, offered, pool, starters);
|
|
1798
|
+
if (renderingRefusal) return { refusal: renderingRefusal };
|
|
1799
|
+
const rendering = await choose(options.rendering, canAsk && offered.length > 1, () => askRendering(io, offered), offered[0]);
|
|
1769
1800
|
const candidates = pool.filter((framework) => starters[framework].renderings.includes(rendering));
|
|
1770
1801
|
const starter = starters[canAsk && candidates.length > 1 ? await askFramework(io, starters, candidates) : candidates[0]];
|
|
1771
|
-
const libraryRefusal =
|
|
1772
|
-
if (libraryRefusal) {
|
|
1773
|
-
io.write(`${libraryRefusal}\n`);
|
|
1774
|
-
return 1;
|
|
1775
|
-
}
|
|
1802
|
+
const libraryRefusal = findLibraryRefusal(options.libraries, rendering, starter);
|
|
1803
|
+
if (libraryRefusal) return { refusal: libraryRefusal };
|
|
1776
1804
|
const takesLibraries = starter.hasLibraries && rendering !== "ssg";
|
|
1777
|
-
const libraries = options.libraries
|
|
1778
|
-
const scheme = options.scheme
|
|
1779
|
-
const hasSampleData = options.hasSampleData
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
packageName:
|
|
1783
|
-
|
|
1805
|
+
const libraries = await choose(options.libraries, canAsk && takesLibraries, () => askLibraries(io), []);
|
|
1806
|
+
const scheme = await choose(options.scheme, canAsk, () => askScheme(io), "light");
|
|
1807
|
+
const hasSampleData = await choose(options.hasSampleData, canAsk, () => askSampleData(io), false);
|
|
1808
|
+
return {
|
|
1809
|
+
...folder,
|
|
1810
|
+
packageName: toPackageName(folder.name),
|
|
1811
|
+
starter,
|
|
1784
1812
|
isTypeScript,
|
|
1813
|
+
packageManager,
|
|
1814
|
+
layout,
|
|
1785
1815
|
rendering,
|
|
1786
1816
|
libraries,
|
|
1787
1817
|
scheme,
|
|
1788
|
-
hasSampleData
|
|
1818
|
+
hasSampleData
|
|
1819
|
+
};
|
|
1820
|
+
}
|
|
1821
|
+
/** The line that says what create will make, and where. */
|
|
1822
|
+
function formatHeadline({ name, packageName, starter, isTypeScript, rendering, layout }) {
|
|
1823
|
+
const article = /^[AEIOU]/.test(starter.title) ? "an" : "a";
|
|
1824
|
+
const language = isTypeScript ? "TypeScript" : "JavaScript";
|
|
1825
|
+
const packageNote = packageName === name ? "" : ` (package ${packageName})`;
|
|
1826
|
+
const renderingName = rendering === "isomorphic" ? rendering : rendering.toUpperCase();
|
|
1827
|
+
const workspaceNote = layout === "workspace" ? "in a workspace, " : "";
|
|
1828
|
+
return `create will make ${name}${packageNote}, ${article} ${starter.title} app in ${language} (${renderingName}), ${workspaceNote}in ./${name}:`;
|
|
1829
|
+
}
|
|
1830
|
+
/**
|
|
1831
|
+
* Starts a new app on the design system, in a new or empty folder in `io.cwd`: asks what it is
|
|
1832
|
+
* not told, plans with the starter, shows the plan, and writes and installs only after a yes.
|
|
1833
|
+
* `designSystem` is the package it installs. Returns the exit code.
|
|
1834
|
+
*/
|
|
1835
|
+
async function runCreate(options, io, designSystem, { starters = STARTERS, fileSystem = nodeFileSystem, userAgent = process.env.npm_config_user_agent } = {}) {
|
|
1836
|
+
const isPreviewOnly = options.isDryRun || !io.isInteractive && !options.isConfirmed;
|
|
1837
|
+
const choices = await readChoices(options, io, starters, userAgent, !isPreviewOnly && !options.isConfirmed);
|
|
1838
|
+
if ("refusal" in choices) {
|
|
1839
|
+
io.write(`${choices.refusal}\n`);
|
|
1840
|
+
return 1;
|
|
1841
|
+
}
|
|
1842
|
+
const { name, packageName, title, layout, packageManager } = choices;
|
|
1843
|
+
const isWorkspace = layout === "workspace";
|
|
1844
|
+
const appFiles = choices.starter.createFiles({
|
|
1845
|
+
name,
|
|
1846
|
+
packageName: isWorkspace ? toAppPackageName(packageName) : packageName,
|
|
1847
|
+
title,
|
|
1848
|
+
isTypeScript: choices.isTypeScript,
|
|
1849
|
+
rendering: choices.rendering,
|
|
1850
|
+
libraries: choices.libraries,
|
|
1851
|
+
scheme: choices.scheme,
|
|
1852
|
+
hasSampleData: choices.hasSampleData,
|
|
1789
1853
|
version: designSystem.version
|
|
1790
1854
|
});
|
|
1791
1855
|
const plan = {
|
|
@@ -1799,16 +1863,14 @@ async function runCreate(options, io, designSystem, { starters = STARTERS, fileS
|
|
|
1799
1863
|
manual: [],
|
|
1800
1864
|
install: createAppInstallCommand(packageManager)
|
|
1801
1865
|
};
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
const renderingName = rendering === "isomorphic" ? rendering : rendering.toUpperCase();
|
|
1805
|
-
io.write(`create will make ${name}${packageNote}, ${/^[AEIOU]/.test(starter.title) ? "an" : "a"} ${starter.title} app in ${language} (${renderingName}), ${isWorkspace ? "in a workspace, " : ""}in ./${name}:\n\n`);
|
|
1866
|
+
io.write(`${formatHeadline(choices)}\n\n`);
|
|
1867
|
+
io.write(`${formatChoices(choices)}\n\n`);
|
|
1806
1868
|
io.write(`${formatPlan(plan)}\n`);
|
|
1807
1869
|
if (!await isApproved(options, isPreviewOnly, io)) return 0;
|
|
1808
1870
|
return writeAndInstall({
|
|
1809
1871
|
name,
|
|
1810
|
-
target,
|
|
1811
|
-
wasMissing:
|
|
1872
|
+
target: choices.target,
|
|
1873
|
+
wasMissing: choices.wasMissing,
|
|
1812
1874
|
plan,
|
|
1813
1875
|
packageManager
|
|
1814
1876
|
}, options, io, fileSystem);
|
|
@@ -1855,7 +1917,10 @@ const getAnswer = ({ cursor, picked }, choices) => picked ? [...picked] : [choic
|
|
|
1855
1917
|
/** The question and its choices, as drawn while the person picks. Ends with a line break. */
|
|
1856
1918
|
function formatChoice(question, { cursor, picked }, choices) {
|
|
1857
1919
|
return `? ${question} (${picked ? "space to pick, enter when done" : "arrows to move, enter to pick"})\n${choices.map(({ value, label }, index) => {
|
|
1858
|
-
|
|
1920
|
+
const pointer = index === cursor ? ">" : " ";
|
|
1921
|
+
let box = "";
|
|
1922
|
+
if (picked) box = picked.includes(value) ? "[x] " : "[ ] ";
|
|
1923
|
+
return `${pointer} ${box}${label}`;
|
|
1859
1924
|
}).join("\n")}\n`;
|
|
1860
1925
|
}
|
|
1861
1926
|
/** The question with its answer, as it stays once picked. Ends with a line break. */
|
|
@@ -1972,6 +2037,18 @@ function findMisuse(command, extra, used) {
|
|
|
1972
2037
|
const maxPositionals = command === "create" ? 1 : 0;
|
|
1973
2038
|
return extra.length > maxPositionals ? `Unknown command: ${command} ${extra.join(" ")}` : void 0;
|
|
1974
2039
|
}
|
|
2040
|
+
/** `--with`'s libraries, named by comma; `--with ''` adds none. */
|
|
2041
|
+
const readLibraries = (names) => names?.split(",").map((name) => name.trim()).filter(Boolean);
|
|
2042
|
+
/** Why an option's value is wrong, or `undefined` when every one is right. */
|
|
2043
|
+
function findValueRefusal({ scheme, ts, js, render, layout, pm }, libraries) {
|
|
2044
|
+
if (scheme !== void 0 && scheme !== "light" && scheme !== "dark") return `--scheme is light or dark, not ${scheme}.`;
|
|
2045
|
+
if (ts && js) return "--ts and --js do not go together: give one.";
|
|
2046
|
+
const unknownLibrary = libraries?.find((name) => !LIBRARY_NAMES.includes(name));
|
|
2047
|
+
if (unknownLibrary !== void 0) return `--with takes ${LIBRARY_NAMES.join(", ")}, not ${unknownLibrary}.`;
|
|
2048
|
+
if (render !== void 0 && !RENDERINGS.includes(render)) return `--render is ${RENDERINGS.join(", ")}, not ${render}.`;
|
|
2049
|
+
if (layout !== void 0 && !LAYOUTS.includes(layout)) return `--layout is ${LAYOUTS.join(", ")}, not ${layout}.`;
|
|
2050
|
+
if (pm !== void 0 && !PACKAGE_MANAGERS.includes(pm)) return `--pm is ${PACKAGE_MANAGERS.join(", ")}, not ${pm}.`;
|
|
2051
|
+
}
|
|
1975
2052
|
/**
|
|
1976
2053
|
* Reads the command line and runs the command, for `designSystem`: the package of
|
|
1977
2054
|
* `@soroush.tech/design-system` the command installs. Returns the exit code: 130 when the person
|
|
@@ -2015,37 +2092,14 @@ async function runCommandLine(argv, io, designSystem) {
|
|
|
2015
2092
|
io.write(`${misuse}\n\n${getHelp(command)}`);
|
|
2016
2093
|
return 1;
|
|
2017
2094
|
}
|
|
2018
|
-
const
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
}
|
|
2023
|
-
if (values.ts && values.js) {
|
|
2024
|
-
io.write("--ts and --js do not go together: give one.\n");
|
|
2025
|
-
return 1;
|
|
2026
|
-
}
|
|
2027
|
-
const libraries = values.with?.split(",").map((name) => name.trim()).filter(Boolean);
|
|
2028
|
-
const unknownLibrary = libraries?.find((name) => !LIBRARY_NAMES.includes(name));
|
|
2029
|
-
if (unknownLibrary !== void 0) {
|
|
2030
|
-
io.write(`--with takes ${LIBRARY_NAMES.join(", ")}, not ${unknownLibrary}.\n`);
|
|
2031
|
-
return 1;
|
|
2032
|
-
}
|
|
2033
|
-
const { render } = values;
|
|
2034
|
-
if (render !== void 0 && !RENDERINGS.includes(render)) {
|
|
2035
|
-
io.write(`--render is ${RENDERINGS.join(", ")}, not ${render}.\n`);
|
|
2036
|
-
return 1;
|
|
2037
|
-
}
|
|
2038
|
-
const { layout } = values;
|
|
2039
|
-
if (layout !== void 0 && !LAYOUTS.includes(layout)) {
|
|
2040
|
-
io.write(`--layout is ${LAYOUTS.join(", ")}, not ${layout}.
|
|
2041
|
-
`);
|
|
2042
|
-
return 1;
|
|
2043
|
-
}
|
|
2044
|
-
const { pm } = values;
|
|
2045
|
-
if (pm !== void 0 && !PACKAGE_MANAGERS.includes(pm)) {
|
|
2046
|
-
io.write(`--pm is ${PACKAGE_MANAGERS.join(", ")}, not ${pm}.\n`);
|
|
2095
|
+
const libraries = readLibraries(values.with);
|
|
2096
|
+
const refusal = findValueRefusal(values, libraries);
|
|
2097
|
+
if (refusal) {
|
|
2098
|
+
io.write(`${refusal}\n`);
|
|
2047
2099
|
return 1;
|
|
2048
2100
|
}
|
|
2101
|
+
const { pm, layout, render } = values;
|
|
2102
|
+
const scheme = values.scheme;
|
|
2049
2103
|
const isConfirmed = Boolean(values.yes);
|
|
2050
2104
|
const isDryRun = Boolean(values["dry-run"]);
|
|
2051
2105
|
if (command === "create") {
|
|
@@ -2055,7 +2109,7 @@ async function runCommandLine(argv, io, designSystem) {
|
|
|
2055
2109
|
title: values.title,
|
|
2056
2110
|
framework: values.framework,
|
|
2057
2111
|
isTypeScript,
|
|
2058
|
-
packageManager: pm,
|
|
2112
|
+
packageManager: PACKAGE_MANAGERS.find((name) => name === pm),
|
|
2059
2113
|
layout,
|
|
2060
2114
|
rendering: render,
|
|
2061
2115
|
libraries,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soroush.design/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0-alpha.0",
|
|
4
4
|
"description": "The command line of the @soroush.tech design system: init sets it up in an existing React app, and create starts a new one, each showing every change first.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cli",
|
|
@@ -43,7 +43,6 @@
|
|
|
43
43
|
"@astrojs/check": "^0.9.12",
|
|
44
44
|
"@astrojs/node": "^11.1.13",
|
|
45
45
|
"@astrojs/react": "^7.1.9",
|
|
46
|
-
"@emotion/server": "^11.11.0",
|
|
47
46
|
"@hookform/resolvers": "^7.0.6",
|
|
48
47
|
"@reduxjs/toolkit": "^2.14.0",
|
|
49
48
|
"@tanstack/react-query": "^5.107.1",
|
|
@@ -52,6 +51,7 @@
|
|
|
52
51
|
"@types/node": "^26.6.6",
|
|
53
52
|
"@types/react": "^19.3.0",
|
|
54
53
|
"@types/react-dom": "^19.3.0",
|
|
54
|
+
"@umber-style/server": "0.3.0",
|
|
55
55
|
"@vitejs/plugin-react": "^6.3.0",
|
|
56
56
|
"@vitest/coverage-v8": "^5.1.0",
|
|
57
57
|
"astro": "^7.4.12",
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
"typecheck": "tsc --noEmit",
|
|
83
83
|
"test": "vitest run",
|
|
84
84
|
"test:coverage": "vitest run --coverage",
|
|
85
|
-
"test:types": "pnpm --filter @soroush.tech/design-system build && tsc -p type-tests/init/tsconfig.json && tsc -p type-tests/tsconfig.create-vike.json && tsc -p type-tests/tsconfig.create-vike-ssg.json && tsc -p type-tests/tsconfig.create-vike-ssr.json && tsc -p type-tests/tsconfig.create-vike-libraries.json && tsc -p type-tests/tsconfig.create-vike-jotai.json && tsc -p type-tests/tsconfig.create-vike-more.json && tsc -p type-tests/tsconfig.create-astro
|
|
85
|
+
"test:types": "pnpm --filter @soroush.tech/design-system build && tsc -p type-tests/init/tsconfig.json && tsc -p type-tests/tsconfig.create-vike.json && tsc -p type-tests/tsconfig.create-vike-ssg.json && tsc -p type-tests/tsconfig.create-vike-ssr.json && tsc -p type-tests/tsconfig.create-vike-libraries.json && tsc -p type-tests/tsconfig.create-vike-jotai.json && tsc -p type-tests/tsconfig.create-vike-more.json && tsc -p type-tests/tsconfig.create-astro-ssg.json && tsc -p type-tests/tsconfig.create-astro-ssr.json && tsc -p type-tests/tsconfig.create-astro-libraries.json && tsc -p type-tests/tsconfig.create-astro-more.json && tsc -p type-tests/tsconfig.create-react-router.json && tsc -p type-tests/tsconfig.create-react-router-libraries.json && tsc -p type-tests/tsconfig.create-react-router-more.json && tsc -p type-tests/tsconfig.create-react-router-jotai.json",
|
|
86
86
|
"gen:templates": "node scripts/gen-templates.mjs"
|
|
87
87
|
},
|
|
88
88
|
"module": "./dist/index.mjs"
|
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
# __TITLE__
|
|
2
2
|
|
|
3
3
|
An [Astro](https://astro.build) app on the [@soroush.tech design system](https://docs.soroush.tech):
|
|
4
|
-
<!-- @if
|
|
5
|
-
every page is HTML from the build, with its styles, and its parts are React islands
|
|
6
|
-
that hydrate in the browser. Astro's client router moves between pages with no reload.
|
|
7
|
-
<!-- @elif ssr -->
|
|
4
|
+
<!-- @if ssr -->
|
|
8
5
|
every page is rendered on the server, on each request, with its styles, and its parts are
|
|
9
6
|
React islands that hydrate in the browser. Astro's client router moves between pages with no
|
|
10
|
-
reload.
|
|
7
|
+
reload: it fetches the next page's HTML from the server and swaps it in.
|
|
11
8
|
<!-- @else -->
|
|
12
9
|
every page is HTML from the build, with its styles, and no JavaScript in the browser: its
|
|
13
10
|
React parts render at build time only.
|
|
@@ -10,11 +10,8 @@ function About() {
|
|
|
10
10
|
{/* @if ssr */}
|
|
11
11
|
A second page: the server renders it, with its styles, and the app moves to it without a
|
|
12
12
|
reload.
|
|
13
|
-
{/* @elif ssg */}
|
|
14
|
-
A second page: it is HTML with its styles from the build, and a link loads it as a new page.
|
|
15
13
|
{/* @else */}
|
|
16
|
-
A second page: it is HTML with its styles from the build, and
|
|
17
|
-
reload.
|
|
14
|
+
A second page: it is HTML with its styles from the build, and a link loads it as a new page.
|
|
18
15
|
{/* @endif */}
|
|
19
16
|
</Typography>
|
|
20
17
|
</Flex>
|