kapi-ui 0.2.0 → 0.2.2
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/nuxt-module.js +24 -0
- package/dist/server.js +4 -0
- package/dist/setup.js +3 -7
- package/dist/utils.js +12 -21
- package/package.json +5 -2
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { defineNuxtModule, addVitePlugin } from '@nuxt/kit';
|
|
2
|
+
import kapiVitePlugin from './vite-plugin.js';
|
|
3
|
+
export default defineNuxtModule({
|
|
4
|
+
meta: {
|
|
5
|
+
name: 'kapi-ui',
|
|
6
|
+
configKey: 'kapi',
|
|
7
|
+
},
|
|
8
|
+
setup(_options, nuxt) {
|
|
9
|
+
var _a;
|
|
10
|
+
if (!nuxt.options.dev)
|
|
11
|
+
return;
|
|
12
|
+
// Nuxt renders HTML through Nitro, not Vite's transformIndexHtml, so the
|
|
13
|
+
// overlay script has to be injected via unhead instead of the vite plugin.
|
|
14
|
+
addVitePlugin(kapiVitePlugin());
|
|
15
|
+
// Nuxt mounts Vite's dev middleware under app.buildAssetsDir (e.g. /_nuxt/),
|
|
16
|
+
// not at the site root, so the script has to be requested from under that
|
|
17
|
+
// prefix or Nitro's page renderer intercepts it before Vite ever sees it.
|
|
18
|
+
(_a = nuxt.options.app.head).script || (_a.script = []);
|
|
19
|
+
nuxt.options.app.head.script.push({
|
|
20
|
+
src: `${nuxt.options.app.buildAssetsDir}@kapi-ui/overlay`,
|
|
21
|
+
type: 'module',
|
|
22
|
+
});
|
|
23
|
+
},
|
|
24
|
+
});
|
package/dist/server.js
CHANGED
|
@@ -91,7 +91,11 @@ function processComments(prompt, socket) {
|
|
|
91
91
|
send(socket, { type: "comments:done" });
|
|
92
92
|
});
|
|
93
93
|
}
|
|
94
|
+
let serverStarted = false;
|
|
94
95
|
export function startServer(portNumber) {
|
|
96
|
+
if (serverStarted)
|
|
97
|
+
return;
|
|
98
|
+
serverStarted = true;
|
|
95
99
|
const server = http.createServer((req, res) => {
|
|
96
100
|
res.writeHead(200, { "Content-Type": "text/plain" });
|
|
97
101
|
res.end("I love capybaras");
|
package/dist/setup.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import prompts from 'prompts';
|
|
3
|
-
import { installKapi, injectVitePlugin,
|
|
3
|
+
import { installKapi, injectVitePlugin, injectNuxtModule, KAPI_PACKAGE_NAME } from './utils.js';
|
|
4
4
|
async function setup() {
|
|
5
5
|
console.log(`
|
|
6
6
|
██ ██ █████ ██████ ██
|
|
@@ -46,7 +46,7 @@ Add this manually to your vite.config:
|
|
|
46
46
|
if (response.setupChoice === 'nuxt') {
|
|
47
47
|
try {
|
|
48
48
|
installKapi(process.cwd());
|
|
49
|
-
await
|
|
49
|
+
await injectNuxtModule(process.cwd());
|
|
50
50
|
console.log('done!');
|
|
51
51
|
}
|
|
52
52
|
catch (err) {
|
|
@@ -54,12 +54,8 @@ Add this manually to your vite.config:
|
|
|
54
54
|
console.log(`
|
|
55
55
|
Add this manually to your nuxt.config:
|
|
56
56
|
|
|
57
|
-
import kapi from '${KAPI_PACKAGE_NAME}/vite-plugin'
|
|
58
|
-
|
|
59
57
|
export default defineNuxtConfig({
|
|
60
|
-
|
|
61
|
-
plugins: [kapi()],
|
|
62
|
-
},
|
|
58
|
+
modules: ['${KAPI_PACKAGE_NAME}/nuxt'],
|
|
63
59
|
})
|
|
64
60
|
`);
|
|
65
61
|
process.exit(1);
|
package/dist/utils.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { loadFile, writeFile
|
|
2
|
-
import { addVitePlugin,
|
|
1
|
+
import { loadFile, writeFile } from 'magicast';
|
|
2
|
+
import { addVitePlugin, addNuxtModule } from 'magicast/helpers';
|
|
3
3
|
import { existsSync, readFileSync } from 'fs';
|
|
4
4
|
import path from 'path';
|
|
5
5
|
import { fileURLToPath } from 'url';
|
|
@@ -34,34 +34,25 @@ export async function injectVitePlugin(cwd) {
|
|
|
34
34
|
await writeFile(mod, configPath);
|
|
35
35
|
console.log(`✔ Added kapi plugin to ${configFile}`);
|
|
36
36
|
}
|
|
37
|
-
export async function
|
|
38
|
-
var _a;
|
|
37
|
+
export async function injectNuxtModule(cwd) {
|
|
39
38
|
const candidates = ['nuxt.config.ts', 'nuxt.config.js', 'nuxt.config.mjs'];
|
|
40
39
|
const configFile = candidates.find((f) => existsSync(path.join(cwd, f)));
|
|
41
40
|
if (!configFile) {
|
|
42
41
|
throw new Error('No nuxt.config found.');
|
|
43
42
|
}
|
|
44
43
|
const configPath = path.join(cwd, configFile);
|
|
45
|
-
const
|
|
44
|
+
const moduleSpecifier = `${KAPI_PACKAGE_NAME}/nuxt`;
|
|
46
45
|
const existingSource = readFileSync(configPath, 'utf-8');
|
|
47
|
-
if (existingSource.includes(
|
|
48
|
-
console.log(`✔ kapi
|
|
46
|
+
if (existingSource.includes(moduleSpecifier)) {
|
|
47
|
+
console.log(`✔ kapi module already configured in ${configFile}`);
|
|
49
48
|
return;
|
|
50
49
|
}
|
|
51
50
|
const mod = await loadFile(configPath);
|
|
52
|
-
|
|
53
|
-
//
|
|
54
|
-
//
|
|
55
|
-
//
|
|
56
|
-
|
|
57
|
-
config.vite || (config.vite = {});
|
|
58
|
-
(_a = config.vite).plugins || (_a.plugins = []);
|
|
59
|
-
config.vite.plugins.push(builders.functionCall(constructor));
|
|
60
|
-
mod.imports.$prepend({
|
|
61
|
-
from: importSpecifier,
|
|
62
|
-
imported: 'default',
|
|
63
|
-
local: constructor,
|
|
64
|
-
});
|
|
51
|
+
// Nuxt renders HTML through Nitro, not Vite's transformIndexHtml, so the
|
|
52
|
+
// overlay can't be injected as a plain Vite plugin the way it is for Vite
|
|
53
|
+
// apps. Registering it as a Nuxt module (kapi-ui/nuxt) lets it inject the
|
|
54
|
+
// overlay script via unhead and add the Vite plugin through @nuxt/kit.
|
|
55
|
+
addNuxtModule(mod, moduleSpecifier);
|
|
65
56
|
await writeFile(mod, configPath);
|
|
66
|
-
console.log(`✔ Added kapi
|
|
57
|
+
console.log(`✔ Added kapi module to ${configFile}`);
|
|
67
58
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kapi-ui",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Visually prompt your UI",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "tsc",
|
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
"kapi-ui": "dist/setup.js"
|
|
14
14
|
},
|
|
15
15
|
"exports": {
|
|
16
|
-
"./vite-plugin": "./dist/vite-plugin.js"
|
|
16
|
+
"./vite-plugin": "./dist/vite-plugin.js",
|
|
17
|
+
"./nuxt": "./dist/nuxt-module.js"
|
|
17
18
|
},
|
|
18
19
|
"repository": {
|
|
19
20
|
"type": "git",
|
|
@@ -32,6 +33,7 @@
|
|
|
32
33
|
},
|
|
33
34
|
"homepage": "https://github.com/jcebermudo/kapi#readme",
|
|
34
35
|
"devDependencies": {
|
|
36
|
+
"@nuxt/schema": "^3.14.0",
|
|
35
37
|
"@types/node": "^26.1.0",
|
|
36
38
|
"@types/prompts": "^2.4.9",
|
|
37
39
|
"@types/ws": "^8.18.1",
|
|
@@ -39,6 +41,7 @@
|
|
|
39
41
|
"vite": "^8.1.3"
|
|
40
42
|
},
|
|
41
43
|
"dependencies": {
|
|
44
|
+
"@nuxt/kit": "^3.14.0",
|
|
42
45
|
"magicast": "^0.5.3",
|
|
43
46
|
"prompts": "^2.4.2",
|
|
44
47
|
"ws": "^8.21.0"
|