@adaptive-js/create-adaptive-app 0.0.0-stage → 0.1.9
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/LICENSE +21 -0
- package/README.md +56 -2
- package/index.mjs +355 -0
- package/package.json +40 -4
- package/template/.env +5 -0
- package/template/_gitignore +5 -0
- package/template/dependency.ts +21 -0
- package/template/index.html +13 -0
- package/template/package.json +23 -0
- package/template/public/styles.css +8 -0
- package/template/src/components/counter.tsx +46 -0
- package/template/src/pages/index.tsx +81 -0
- package/template/tsconfig.json +15 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Antonio Johnathan
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,57 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @adaptive-js/create-adaptive-app
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Create an [AdaptiveJS](https://github.com/SrJohnathan/adaptive-js) application with TypeScript, SSR, DOM-first hydration, and Tailwind 4.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install -g @adaptive-js/create-adaptive-app
|
|
9
|
+
create-adaptive-app my-app
|
|
10
|
+
cd my-app
|
|
11
|
+
npm install
|
|
12
|
+
npm run dev
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Optional extensions
|
|
16
|
+
|
|
17
|
+
During creation the CLI lists the available extensions and asks which ones to install. Press Enter to install none of them.
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
create-adaptive-app my-app --ext i18n,icons # skip the prompt, pick extensions
|
|
21
|
+
create-adaptive-app my-app --no-ext # skip the prompt, no extensions
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Keys: `components`, `auth`, `security`, `i18n`, `icons` (the full package name or the `extension/` folder name also work). Non-interactive runs (CI, piped stdin) skip the prompt automatically, so the command never blocks in a pipeline.
|
|
25
|
+
|
|
26
|
+
## Framework development
|
|
27
|
+
|
|
28
|
+
When running the scaffold from an AdaptiveJS checkout, `--local` points `@adaptive-js/adapter`, `@adaptive-js/web`, `@adaptive-js/ci` and `@adaptive-js/shared` at the local packages. This option is for framework development; application users should omit it.
|
|
29
|
+
|
|
30
|
+
## What you get
|
|
31
|
+
|
|
32
|
+
- `src/pages` file-based routes
|
|
33
|
+
- an SSR-rendered page
|
|
34
|
+
- a `"hydrate"` island using signals and `memo`
|
|
35
|
+
- `dependency.ts`, the global client entry (theme bootstrapping, global UI libraries)
|
|
36
|
+
- Tailwind 4 through `public/styles.css`
|
|
37
|
+
- `generateMetadata` for `<title>`, description, canonical and Open Graph/Twitter tags (injected into the `<!--adaptive-head-->` marker of `index.html`)
|
|
38
|
+
- `@adaptive-js/adapter` available for deploy presets (`--preset vercel`, `netlify`, …) and build plugins
|
|
39
|
+
- `adaptive.config.ts` support from `@adaptive-js/ci`
|
|
40
|
+
|
|
41
|
+
## Page metadata
|
|
42
|
+
|
|
43
|
+
`src/pages/index.tsx` exports `generateMetadata({ url })`. The `url` is absolute, so
|
|
44
|
+
`canonical` and `og:url` work in production without extra setup. Set `SITE_URL` in
|
|
45
|
+
`.env` to force a fixed public origin, and add `public/og-image.png` to enable
|
|
46
|
+
`og:image`/`twitter:image`.
|
|
47
|
+
|
|
48
|
+
```tsx
|
|
49
|
+
export function generateMetadata({ url }: { url: string }) {
|
|
50
|
+
const origin = new URL(url, "http://localhost").origin;
|
|
51
|
+
return { title: "My App", description: "…", canonical: `${origin}/` };
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## License
|
|
56
|
+
|
|
57
|
+
MIT
|
package/index.mjs
ADDED
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import readline from "node:readline/promises";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
|
|
7
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
8
|
+
const templateDir = path.join(__dirname, "template");
|
|
9
|
+
const monorepoRoot = path.resolve(__dirname, "..");
|
|
10
|
+
|
|
11
|
+
// Kept in sync with packages/* and extension/* by scripts/check-packages.mjs.
|
|
12
|
+
const ADAPTER_VERSION = "0.1.1";
|
|
13
|
+
const WEB_VERSION = "0.0.2";
|
|
14
|
+
const CI_VERSION = "0.0.2";
|
|
15
|
+
const SHARED_VERSION = "0.0.1";
|
|
16
|
+
const EXT_COMPONENTS_VERSION = "0.0.2";
|
|
17
|
+
const EXT_AUTH_VERSION = "0.0.2";
|
|
18
|
+
const EXT_SECURITY_VERSION = "0.0.1";
|
|
19
|
+
const EXT_I18N_VERSION = "0.0.2";
|
|
20
|
+
const EXT_ICONS_VERSION = "0.0.2";
|
|
21
|
+
|
|
22
|
+
const EXTENSIONS = [
|
|
23
|
+
{
|
|
24
|
+
key: "components",
|
|
25
|
+
dir: "components",
|
|
26
|
+
packageName: "@adaptive-js/components",
|
|
27
|
+
version: EXT_COMPONENTS_VERSION,
|
|
28
|
+
description: "UI primitives, virtualization and Reveal",
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
key: "auth",
|
|
32
|
+
dir: "auth",
|
|
33
|
+
packageName: "@adaptive-js/extension-auth",
|
|
34
|
+
version: EXT_AUTH_VERSION,
|
|
35
|
+
description: "server-first authentication and sessions",
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
key: "security",
|
|
39
|
+
dir: "security",
|
|
40
|
+
packageName: "@adaptive-js/extension-security",
|
|
41
|
+
version: EXT_SECURITY_VERSION,
|
|
42
|
+
description: "security headers, rate limiting and runtime guards",
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
key: "i18n",
|
|
46
|
+
dir: "i18n",
|
|
47
|
+
packageName: "@adaptive-js/extension-i18n",
|
|
48
|
+
version: EXT_I18N_VERSION,
|
|
49
|
+
description: "reactive translations, fallback and server-side loader",
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
key: "icons",
|
|
53
|
+
dir: "lucide-animation-icons",
|
|
54
|
+
packageName: "@adaptive-js/extension-lucide-animation-icons",
|
|
55
|
+
version: EXT_ICONS_VERSION,
|
|
56
|
+
description: "animated Lucide icons",
|
|
57
|
+
},
|
|
58
|
+
];
|
|
59
|
+
|
|
60
|
+
const args = process.argv.slice(2);
|
|
61
|
+
const positionals = [];
|
|
62
|
+
const unsupportedOptions = [];
|
|
63
|
+
let localMode = false;
|
|
64
|
+
// undefined = ask, "" = none, "i18n,icons" = explicit list.
|
|
65
|
+
let extensionSelection;
|
|
66
|
+
|
|
67
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
68
|
+
const arg = args[index];
|
|
69
|
+
|
|
70
|
+
if (arg === "--local") {
|
|
71
|
+
localMode = true;
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (arg === "--no-ext") {
|
|
76
|
+
extensionSelection = "";
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (arg === "--ext") {
|
|
81
|
+
extensionSelection = args[index + 1] ?? "";
|
|
82
|
+
index += 1;
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (arg.startsWith("--ext=")) {
|
|
87
|
+
extensionSelection = arg.slice("--ext=".length);
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (arg.startsWith("-")) {
|
|
92
|
+
unsupportedOptions.push(arg);
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
positionals.push(arg);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (positionals.length === 0 || positionals.length > 1) {
|
|
100
|
+
console.error("Usage: create-adaptive-app <project-name> [--local] [--ext <list> | --no-ext]");
|
|
101
|
+
console.error("");
|
|
102
|
+
console.error("Extensions:");
|
|
103
|
+
for (const extension of EXTENSIONS) {
|
|
104
|
+
console.error(` ${extension.key.padEnd(12)} ${extension.packageName}`);
|
|
105
|
+
}
|
|
106
|
+
process.exit(1);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (unsupportedOptions.length > 0) {
|
|
110
|
+
console.error(`Unsupported option: ${unsupportedOptions[0]}`);
|
|
111
|
+
console.error("Supported options: --local, --ext <list>, --no-ext");
|
|
112
|
+
process.exit(1);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const projectName = positionals[0];
|
|
116
|
+
const targetDir = path.resolve(process.cwd(), projectName);
|
|
117
|
+
const appName = path.basename(targetDir);
|
|
118
|
+
|
|
119
|
+
if (!/^[a-z0-9][a-z0-9._-]*$/i.test(appName)) {
|
|
120
|
+
console.error(`Invalid project name: ${appName}`);
|
|
121
|
+
process.exit(1);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
try {
|
|
125
|
+
await fs.access(targetDir);
|
|
126
|
+
console.error(`Directory already exists: ${targetDir}`);
|
|
127
|
+
process.exit(1);
|
|
128
|
+
} catch (error) {
|
|
129
|
+
if (error?.code !== "ENOENT") throw error;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const selectedExtensions = await selectExtensions();
|
|
133
|
+
|
|
134
|
+
const replacements = createReplacements(targetDir);
|
|
135
|
+
await copyDir(templateDir, targetDir, replacements);
|
|
136
|
+
|
|
137
|
+
if (selectedExtensions.length > 0) {
|
|
138
|
+
await addExtensionDependencies(targetDir, selectedExtensions);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
console.log(`Adaptive app created at ${targetDir}`);
|
|
142
|
+
|
|
143
|
+
if (selectedExtensions.length > 0) {
|
|
144
|
+
console.log(`Extensions: ${selectedExtensions.map((extension) => extension.packageName).join(", ")}`);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
console.log("");
|
|
148
|
+
console.log("Next steps:");
|
|
149
|
+
console.log(` cd ${projectName}`);
|
|
150
|
+
console.log(" npm install");
|
|
151
|
+
console.log(" npm run dev");
|
|
152
|
+
|
|
153
|
+
function createReplacements(targetDir) {
|
|
154
|
+
const replacements = {
|
|
155
|
+
__APP_NAME__: appName,
|
|
156
|
+
__ADAPTER_DEP__: `^${ADAPTER_VERSION}`,
|
|
157
|
+
__WEB_DEP__: `^${WEB_VERSION}`,
|
|
158
|
+
__CI_DEP__: `^${CI_VERSION}`,
|
|
159
|
+
__SHARED_DEP__: `^${SHARED_VERSION}`,
|
|
160
|
+
__ADAPTIVE_DEV__: "adaptive dev .",
|
|
161
|
+
__ADAPTIVE_BUILD__: "adaptive build .",
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
if (!localMode) return replacements;
|
|
165
|
+
|
|
166
|
+
const relativeRoot = normalizePath(path.relative(targetDir, monorepoRoot));
|
|
167
|
+
const ciEntry = normalizePath(path.join(relativeRoot, "packages", "ci", "dist", "index.js"));
|
|
168
|
+
|
|
169
|
+
replacements.__ADAPTER_DEP__ = `file:${normalizePath(path.join(relativeRoot, "packages", "adaptive-adapter"))}`;
|
|
170
|
+
replacements.__WEB_DEP__ = `file:${normalizePath(path.join(relativeRoot, "packages", "web"))}`;
|
|
171
|
+
replacements.__CI_DEP__ = `file:${normalizePath(path.join(relativeRoot, "packages", "ci"))}`;
|
|
172
|
+
replacements.__SHARED_DEP__ = `file:${normalizePath(path.join(relativeRoot, "packages", "shared"))}`;
|
|
173
|
+
replacements.__ADAPTIVE_DEV__ = jsonStringContent(`node "${ciEntry}" dev .`);
|
|
174
|
+
replacements.__ADAPTIVE_BUILD__ = jsonStringContent(`node "${ciEntry}" build .`);
|
|
175
|
+
|
|
176
|
+
return replacements;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
async function selectExtensions() {
|
|
180
|
+
if (extensionSelection !== undefined) {
|
|
181
|
+
return resolveExtensionSelection(extensionSelection);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (!process.stdin.isTTY) {
|
|
185
|
+
console.log("No extensions selected (non-interactive run). Pass --ext <list> to add them.");
|
|
186
|
+
return [];
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
printExtensionMenu();
|
|
190
|
+
|
|
191
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
192
|
+
|
|
193
|
+
try {
|
|
194
|
+
while (true) {
|
|
195
|
+
const answer = await askLine(rl, "Which extensions? (numbers separated by comma, Enter for none): ");
|
|
196
|
+
|
|
197
|
+
// null = stdin fechou (EOF) no meio do prompt: segue sem extensões.
|
|
198
|
+
if (answer === null || answer.trim() === "") return [];
|
|
199
|
+
|
|
200
|
+
const selection = parseExtensionNumbers(answer);
|
|
201
|
+
if (selection) return selection;
|
|
202
|
+
|
|
203
|
+
console.log("Invalid selection. Use the numbers from the list, for example: 1,3");
|
|
204
|
+
}
|
|
205
|
+
} catch (error) {
|
|
206
|
+
if (error?.name === "AbortError" || error?.code === "ERR_USE_AFTER_CLOSE") {
|
|
207
|
+
console.log("");
|
|
208
|
+
console.log("Cancelled.");
|
|
209
|
+
process.exit(1);
|
|
210
|
+
}
|
|
211
|
+
throw error;
|
|
212
|
+
} finally {
|
|
213
|
+
rl.close();
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* `rl.question` nunca resolve se o stdin fechar antes da resposta, então
|
|
219
|
+
* corremos a pergunta contra o evento "close".
|
|
220
|
+
*/
|
|
221
|
+
function askLine(rl, prompt) {
|
|
222
|
+
return new Promise((resolve) => {
|
|
223
|
+
let settled = false;
|
|
224
|
+
|
|
225
|
+
const onClose = () => {
|
|
226
|
+
if (settled) return;
|
|
227
|
+
settled = true;
|
|
228
|
+
resolve(null);
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
rl.once("close", onClose);
|
|
232
|
+
|
|
233
|
+
rl.question(prompt).then(
|
|
234
|
+
(value) => {
|
|
235
|
+
if (settled) return;
|
|
236
|
+
settled = true;
|
|
237
|
+
rl.off("close", onClose);
|
|
238
|
+
resolve(value);
|
|
239
|
+
},
|
|
240
|
+
() => {
|
|
241
|
+
if (settled) return;
|
|
242
|
+
settled = true;
|
|
243
|
+
rl.off("close", onClose);
|
|
244
|
+
resolve(null);
|
|
245
|
+
},
|
|
246
|
+
);
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
function printExtensionMenu() {
|
|
251
|
+
console.log("");
|
|
252
|
+
console.log("Optional extensions:");
|
|
253
|
+
for (const [index, extension] of EXTENSIONS.entries()) {
|
|
254
|
+
console.log(` ${`${index + 1})`.padEnd(3)} ${extension.packageName.padEnd(48)} ${extension.description}`);
|
|
255
|
+
}
|
|
256
|
+
console.log("");
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
function parseExtensionNumbers(value) {
|
|
260
|
+
const tokens = value.split(/[\s,]+/).filter(Boolean);
|
|
261
|
+
if (tokens.length === 0) return null;
|
|
262
|
+
|
|
263
|
+
const selected = [];
|
|
264
|
+
|
|
265
|
+
for (const token of tokens) {
|
|
266
|
+
const index = Number(token);
|
|
267
|
+
if (!Number.isInteger(index) || index < 1 || index > EXTENSIONS.length) return null;
|
|
268
|
+
|
|
269
|
+
const extension = EXTENSIONS[index - 1];
|
|
270
|
+
if (!selected.includes(extension)) selected.push(extension);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
return selected;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
function resolveExtensionSelection(value) {
|
|
277
|
+
const tokens = String(value).split(/[\s,]+/).filter(Boolean);
|
|
278
|
+
if (tokens.length === 0) return [];
|
|
279
|
+
|
|
280
|
+
const selected = [];
|
|
281
|
+
|
|
282
|
+
for (const token of tokens) {
|
|
283
|
+
const normalized = token.toLowerCase();
|
|
284
|
+
const extension = EXTENSIONS.find(
|
|
285
|
+
(item) =>
|
|
286
|
+
item.key === normalized ||
|
|
287
|
+
item.dir === normalized ||
|
|
288
|
+
item.packageName === normalized,
|
|
289
|
+
);
|
|
290
|
+
|
|
291
|
+
if (!extension) {
|
|
292
|
+
console.error(`Unknown extension: ${token}`);
|
|
293
|
+
console.error(`Available: ${EXTENSIONS.map((item) => item.key).join(", ")}`);
|
|
294
|
+
process.exit(1);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
if (!selected.includes(extension)) selected.push(extension);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
return selected;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
async function addExtensionDependencies(targetDir, extensions) {
|
|
304
|
+
const packageJsonPath = path.join(targetDir, "package.json");
|
|
305
|
+
const packageJson = JSON.parse(await fs.readFile(packageJsonPath, "utf8"));
|
|
306
|
+
const dependencies = packageJson.dependencies ?? {};
|
|
307
|
+
|
|
308
|
+
for (const extension of extensions) {
|
|
309
|
+
dependencies[extension.packageName] = localMode
|
|
310
|
+
? `file:${localExtensionSpec(targetDir, extension)}`
|
|
311
|
+
: `^${extension.version}`;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
packageJson.dependencies = sortKeys(dependencies);
|
|
315
|
+
await fs.writeFile(packageJsonPath, `${JSON.stringify(packageJson, null, 2)}\n`, "utf8");
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
function localExtensionSpec(targetDir, extension) {
|
|
319
|
+
const relativeRoot = normalizePath(path.relative(targetDir, monorepoRoot));
|
|
320
|
+
return normalizePath(path.join(relativeRoot, "extension", extension.dir));
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
function sortKeys(record) {
|
|
324
|
+
return Object.fromEntries(Object.entries(record).sort(([a], [b]) => a.localeCompare(b)));
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
function jsonStringContent(value) {
|
|
328
|
+
return JSON.stringify(value).slice(1, -1);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
function normalizePath(value) {
|
|
332
|
+
return value.split(path.sep).join("/");
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
async function copyDir(fromDir, toDir, replacements) {
|
|
336
|
+
await fs.mkdir(toDir, { recursive: true });
|
|
337
|
+
const entries = await fs.readdir(fromDir, { withFileTypes: true });
|
|
338
|
+
|
|
339
|
+
for (const entry of entries) {
|
|
340
|
+
const sourcePath = path.join(fromDir, entry.name);
|
|
341
|
+
const targetName = entry.name === "_gitignore" ? ".gitignore" : entry.name;
|
|
342
|
+
const targetPath = path.join(toDir, targetName);
|
|
343
|
+
|
|
344
|
+
if (entry.isDirectory()) {
|
|
345
|
+
await copyDir(sourcePath, targetPath, replacements);
|
|
346
|
+
continue;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
let content = await fs.readFile(sourcePath, "utf8");
|
|
350
|
+
for (const [token, replacement] of Object.entries(replacements)) {
|
|
351
|
+
content = content.replaceAll(token, replacement);
|
|
352
|
+
}
|
|
353
|
+
await fs.writeFile(targetPath, content, "utf8");
|
|
354
|
+
}
|
|
355
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,42 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adaptive-js/create-adaptive-app",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.9",
|
|
4
|
+
"description": "Create an AdaptiveJS application with SSR, DOM-first hydration, and Tailwind 4.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"adaptive-js",
|
|
7
|
+
"create",
|
|
8
|
+
"scaffold",
|
|
9
|
+
"starter",
|
|
10
|
+
"template"
|
|
11
|
+
],
|
|
12
|
+
"author": "Antonio Johnathan",
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/SrJohnathan/adaptive-js.git",
|
|
17
|
+
"directory": "create-adaptive-app"
|
|
18
|
+
},
|
|
19
|
+
"homepage": "https://github.com/SrJohnathan/adaptive-js/tree/main/create-adaptive-app#readme",
|
|
20
|
+
"bugs": {
|
|
21
|
+
"url": "https://github.com/SrJohnathan/adaptive-js/issues"
|
|
22
|
+
},
|
|
23
|
+
"type": "module",
|
|
24
|
+
"bin": {
|
|
25
|
+
"create-adaptive-app": "index.mjs"
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"index.mjs",
|
|
29
|
+
"template"
|
|
30
|
+
],
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "node --check index.mjs",
|
|
33
|
+
"typecheck": "node --check index.mjs",
|
|
34
|
+
"prepublishOnly": "node --check index.mjs"
|
|
35
|
+
},
|
|
36
|
+
"engines": {
|
|
37
|
+
"node": ">=20.0.0"
|
|
38
|
+
},
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"access": "public"
|
|
41
|
+
}
|
|
42
|
+
}
|
package/template/.env
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Entrada global do cliente.
|
|
3
|
+
*
|
|
4
|
+
* O AdaptiveJS empacota este arquivo em todas as páginas. Não precisa de
|
|
5
|
+
* "client" nem de `export {}`: use para efeitos globais (tema, bibliotecas de
|
|
6
|
+
* UI, listeners da aplicação).
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const THEME_KEY = "adaptive-theme";
|
|
10
|
+
|
|
11
|
+
try {
|
|
12
|
+
const theme = localStorage.getItem(THEME_KEY);
|
|
13
|
+
if (theme === "light" || theme === "dark") {
|
|
14
|
+
document.documentElement.dataset.theme = theme;
|
|
15
|
+
}
|
|
16
|
+
} catch {
|
|
17
|
+
// localStorage pode estar bloqueado (modo privado, iframe restrito).
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Marca no <html> que o bundle global do cliente carregou.
|
|
21
|
+
document.documentElement.dataset.adaptiveClient = "ready";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="pt-BR">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<!--adaptive-head-->
|
|
7
|
+
<link rel="stylesheet" href="/styles.css" />
|
|
8
|
+
<!--hydration-script-->
|
|
9
|
+
</head>
|
|
10
|
+
<body>
|
|
11
|
+
<div id="root"><!--app-html--></div>
|
|
12
|
+
</body>
|
|
13
|
+
</html>
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "__APP_NAME__",
|
|
3
|
+
"private": true,
|
|
4
|
+
"type": "module",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"dev": "__ADAPTIVE_DEV__",
|
|
7
|
+
"build": "__ADAPTIVE_BUILD__",
|
|
8
|
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
9
|
+
},
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"@adaptive-js/adapter": "__ADAPTER_DEP__",
|
|
12
|
+
"@adaptive-js/ci": "__CI_DEP__",
|
|
13
|
+
"@adaptive-js/shared": "__SHARED_DEP__",
|
|
14
|
+
"@adaptive-js/web": "__WEB_DEP__"
|
|
15
|
+
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"@tailwindcss/postcss": "^4.1.7",
|
|
18
|
+
"@types/node": "^25.6.0",
|
|
19
|
+
"postcss": "^8.5.6",
|
|
20
|
+
"tailwindcss": "^4.1.7",
|
|
21
|
+
"typescript": "^6.0.3"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"hydrate";
|
|
2
|
+
|
|
3
|
+
import { memo, signal } from "@adaptive-js/web";
|
|
4
|
+
|
|
5
|
+
export default function Counter() {
|
|
6
|
+
const [count, setCount] = signal(0);
|
|
7
|
+
const double = memo(() => count() * 2);
|
|
8
|
+
|
|
9
|
+
return (
|
|
10
|
+
<section className="rounded-3xl border border-emerald-950/10 bg-white p-6 shadow-xl shadow-emerald-950/5 sm:p-8">
|
|
11
|
+
<div className="flex items-center justify-between gap-4">
|
|
12
|
+
<div>
|
|
13
|
+
<p className="text-xs font-bold uppercase tracking-[0.18em] text-emerald-700">Ilha hidratada</p>
|
|
14
|
+
<h2 className="mt-2 text-2xl font-bold tracking-tight">Contador reativo</h2>
|
|
15
|
+
</div>
|
|
16
|
+
<span className="rounded-full bg-emerald-950 px-3 py-1 font-mono text-xs text-lime-200">"hydrate"</span>
|
|
17
|
+
</div>
|
|
18
|
+
|
|
19
|
+
<div className="mt-8 flex items-center justify-center gap-5">
|
|
20
|
+
<button
|
|
21
|
+
type="button"
|
|
22
|
+
onClick={() => setCount((value) => value - 1)}
|
|
23
|
+
className="h-12 w-12 rounded-2xl border border-emerald-950/10 text-2xl font-bold transition hover:bg-emerald-50"
|
|
24
|
+
aria-label="Diminuir"
|
|
25
|
+
>
|
|
26
|
+
−
|
|
27
|
+
</button>
|
|
28
|
+
<strong className="min-w-20 text-center font-mono text-5xl tracking-tight text-emerald-950" aria-live="polite">
|
|
29
|
+
{() => count()}
|
|
30
|
+
</strong>
|
|
31
|
+
<button
|
|
32
|
+
type="button"
|
|
33
|
+
onClick={() => setCount((value) => value + 1)}
|
|
34
|
+
className="h-12 w-12 rounded-2xl bg-emerald-950 text-2xl font-bold text-lime-200 transition hover:bg-emerald-800"
|
|
35
|
+
aria-label="Aumentar"
|
|
36
|
+
>
|
|
37
|
+
+
|
|
38
|
+
</button>
|
|
39
|
+
</div>
|
|
40
|
+
|
|
41
|
+
<p className="mt-6 text-center text-sm text-slate-600">
|
|
42
|
+
O dobro do valor é <span className="font-mono font-bold text-emerald-700">{() => double()}</span>.
|
|
43
|
+
</p>
|
|
44
|
+
</section>
|
|
45
|
+
);
|
|
46
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import Counter from "../components/counter";
|
|
2
|
+
import type { AdaptiveMetadata, AdaptiveMetadataContext } from "@adaptive-js/shared";
|
|
3
|
+
|
|
4
|
+
const TITLE = "__APP_NAME__ · AdaptiveJS";
|
|
5
|
+
const DESCRIPTION =
|
|
6
|
+
"Aplicação AdaptiveJS com SSR, hidratação DOM-first, reatividade granular e Tailwind 4.";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Metadados da página (SEO / Open Graph). O AdaptiveJS chama esta função no
|
|
10
|
+
* servidor e injeta as tags no <head>, no lugar do <!--adaptive-head-->.
|
|
11
|
+
* `url` chega absoluta, então o canonical já sai correto em produção.
|
|
12
|
+
*
|
|
13
|
+
* Para og:image/twitter:image, coloque a arte em public/og-image.png e
|
|
14
|
+
* descomente as linhas `image`.
|
|
15
|
+
*/
|
|
16
|
+
export function generateMetadata({ url }: AdaptiveMetadataContext): AdaptiveMetadata {
|
|
17
|
+
const origin = new URL(url, "http://localhost").origin;
|
|
18
|
+
|
|
19
|
+
return {
|
|
20
|
+
title: TITLE,
|
|
21
|
+
description: DESCRIPTION,
|
|
22
|
+
canonical: `${origin}/`,
|
|
23
|
+
// image: `${origin}/og-image.png`,
|
|
24
|
+
siteName: "__APP_NAME__",
|
|
25
|
+
locale: "pt_BR",
|
|
26
|
+
type: "website",
|
|
27
|
+
openGraph: {
|
|
28
|
+
title: TITLE,
|
|
29
|
+
description: DESCRIPTION,
|
|
30
|
+
url: `${origin}/`,
|
|
31
|
+
// image: `${origin}/og-image.png`,
|
|
32
|
+
siteName: "__APP_NAME__",
|
|
33
|
+
locale: "pt_BR",
|
|
34
|
+
type: "website",
|
|
35
|
+
},
|
|
36
|
+
twitter: {
|
|
37
|
+
card: "summary_large_image",
|
|
38
|
+
title: TITLE,
|
|
39
|
+
description: DESCRIPTION,
|
|
40
|
+
// image: `${origin}/og-image.png`,
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export default function HomePage() {
|
|
46
|
+
return (
|
|
47
|
+
<main className="min-h-screen bg-[#f6f7f2] px-5 py-10 text-[#17231d] sm:px-8 sm:py-16">
|
|
48
|
+
<div className="mx-auto max-w-5xl">
|
|
49
|
+
<header className="flex flex-wrap items-center justify-between gap-4">
|
|
50
|
+
<a href="/" className="text-lg font-bold tracking-tight text-emerald-950">__APP_NAME__</a>
|
|
51
|
+
<span className="rounded-full border border-emerald-950/10 bg-white px-3 py-1 text-xs font-semibold text-emerald-700">
|
|
52
|
+
AdaptiveJS + Tailwind 4
|
|
53
|
+
</span>
|
|
54
|
+
</header>
|
|
55
|
+
|
|
56
|
+
<section className="mt-12 grid items-center gap-10 lg:grid-cols-[1.15fr_0.85fr]">
|
|
57
|
+
<div>
|
|
58
|
+
<p className="text-xs font-bold uppercase tracking-[0.2em] text-emerald-700">SSR · DOM-first · TypeScript</p>
|
|
59
|
+
<h1 className="mt-5 max-w-3xl text-5xl font-bold leading-[0.98] tracking-[-0.055em] text-emerald-950 sm:text-6xl">
|
|
60
|
+
Seu projeto já começa renderizado no servidor.
|
|
61
|
+
</h1>
|
|
62
|
+
<p className="mt-6 max-w-2xl text-lg leading-8 text-slate-600">
|
|
63
|
+
Esta página veio do SSR. O contador ao lado é uma ilha <code className="font-mono text-emerald-700">"hydrate"</code> que conecta eventos e sinais ao DOM existente.
|
|
64
|
+
</p>
|
|
65
|
+
<div className="mt-8 flex flex-wrap gap-3 text-xs font-semibold text-slate-600">
|
|
66
|
+
<span className="rounded-xl border border-emerald-950/10 bg-white px-3 py-2">src/pages define as rotas</span>
|
|
67
|
+
<span className="rounded-xl border border-emerald-950/10 bg-white px-3 py-2">public/styles.css carrega o Tailwind</span>
|
|
68
|
+
<span className="rounded-xl border border-emerald-950/10 bg-white px-3 py-2">signal atualiza sem VDOM global</span>
|
|
69
|
+
</div>
|
|
70
|
+
</div>
|
|
71
|
+
|
|
72
|
+
<Counter />
|
|
73
|
+
</section>
|
|
74
|
+
|
|
75
|
+
<footer className="mt-14 border-t border-emerald-950/10 pt-6 text-sm text-slate-500">
|
|
76
|
+
Edite <code className="font-mono text-emerald-700">src/pages/index.tsx</code> e execute <code className="font-mono text-emerald-700">npm run dev</code>.
|
|
77
|
+
</footer>
|
|
78
|
+
</div>
|
|
79
|
+
</main>
|
|
80
|
+
);
|
|
81
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "Bundler",
|
|
6
|
+
"lib": ["ES2022", "DOM", "DOM.Iterable"],
|
|
7
|
+
"types": ["node"],
|
|
8
|
+
"jsx": "react-jsx",
|
|
9
|
+
"jsxImportSource": "@adaptive-js/web",
|
|
10
|
+
"strict": true,
|
|
11
|
+
"skipLibCheck": true,
|
|
12
|
+
"noEmit": true
|
|
13
|
+
},
|
|
14
|
+
"include": ["src", "dependency.ts"]
|
|
15
|
+
}
|