coc-live-server 0.0.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) 2022 cyl
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,25 @@
1
+ # coc-live-server
2
+
3
+ Launch a development local Server with live reload feature for static & dynamic pages.
4
+
5
+ ## Install
6
+
7
+ ```vim
8
+ :CocInstall coc-live-server
9
+
10
+ ```
11
+
12
+ ## Configuration options
13
+
14
+ - `coc-live-server.enabled`: Enable coc-live-server extension, default: `true`
15
+ - `coc-live-server.port`: server port, default: 8080
16
+
17
+ ## Commands
18
+
19
+ - `coc-live-server.toggle`: Toggle Live Server
20
+ - `coc-live-server.start`: Start Live Server
21
+ - `coc-live-server.stop`: Stop Live Server
22
+
23
+ ---
24
+
25
+ > This extension is built with [create-coc-extension](https://github.com/fannheyward/create-coc-extension)
package/esbuild.mjs ADDED
@@ -0,0 +1,24 @@
1
+ import * as esbuild from 'esbuild';
2
+
3
+ const options = {
4
+ entryPoints: ['src/index.ts'],
5
+ bundle: true,
6
+ minify: process.env.NODE_ENV === 'production',
7
+ sourcemap: process.env.NODE_ENV === 'development',
8
+ mainFields: ['module', 'main'],
9
+ external: ['coc.nvim', 'live-server'],
10
+ platform: 'node',
11
+ target: 'node18',
12
+ outfile: 'lib/index.js',
13
+ };
14
+
15
+ if (process.argv.length > 2 && process.argv[2] === '--watch') {
16
+ const ctx = await esbuild.context(options);
17
+ await ctx.watch();
18
+ console.log('watching...');
19
+ } else {
20
+ const result = await esbuild.build(options);
21
+ if (result.errors.length) {
22
+ console.error(result.errors);
23
+ }
24
+ }
package/lib/index.js ADDED
@@ -0,0 +1,144 @@
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 __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var src_exports = {};
32
+ __export(src_exports, {
33
+ activate: () => activate
34
+ });
35
+ module.exports = __toCommonJS(src_exports);
36
+ var import_coc3 = require("coc.nvim");
37
+
38
+ // src/config.ts
39
+ var import_coc = require("coc.nvim");
40
+ function getConfigItem(name, defaultValue = null) {
41
+ const config = import_coc.workspace.getConfiguration();
42
+ if (defaultValue) {
43
+ return config.get(`coc-live-server.` + name) || defaultValue;
44
+ } else {
45
+ return config.get(`coc-live-server.` + name);
46
+ }
47
+ }
48
+
49
+ // src/server.ts
50
+ var import_coc2 = require("coc.nvim");
51
+ var import_child_process = require("child_process");
52
+ var liveServerProcess = null;
53
+ var statusItem = null;
54
+ function startLiveServer() {
55
+ const serverModule = require.resolve("live-server/live-server");
56
+ const port = getConfigItem("port", 8080);
57
+ const args = [];
58
+ if (liveServerProcess) {
59
+ stopLiveServer(false);
60
+ }
61
+ statusItem = import_coc2.window.createStatusBarItem(0);
62
+ statusItem.text = "Live Server: starting";
63
+ statusItem.show();
64
+ if (port && typeof port === "number") {
65
+ args.push(" --port=" + port);
66
+ }
67
+ args.push(` ${import_coc2.workspace.root}`);
68
+ liveServerProcess = (0, import_child_process.spawn)("node", [serverModule, ...args], { shell: true });
69
+ if (liveServerProcess) {
70
+ liveServerProcess.stdout.on("data", (data) => {
71
+ if (statusItem && statusItem?.text !== "Port: " + port) {
72
+ statusItem.text = "Port: " + port;
73
+ }
74
+ const output = data.toString();
75
+ const ansiRegex = /\x1b\[[0-9;]*m/g;
76
+ import_coc2.window.showInformationMessage(`coc-live-server: ${output.replace(ansiRegex, "")}`);
77
+ });
78
+ liveServerProcess.stderr.on("data", () => {
79
+ if (statusItem) {
80
+ statusItem.text = "Live Server: error";
81
+ }
82
+ import_coc2.window.showErrorMessage(
83
+ "Failed to start coc-live-server. Please ensure live-server is installed."
84
+ );
85
+ });
86
+ liveServerProcess.on("close", () => {
87
+ stopLiveServer();
88
+ });
89
+ }
90
+ }
91
+ function stopLiveServer(showMsg = true) {
92
+ if (liveServerProcess) {
93
+ liveServerProcess.kill();
94
+ liveServerProcess = null;
95
+ } else {
96
+ liveServerProcess = null;
97
+ }
98
+ if (statusItem) {
99
+ statusItem.text = "";
100
+ statusItem.hide();
101
+ statusItem.dispose();
102
+ }
103
+ if (showMsg) {
104
+ import_coc2.window.showInformationMessage("coc-live-server stopped");
105
+ }
106
+ }
107
+ function toggleLiveServer() {
108
+ if (liveServerProcess) {
109
+ stopLiveServer();
110
+ } else {
111
+ startLiveServer();
112
+ }
113
+ }
114
+
115
+ // src/index.ts
116
+ process.on("exit", () => {
117
+ if (liveServerProcess) {
118
+ liveServerProcess.kill();
119
+ }
120
+ if (statusItem) {
121
+ statusItem.dispose();
122
+ }
123
+ });
124
+ async function activate(context) {
125
+ const enabled = getConfigItem("enabled");
126
+ if (!enabled) {
127
+ return;
128
+ }
129
+ context.subscriptions.push(
130
+ import_coc3.commands.registerCommand("coc-live-server.start", () => {
131
+ startLiveServer();
132
+ }),
133
+ import_coc3.commands.registerCommand("coc-live-server.stop", () => {
134
+ stopLiveServer();
135
+ }),
136
+ import_coc3.commands.registerCommand("coc-live-server.toggle", () => {
137
+ toggleLiveServer();
138
+ })
139
+ );
140
+ }
141
+ // Annotate the CommonJS export names for ESM import in node:
142
+ 0 && (module.exports = {
143
+ activate
144
+ });
package/package.json ADDED
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "coc-live-server",
3
+ "version": "0.0.1",
4
+ "description": "Launch a development local Server with live reload feature for static & dynamic pages.",
5
+ "author": "cyl <a1008611abcd@126.com>",
6
+ "license": "MIT",
7
+ "main": "lib/index.js",
8
+ "keywords": [
9
+ "coc.nvim"
10
+ ],
11
+ "engines": {
12
+ "coc": "^0.0.82"
13
+ },
14
+ "scripts": {
15
+ "watch": "node esbuild.mjs --watch",
16
+ "build": "node esbuild.mjs",
17
+ "prepare": "node esbuild.mjs"
18
+ },
19
+ "devDependencies": {
20
+ "@types/live-server": "^1.2.3",
21
+ "@types/node": "^25.5.0",
22
+ "coc.nvim": "^0.0.83-next.18",
23
+ "esbuild": "^0.19.8",
24
+ "typescript": "^5.3.3"
25
+ },
26
+ "activationEvents": [
27
+ "*"
28
+ ],
29
+ "contributes": {
30
+ "configuration": {
31
+ "type": "object",
32
+ "title": "coc-live-server configuration",
33
+ "properties": {
34
+ "coc-live-server.enabled": {
35
+ "type": "boolean",
36
+ "default": true,
37
+ "description": "Enable coc-live-server extension"
38
+ },
39
+ "coc-live-server.port": {
40
+ "type": "number",
41
+ "default": 8080,
42
+ "description": "Port number for the live server"
43
+ }
44
+ }
45
+ },
46
+ "commands": [
47
+ {
48
+ "command": "coc-live-server.start",
49
+ "title": "Start Live Server"
50
+ },
51
+ {
52
+ "command": "coc-live-server.stop",
53
+ "title": "Stop Live Server"
54
+ },
55
+ {
56
+ "command": "coc-live-server.toggle",
57
+ "title": "Toggle Live Server"
58
+ }
59
+ ]
60
+ },
61
+ "dependencies": {
62
+ "live-server": "^1.2.2"
63
+ }
64
+ }