|
| 1 | +diff --git a/dist/unplugin.mjs b/dist/unplugin.mjs |
| 2 | +index c2dbc024a6c8057d56a83d048519407ac1ac103d..90509ee63b97a6866329390969daeef76d392161 100644 |
| 3 | +--- a/dist/unplugin.mjs |
| 4 | ++++ b/dist/unplugin.mjs |
| 5 | +@@ -5,7 +5,7 @@ import { defu } from 'defu'; |
| 6 | + import { createUnplugin } from 'unplugin'; |
| 7 | + import ui from '@nuxt/ui/vite'; |
| 8 | + import { g as getTemplates, i as icons, t as theme, v as validateLicense } from './shared/ui-pro.CXNmoj_B.mjs'; |
| 9 | +-import dotenv from 'dotenv'; |
| 10 | ++import dotenv from '@dotenvx/dotenvx'; |
| 11 | + import { consola } from 'consola'; |
| 12 | + import { colors } from 'consola/utils'; |
| 13 | + import 'scule'; |
| 14 | +@@ -14,151 +14,151 @@ import 'ofetch'; |
| 15 | + import 'pkg-types'; |
| 16 | + |
| 17 | + function TemplatePlugin(options) { |
| 18 | +- const templates = getTemplates(options, options); |
| 19 | +- const templateKeys = new Set(templates.map((t) => `#build/${t.filename}`)); |
| 20 | +- return { |
| 21 | +- name: "nuxt:ui-pro:templates", |
| 22 | +- enforce: "pre", |
| 23 | +- resolveId(id) { |
| 24 | +- if (templateKeys.has(id + ".ts")) { |
| 25 | +- return id.replace("#build/", "virtual:nuxt-ui-pro-templates/") + ".ts"; |
| 26 | +- } |
| 27 | +- }, |
| 28 | +- loadInclude: (id) => templateKeys.has(id.replace("virtual:nuxt-ui-pro-templates/", "#build/")), |
| 29 | +- load(id) { |
| 30 | +- id = id.replace("virtual:nuxt-ui-pro-templates/", "#build/"); |
| 31 | +- return templates.find((t) => `#build/${t.filename}` === id).getContents({}); |
| 32 | +- } |
| 33 | +- }; |
| 34 | ++ const templates = getTemplates(options, options); |
| 35 | ++ const templateKeys = new Set(templates.map((t) => `#build/${t.filename}`)); |
| 36 | ++ return { |
| 37 | ++ name: "nuxt:ui-pro:templates", |
| 38 | ++ enforce: "pre", |
| 39 | ++ resolveId(id) { |
| 40 | ++ if (templateKeys.has(id + ".ts")) { |
| 41 | ++ return id.replace("#build/", "virtual:nuxt-ui-pro-templates/") + ".ts"; |
| 42 | ++ } |
| 43 | ++ }, |
| 44 | ++ loadInclude: (id) => templateKeys.has(id.replace("virtual:nuxt-ui-pro-templates/", "#build/")), |
| 45 | ++ load(id) { |
| 46 | ++ id = id.replace("virtual:nuxt-ui-pro-templates/", "#build/"); |
| 47 | ++ return templates.find((t) => `#build/${t.filename}` === id).getContents({}); |
| 48 | ++ } |
| 49 | ++ }; |
| 50 | + } |
| 51 | + |
| 52 | + function AppConfigPlugin(appConfig) { |
| 53 | +- return { |
| 54 | +- name: "nuxt:ui-pro:app-config", |
| 55 | +- enforce: "pre", |
| 56 | +- resolveId(id) { |
| 57 | +- if (id === "#build/app.config") { |
| 58 | +- return "virtual:nuxt-ui-app-config"; |
| 59 | +- } |
| 60 | +- }, |
| 61 | +- transform(code, id) { |
| 62 | +- if (id === "virtual:nuxt-ui-app-config") { |
| 63 | +- const existingConfig = new Function(`return ${code.match(/export default (.*)/s)?.[1]}`)(); |
| 64 | +- const mergedConfig = defu(existingConfig, { |
| 65 | +- ui: { |
| 66 | +- icons |
| 67 | +- }, |
| 68 | +- uiPro: appConfig.uiPro |
| 69 | +- }); |
| 70 | +- return `export default ${JSON.stringify(mergedConfig)}`; |
| 71 | +- } |
| 72 | +- } |
| 73 | +- }; |
| 74 | ++ return { |
| 75 | ++ name: "nuxt:ui-pro:app-config", |
| 76 | ++ enforce: "pre", |
| 77 | ++ resolveId(id) { |
| 78 | ++ if (id === "#build/app.config") { |
| 79 | ++ return "virtual:nuxt-ui-app-config"; |
| 80 | ++ } |
| 81 | ++ }, |
| 82 | ++ transform(code, id) { |
| 83 | ++ if (id === "virtual:nuxt-ui-app-config") { |
| 84 | ++ const existingConfig = new Function(`return ${code.match(/export default (.*)/s)?.[1]}`)(); |
| 85 | ++ const mergedConfig = defu(existingConfig, { |
| 86 | ++ ui: { |
| 87 | ++ icons |
| 88 | ++ }, |
| 89 | ++ uiPro: appConfig.uiPro |
| 90 | ++ }); |
| 91 | ++ return `export default ${JSON.stringify(mergedConfig)}`; |
| 92 | ++ } |
| 93 | ++ } |
| 94 | ++ }; |
| 95 | + } |
| 96 | + |
| 97 | + dotenv.config(); |
| 98 | + function LicensePlugin(license) { |
| 99 | +- const theme$1 = theme || { env: "NUXT_UI_PRO_LICENSE", link: "https://ui.nuxt.com/pro" }; |
| 100 | +- const key = process.env[theme$1.env] || license; |
| 101 | +- return { |
| 102 | +- name: "nuxt:ui-pro:license", |
| 103 | +- vite: { |
| 104 | +- enforce: "pre", |
| 105 | +- apply(config, { command }) { |
| 106 | +- if (command === "serve") { |
| 107 | +- if (!key) { |
| 108 | +- consola.box( |
| 109 | +- colors.greenBright("Nuxt UI Pro") + ` |
| 110 | ++ const theme$1 = theme || { env: "NUXT_UI_PRO_LICENSE", link: "https://ui.nuxt.com/pro" }; |
| 111 | ++ const key = dotenv.get(theme$1.env) || license; |
| 112 | ++ return { |
| 113 | ++ name: "nuxt:ui-pro:license", |
| 114 | ++ vite: { |
| 115 | ++ enforce: "pre", |
| 116 | ++ apply(config, { command }) { |
| 117 | ++ if (command === "serve") { |
| 118 | ++ if (!key) { |
| 119 | ++ consola.box( |
| 120 | ++ colors.greenBright("Nuxt UI Pro") + ` |
| 121 | + |
| 122 | + Missing \`${theme$1.env}\` env variable, please add it to your \`.env\`. |
| 123 | + |
| 124 | + ` + colors.blueBright(`Purchase Nuxt UI Pro at ${theme$1.link} to build your app in production.`) |
| 125 | +- ); |
| 126 | +- } |
| 127 | ++ ); |
| 128 | ++ } |
| 129 | ++ } |
| 130 | ++ return command === "build"; |
| 131 | ++ } |
| 132 | ++ }, |
| 133 | ++ async buildStart() { |
| 134 | ++ await validateLicense({ key, theme: theme$1, dir: process.cwd() }); |
| 135 | + } |
| 136 | +- return command === "build"; |
| 137 | +- } |
| 138 | +- }, |
| 139 | +- async buildStart() { |
| 140 | +- await validateLicense({ key, theme: theme$1, dir: process.cwd() }); |
| 141 | +- } |
| 142 | +- }; |
| 143 | ++ }; |
| 144 | + } |
| 145 | + |
| 146 | + const runtimeDir = normalize(fileURLToPath(new URL("./runtime", import.meta.url))); |
| 147 | + const resolveColors = (colors) => { |
| 148 | +- return colors?.length ? [.../* @__PURE__ */ new Set(["primary", ...colors])] : ["primary", "secondary", "success", "info", "warning", "error"]; |
| 149 | ++ return colors?.length ? [.../* @__PURE__ */ new Set(["primary", ...colors])] : ["primary", "secondary", "success", "info", "warning", "error"]; |
| 150 | + }; |
| 151 | + const NuxtUIProPlugin = createUnplugin((_options = {}) => { |
| 152 | +- let options = defu(_options, { |
| 153 | +- prefix: "U", |
| 154 | +- colorMode: true, |
| 155 | +- theme: { |
| 156 | +- colors: void 0, |
| 157 | +- transitions: true |
| 158 | +- }, |
| 159 | +- autoImport: { |
| 160 | +- dirs: [join(runtimeDir, "composables")] |
| 161 | +- }, |
| 162 | +- extraRuntimeDir: runtimeDir |
| 163 | +- }); |
| 164 | +- options.theme = options.theme || {}; |
| 165 | +- options.theme.colors = resolveColors(options.theme.colors); |
| 166 | +- const components = globSync("**/*.vue", { |
| 167 | +- cwd: join(runtimeDir, "components"), |
| 168 | +- ignore: [ |
| 169 | +- !options.colorMode && "color-mode/**/*.vue", |
| 170 | +- "content/*.vue", |
| 171 | +- "prose/**/*.vue" |
| 172 | +- ].filter(Boolean) |
| 173 | +- }); |
| 174 | +- const componentNames = new Set(components.map((c) => `${options.prefix}${c.split("/").pop()?.replace(/\.vue$/, "")}`)); |
| 175 | +- const componentPaths = new Map(components.map((c) => { |
| 176 | +- const name = c.replace(/\.vue$/, ""); |
| 177 | +- const componentName = `${options.prefix}${name.split("/").pop()}`; |
| 178 | +- return [componentName, c]; |
| 179 | +- })); |
| 180 | +- const overrides = globSync("**/*.vue", { |
| 181 | +- cwd: join(runtimeDir, "vue/components"), |
| 182 | +- ignore: [ |
| 183 | +- !options.colorMode && "color-mode/**/*.vue" |
| 184 | +- ].filter(Boolean) |
| 185 | +- }); |
| 186 | +- const overrideNames = new Set(overrides.map((c) => `${options.prefix}${c.split("/").pop()?.replace(/\.vue$/, "")}`)); |
| 187 | +- const overridePaths = new Map(overrides.map((c) => { |
| 188 | +- const name = c.replace(/\.vue$/, ""); |
| 189 | +- const componentName = `${options.prefix}${name.split("/").pop()}`; |
| 190 | +- return [componentName, c]; |
| 191 | +- })); |
| 192 | +- options = defu(options, { |
| 193 | +- components: { |
| 194 | +- resolvers: [ |
| 195 | +- (componentName) => { |
| 196 | +- if (overrideNames.has(componentName)) { |
| 197 | +- const relativePath = overridePaths.get(componentName); |
| 198 | +- return { |
| 199 | +- name: "default", |
| 200 | +- from: join(runtimeDir, "vue/components", relativePath) |
| 201 | +- }; |
| 202 | +- } |
| 203 | +- if (componentNames.has(componentName)) { |
| 204 | +- const relativePath = componentPaths.get(componentName); |
| 205 | +- return { |
| 206 | +- name: "default", |
| 207 | +- from: join(runtimeDir, "components", relativePath) |
| 208 | +- }; |
| 209 | +- } |
| 210 | ++ let options = defu(_options, { |
| 211 | ++ prefix: "U", |
| 212 | ++ colorMode: true, |
| 213 | ++ theme: { |
| 214 | ++ colors: void 0, |
| 215 | ++ transitions: true |
| 216 | ++ }, |
| 217 | ++ autoImport: { |
| 218 | ++ dirs: [join(runtimeDir, "composables")] |
| 219 | ++ }, |
| 220 | ++ extraRuntimeDir: runtimeDir |
| 221 | ++ }); |
| 222 | ++ options.theme = options.theme || {}; |
| 223 | ++ options.theme.colors = resolveColors(options.theme.colors); |
| 224 | ++ const components = globSync("**/*.vue", { |
| 225 | ++ cwd: join(runtimeDir, "components"), |
| 226 | ++ ignore: [ |
| 227 | ++ !options.colorMode && "color-mode/**/*.vue", |
| 228 | ++ "content/*.vue", |
| 229 | ++ "prose/**/*.vue" |
| 230 | ++ ].filter(Boolean) |
| 231 | ++ }); |
| 232 | ++ const componentNames = new Set(components.map((c) => `${options.prefix}${c.split("/").pop()?.replace(/\.vue$/, "")}`)); |
| 233 | ++ const componentPaths = new Map(components.map((c) => { |
| 234 | ++ const name = c.replace(/\.vue$/, ""); |
| 235 | ++ const componentName = `${options.prefix}${name.split("/").pop()}`; |
| 236 | ++ return [componentName, c]; |
| 237 | ++ })); |
| 238 | ++ const overrides = globSync("**/*.vue", { |
| 239 | ++ cwd: join(runtimeDir, "vue/components"), |
| 240 | ++ ignore: [ |
| 241 | ++ !options.colorMode && "color-mode/**/*.vue" |
| 242 | ++ ].filter(Boolean) |
| 243 | ++ }); |
| 244 | ++ const overrideNames = new Set(overrides.map((c) => `${options.prefix}${c.split("/").pop()?.replace(/\.vue$/, "")}`)); |
| 245 | ++ const overridePaths = new Map(overrides.map((c) => { |
| 246 | ++ const name = c.replace(/\.vue$/, ""); |
| 247 | ++ const componentName = `${options.prefix}${name.split("/").pop()}`; |
| 248 | ++ return [componentName, c]; |
| 249 | ++ })); |
| 250 | ++ options = defu(options, { |
| 251 | ++ components: { |
| 252 | ++ resolvers: [ |
| 253 | ++ (componentName) => { |
| 254 | ++ if (overrideNames.has(componentName)) { |
| 255 | ++ const relativePath = overridePaths.get(componentName); |
| 256 | ++ return { |
| 257 | ++ name: "default", |
| 258 | ++ from: join(runtimeDir, "vue/components", relativePath) |
| 259 | ++ }; |
| 260 | ++ } |
| 261 | ++ if (componentNames.has(componentName)) { |
| 262 | ++ const relativePath = componentPaths.get(componentName); |
| 263 | ++ return { |
| 264 | ++ name: "default", |
| 265 | ++ from: join(runtimeDir, "components", relativePath) |
| 266 | ++ }; |
| 267 | ++ } |
| 268 | ++ } |
| 269 | ++ ] |
| 270 | + } |
| 271 | +- ] |
| 272 | +- } |
| 273 | +- }); |
| 274 | +- const appConfig = { uiPro: options.uiPro }; |
| 275 | +- return [ |
| 276 | +- ui(options), |
| 277 | +- TemplatePlugin(options), |
| 278 | +- AppConfigPlugin(appConfig), |
| 279 | +- LicensePlugin(options.license) |
| 280 | +- ].flat(1); |
| 281 | ++ }); |
| 282 | ++ const appConfig = { uiPro: options.uiPro }; |
| 283 | ++ return [ |
| 284 | ++ ui(options), |
| 285 | ++ TemplatePlugin(options), |
| 286 | ++ AppConfigPlugin(appConfig), |
| 287 | ++ LicensePlugin(options.license) |
| 288 | ++ ].flat(1); |
| 289 | + }); |
| 290 | + |
| 291 | + export { NuxtUIProPlugin, runtimeDir }; |
0 commit comments