Website Structure

This commit is contained in:
supalerk-ar66 2026-01-13 10:46:40 +07:00
parent 62812f2090
commit 71f0676a62
22365 changed files with 4265753 additions and 791 deletions

View file

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2022-PRESENT Nuxt Team
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View file

@ -0,0 +1,2 @@
#!/usr/bin/env node
import('./dist/index.mjs')

View file

@ -0,0 +1,103 @@
import { existsSync } from 'node:fs';
import fsp from 'node:fs/promises';
import { relative } from 'node:path';
import { consola } from 'consola';
import { colors } from 'consola/utils';
import { diffLines } from 'diff';
import { parseModule } from 'magicast';
import { join } from 'pathe';
import prompts from 'prompts';
function findNuxtConfig(cwd) {
const names = [
"nuxt.config.ts",
"nuxt.config.js"
];
for (const name of names) {
const path = join(cwd, name);
if (existsSync(path))
return path;
}
}
function printOutManual(value) {
consola.info(colors.yellow("To manually enable Nuxt DevTools, add the following to your Nuxt config:"));
consola.info(colors.cyan(`
devtools: { enabled: ${value} }
`));
}
async function toggleConfig(cwd, value) {
const nuxtConfig = findNuxtConfig(cwd);
if (!nuxtConfig) {
consola.error(colors.red("Unable to find Nuxt config file in current directory"));
process.exitCode = 1;
printOutManual(true);
return false;
}
try {
const source = await fsp.readFile(nuxtConfig, "utf-8");
const mod = await parseModule(source, { sourceFileName: nuxtConfig });
const config = mod.exports.default.$type === "function-call" ? mod.exports.default.$args[0] : mod.exports.default;
if (config.devtools || value) {
config.devtools ||= {};
if (typeof config.devtools === "object")
config.devtools.enabled = value;
}
const generated = mod.generate().code;
if (source.trim() === generated.trim()) {
consola.info(colors.yellow(`Nuxt DevTools is already ${value ? "enabled" : "disabled"}`));
} else {
consola.log("");
consola.log("We are going to update the Nuxt config with with the following changes:");
consola.log(colors.bold(colors.green(`./${relative(cwd, nuxtConfig)}`)));
consola.log("");
printDiffToCLI(source, generated);
consola.log("");
const { confirm } = await prompts({
type: "confirm",
name: "confirm",
message: "Continue?",
initial: true
});
if (!confirm)
return false;
await fsp.writeFile(nuxtConfig, `${generated.trimEnd()}
`, "utf-8");
}
} catch {
consola.error(colors.red("Unable to update Nuxt config file automatically"));
process.exitCode = 1;
printOutManual(true);
return false;
}
return true;
}
async function enable(cwd) {
await toggleConfig(cwd, true);
}
async function disable(cwd) {
await toggleConfig(cwd, false);
}
function printDiffToCLI(from, to) {
const diffs = diffLines(from.trim(), to.trim());
let output = "";
let no = 0;
for (const diff of diffs) {
const lines = diff.value.trimEnd().split("\n");
for (const line of lines) {
if (!diff.added)
no += 1;
if (diff.added)
output += colors.green(`+ | ${line}
`);
else if (diff.removed)
output += colors.red(`-${no.toString().padStart(3, " ")} | ${line}
`);
else
output += colors.gray(`${colors.dim(`${no.toString().padStart(4, " ")} |`)} ${line}
`);
}
}
consola.log(output.trimEnd());
}
export { disable, enable };

View file

@ -0,0 +1,51 @@
import { consola } from 'consola';
import { colors } from 'consola/utils';
import { readPackageJSON } from 'pkg-types';
const name = "@nuxt/devtools-wizard";
const version = "3.1.1";
async function getNuxtVersion(path) {
try {
const pkg = await readPackageJSON("nuxt", { url: path });
if (!pkg.version)
consola.warn("Cannot find any installed nuxt versions in ", path);
return pkg.version || null;
} catch {
return null;
}
}
async function run() {
const args = process.argv.slice(2);
const command = args[0];
const cwd = process.cwd();
consola.log("");
consola.log(colors.bold(colors.green(" Nuxt ")));
consola.log(`${colors.inverse(colors.bold(colors.green(" DevTools ")))} ${colors.green(`v${version}`)}`);
consola.log(`
${colors.gray("Learn more at https://devtools.nuxt.com\n")}`);
if (name.endsWith("-edge") || name.endsWith("-nightly"))
throw new Error("[Nuxt DevTools] Nightly release of Nuxt DevTools requires to be installed locally. Learn more at https://github.com/nuxt/devtools/#nightly-release-channel");
const nuxtVersion = await getNuxtVersion(cwd);
if (!nuxtVersion) {
consola.error("[Nuxt DevTools] Unable to find any installed nuxt version in the current directory");
process.exit(1);
}
if (command === "enable") {
consola.log(colors.green("Enabling Nuxt DevTools..."));
await import('./chunks/builtin.mjs').then((r) => r.enable(cwd));
} else if (command === "disable") {
consola.log(colors.magenta("Disabling Nuxt DevTools..."));
await import('./chunks/builtin.mjs').then((r) => r.disable(cwd));
} else if (!command) {
consola.log(`npx ${name} enable|disable`);
process.exit(1);
} else {
consola.log(colors.red(`Unknown command "${command}"`));
process.exit(1);
}
}
run().catch((err) => {
consola.error(err);
process.exit(1);
});

View file

@ -0,0 +1,41 @@
{
"name": "@nuxt/devtools-wizard",
"type": "module",
"version": "3.1.1",
"description": "CLI Wizard to toggle Nuxt DevTools",
"license": "MIT",
"homepage": "https://devtools.nuxt.com",
"repository": {
"type": "git",
"url": "git+https://github.com/nuxt/devtools.git",
"directory": "packages/devtools-wizard"
},
"main": "./dist/index.mjs",
"bin": "./cli.mjs",
"files": [
"*.cjs",
"*.d.ts",
"*.mjs",
"dist"
],
"dependencies": {
"consola": "^3.4.2",
"diff": "^8.0.2",
"execa": "^8.0.1",
"magicast": "^0.5.1",
"pathe": "^2.0.3",
"pkg-types": "^2.3.0",
"prompts": "^2.4.2",
"semver": "^7.7.3"
},
"devDependencies": {
"@types/diff": "^8.0.0",
"@types/prompts": "^2.4.9",
"unbuild": "^3.6.1"
},
"scripts": {
"build": "unbuild",
"stub": "unbuild --stub",
"dev:prepare": "nr stub"
}
}