unplugin-dingtalk 0.1.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.cjs ADDED
@@ -0,0 +1,350 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __commonJS = (cb, mod) => function __require() {
9
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
10
+ };
11
+ var __export = (target, all) => {
12
+ for (var name in all)
13
+ __defProp(target, name, { get: all[name], enumerable: true });
14
+ };
15
+ var __copyProps = (to, from, except, desc) => {
16
+ if (from && typeof from === "object" || typeof from === "function") {
17
+ for (let key of __getOwnPropNames(from))
18
+ if (!__hasOwnProp.call(to, key) && key !== except)
19
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
20
+ }
21
+ return to;
22
+ };
23
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
24
+ // If the importer is in node compatibility mode or this is not an ESM
25
+ // file that has been converted to a CommonJS file using a Babel-
26
+ // compatible transform (i.e. "__esModule" has not been set), then set
27
+ // "default" to the CommonJS "module.exports" for node compatibility.
28
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
29
+ mod
30
+ ));
31
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
+
33
+ // node_modules/.pnpm/picocolors@1.0.1/node_modules/picocolors/picocolors.js
34
+ var require_picocolors = __commonJS({
35
+ "node_modules/.pnpm/picocolors@1.0.1/node_modules/picocolors/picocolors.js"(exports2, module2) {
36
+ "use strict";
37
+ var argv = process.argv || [];
38
+ var env = process.env;
39
+ var isColorSupported = !("NO_COLOR" in env || argv.includes("--no-color")) && ("FORCE_COLOR" in env || argv.includes("--color") || process.platform === "win32" || require != null && require("tty").isatty(1) && env.TERM !== "dumb" || "CI" in env);
40
+ var formatter = (open, close, replace = open) => (input) => {
41
+ let string = "" + input;
42
+ let index = string.indexOf(close, open.length);
43
+ return ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close;
44
+ };
45
+ var replaceClose = (string, close, replace, index) => {
46
+ let result = "";
47
+ let cursor = 0;
48
+ do {
49
+ result += string.substring(cursor, index) + replace;
50
+ cursor = index + close.length;
51
+ index = string.indexOf(close, cursor);
52
+ } while (~index);
53
+ return result + string.substring(cursor);
54
+ };
55
+ var createColors = (enabled = isColorSupported) => {
56
+ let init = enabled ? formatter : () => String;
57
+ return {
58
+ isColorSupported: enabled,
59
+ reset: init("\x1B[0m", "\x1B[0m"),
60
+ bold: init("\x1B[1m", "\x1B[22m", "\x1B[22m\x1B[1m"),
61
+ dim: init("\x1B[2m", "\x1B[22m", "\x1B[22m\x1B[2m"),
62
+ italic: init("\x1B[3m", "\x1B[23m"),
63
+ underline: init("\x1B[4m", "\x1B[24m"),
64
+ inverse: init("\x1B[7m", "\x1B[27m"),
65
+ hidden: init("\x1B[8m", "\x1B[28m"),
66
+ strikethrough: init("\x1B[9m", "\x1B[29m"),
67
+ black: init("\x1B[30m", "\x1B[39m"),
68
+ red: init("\x1B[31m", "\x1B[39m"),
69
+ green: init("\x1B[32m", "\x1B[39m"),
70
+ yellow: init("\x1B[33m", "\x1B[39m"),
71
+ blue: init("\x1B[34m", "\x1B[39m"),
72
+ magenta: init("\x1B[35m", "\x1B[39m"),
73
+ cyan: init("\x1B[36m", "\x1B[39m"),
74
+ white: init("\x1B[37m", "\x1B[39m"),
75
+ gray: init("\x1B[90m", "\x1B[39m"),
76
+ bgBlack: init("\x1B[40m", "\x1B[49m"),
77
+ bgRed: init("\x1B[41m", "\x1B[49m"),
78
+ bgGreen: init("\x1B[42m", "\x1B[49m"),
79
+ bgYellow: init("\x1B[43m", "\x1B[49m"),
80
+ bgBlue: init("\x1B[44m", "\x1B[49m"),
81
+ bgMagenta: init("\x1B[45m", "\x1B[49m"),
82
+ bgCyan: init("\x1B[46m", "\x1B[49m"),
83
+ bgWhite: init("\x1B[47m", "\x1B[49m")
84
+ };
85
+ };
86
+ module2.exports = createColors();
87
+ module2.exports.createColors = createColors;
88
+ }
89
+ });
90
+
91
+ // src/nuxt.ts
92
+ var nuxt_exports = {};
93
+ __export(nuxt_exports, {
94
+ default: () => nuxt_default
95
+ });
96
+ module.exports = __toCommonJS(nuxt_exports);
97
+ var import_kit = require("@nuxt/kit");
98
+
99
+ // src/vite.ts
100
+ var import_unplugin2 = require("unplugin");
101
+
102
+ // src/index.ts
103
+ var import_node_child_process = require("child_process");
104
+ var import_node_process = __toESM(require("process"), 1);
105
+ var import_unplugin = require("unplugin");
106
+ var import_picocolors = __toESM(require_picocolors(), 1);
107
+
108
+ // node_modules/.pnpm/vite-plugin-vconsole@2.1.1/node_modules/vite-plugin-vconsole/dist/main.mjs
109
+ var parseVConsoleOptions = (config2) => Object.keys(config2).reduce((code, key) => {
110
+ const value = config2[key];
111
+ if (typeof value === "function") {
112
+ if (/^[(f]/.test(value.toString())) {
113
+ code += `${key}: ${value},`;
114
+ return code;
115
+ } else {
116
+ code += `${value},`;
117
+ return code;
118
+ }
119
+ }
120
+ code += `${key}: ${JSON.stringify(config2[key])},`;
121
+ return code;
122
+ }, "");
123
+ var getEventItems = (event, id) => {
124
+ return event.map(
125
+ (ele) => `
126
+ ${id}.on('${ele.eventName}', ${ele.callback})
127
+ `
128
+ ).join(";");
129
+ };
130
+ var getDynamicConfig = (dynamicConfig) => {
131
+ let configString = "";
132
+ if (!dynamicConfig) {
133
+ return configString;
134
+ }
135
+ for (const key in dynamicConfig) {
136
+ if (typeof dynamicConfig[key] === "string") {
137
+ configString += `${key}: ${dynamicConfig[key]},`;
138
+ }
139
+ }
140
+ return configString;
141
+ };
142
+ var getPlugins = (plugin) => {
143
+ let plugins = "";
144
+ if (plugin && plugin.length) {
145
+ plugins = plugin.map(
146
+ (e) => `
147
+ const ${e.id} = new VConsole.VConsolePlugin('${e.id}', '${e.name}');
148
+ ${getEventItems(e.event, e.id)}
149
+ vConsole.addPlugin(${e.id})
150
+ `
151
+ ).join(";");
152
+ }
153
+ return plugins;
154
+ };
155
+ function viteVConsole(opt) {
156
+ const {
157
+ entry,
158
+ enabled = true,
159
+ config: config2 = {},
160
+ plugin,
161
+ customHide = false,
162
+ dynamicConfig = {},
163
+ eventListener = ""
164
+ } = opt;
165
+ let entryPath = Array.isArray(entry) ? entry : [entry];
166
+ if (process.platform === "win32")
167
+ entryPath = entryPath.map((item) => item.replace(/\\/g, "/"));
168
+ const enabledTruly = enabled;
169
+ return {
170
+ name: "vite:vconsole",
171
+ enforce: "pre",
172
+ transform(_source, id) {
173
+ if (entryPath.includes(id) && enabledTruly) {
174
+ const code = `/* eslint-disable */;
175
+ import VConsole from 'vconsole';
176
+ // config
177
+ const vConsole = new VConsole({${parseVConsoleOptions(
178
+ config2
179
+ )}});
180
+ window.vConsole = vConsole;
181
+
182
+ // plugins
183
+ ${getPlugins(plugin)}
184
+
185
+ // dynamic config
186
+ window.vConsole.dynamicFunction = function() {
187
+ if (${getDynamicConfig(dynamicConfig).length > 0}) {
188
+ vConsole.setOption({${getDynamicConfig(dynamicConfig)}});
189
+ }
190
+ };
191
+
192
+ window.vConsole.dynamicChange = {
193
+ value: new Date().getTime()
194
+ };
195
+
196
+ window.vConsole.dynamicFunction();
197
+
198
+ if (${customHide}) {
199
+ vConsole.hideSwitch();
200
+ }
201
+
202
+ // In order to be compatible with old equipment, I used defineProperty. In the future, when proxy covers enough devices, proxy will be used.
203
+ Object.defineProperty(window.vConsole.dynamicChange, 'value', {
204
+ get: function() {
205
+ return this._value;
206
+ },
207
+ set: function(newValue) {
208
+ window.vConsole.dynamicFunction();
209
+ this._value = newValue;
210
+ }
211
+ });
212
+
213
+ // eventListener
214
+ ${eventListener}
215
+ /* eslint-enable */${_source}`;
216
+ return {
217
+ code,
218
+ map: null
219
+ // support source map
220
+ };
221
+ }
222
+ return {
223
+ code: _source,
224
+ map: null
225
+ // support source map
226
+ };
227
+ }
228
+ };
229
+ }
230
+
231
+ // src/index.ts
232
+ var config;
233
+ var devtoolsInstance;
234
+ var colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
235
+ var unpluginFactory = (options) => {
236
+ var _a;
237
+ const unpluginDing = {
238
+ name: "unplugin-dingtalk",
239
+ enforce: "pre",
240
+ transformInclude(id) {
241
+ return id.endsWith("main.ts") || id.endsWith("main.js");
242
+ },
243
+ transform(_source) {
244
+ var _a2, _b, _c;
245
+ if ((_a2 = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _a2.enable) {
246
+ const code = `/* eslint-disable */;
247
+ import { devtools } from '@vue/devtools'
248
+ devtools.connect(${(_b = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _b.host}, ${(_c = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _c.port})
249
+ /* eslint-enable */${_source};
250
+ `;
251
+ return {
252
+ code,
253
+ map: null
254
+ // support source map
255
+ };
256
+ }
257
+ return {
258
+ code: _source,
259
+ map: null
260
+ // support source map
261
+ };
262
+ },
263
+ vite: {
264
+ configResolved(_config) {
265
+ config = _config;
266
+ },
267
+ configureServer(server) {
268
+ var _a2, _b;
269
+ if (!(options == null ? void 0 : options.enable)) {
270
+ return;
271
+ }
272
+ function debug(...args) {
273
+ if (options == null ? void 0 : options.debug) {
274
+ console.log(` ${import_picocolors.default.yellow("DEBUG")} `, ...args);
275
+ }
276
+ }
277
+ const _printUrls = server.printUrls.bind(server);
278
+ let source = `localhost:${config.server.port || 5173}`;
279
+ const url = (_a2 = server.resolvedUrls) == null ? void 0 : _a2.local[0];
280
+ if (url) {
281
+ const u = new URL(url);
282
+ source = u.host;
283
+ }
284
+ const base = server.config.base || "/";
285
+ const _targetUrl = (_b = options == null ? void 0 : options.targetUrl) != null ? _b : `http://${source}${base}`;
286
+ server.printUrls = () => {
287
+ var _a3;
288
+ _printUrls();
289
+ console.log(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold(
290
+ `Open in dingtalk${((_a3 = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _a3.enable) ? " (with vue-devtools)" : ""}`
291
+ )}: ${colorUrl(`http://${source}${base}open-dingtalk`)}`);
292
+ };
293
+ const targetURL = new URL(_targetUrl);
294
+ targetURL.searchParams.append("ddtab", "true");
295
+ if (options == null ? void 0 : options.corpId) {
296
+ targetURL.searchParams.append("corpId", options.corpId);
297
+ }
298
+ server.middlewares.use("/open-dingtalk", (req, res) => {
299
+ var _a3;
300
+ debug(targetURL.toString());
301
+ res.writeHead(302, {
302
+ Location: `dingtalk://dingtalkclient/page/link?url=${encodeURIComponent(targetURL.toString())}`
303
+ });
304
+ if (((_a3 = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _a3.enable) && !devtoolsInstance) {
305
+ devtoolsInstance = (0, import_node_child_process.exec)("npx vue-devtools");
306
+ console.log(` ${import_picocolors.default.green("\u279C")} vue-devtools is running. If the devtools has no data, please refresh the page in dingtalk.`);
307
+ devtoolsInstance.on("exit", () => {
308
+ devtoolsInstance = void 0;
309
+ });
310
+ import_node_process.default.on("exit", () => {
311
+ if (devtoolsInstance) {
312
+ devtoolsInstance.kill();
313
+ }
314
+ });
315
+ }
316
+ res.end();
317
+ });
318
+ }
319
+ }
320
+ };
321
+ if ((options == null ? void 0 : options.enable) && ((_a = options == null ? void 0 : options.vconsole) == null ? void 0 : _a.enabled)) {
322
+ return [viteVConsole(options == null ? void 0 : options.vconsole), unpluginDing];
323
+ } else {
324
+ return unpluginDing;
325
+ }
326
+ };
327
+
328
+ // src/vite.ts
329
+ var vite_default = (0, import_unplugin2.createVitePlugin)(unpluginFactory);
330
+
331
+ // src/webpack.ts
332
+ var import_unplugin3 = require("unplugin");
333
+ var webpack_default = (0, import_unplugin3.createWebpackPlugin)(unpluginFactory);
334
+
335
+ // src/nuxt.ts
336
+ var import_schema = require("@nuxt/schema");
337
+ var nuxt_default = (0, import_kit.defineNuxtModule)({
338
+ meta: {
339
+ name: "nuxt-unplugin-dingtalk",
340
+ configKey: "unpluginStarter"
341
+ },
342
+ defaults: {
343
+ // ...default options
344
+ },
345
+ setup(options, _nuxt) {
346
+ (0, import_kit.addVitePlugin)(() => vite_default(options));
347
+ (0, import_kit.addWebpackPlugin)(() => webpack_default(options));
348
+ }
349
+ });
350
+ exports.default = module.exports;
@@ -0,0 +1,9 @@
1
+ import * as _nuxt_schema from '@nuxt/schema';
2
+ import { Options } from './types.cjs';
3
+ import 'vite-plugin-vconsole';
4
+
5
+ interface ModuleOptions extends Options {
6
+ }
7
+ declare const _default: _nuxt_schema.NuxtModule<ModuleOptions>;
8
+
9
+ export { type ModuleOptions, _default as default };
package/dist/nuxt.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ import * as _nuxt_schema from '@nuxt/schema';
2
+ import { Options } from './types.js';
3
+ import 'vite-plugin-vconsole';
4
+
5
+ interface ModuleOptions extends Options {
6
+ }
7
+ declare const _default: _nuxt_schema.NuxtModule<ModuleOptions>;
8
+
9
+ export { type ModuleOptions, _default as default };
package/dist/nuxt.js ADDED
@@ -0,0 +1,27 @@
1
+ import {
2
+ webpack_default
3
+ } from "./chunk-KYZ5HD2N.js";
4
+ import {
5
+ vite_default
6
+ } from "./chunk-NRP2YPPZ.js";
7
+ import "./chunk-I4UPMGWK.js";
8
+
9
+ // src/nuxt.ts
10
+ import { addVitePlugin, addWebpackPlugin, defineNuxtModule } from "@nuxt/kit";
11
+ import "@nuxt/schema";
12
+ var nuxt_default = defineNuxtModule({
13
+ meta: {
14
+ name: "nuxt-unplugin-dingtalk",
15
+ configKey: "unpluginStarter"
16
+ },
17
+ defaults: {
18
+ // ...default options
19
+ },
20
+ setup(options, _nuxt) {
21
+ addVitePlugin(() => vite_default(options));
22
+ addWebpackPlugin(() => webpack_default(options));
23
+ }
24
+ });
25
+ export {
26
+ nuxt_default as default
27
+ };