create-ardo 2.6.0 → 2.7.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/index.js
CHANGED
|
@@ -36,9 +36,7 @@ function createProjectStructure(root, template, options) {
|
|
|
36
36
|
GITHUB_PAGES_BASENAME: options.githubPages ? "basename: detectGitHubBasename()," : "// basename: detectGitHubBasename(), // Uncomment for GitHub Pages",
|
|
37
37
|
DESCRIPTION: options.description,
|
|
38
38
|
TYPEDOC_NAV: options.typedoc ? "{ text: 'API', link: '/api-reference' }," : "",
|
|
39
|
-
TYPEDOC_SIDEBAR: options.typedoc ? "{ text: 'API Reference', link: '/api-reference' }," : ""
|
|
40
|
-
TYPEDOC_NAVLINK: options.typedoc ? '<NavLink to="/api-reference">API</NavLink>' : "",
|
|
41
|
-
TYPEDOC_SIDEBARLINK: options.typedoc ? '<SidebarLink to="/api-reference">API Reference</SidebarLink>' : ""
|
|
39
|
+
TYPEDOC_SIDEBAR: options.typedoc ? "{ text: 'API Reference', link: '/api-reference' }," : ""
|
|
42
40
|
};
|
|
43
41
|
copyDir(templateDir, root, vars);
|
|
44
42
|
}
|
|
@@ -93,9 +91,76 @@ function detectProjectDescription(targetDir) {
|
|
|
93
91
|
}
|
|
94
92
|
return void 0;
|
|
95
93
|
}
|
|
94
|
+
function isArdoProject(dir) {
|
|
95
|
+
try {
|
|
96
|
+
const pkgPath = path.join(dir, "package.json");
|
|
97
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
|
|
98
|
+
return Boolean(pkg.dependencies?.ardo);
|
|
99
|
+
} catch {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
function upgradeProject(root) {
|
|
104
|
+
const templateDir = path.join(templatesRoot, "minimal");
|
|
105
|
+
const cliVersion = getCliVersion();
|
|
106
|
+
const result = { updated: [], deleted: [], skipped: [] };
|
|
107
|
+
const skeletonFiles = [
|
|
108
|
+
"app/entry.client.tsx",
|
|
109
|
+
"app/entry.server.tsx",
|
|
110
|
+
"app/root.tsx",
|
|
111
|
+
"tsconfig.json"
|
|
112
|
+
];
|
|
113
|
+
for (const file of skeletonFiles) {
|
|
114
|
+
const src = path.join(templateDir, file);
|
|
115
|
+
const dest = path.join(root, file);
|
|
116
|
+
if (fs.existsSync(src)) {
|
|
117
|
+
fs.mkdirSync(path.dirname(dest), { recursive: true });
|
|
118
|
+
fs.copyFileSync(src, dest);
|
|
119
|
+
result.updated.push(file);
|
|
120
|
+
} else {
|
|
121
|
+
result.skipped.push(file);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
const userPkgPath = path.join(root, "package.json");
|
|
125
|
+
const templatePkgPath = path.join(templateDir, "package.json");
|
|
126
|
+
const userPkg = JSON.parse(fs.readFileSync(userPkgPath, "utf-8"));
|
|
127
|
+
const templatePkg = JSON.parse(fs.readFileSync(templatePkgPath, "utf-8"));
|
|
128
|
+
if (userPkg.dependencies) {
|
|
129
|
+
userPkg.dependencies.ardo = `^${cliVersion}`;
|
|
130
|
+
}
|
|
131
|
+
for (const [dep, version] of Object.entries(
|
|
132
|
+
templatePkg.dependencies || {}
|
|
133
|
+
)) {
|
|
134
|
+
if (dep === "ardo") continue;
|
|
135
|
+
if (!userPkg.dependencies?.[dep]) {
|
|
136
|
+
userPkg.dependencies = userPkg.dependencies || {};
|
|
137
|
+
userPkg.dependencies[dep] = version;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
for (const [dep, version] of Object.entries(
|
|
141
|
+
templatePkg.devDependencies || {}
|
|
142
|
+
)) {
|
|
143
|
+
userPkg.devDependencies = userPkg.devDependencies || {};
|
|
144
|
+
userPkg.devDependencies[dep] = version;
|
|
145
|
+
}
|
|
146
|
+
fs.writeFileSync(userPkgPath, JSON.stringify(userPkg, null, 2) + "\n");
|
|
147
|
+
result.updated.push("package.json");
|
|
148
|
+
const obsoleteFiles = ["app/vite-env.d.ts"];
|
|
149
|
+
for (const file of obsoleteFiles) {
|
|
150
|
+
const filePath = path.join(root, file);
|
|
151
|
+
if (fs.existsSync(filePath)) {
|
|
152
|
+
fs.unlinkSync(filePath);
|
|
153
|
+
result.deleted.push(file);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return result;
|
|
157
|
+
}
|
|
96
158
|
|
|
97
159
|
// src/index.ts
|
|
98
160
|
var defaultTargetDir = "my-docs";
|
|
161
|
+
var onCancel = () => {
|
|
162
|
+
throw new Error(red("\u2716") + " Operation cancelled");
|
|
163
|
+
};
|
|
99
164
|
async function main() {
|
|
100
165
|
console.log();
|
|
101
166
|
console.log(` ${cyan("\u25C6")} ${green("create-ardo")}`);
|
|
@@ -103,11 +168,10 @@ async function main() {
|
|
|
103
168
|
const argTargetDir = process.argv[2];
|
|
104
169
|
const argTemplate = process.argv[3];
|
|
105
170
|
let targetDir = argTargetDir || defaultTargetDir;
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
[
|
|
171
|
+
if (!argTargetDir) {
|
|
172
|
+
const { projectName } = await prompts(
|
|
109
173
|
{
|
|
110
|
-
type:
|
|
174
|
+
type: "text",
|
|
111
175
|
name: "projectName",
|
|
112
176
|
message: reset("Project name:"),
|
|
113
177
|
initial: defaultTargetDir,
|
|
@@ -118,13 +182,55 @@ async function main() {
|
|
|
118
182
|
if (!/^[a-z0-9-]+$/.test(name))
|
|
119
183
|
return "Project name may only contain lowercase letters, digits, and hyphens";
|
|
120
184
|
return true;
|
|
121
|
-
},
|
|
122
|
-
onState: (state) => {
|
|
123
|
-
targetDir = formatTargetDir(state.value) || defaultTargetDir;
|
|
124
185
|
}
|
|
125
186
|
},
|
|
187
|
+
{ onCancel }
|
|
188
|
+
);
|
|
189
|
+
targetDir = formatTargetDir(projectName) || defaultTargetDir;
|
|
190
|
+
}
|
|
191
|
+
const root = path2.join(process.cwd(), targetDir);
|
|
192
|
+
if (fs2.existsSync(root) && !isEmpty(root) && isArdoProject(root)) {
|
|
193
|
+
const cliVersion = getCliVersion();
|
|
194
|
+
const { action } = await prompts(
|
|
195
|
+
{
|
|
196
|
+
type: "select",
|
|
197
|
+
name: "action",
|
|
198
|
+
message: `Existing Ardo project detected. Upgrade to v${cliVersion}?`,
|
|
199
|
+
choices: [
|
|
200
|
+
{ title: "Upgrade framework files", value: "upgrade" },
|
|
201
|
+
{ title: "Cancel", value: "cancel" }
|
|
202
|
+
]
|
|
203
|
+
},
|
|
204
|
+
{ onCancel }
|
|
205
|
+
);
|
|
206
|
+
if (action === "cancel") {
|
|
207
|
+
throw new Error(red("\u2716") + " Operation cancelled");
|
|
208
|
+
}
|
|
209
|
+
console.log();
|
|
210
|
+
console.log(` ${cyan("Upgrading project in")} ${root}...`);
|
|
211
|
+
console.log();
|
|
212
|
+
const result = upgradeProject(root);
|
|
213
|
+
for (const file of result.updated) {
|
|
214
|
+
console.log(` ${green("\u25CF")} ${file}`);
|
|
215
|
+
}
|
|
216
|
+
for (const file of result.deleted) {
|
|
217
|
+
console.log(` ${yellow("\u25CF")} ${file} ${dim("(removed)")}`);
|
|
218
|
+
}
|
|
219
|
+
for (const file of result.skipped) {
|
|
220
|
+
console.log(` ${dim("\u25CB")} ${file} ${dim("(not found, skipped)")}`);
|
|
221
|
+
}
|
|
222
|
+
console.log();
|
|
223
|
+
console.log(` ${green("Done!")} Now run:`);
|
|
224
|
+
console.log();
|
|
225
|
+
console.log(` ${blue("pnpm install")}`);
|
|
226
|
+
console.log();
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
let template = argTemplate;
|
|
230
|
+
const response = await prompts(
|
|
231
|
+
[
|
|
126
232
|
{
|
|
127
|
-
type: () => !fs2.existsSync(
|
|
233
|
+
type: () => !fs2.existsSync(root) || isEmpty(root) ? null : "select",
|
|
128
234
|
name: "overwrite",
|
|
129
235
|
message: () => `${targetDir === "." ? "Current directory" : `Target directory "${targetDir}"`} is not empty. How would you like to proceed?`,
|
|
130
236
|
choices: [
|
|
@@ -188,15 +294,10 @@ async function main() {
|
|
|
188
294
|
]
|
|
189
295
|
}
|
|
190
296
|
],
|
|
191
|
-
{
|
|
192
|
-
onCancel: () => {
|
|
193
|
-
throw new Error(red("\u2716") + " Operation cancelled");
|
|
194
|
-
}
|
|
195
|
-
}
|
|
297
|
+
{ onCancel }
|
|
196
298
|
);
|
|
197
299
|
const { overwrite, template: templateChoice, siteTitle, docType, githubPages } = response;
|
|
198
300
|
template = templateChoice || template || "minimal";
|
|
199
|
-
const root = path2.join(process.cwd(), targetDir);
|
|
200
301
|
if (overwrite === "yes") {
|
|
201
302
|
emptyDir(root);
|
|
202
303
|
} else if (!fs2.existsSync(root)) {
|
package/package.json
CHANGED
|
@@ -1,89 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
Layout as ArdoLayout,
|
|
4
|
-
Header,
|
|
5
|
-
Nav,
|
|
6
|
-
NavLink,
|
|
7
|
-
Sidebar,
|
|
8
|
-
SidebarGroup,
|
|
9
|
-
SidebarLink,
|
|
10
|
-
Footer,
|
|
11
|
-
} from "ardo/ui"
|
|
12
|
-
import { ArdoProvider } from "ardo/runtime"
|
|
1
|
+
import { RootLayout, ArdoRoot } from "ardo/ui"
|
|
13
2
|
import config from "virtual:ardo/config"
|
|
14
3
|
import sidebar from "virtual:ardo/sidebar"
|
|
15
4
|
import type { MetaFunction } from "react-router"
|
|
16
5
|
import "ardo/ui/styles.css"
|
|
17
6
|
|
|
18
|
-
export const meta: MetaFunction = () => [
|
|
19
|
-
{ title: "{{SITE_TITLE}}" },
|
|
20
|
-
]
|
|
7
|
+
export const meta: MetaFunction = () => [{ title: config.title }]
|
|
21
8
|
|
|
22
9
|
export function Layout({ children }: { children: React.ReactNode }) {
|
|
23
|
-
return
|
|
24
|
-
<html lang="en" suppressHydrationWarning>
|
|
25
|
-
<head>
|
|
26
|
-
<meta charSet="utf-8" />
|
|
27
|
-
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
28
|
-
<Meta />
|
|
29
|
-
<Links />
|
|
30
|
-
</head>
|
|
31
|
-
<body suppressHydrationWarning>
|
|
32
|
-
{children}
|
|
33
|
-
<ScrollRestoration />
|
|
34
|
-
<Scripts />
|
|
35
|
-
</body>
|
|
36
|
-
</html>
|
|
37
|
-
)
|
|
10
|
+
return <RootLayout>{children}</RootLayout>
|
|
38
11
|
}
|
|
39
12
|
|
|
40
13
|
export default function Root() {
|
|
41
|
-
|
|
42
|
-
const isHomePage = location.pathname === "/"
|
|
43
|
-
|
|
44
|
-
return (
|
|
45
|
-
<ArdoProvider config={config} sidebar={sidebar}>
|
|
46
|
-
<ArdoLayout
|
|
47
|
-
className={isHomePage ? "ardo-layout ardo-home" : "ardo-layout"}
|
|
48
|
-
header={
|
|
49
|
-
<Header
|
|
50
|
-
title="{{SITE_TITLE}}"
|
|
51
|
-
nav={
|
|
52
|
-
<Nav>
|
|
53
|
-
<NavLink to="/guide/getting-started">Guide</NavLink>
|
|
54
|
-
{{TYPEDOC_NAVLINK}}
|
|
55
|
-
</Nav>
|
|
56
|
-
}
|
|
57
|
-
/>
|
|
58
|
-
}
|
|
59
|
-
sidebar={
|
|
60
|
-
isHomePage ? undefined : (
|
|
61
|
-
<Sidebar>
|
|
62
|
-
<SidebarGroup title="Guide">
|
|
63
|
-
<SidebarLink to="/guide/getting-started">Getting Started</SidebarLink>
|
|
64
|
-
</SidebarGroup>
|
|
65
|
-
{{TYPEDOC_SIDEBARLINK}}
|
|
66
|
-
</Sidebar>
|
|
67
|
-
)
|
|
68
|
-
}
|
|
69
|
-
footer={
|
|
70
|
-
<Footer
|
|
71
|
-
message={[
|
|
72
|
-
config.project?.homepage
|
|
73
|
-
? `<a href="${config.project.homepage}">${config.title}</a>`
|
|
74
|
-
: config.title,
|
|
75
|
-
"Built with <a href='https://github.com/sebastian-software/ardo'>Ardo</a>",
|
|
76
|
-
].join(" · ")}
|
|
77
|
-
copyright={
|
|
78
|
-
config.project?.author
|
|
79
|
-
? `Copyright © ${new Date().getFullYear()} ${config.project.author}`
|
|
80
|
-
: undefined
|
|
81
|
-
}
|
|
82
|
-
/>
|
|
83
|
-
}
|
|
84
|
-
>
|
|
85
|
-
<Outlet />
|
|
86
|
-
</ArdoLayout>
|
|
87
|
-
</ArdoProvider>
|
|
88
|
-
)
|
|
14
|
+
return <ArdoRoot config={config} sidebar={sidebar} />
|
|
89
15
|
}
|
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
"esModuleInterop": true,
|
|
12
12
|
"skipLibCheck": true,
|
|
13
13
|
"forceConsistentCasingInFileNames": true,
|
|
14
|
-
"jsx": "react-jsx"
|
|
14
|
+
"jsx": "react-jsx",
|
|
15
|
+
"types": ["vite/client", "ardo/virtual"]
|
|
15
16
|
},
|
|
16
17
|
"include": ["app/**/*", "*.ts", "*.config.ts"],
|
|
17
18
|
"exclude": ["node_modules", "build"]
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/// <reference types="vite/client" />
|
|
2
|
-
|
|
3
|
-
declare module "virtual:ardo/config" {
|
|
4
|
-
import type { ArdoConfig } from "ardo"
|
|
5
|
-
const config: ArdoConfig
|
|
6
|
-
export default config
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
declare module "virtual:ardo/sidebar" {
|
|
10
|
-
import type { SidebarItem } from "ardo"
|
|
11
|
-
const sidebar: SidebarItem[]
|
|
12
|
-
export default sidebar
|
|
13
|
-
}
|