kapi-ui 0.1.3 → 0.2.1
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 +21 -0
- package/dist/setup.js +20 -1
- package/dist/utils.js +23 -1
- package/package.json +5 -2
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
(_a = nuxt.options.app.head).script || (_a.script = []);
|
|
16
|
+
nuxt.options.app.head.script.push({
|
|
17
|
+
src: '/@kapi-ui/overlay',
|
|
18
|
+
type: 'module',
|
|
19
|
+
});
|
|
20
|
+
},
|
|
21
|
+
});
|
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, KAPI_PACKAGE_NAME } from './utils.js';
|
|
3
|
+
import { installKapi, injectVitePlugin, injectNuxtModule, KAPI_PACKAGE_NAME } from './utils.js';
|
|
4
4
|
async function setup() {
|
|
5
5
|
console.log(`
|
|
6
6
|
██ ██ █████ ██████ ██
|
|
@@ -15,6 +15,7 @@ async function setup() {
|
|
|
15
15
|
message: 'Setup',
|
|
16
16
|
choices: [
|
|
17
17
|
{ title: 'Vite', value: 'vite' },
|
|
18
|
+
{ title: 'Nuxt', value: 'nuxt' },
|
|
18
19
|
],
|
|
19
20
|
});
|
|
20
21
|
if (!response.setupChoice) {
|
|
@@ -38,6 +39,24 @@ Add this manually to your vite.config:
|
|
|
38
39
|
export default defineConfig({
|
|
39
40
|
plugins: [kapi()],
|
|
40
41
|
})
|
|
42
|
+
`);
|
|
43
|
+
process.exit(1);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (response.setupChoice === 'nuxt') {
|
|
47
|
+
try {
|
|
48
|
+
installKapi(process.cwd());
|
|
49
|
+
await injectNuxtModule(process.cwd());
|
|
50
|
+
console.log('done!');
|
|
51
|
+
}
|
|
52
|
+
catch (err) {
|
|
53
|
+
console.error('Failed to update nuxt.config automatically:', err);
|
|
54
|
+
console.log(`
|
|
55
|
+
Add this manually to your nuxt.config:
|
|
56
|
+
|
|
57
|
+
export default defineNuxtConfig({
|
|
58
|
+
modules: ['${KAPI_PACKAGE_NAME}/nuxt'],
|
|
59
|
+
})
|
|
41
60
|
`);
|
|
42
61
|
process.exit(1);
|
|
43
62
|
}
|
package/dist/utils.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { loadFile, writeFile } from 'magicast';
|
|
2
|
-
import { addVitePlugin } from 'magicast/helpers';
|
|
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,3 +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 injectNuxtModule(cwd) {
|
|
38
|
+
const candidates = ['nuxt.config.ts', 'nuxt.config.js', 'nuxt.config.mjs'];
|
|
39
|
+
const configFile = candidates.find((f) => existsSync(path.join(cwd, f)));
|
|
40
|
+
if (!configFile) {
|
|
41
|
+
throw new Error('No nuxt.config found.');
|
|
42
|
+
}
|
|
43
|
+
const configPath = path.join(cwd, configFile);
|
|
44
|
+
const moduleSpecifier = `${KAPI_PACKAGE_NAME}/nuxt`;
|
|
45
|
+
const existingSource = readFileSync(configPath, 'utf-8');
|
|
46
|
+
if (existingSource.includes(moduleSpecifier)) {
|
|
47
|
+
console.log(`✔ kapi module already configured in ${configFile}`);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const mod = await loadFile(configPath);
|
|
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);
|
|
56
|
+
await writeFile(mod, configPath);
|
|
57
|
+
console.log(`✔ Added kapi module to ${configFile}`);
|
|
58
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kapi-ui",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
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"
|