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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Anthony Fu <https://github.com/antfu>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,52 @@
1
+ # unplugin-dingtalk
2
+
3
+ [![NPM version](https://img.shields.io/npm/v/unplugin-dingtalk?color=a1b858&label=)](https://www.npmjs.com/package/unplugin-dingtalk)
4
+
5
+ 一键启动钉钉内调试。(目前仅支持 vite )
6
+
7
+ ## 功能
8
+ - [x] 在钉钉内打开调试链接
9
+ - [x] 可选注入 [vConsole](https://github.com/Tencent/vConsole) 用于调试
10
+ - [x] 可选打开 [vue-devtools](https://github.com/vuejs/devtools) 用于调试
11
+
12
+ ![images](https://github.com/zcf0508/unplugin-dingtalk/raw/main/images/Snipaste_2024-05-22_11-25-35.png)
13
+
14
+ ## 安装
15
+
16
+ ```bash
17
+ npm i unplugin-dingtalk --save-dev
18
+ ```
19
+
20
+ ```ts
21
+ interface Options {
22
+ enable?: boolean
23
+ targetUrl?: string
24
+ corpId?: string
25
+ debug?: boolean
26
+ /** @link https://github.com/vadxq/vite-plugin-vconsole#vitevconsole-options */
27
+ vconsole?: viteVConsoleOptions
28
+ vueDevtools?: {
29
+ enable?: boolean
30
+ host?: string
31
+ port?: number
32
+ }
33
+ }
34
+ ```
35
+
36
+ <details>
37
+ <summary>Vite</summary><br>
38
+
39
+ ```ts
40
+ // vite.config.ts
41
+ import UnpluginDingtalk from 'unplugin-dingtalk/vite';
42
+
43
+ export default defineConfig({
44
+ plugins: [
45
+ UnpluginDingtalk({
46
+ enable: true,
47
+ }),
48
+ ],
49
+ });
50
+ ```
51
+
52
+ <br></details>
package/dist/astro.cjs ADDED
@@ -0,0 +1,337 @@
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/astro.ts
92
+ var astro_exports = {};
93
+ __export(astro_exports, {
94
+ default: () => astro_default
95
+ });
96
+ module.exports = __toCommonJS(astro_exports);
97
+
98
+ // src/index.ts
99
+ var import_node_child_process = require("child_process");
100
+ var import_node_process = __toESM(require("process"), 1);
101
+ var import_unplugin = require("unplugin");
102
+ var import_picocolors = __toESM(require_picocolors(), 1);
103
+
104
+ // node_modules/.pnpm/vite-plugin-vconsole@2.1.1/node_modules/vite-plugin-vconsole/dist/main.mjs
105
+ var parseVConsoleOptions = (config2) => Object.keys(config2).reduce((code, key) => {
106
+ const value = config2[key];
107
+ if (typeof value === "function") {
108
+ if (/^[(f]/.test(value.toString())) {
109
+ code += `${key}: ${value},`;
110
+ return code;
111
+ } else {
112
+ code += `${value},`;
113
+ return code;
114
+ }
115
+ }
116
+ code += `${key}: ${JSON.stringify(config2[key])},`;
117
+ return code;
118
+ }, "");
119
+ var getEventItems = (event, id) => {
120
+ return event.map(
121
+ (ele) => `
122
+ ${id}.on('${ele.eventName}', ${ele.callback})
123
+ `
124
+ ).join(";");
125
+ };
126
+ var getDynamicConfig = (dynamicConfig) => {
127
+ let configString = "";
128
+ if (!dynamicConfig) {
129
+ return configString;
130
+ }
131
+ for (const key in dynamicConfig) {
132
+ if (typeof dynamicConfig[key] === "string") {
133
+ configString += `${key}: ${dynamicConfig[key]},`;
134
+ }
135
+ }
136
+ return configString;
137
+ };
138
+ var getPlugins = (plugin) => {
139
+ let plugins = "";
140
+ if (plugin && plugin.length) {
141
+ plugins = plugin.map(
142
+ (e) => `
143
+ const ${e.id} = new VConsole.VConsolePlugin('${e.id}', '${e.name}');
144
+ ${getEventItems(e.event, e.id)}
145
+ vConsole.addPlugin(${e.id})
146
+ `
147
+ ).join(";");
148
+ }
149
+ return plugins;
150
+ };
151
+ function viteVConsole(opt) {
152
+ const {
153
+ entry,
154
+ enabled = true,
155
+ config: config2 = {},
156
+ plugin,
157
+ customHide = false,
158
+ dynamicConfig = {},
159
+ eventListener = ""
160
+ } = opt;
161
+ let entryPath = Array.isArray(entry) ? entry : [entry];
162
+ if (process.platform === "win32")
163
+ entryPath = entryPath.map((item) => item.replace(/\\/g, "/"));
164
+ const enabledTruly = enabled;
165
+ return {
166
+ name: "vite:vconsole",
167
+ enforce: "pre",
168
+ transform(_source, id) {
169
+ if (entryPath.includes(id) && enabledTruly) {
170
+ const code = `/* eslint-disable */;
171
+ import VConsole from 'vconsole';
172
+ // config
173
+ const vConsole = new VConsole({${parseVConsoleOptions(
174
+ config2
175
+ )}});
176
+ window.vConsole = vConsole;
177
+
178
+ // plugins
179
+ ${getPlugins(plugin)}
180
+
181
+ // dynamic config
182
+ window.vConsole.dynamicFunction = function() {
183
+ if (${getDynamicConfig(dynamicConfig).length > 0}) {
184
+ vConsole.setOption({${getDynamicConfig(dynamicConfig)}});
185
+ }
186
+ };
187
+
188
+ window.vConsole.dynamicChange = {
189
+ value: new Date().getTime()
190
+ };
191
+
192
+ window.vConsole.dynamicFunction();
193
+
194
+ if (${customHide}) {
195
+ vConsole.hideSwitch();
196
+ }
197
+
198
+ // In order to be compatible with old equipment, I used defineProperty. In the future, when proxy covers enough devices, proxy will be used.
199
+ Object.defineProperty(window.vConsole.dynamicChange, 'value', {
200
+ get: function() {
201
+ return this._value;
202
+ },
203
+ set: function(newValue) {
204
+ window.vConsole.dynamicFunction();
205
+ this._value = newValue;
206
+ }
207
+ });
208
+
209
+ // eventListener
210
+ ${eventListener}
211
+ /* eslint-enable */${_source}`;
212
+ return {
213
+ code,
214
+ map: null
215
+ // support source map
216
+ };
217
+ }
218
+ return {
219
+ code: _source,
220
+ map: null
221
+ // support source map
222
+ };
223
+ }
224
+ };
225
+ }
226
+
227
+ // src/index.ts
228
+ var config;
229
+ var devtoolsInstance;
230
+ var colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
231
+ var unpluginFactory = (options) => {
232
+ var _a;
233
+ const unpluginDing = {
234
+ name: "unplugin-dingtalk",
235
+ enforce: "pre",
236
+ transformInclude(id) {
237
+ return id.endsWith("main.ts") || id.endsWith("main.js");
238
+ },
239
+ transform(_source) {
240
+ var _a2, _b, _c;
241
+ if ((_a2 = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _a2.enable) {
242
+ const code = `/* eslint-disable */;
243
+ import { devtools } from '@vue/devtools'
244
+ 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})
245
+ /* eslint-enable */${_source};
246
+ `;
247
+ return {
248
+ code,
249
+ map: null
250
+ // support source map
251
+ };
252
+ }
253
+ return {
254
+ code: _source,
255
+ map: null
256
+ // support source map
257
+ };
258
+ },
259
+ vite: {
260
+ configResolved(_config) {
261
+ config = _config;
262
+ },
263
+ configureServer(server) {
264
+ var _a2, _b;
265
+ if (!(options == null ? void 0 : options.enable)) {
266
+ return;
267
+ }
268
+ function debug(...args) {
269
+ if (options == null ? void 0 : options.debug) {
270
+ console.log(` ${import_picocolors.default.yellow("DEBUG")} `, ...args);
271
+ }
272
+ }
273
+ const _printUrls = server.printUrls.bind(server);
274
+ let source = `localhost:${config.server.port || 5173}`;
275
+ const url = (_a2 = server.resolvedUrls) == null ? void 0 : _a2.local[0];
276
+ if (url) {
277
+ const u = new URL(url);
278
+ source = u.host;
279
+ }
280
+ const base = server.config.base || "/";
281
+ const _targetUrl = (_b = options == null ? void 0 : options.targetUrl) != null ? _b : `http://${source}${base}`;
282
+ server.printUrls = () => {
283
+ var _a3;
284
+ _printUrls();
285
+ console.log(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold(
286
+ `Open in dingtalk${((_a3 = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _a3.enable) ? " (with vue-devtools)" : ""}`
287
+ )}: ${colorUrl(`http://${source}${base}open-dingtalk`)}`);
288
+ };
289
+ const targetURL = new URL(_targetUrl);
290
+ targetURL.searchParams.append("ddtab", "true");
291
+ if (options == null ? void 0 : options.corpId) {
292
+ targetURL.searchParams.append("corpId", options.corpId);
293
+ }
294
+ server.middlewares.use("/open-dingtalk", (req, res) => {
295
+ var _a3;
296
+ debug(targetURL.toString());
297
+ res.writeHead(302, {
298
+ Location: `dingtalk://dingtalkclient/page/link?url=${encodeURIComponent(targetURL.toString())}`
299
+ });
300
+ if (((_a3 = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _a3.enable) && !devtoolsInstance) {
301
+ devtoolsInstance = (0, import_node_child_process.exec)("npx vue-devtools");
302
+ console.log(` ${import_picocolors.default.green("\u279C")} vue-devtools is running. If the devtools has no data, please refresh the page in dingtalk.`);
303
+ devtoolsInstance.on("exit", () => {
304
+ devtoolsInstance = void 0;
305
+ });
306
+ import_node_process.default.on("exit", () => {
307
+ if (devtoolsInstance) {
308
+ devtoolsInstance.kill();
309
+ }
310
+ });
311
+ }
312
+ res.end();
313
+ });
314
+ }
315
+ }
316
+ };
317
+ if ((options == null ? void 0 : options.enable) && ((_a = options == null ? void 0 : options.vconsole) == null ? void 0 : _a.enabled)) {
318
+ return [viteVConsole(options == null ? void 0 : options.vconsole), unpluginDing];
319
+ } else {
320
+ return unpluginDing;
321
+ }
322
+ };
323
+ var unplugin = /* @__PURE__ */ (0, import_unplugin.createUnplugin)(unpluginFactory);
324
+ var src_default = unplugin;
325
+
326
+ // src/astro.ts
327
+ var astro_default = (options) => ({
328
+ name: "unplugin-dingtalk",
329
+ hooks: {
330
+ "astro:config:setup": async (astro) => {
331
+ var _a;
332
+ (_a = astro.config.vite).plugins || (_a.plugins = []);
333
+ astro.config.vite.plugins.push(src_default.vite(options));
334
+ }
335
+ }
336
+ });
337
+ exports.default = module.exports;
@@ -0,0 +1,11 @@
1
+ import { Options } from './types.cjs';
2
+ import 'vite-plugin-vconsole';
3
+
4
+ declare const _default: (options: Options) => {
5
+ name: string;
6
+ hooks: {
7
+ 'astro:config:setup': (astro: any) => Promise<void>;
8
+ };
9
+ };
10
+
11
+ export { _default as default };
@@ -0,0 +1,11 @@
1
+ import { Options } from './types.js';
2
+ import 'vite-plugin-vconsole';
3
+
4
+ declare const _default: (options: Options) => {
5
+ name: string;
6
+ hooks: {
7
+ 'astro:config:setup': (astro: any) => Promise<void>;
8
+ };
9
+ };
10
+
11
+ export { _default as default };
package/dist/astro.js ADDED
@@ -0,0 +1,18 @@
1
+ import {
2
+ src_default
3
+ } from "./chunk-I4UPMGWK.js";
4
+
5
+ // src/astro.ts
6
+ var astro_default = (options) => ({
7
+ name: "unplugin-dingtalk",
8
+ hooks: {
9
+ "astro:config:setup": async (astro) => {
10
+ var _a;
11
+ (_a = astro.config.vite).plugins || (_a.plugins = []);
12
+ astro.config.vite.plugins.push(src_default.vite(options));
13
+ }
14
+ }
15
+ });
16
+ export {
17
+ astro_default as default
18
+ };