hackmud-script-manager 0.12.0-c276bb2 → 0.13.0-02e8706

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1 @@
1
+ class CustomError extends Error{constructor(...r){super(...r),function _defineProperty(r,e,s){return e in r?Object.defineProperty(r,e,{value:s,enumerable:!0,configurable:!0,writable:!0}):r[e]=s,r}(this,"name",this.constructor.name)}}class AssertError extends CustomError{}function assert(r,e="assertion failed"){if(!r)throw new AssertError(e)}function ensure(r,e="ensure failed"){return assert(r,e),r}export{assert as a,ensure as e};
package/bin/hsm.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/bin/hsm.js CHANGED
@@ -1,402 +1,2 @@
1
1
  #!/usr/bin/env node
2
- import { resolve, basename, extname, dirname, relative } from 'path';
3
- import { homedir } from 'os';
4
- import chalk from 'chalk';
5
- import fs from 'fs';
6
- import { D as DynamicMap, s as supportedExtensions, p as processScript, h as hackmudLength, w as writeFilePersist, g as generateTypings, t as test, a as syncMacros, b as pull, c as watch, d as push } from '../shared.js';
7
- import 'acorn';
8
- import 'chokidar';
9
- import 'escodegen';
10
- import 'esprima';
11
- import 'esquery';
12
- import 'terser';
13
- import 'typescript';
14
-
15
- const { readFile: readFile, rmdir: removeDirectory, writeFile: writeFile, mkdir: makeDirectory } = fs.promises;
16
- const configDirPath = resolve(homedir(), ".config");
17
- const configFilePath = resolve(configDirPath, "hsm.json");
18
- const options = new Map();
19
- const commands = [];
20
- let config;
21
- const colourJ = chalk.rgb(0xFF, 0xF4, 0x04);
22
- const colourK = chalk.rgb(0xF3, 0xF9, 0x98);
23
- const colourM = chalk.rgb(0xB3, 0xFF, 0x9B);
24
- const colourW = chalk.rgb(0xFF, 0x96, 0xE0);
25
- const colourL = chalk.rgb(0x1E, 0xFF, 0x00);
26
- const colourB = chalk.rgb(0xCA, 0xCA, 0xCA);
27
- const userColours = new DynamicMap(user => {
28
- let hash = 0;
29
- for (const char of user)
30
- hash += (hash >> 1) + hash + "xi1_8ratvsw9hlbgm02y5zpdcn7uekof463qj".indexOf(char) + 1;
31
- return [colourJ, colourK, colourM, colourW, colourL, colourB][hash % 6](user);
32
- });
33
- for (const arg of process.argv.slice(2)) {
34
- if (arg[0] == "-") {
35
- const [key, valueRaw] = arg.split("=");
36
- let value = valueRaw;
37
- if (value) {
38
- if (value == "true")
39
- value = true;
40
- else if (value == "false")
41
- value = false;
42
- else {
43
- const number = Number(value);
44
- if (isFinite(number))
45
- value = number;
46
- }
47
- }
48
- else
49
- value = true;
50
- if (arg[1] == "-")
51
- options.set(key.slice(2), value);
52
- else {
53
- for (const option of key.slice(1))
54
- options.set(option, value);
55
- }
56
- }
57
- else
58
- commands.push(arg);
59
- }
60
- (async () => {
61
- var _a, _b, _c, _d, _e, _f;
62
- if (options.get("version") || options.get("v")) {
63
- version();
64
- return;
65
- }
66
- if (options.get("help") || options.get("h")) {
67
- help();
68
- return;
69
- }
70
- switch (commands[0]) {
71
- case "push":
72
- {
73
- const config = await getConfig();
74
- if (!config.hackmudPath) {
75
- console.log("you need to set hackmudPath in config before you can use this command");
76
- break;
77
- }
78
- const srcPath = commands[1] || ".";
79
- const hackmudPath = config.hackmudPath;
80
- let users;
81
- let scripts;
82
- if (commands[2]) {
83
- const match = commands[2].match(/^([a-z_][a-z_0-9]{0,24})\.([a-z_][a-z_0-9]{0,24})$/);
84
- if (!match) {
85
- console.log(`"${chalk.bold(commands[2])}" is not a valid script name`);
86
- break;
87
- }
88
- users = [match[1]];
89
- scripts = [match[2]];
90
- }
91
- else {
92
- users = ((_a = options.get("users")) === null || _a === void 0 ? void 0 : _a.toString().split(",")) || [];
93
- scripts = ((_b = options.get("scripts")) === null || _b === void 0 ? void 0 : _b.toString().split(",")) || [];
94
- }
95
- await push(srcPath, hackmudPath, users, scripts, onPushLogger);
96
- updateConfig();
97
- }
98
- break;
99
- case "dev":
100
- case "watch":
101
- {
102
- const config = await getConfig();
103
- if (!config.hackmudPath) {
104
- console.log("you need to set hackmudPath in config before you can use this command");
105
- break;
106
- }
107
- const srcPath = commands[1] || ".";
108
- const hackmudPath = config.hackmudPath;
109
- const users = ((_c = options.get("users")) === null || _c === void 0 ? void 0 : _c.toString().split(",")) || [];
110
- const scripts = ((_d = options.get("scripts")) === null || _d === void 0 ? void 0 : _d.toString().split(",")) || [];
111
- const genTypes = (_e = options.get("gen-types")) === null || _e === void 0 ? void 0 : _e.toString();
112
- watch(srcPath, hackmudPath, users, scripts, onPushLogger, { genTypes });
113
- }
114
- break;
115
- case "pull":
116
- {
117
- const config = await getConfig();
118
- if (!config.hackmudPath) {
119
- console.log("you need to set hackmudPath in config before you can use this command");
120
- break;
121
- }
122
- const script = commands[1];
123
- if (!script) {
124
- help();
125
- break;
126
- }
127
- const srcPath = commands[2] || ".";
128
- const hackmudPath = config.hackmudPath;
129
- try {
130
- await pull(srcPath, hackmudPath, script);
131
- }
132
- catch (error) {
133
- console.log("something went wrong, did you forget to #down the script?");
134
- }
135
- }
136
- break;
137
- case "sync-macros":
138
- {
139
- const { hackmudPath } = await getConfig();
140
- if (!hackmudPath) {
141
- console.log("you need to set hackmudPath in config before you can use this command");
142
- break;
143
- }
144
- const { macrosSynced, usersSynced } = await syncMacros(hackmudPath);
145
- console.log(`synced ${macrosSynced} macros to ${usersSynced} users`);
146
- }
147
- break;
148
- case "test":
149
- {
150
- const srcPath = resolve(commands[1] || ".");
151
- let errors = 0;
152
- console.log(`testing scripts in ${chalk.bold(srcPath)}\n`);
153
- for (const { file, line, message } of await test(srcPath)) {
154
- console.log(`error "${chalk.bold(message)}" in ${chalk.bold(file)} on line ${chalk.bold(String(line))}`);
155
- errors++;
156
- }
157
- if (!errors) {
158
- console.log("no errors found");
159
- break;
160
- }
161
- if (errors) {
162
- process.exitCode = 1;
163
- console.log(`\nencountered ${chalk.bold(String(errors))} errors`);
164
- break;
165
- }
166
- console.log("no errors found");
167
- }
168
- break;
169
- case "gen-types":
170
- {
171
- const srcPath = resolve(commands[1] || ".");
172
- let targetPath;
173
- if (commands[2])
174
- targetPath = resolve(commands[2]);
175
- else
176
- targetPath = resolve(srcPath, "../player.d.ts");
177
- generateTypings(srcPath, targetPath, (await getConfig()).hackmudPath);
178
- }
179
- break;
180
- case "config":
181
- switch (commands[1]) {
182
- case "get":
183
- {
184
- console.log(exploreObject(await getConfig(), commands.slice(2)));
185
- }
186
- break;
187
- case "delete":
188
- {
189
- const keys = commands.slice(2);
190
- if (!keys.length) {
191
- help();
192
- break;
193
- }
194
- const config = await getConfig();
195
- (_f = exploreObject(config, keys.slice(0, -1))) === null || _f === void 0 ? true : delete _f[keys.slice(-1)[0]];
196
- console.log(config);
197
- }
198
- break;
199
- case "set":
200
- {
201
- const keys = commands.slice(2);
202
- const value = keys.pop();
203
- if (!keys.length) {
204
- help();
205
- break;
206
- }
207
- const config = await getConfig();
208
- let object = config;
209
- for (let key of keys.slice(0, -1))
210
- object = typeof object[key] == "object" ? object[key] : object[key] = {};
211
- object[keys.slice(-1)[0]] = value;
212
- if (config.hackmudPath)
213
- config.hackmudPath = resolve(config.hackmudPath);
214
- console.log(config);
215
- }
216
- break;
217
- default: {
218
- if (commands[1])
219
- console.log("unknown command");
220
- help();
221
- }
222
- }
223
- break;
224
- case "help":
225
- case "h":
226
- {
227
- help();
228
- }
229
- break;
230
- case "version":
231
- case "v":
232
- {
233
- version();
234
- }
235
- break;
236
- case "golf":
237
- case "minify":
238
- {
239
- if (!commands[1]) {
240
- console.log(`Target required\nUsage: ${basename(process.argv[1])} ${commands[0]} <target> [output]`);
241
- break;
242
- }
243
- const fileExtension = extname(commands[1]);
244
- if (!supportedExtensions.includes(fileExtension)) {
245
- console.log(`Unsupported file extension "${chalk.bold(fileExtension)}"\nSupported extensions are "${supportedExtensions.map(extension => chalk.bold(extension)).join('", "')}"`);
246
- break;
247
- }
248
- await readFile(commands[1], { encoding: "utf-8" }).then(async (source) => {
249
- const { script, srcLength, warnings } = await processScript(source);
250
- for (const { message, line } of warnings)
251
- console.log(`warning "${chalk.bold(message)}" on line ${chalk.bold(String(line))}`);
252
- let outputPath;
253
- if (commands[2])
254
- outputPath = commands[2];
255
- else {
256
- const fileBaseName = basename(commands[1], fileExtension);
257
- outputPath = resolve(dirname(commands[1]), fileBaseName.endsWith(".src")
258
- ? `${fileBaseName.slice(0, -4)}.js` :
259
- fileExtension == ".js"
260
- ? `${fileBaseName}.min.js`
261
- : `${fileBaseName}.js`);
262
- }
263
- const scriptLength = hackmudLength(script);
264
- await writeFilePersist(outputPath, script)
265
- .catch(async (error) => {
266
- if (!commands[2] || error.code != "EISDIR")
267
- throw error;
268
- outputPath = resolve(outputPath, `${basename(commands[1], fileExtension)}.js`);
269
- await writeFilePersist(outputPath, script);
270
- })
271
- .then(() => console.log(`wrote ${chalk.bold(scriptLength)} chars to ${chalk.bold(relative(".", outputPath))} | saved ${chalk.bold(srcLength - scriptLength)} chars`), (error) => console.log(error.message));
272
- }, (error) => console.log(error.message));
273
- }
274
- break;
275
- default: {
276
- if (commands[0])
277
- console.log("unknown command");
278
- help();
279
- }
280
- }
281
- updateConfig();
282
- })();
283
- function help() {
284
- switch (commands[0]) {
285
- case "config":
286
- {
287
- switch (commands[1]) {
288
- case "get":
289
- {
290
- console.log("hsm config get <key>");
291
- }
292
- break;
293
- case "set":
294
- {
295
- console.log("hsm config set <key> <value>");
296
- }
297
- break;
298
- case "delete":
299
- {
300
- console.log("hsm config delete <key>");
301
- }
302
- break;
303
- default: {
304
- console.log("hsm config <get, delete, set>");
305
- }
306
- }
307
- }
308
- break;
309
- case "push":
310
- {
311
- console.log("hsm push [dir]");
312
- }
313
- break;
314
- case "watch":
315
- {
316
- console.log("hsm watch [dir]");
317
- }
318
- break;
319
- case "pull":
320
- {
321
- console.log("hsm pull <user.script>");
322
- }
323
- break;
324
- case "minify":
325
- case "golf":
326
- {
327
- console.log(`${basename(process.argv[1])} ${commands[0]} <target> [output]`);
328
- }
329
- break;
330
- default: {
331
- console.log("hsm <push, watch, pull, config, golf>");
332
- }
333
- }
334
- }
335
- async function version() {
336
- console.log(JSON.parse(await readFile(resolve(__dirname, "../package.json"), { encoding: "utf-8" })).version || "unknown");
337
- }
338
- async function getConfig() {
339
- if (config)
340
- return config;
341
- return config = await readFile(configFilePath, { encoding: "utf-8" })
342
- .then(configFile => {
343
- let tempConfig;
344
- try {
345
- tempConfig = JSON.parse(configFile);
346
- }
347
- catch {
348
- // TODO log to error log file
349
- console.log("config file was corrupted, resetting");
350
- return {};
351
- }
352
- if (!tempConfig || typeof tempConfig != "object") {
353
- console.log("config file was corrupted, resetting");
354
- return {};
355
- }
356
- return tempConfig;
357
- }, () => {
358
- console.log(`creating config file at ${configFilePath}`);
359
- return {};
360
- });
361
- }
362
- function exploreObject(object, keys, createPath = false) {
363
- for (const key of keys) {
364
- if (createPath)
365
- object = typeof object[key] == "object" ? object[key] : object[key] = {};
366
- else
367
- object = object === null || object === void 0 ? void 0 : object[key];
368
- }
369
- return object;
370
- }
371
- function updateConfig() {
372
- if (config) {
373
- const json = JSON.stringify(config);
374
- writeFile(configFilePath, json).catch(async (error) => {
375
- switch (error.code) {
376
- case "EISDIR":
377
- {
378
- await removeDirectory(configFilePath);
379
- }
380
- break;
381
- case "ENOENT":
382
- {
383
- await makeDirectory(configDirPath);
384
- }
385
- break;
386
- default: {
387
- throw error;
388
- }
389
- }
390
- writeFile(configFilePath, json);
391
- });
392
- }
393
- }
394
- function onPushLogger({ file, users, srcLength, minLength, error }) {
395
- if (!users.length)
396
- return;
397
- if (error) {
398
- console.log(`error "${chalk.bold(error.message)}" in ${chalk.bold(file)}`);
399
- return;
400
- }
401
- console.log(`pushed ${chalk.bold(file)} to ${users.map(user => chalk.bold(userColours.get(user))).join(", ")} | ${chalk.bold(String(minLength))} chars from ${chalk.bold(String(srcLength))} | saved ${chalk.bold(String(srcLength - minLength))} (${chalk.bold(`${Math.round((1 - (minLength / srcLength)) * 100)}%`)}) | ${chalk.bold(`${resolve(config.hackmudPath, users[0], "scripts", basename(file, extname(file)))}.js`)}`);
402
- }
2
+ import o from"fs";import{resolve as e,basename as s,extname as t,dirname as r,relative as n}from"path";import{c as i}from"../processScript/minify.js";import{D as a,w as l,push as c}from"../push.js";import p from"chalk";import{homedir as g}from"os";import{s as m,processScript as f}from"../processScript/index.js";import{generateTypings as u}from"../generateTypings.js";import{pull as b}from"../pull.js";import{syncMacros as d}from"../syncMacros.js";import{test as h}from"../test.js";import{watch as k}from"../watch.js";import"@babel/generator";import"@babel/traverse";import"@babel/types";import"../assert-1b7dada8.js";import"../spliceString-2c6f214f.js";import"acorn";import"terser";import"../processScript/shared.js";import"@babel/parser";import"@babel/plugin-proposal-class-properties";import"@babel/plugin-proposal-class-static-block";import"@babel/plugin-proposal-decorators";import"@babel/plugin-proposal-do-expressions";import"@babel/plugin-proposal-function-bind";import"@babel/plugin-proposal-function-sent";import"@babel/plugin-proposal-json-strings";import"@babel/plugin-proposal-logical-assignment-operators";import"@babel/plugin-proposal-nullish-coalescing-operator";import"@babel/plugin-proposal-numeric-separator";import"@babel/plugin-proposal-object-rest-spread";import"@babel/plugin-proposal-optional-catch-binding";import"@babel/plugin-proposal-optional-chaining";import"@babel/plugin-proposal-partial-application";import"@babel/plugin-proposal-pipeline-operator";import"@babel/plugin-proposal-private-property-in-object";import"@babel/plugin-proposal-record-and-tuple";import"@babel/plugin-proposal-throw-expressions";import"@babel/plugin-transform-exponentiation-operator";import"@babel/plugin-transform-typescript";import"@rollup/plugin-babel";import"@rollup/plugin-commonjs";import"@rollup/plugin-json";import"@rollup/plugin-node-resolve";import"perf_hooks";import"prettier";import"rollup";import"../processScript/postprocess.js";import"../processScript/preprocess.js";import"../processScript/transform.js";import"chokidar";const{readFile:w,rmdir:y,writeFile:j,mkdir:$}=o.promises,v=e(g(),".config"),S=e(v,"hsm.json"),P=new Map,C=[];let x;const N=p.rgb(255,244,4),O=p.rgb(243,249,152),L=p.rgb(179,255,155),U=p.rgb(255,150,224),T=p.rgb(30,255,0),E=p.rgb(202,202,202),I=new a((o=>{let e=0;for(const s of o)e+=(e>>1)+e+"xi1_8ratvsw9hlbgm02y5zpdcn7uekof463qj".indexOf(s)+1;return[N,O,L,U,T,E][e%6](o)}));for(const o of process.argv.slice(2))if("-"==o[0]){const[e,s]=o.split("=");let t=s;if(t)if("true"==t)t=!0;else if("false"==t)t=!1;else{const o=Number(t);isFinite(o)&&(t=o)}else t=!0;if("-"==o[1])P.set(e.slice(2),t);else for(const o of e.slice(1))P.set(o,t)}else C.push(o);function help(){switch(C[0]){case"config":switch(C[1]){case"get":console.log("hsm config get <key>");break;case"set":console.log("hsm config set <key> <value>");break;case"delete":console.log("hsm config delete <key>");break;default:console.log("hsm config <get, delete, set>")}break;case"push":console.log('hsm push [<dir> [..."<script user>.<script name>"]]');break;case"watch":console.log("hsm watch [dir]");break;case"pull":console.log("hsm pull <script user>.<script name>");break;case"minify":case"golf":console.log(`${s(process.argv[1])} ${C[0]} <target> [output]`);break;default:console.log("hsm <push, watch, pull, config, golf>")}}function version(){console.log("0.13.0-02e8706")}function getConfig(){return x||(x=w(S,{encoding:"utf-8"}).then((o=>{let e;try{e=JSON.parse(o)}catch{return console.log("config file was corrupted, resetting"),{}}return e&&"object"==typeof e?e:(console.log("config file was corrupted, resetting"),{})}),(()=>(console.log(`creating config file at ${S}`),{}))))}function exploreObject(o,e,s=!1){for(const r of e){var t;o=s?"object"==typeof o[r]?o[r]:o[r]={}:null===(t=o)||void 0===t?void 0:t[r]}return o}function updateConfig(){if(x){const o=JSON.stringify(x);j(S,o).catch((async e=>{switch(e.code){case"EISDIR":await y(S);break;case"ENOENT":await $(v);break;default:throw e}j(S,o)}))}}function onPushLogger({file:o,users:r,srcLength:n,minLength:i,error:a}){r.length&&(a?console.log(`error "${p.bold(a.message)}" in ${p.bold(o)}`):console.log(`pushed ${p.bold(o)} to ${r.map((o=>p.bold(I.get(o)))).join(", ")} | ${p.bold(String(i))} chars from ${p.bold(String(n))} | saved ${p.bold(String(n-i))} (${p.bold(`${Math.round(100*(1-i/n))}%`)}) | ${p.bold(`${e(x.hackmudPath,r[0],"scripts",s(o,t(o)))}.js`)}`))}(async()=>{if(P.get("version")||P.get("v"))version();else if(P.get("help")||P.get("h"))help();else{switch(C[0]){case"push":{const o=await getConfig();if(!o.hackmudPath){console.log("you need to set hackmudPath in config before you can use this command");break}const e=C[1]||".",s=o.hackmudPath,t=C.slice(2);t.length||t.push("*.*");(await c(e,s,{scripts:t,onPush:onPushLogger,minify:!P.get("skip-minify")})).length||console.warn("couldn't find any scripts to push"),updateConfig()}break;case"dev":case"watch":{var o,a,g;const e=await getConfig();if(!e.hackmudPath){console.log("you need to set hackmudPath in config before you can use this command");break}const s=C[1]||".",t=e.hackmudPath,r=(null===(o=P.get("users"))||void 0===o?void 0:o.toString().split(","))||[],n=(null===(a=P.get("scripts"))||void 0===a?void 0:a.toString().split(","))||[],i=null===(g=P.get("gen-types"))||void 0===g?void 0:g.toString();k(s,t,r,n,onPushLogger,{genTypes:i})}break;case"pull":{const o=await getConfig();if(!o.hackmudPath){console.log("you need to set hackmudPath in config before you can use this command");break}const e=C[1];if(!e){help();break}const s=C[2]||".",t=o.hackmudPath;try{await b(s,t,e)}catch{console.log("something went wrong, did you forget to #down the script?")}}break;case"sync-macros":{const{hackmudPath:o}=await getConfig();if(!o){console.log("you need to set hackmudPath in config before you can use this command");break}const{macrosSynced:e,usersSynced:s}=await d(o);console.log(`synced ${e} macros to ${s} users`)}break;case"test":{const o=e(C[1]||".");let s=0;console.log(`testing scripts in ${p.bold(o)}\n`);for(const{file:e,line:t,message:r}of await h(o))console.log(`error "${p.bold(r)}" in ${p.bold(e)} on line ${p.bold(String(t))}`),s++;if(!s){console.log("no errors found");break}if(s){process.exitCode=1,console.log(`\nencountered ${p.bold(String(s))} errors`);break}console.log("no errors found")}break;case"gen-types":{const o=e(C[1]||".");u(o,C[2]?e(C[2]):e(o,"../player.d.ts"),(await getConfig()).hackmudPath)}break;case"config":switch(C[1]){case"get":C[2]?console.log(exploreObject(await getConfig(),C[2].split("."))):console.log(await getConfig());break;case"delete":if(C[2]){var y;const o=C[2].split("."),e=o.pop();if(!o.length){help();break}const s=await getConfig();null===(y=exploreObject(s,o))||void 0===y||delete y[e],console.log(s)}else console.log("Usage:\nhsm config delete <key>");break;case"set":if(C[2]&&C[3]){const o=C[2].split("."),s=o.pop();if(!o.length){help();break}const t=await getConfig();if(o.length||"hackmudPath"!=s){let e=t;for(const s of o)"object"==typeof e[s]||(e[s]={}),e=e[s];e[s]=C[3]}else t.hackmudPath=e(C[3]);console.log(t)}else console.log("Usage:\nhsm config set <key> <value>");break;default:C[1]&&console.log("unknown command"),help()}break;case"help":case"h":help();break;case"version":case"v":version();break;case"golf":case"minify":{const o=C[1];if(!o){console.log(`Target required\nUsage: ${s(process.argv[1])} ${C[0]} <target> [output]`);break}const a=t(o);if(!m.includes(a)){console.log(`Unsupported file extension "${p.bold(a)}"\nSupported extensions are "${m.map((o=>p.bold(o))).join('", "')}"`);break}await w(o,{encoding:"utf-8"}).then((async t=>{const c=s(o,a),g=c.endsWith(".src"),m=g?c.slice(0,-4):c;let u="UNKNOWN";"scripts"==s(e(o,".."))&&"hackmud"==s(e(o,"../../.."))&&(u=s(e(o,"../..")));const b=!P.get("skip-minify"),d=Boolean(P.get("mangle-names"));!b&&d&&console.warn("warning: `--mangle-names` has no effect while `--skip-minify` is active");const{script:h,srcLength:k,warnings:w,timeTook:y}=await f(t,{minify:b,scriptUser:u,scriptName:m,filePath:o,mangleNames:d});for(const{message:o,line:e}of w)console.log(`warning "${p.bold(o)}" on line ${p.bold(String(e))}`);let j;j=C[2]?C[2]:e(r(o),g?`${m}.js`:".js"==a?`${c}.min.js`:`${c}.js`);const $=i(h);await l(j,h).catch((async t=>{if(!C[2]||"EISDIR"!=t.code)throw t;j=e(j,`${s(o,a)}.js`),await l(j,h)})).then((()=>console.log(`wrote ${p.bold($)} chars to ${p.bold(n(".",j))} | saved ${p.bold(k-$)} chars | took ${Math.round(100*y)/100}ms`)),(o=>console.log(o.message)))}),(o=>console.log(o.message)))}break;default:C[0]&&console.log("unknown command"),help()}updateConfig()}})();
@@ -0,0 +1,2 @@
1
+ export declare function generateTypings(sourceDirectory: string, target: string, hackmudPath?: string): Promise<void>;
2
+ export default generateTypings;
@@ -0,0 +1 @@
1
+ import e from"fs";import{extname as t,basename as n,resolve as s}from"path";const{readdir:r,writeFile:a}=e.promises;async function generateTypings(e,i,o){const f=new Set;if(o)for(const e of await r(o,{withFileTypes:!0}))e.isFile()&&".key"==t(e.name)&&f.add(n(e.name,".key"));const c=[],l=[],p={},m={};await Promise.all((await r(e,{withFileTypes:!0})).map((async a=>{if(a.isFile())".ts"==t(a.name)?c.push(n(a.name,".ts")):".js"==t(a.name)&&l.push(n(a.name,".js"));else if(a.isDirectory()){const i=[],o=[];p[a.name]=i,m[a.name]=o,f.add(a.name);for(const f of await r(s(e,a.name),{withFileTypes:!0}))f.isFile()&&(".ts"==t(f.name)?i.push(n(f.name,".ts")):".js"==t(f.name)&&o.push(n(f.name,".js")))}})));let y="";for(const e of c)y+=`import { script as $${e}$ } from "./src/${e}"\n`;y+="\n";for(const e in p){const t=p[e];for(const n of t)y+=`import { script as $${e}$${n}$ } from "./src/${e}/${n}"\n`}y+="\ntype ArrayRemoveFirst<A> = A extends [ infer FirstItem, ...infer Rest ] ? Rest : never\n\ntype Subscript<T extends (...args: any) => any> =\n\t(...args: ArrayRemoveFirst<Parameters<T>>) => ReturnType<T> | ScriptFailure\n\ntype WildFullsec = Record<string, () => ScriptFailure> & {\n";for(const e of c)y+=`\t${e}: Subscript<typeof $${e}$>\n`;for(const e of l)y+=`\t${e}: (...args: any) => any\n`;y+="}\n\ndeclare global {\n\tinterface PlayerFullsec {";let $=!0;for(const e of f){const t=p[e],n=m[e];if(t&&t.length||n&&n.length){if($=!0,y+=`\n\t\t${e}: WildFullsec & {\n`,t)for(const n of t)y+=`\t\t\t${n}: Subscript<typeof $${e}$${n}$>\n`;if(n)for(const e of n)y+=`\t\t\t${e}: (...args: any) => any\n`;y+="\t\t}"}else $&&(y+="\n",$=!1),y+=`\t\t${e}: WildFullsec`;y+="\n"}y+="\t}\n}\n",await a(i,y)}export{generateTypings as default,generateTypings};
package/index.cjs ADDED
@@ -0,0 +1,3 @@
1
+ module.exports = null
2
+ import("./index.js").then(esModule => module.exports = esModule)
3
+ require("deasync").loopWhile(() => !module.exports)
package/index.d.ts CHANGED
@@ -1,65 +1,15 @@
1
- export interface Info {
1
+ export { supportedExtensions } from "./constants.json";
2
+ export { generateTypings } from "./generateTypings";
3
+ export { processScript } from "./processScript";
4
+ export { pull } from "./pull";
5
+ export { push } from "./push";
6
+ export { syncMacros } from "./syncMacros";
7
+ export { test } from "./test";
8
+ export { watch } from "./watch";
9
+ export declare type Info = {
2
10
  file: string;
3
11
  users: string[];
4
12
  srcLength: number;
5
13
  minLength: number;
6
14
  error: Error | null;
7
- }
8
- export declare const supportedExtensions: string[];
9
- /**
10
- * Push a specific or all scripts to a specific or all users.
11
- * In source directory, scripts in folders will override scripts with same name for user with folder name.
12
- *
13
- * e.g. foo/bar.js overrides other bar.js script just for user foo.
14
- *
15
- * @param srcDir path to folder containing source files
16
- * @param hackmudDir path to hackmud directory
17
- * @param users users to push to (pushes to all if empty)
18
- * @param scripts scripts to push from (pushes from all if empty)
19
- * @param onPush function that's called when a script has been pushed
20
- */
21
- export declare function push(srcDir: string, hackmudDir: string, users: string[], scripts: string[], onPush?: (info: Info) => void): Promise<Info[]>;
22
- /**
23
- * Watches target file or folder for updates and builds and pushes updated file.
24
- *
25
- * @param srcDir path to folder containing source files
26
- * @param hackmudDir path to hackmud directory
27
- * @param users users to push to (pushes to all if empty)
28
- * @param scripts scripts to push from (pushes from all if empty)
29
- * @param onPush function that's called after each script has been built and written
30
- */
31
- export declare function watch(srcDir: string, hackmudDir: string, users: string[], scripts: string[], onPush?: (info: Info) => void, { genTypes }?: {
32
- genTypes?: string | undefined;
33
- }): void;
34
- /**
35
- * Copies script from hackmud to local source folder.
36
- *
37
- * @param sourceFolderPath path to folder containing source files
38
- * @param hackmudPath path to hackmud directory
39
- * @param script script to pull in `user.name` format
40
- */
41
- export declare function pull(sourceFolderPath: string, hackmudPath: string, script: string): Promise<void>;
42
- export declare function syncMacros(hackmudPath: string): Promise<{
43
- macrosSynced: number;
44
- usersSynced: number;
45
- }>;
46
- export declare function test(srcPath: string): Promise<{
47
- file: string;
48
- message: string;
49
- line: number;
50
- }[]>;
51
- export declare function generateTypings(srcDir: string, target: string, hackmudPath?: string): Promise<void>;
52
- /**
53
- * Minifies a given script
54
- *
55
- * @param script JavaScript or TypeScript code
56
- */
57
- export declare function processScript(script: string): Promise<{
58
- srcLength: number;
59
- script: string;
60
- warnings: {
61
- message: string;
62
- line: number;
63
- }[];
64
- }>;
65
- export declare function getFunctionBodyStart(code: string): number;
15
+ };
package/index.js CHANGED
@@ -1,10 +1 @@
1
- import 'acorn';
2
- import 'chokidar';
3
- import 'escodegen';
4
- import 'esprima';
5
- import 'esquery';
6
- import 'fs';
7
- import 'path';
8
- import 'terser';
9
- import 'typescript';
10
- export { g as generateTypings, e as getFunctionBodyStart, p as processScript, b as pull, d as push, s as supportedExtensions, a as syncMacros, t as test, c as watch } from './shared.js';
1
+ export{processScript,s as supportedExtensions}from"./processScript/index.js";export{generateTypings}from"./generateTypings.js";export{pull}from"./pull.js";export{push}from"./push.js";export{syncMacros}from"./syncMacros.js";export{test}from"./test.js";export{watch}from"./watch.js";import"@babel/generator";import"@babel/parser";import"@babel/plugin-proposal-class-properties";import"@babel/plugin-proposal-class-static-block";import"@babel/plugin-proposal-decorators";import"@babel/plugin-proposal-do-expressions";import"@babel/plugin-proposal-function-bind";import"@babel/plugin-proposal-function-sent";import"@babel/plugin-proposal-json-strings";import"@babel/plugin-proposal-logical-assignment-operators";import"@babel/plugin-proposal-nullish-coalescing-operator";import"@babel/plugin-proposal-numeric-separator";import"@babel/plugin-proposal-object-rest-spread";import"@babel/plugin-proposal-optional-catch-binding";import"@babel/plugin-proposal-optional-chaining";import"@babel/plugin-proposal-partial-application";import"@babel/plugin-proposal-pipeline-operator";import"@babel/plugin-proposal-private-property-in-object";import"@babel/plugin-proposal-record-and-tuple";import"@babel/plugin-proposal-throw-expressions";import"@babel/plugin-transform-exponentiation-operator";import"@babel/plugin-transform-typescript";import"@babel/traverse";import"@babel/types";import"@rollup/plugin-babel";import"@rollup/plugin-commonjs";import"@rollup/plugin-json";import"@rollup/plugin-node-resolve";import"./assert-1b7dada8.js";import"path";import"./processScript/minify.js";import"./spliceString-2c6f214f.js";import"acorn";import"terser";import"./processScript/shared.js";import"perf_hooks";import"prettier";import"rollup";import"./processScript/postprocess.js";import"./processScript/preprocess.js";import"./processScript/transform.js";import"fs";import"chokidar";