index.ts.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  1. 'use strict';
  2. require('./chunk-5ab72169.js');
  3. const EQQ = /\s|=/;
  4. const FLAG = /^-{1,2}/;
  5. const PREFIX = /^--no-/i;
  6. function isBool(any) {
  7. return typeof any === 'boolean';
  8. }
  9. function toArr(any) {
  10. return Array.isArray(any) ? any : any == null ? [] : [any];
  11. }
  12. function toString(any) {
  13. return any == null || any === true ? '' : String(any);
  14. }
  15. function toBool(any) {
  16. return any === 'false' ? false : Boolean(any);
  17. }
  18. function toNum(any) {
  19. return (!isBool(any) && Number(any)) || any;
  20. }
  21. function getAlibi(names, arr) {
  22. if (arr.length === 0) return arr;
  23. let k, i = 0, len = arr.length, vals = [];
  24. for (; i < len; i++) {
  25. k = arr[i];
  26. vals.push(k);
  27. if (names[k] !== void 0) {
  28. vals = vals.concat(names[k]);
  29. }
  30. }
  31. return vals;
  32. }
  33. function typecast(key, val, strings, booleans) {
  34. if (strings.indexOf(key) !== -1) return toString(val);
  35. if (booleans.indexOf(key) !== -1) return toBool(val);
  36. return toNum(val);
  37. }
  38. var lib = function(args, opts) {
  39. args = args || [];
  40. opts = opts || {};
  41. opts.string = toArr(opts.string);
  42. opts.boolean = toArr(opts.boolean);
  43. const aliases = {};
  44. let k, i, j, x, y, len, type;
  45. if (opts.alias !== void 0) {
  46. for (k in opts.alias) {
  47. aliases[k] = toArr(opts.alias[k]);
  48. len = aliases[k].length; // save length
  49. for (i = 0; i < len; i++) {
  50. x = aliases[k][i]; // alias's key name
  51. aliases[x] = [k]; // set initial array
  52. for (j = 0; j < len; j++) {
  53. if (x !== aliases[k][j]) {
  54. aliases[x].push(aliases[k][j]);
  55. }
  56. }
  57. }
  58. }
  59. }
  60. if (opts.default !== void 0) {
  61. for (k in opts.default) {
  62. type = typeof opts.default[k];
  63. opts[type] = (opts[type] || []).concat(k);
  64. }
  65. }
  66. // apply to all aliases
  67. opts.string = getAlibi(aliases, opts.string);
  68. opts.boolean = getAlibi(aliases, opts.boolean);
  69. let idx = 0;
  70. const out = { _: [] };
  71. while (args[idx] !== void 0) {
  72. let incr = 1;
  73. const val = args[idx];
  74. if (val === '--') {
  75. out._ = out._.concat(args.slice(idx + 1));
  76. break;
  77. } else if (!FLAG.test(val)) {
  78. out._.push(val);
  79. } else if (PREFIX.test(val)) {
  80. out[val.replace(PREFIX, '')] = false;
  81. } else {
  82. let tmp;
  83. const segs = val.split(EQQ);
  84. const isGroup = segs[0].charCodeAt(1) !== 45; // '-'
  85. const flag = segs[0].substr(isGroup ? 1 : 2);
  86. len = flag.length;
  87. const key = isGroup ? flag[len - 1] : flag;
  88. if (opts.unknown !== void 0 && aliases[key] === void 0) {
  89. return opts.unknown(segs[0]);
  90. }
  91. if (segs.length > 1) {
  92. tmp = segs[1];
  93. } else {
  94. tmp = args[idx + 1] || true;
  95. FLAG.test(tmp) ? (tmp = true) : (incr = 2);
  96. }
  97. if (isGroup && len > 1) {
  98. for (i = len - 1; i--; ) {
  99. k = flag[i]; // all but last key
  100. out[k] = typecast(k, true, opts.string, opts.boolean);
  101. }
  102. }
  103. const value = typecast(key, tmp, opts.string, opts.boolean);
  104. out[key] = out[key] !== void 0 ? toArr(out[key]).concat(value) : value;
  105. // handle discarded args when dealing with booleans
  106. if (isBool(value) && !isBool(tmp) && tmp !== 'true' && tmp !== 'false') {
  107. out._.push(tmp);
  108. }
  109. }
  110. idx += incr;
  111. }
  112. if (opts.default !== void 0) {
  113. for (k in opts.default) {
  114. if (out[k] === void 0) {
  115. out[k] = opts.default[k];
  116. }
  117. }
  118. }
  119. for (k in out) {
  120. if (aliases[k] === void 0) continue;
  121. y = out[k];
  122. len = aliases[k].length;
  123. for (i = 0; i < len; i++) {
  124. out[aliases[k][i]] = y; // assign value
  125. }
  126. }
  127. return out;
  128. };
  129. var lib$1 = /*#__PURE__*/Object.freeze({
  130. default: lib,
  131. __moduleExports: lib
  132. });
  133. /*!
  134. * repeat-string <https://github.com/jonschlinkert/repeat-string>
  135. *
  136. * Copyright (c) 2014-2015, Jon Schlinkert.
  137. * Licensed under the MIT License.
  138. */
  139. /**
  140. * Results cache
  141. */
  142. var res = '';
  143. var cache;
  144. /**
  145. * Expose `repeat`
  146. */
  147. var repeatString = repeat;
  148. /**
  149. * Repeat the given `string` the specified `number`
  150. * of times.
  151. *
  152. * **Example:**
  153. *
  154. * ```js
  155. * var repeat = require('repeat-string');
  156. * repeat('A', 5);
  157. * //=> AAAAA
  158. * ```
  159. *
  160. * @param {String} `string` The string to repeat
  161. * @param {Number} `number` The number of times to repeat the string
  162. * @return {String} Repeated string
  163. * @api public
  164. */
  165. function repeat(str, num) {
  166. if (typeof str !== 'string') {
  167. throw new TypeError('expected a string');
  168. }
  169. // cover common, quick use cases
  170. if (num === 1) return str;
  171. if (num === 2) return str + str;
  172. var max = str.length * num;
  173. if (cache !== str || typeof cache === 'undefined') {
  174. cache = str;
  175. res = '';
  176. } else if (res.length >= max) {
  177. return res.substr(0, max);
  178. }
  179. while (max > res.length && num > 1) {
  180. if (num & 1) {
  181. res += str;
  182. }
  183. num >>= 1;
  184. str += str;
  185. }
  186. res += str;
  187. res = res.substr(0, max);
  188. return res;
  189. }
  190. var repeatString$1 = /*#__PURE__*/Object.freeze({
  191. default: repeatString,
  192. __moduleExports: repeatString
  193. });
  194. var repeat$1 = ( repeatString$1 && repeatString ) || repeatString$1;
  195. var padRight = function padLeft(val, num, str) {
  196. var padding = '';
  197. var diff = num - val.length;
  198. // Breakpoints based on benchmarks to use the fastest approach
  199. // for the given number of zeros
  200. if (diff <= 5 && !str) {
  201. padding = '00000';
  202. } else if (diff <= 25 && !str) {
  203. padding = '000000000000000000000000000';
  204. } else {
  205. return val + repeat$1(str || '0', diff);
  206. }
  207. return val + padding.slice(0, diff);
  208. };
  209. var padRight$1 = /*#__PURE__*/Object.freeze({
  210. default: padRight,
  211. __moduleExports: padRight
  212. });
  213. var rpad = ( padRight$1 && padRight ) || padRight$1;
  214. const GAP = 4;
  215. const __ = ' ';
  216. const ALL = '__all__';
  217. const DEF = '__default__';
  218. const NL = '\n';
  219. function format(arr) {
  220. if (!arr.length) return '';
  221. let len = maxLen( arr.map(x => x[0]) ) + GAP;
  222. let join = a => rpad(a[0], len, ' ') + a[1] + (a[2] == null ? '' : ` (default ${a[2]})`);
  223. return arr.map(join);
  224. }
  225. function maxLen(arr) {
  226. let c=0, d=0, l=0, i=arr.length;
  227. if (i) while (i--) {
  228. d = arr[i].length;
  229. if (d > c) {
  230. l = i; c = d;
  231. }
  232. }
  233. return arr[l].length;
  234. }
  235. function noop(s) {
  236. return s;
  237. }
  238. function section(str, arr, fn) {
  239. if (!arr || !arr.length) return '';
  240. let i=0, out='';
  241. out += (NL + __ + str);
  242. for (; i < arr.length; i++) {
  243. out += (NL + __ + __ + fn(arr[i]));
  244. }
  245. return out + NL;
  246. }
  247. var help = function (bin, tree, key) {
  248. let out='', cmd=tree[key], pfx=`$ ${bin}`, all=tree[ALL];
  249. let prefix = s => `${pfx} ${s}`;
  250. // update ALL & CMD options
  251. all.options.push(['-h, --help', 'Displays this message']);
  252. cmd.options = (cmd.options || []).concat(all.options);
  253. // write options placeholder
  254. (cmd.options.length > 0) && (cmd.usage += ' [options]');
  255. // description ~> text only; usage ~> prefixed
  256. out += section('Description', cmd.describe, noop);
  257. out += section('Usage', [cmd.usage], prefix);
  258. if (key === DEF) {
  259. // General help :: print all non-internal commands & their 1st line of text
  260. let cmds = Object.keys(tree).filter(k => !/__/.test(k));
  261. let text = cmds.map(k => [k, (tree[k].describe || [''])[0]]);
  262. out += section('Available Commands', format(text), noop);
  263. out += (NL + __ + 'For more info, run any command with the `--help` flag');
  264. cmds.slice(0, 2).forEach(k => {
  265. out += (NL + __ + __ + `${pfx} ${k} --help`);
  266. });
  267. out += NL;
  268. }
  269. out += section('Options', format(cmd.options), noop);
  270. out += section('Examples', cmd.examples.map(prefix), noop);
  271. return out;
  272. };
  273. var error = function (bin, str, num=1) {
  274. let out = section('ERROR', [str], noop);
  275. out += (NL + __ + `Run \`$ ${bin} --help\` for more info.` + NL);
  276. console.error(out);
  277. process.exit(num);
  278. };
  279. // Strips leading `-|--` & extra space(s)
  280. var parse = function (str) {
  281. return (str || '').split(/^-{1,2}|,|\s+-{1,2}|\s+/).filter(Boolean);
  282. };
  283. // @see https://stackoverflow.com/a/18914855/3577474
  284. var sentences = function (str) {
  285. return (str || '').replace(/([.?!])\s*(?=[A-Z])/g, '$1|').split('|');
  286. };
  287. var utils = {
  288. help: help,
  289. error: error,
  290. parse: parse,
  291. sentences: sentences
  292. };
  293. var utils$1 = /*#__PURE__*/Object.freeze({
  294. default: utils,
  295. __moduleExports: utils,
  296. help: help,
  297. error: error,
  298. parse: parse,
  299. sentences: sentences
  300. });
  301. var mri = ( lib$1 && lib ) || lib$1;
  302. var $ = ( utils$1 && utils ) || utils$1;
  303. const ALL$1 = '__all__';
  304. const DEF$1 = '__default__';
  305. class Sade {
  306. constructor(name) {
  307. this.tree = {};
  308. this.name = name;
  309. this.ver = '0.0.0';
  310. this.default = '';
  311. // set internal shapes;
  312. this.command(ALL$1);
  313. this.command(`${DEF$1} <command>`)
  314. .option('-v, --version', 'Displays current version');
  315. this.curr = ''; // reset
  316. }
  317. command(str, desc, opts) {
  318. let cmd=[], usage=[], rgx=/(\[|<)/;
  319. // All non-([|<) are commands
  320. str.split(/\s+/).forEach(x => {
  321. (rgx.test(x.charAt(0)) ? usage : cmd).push(x);
  322. });
  323. // Back to string~!
  324. cmd = cmd.join(' ');
  325. if (cmd in this.tree) {
  326. throw new Error(`Command already exists: ${cmd}`);
  327. }
  328. this.curr = cmd;
  329. (opts && opts.default) && (this.default=cmd);
  330. !~cmd.indexOf('__') && usage.unshift(cmd); // re-include `cmd`
  331. usage = usage.join(' '); // to string
  332. this.tree[cmd] = { usage, options:[], alias:{}, default:{}, examples:[] };
  333. desc && this.describe(desc);
  334. return this;
  335. }
  336. describe(str) {
  337. this.tree[this.curr || DEF$1].describe = Array.isArray(str) ? str : $.sentences(str);
  338. return this;
  339. }
  340. option(str, desc, val) {
  341. let cmd = this.tree[ this.curr || ALL$1 ];
  342. let [flag, alias] = $.parse(str);
  343. (alias && alias.length > 1) && ([flag, alias]=[alias, flag]);
  344. str = `--${flag}`;
  345. if (alias && alias.length > 0) {
  346. str = `-${alias}, ${str}`;
  347. let old = cmd.alias[alias];
  348. cmd.alias[alias] = (old || []).concat(flag);
  349. }
  350. let arr = [str, desc || ''];
  351. if (val !== void 0) {
  352. arr.push(val);
  353. cmd.default[flag] = val;
  354. }
  355. cmd.options.push(arr);
  356. return this;
  357. }
  358. action(handler) {
  359. this.tree[ this.curr || DEF$1 ].handler = handler;
  360. return this;
  361. }
  362. example(str) {
  363. this.tree[ this.curr || DEF$1 ].examples.push(str);
  364. return this;
  365. }
  366. version(str) {
  367. this.ver = str;
  368. return this;
  369. }
  370. parse(arr, opts={}) {
  371. let offset = 2; // argv slicer
  372. let alias = { h:'help', v:'version' };
  373. let argv = mri(arr.slice(offset), { alias });
  374. let bin = this.name;
  375. // Loop thru possible command(s)
  376. let tmp, name='';
  377. let i=1, len=argv._.length + 1;
  378. for (; i < len; i++) {
  379. tmp = argv._.slice(0, i).join(' ');
  380. if (this.tree[tmp] !== void 0) {
  381. name=tmp; offset=(i + 2); // argv slicer
  382. }
  383. }
  384. let cmd = this.tree[name];
  385. let isVoid = (cmd === void 0);
  386. if (isVoid) {
  387. if (this.default) {
  388. name = this.default;
  389. cmd = this.tree[name];
  390. arr.unshift(name);
  391. offset++;
  392. } else if (name) {
  393. return $.error(bin, `Invalid command: ${name}`);
  394. } //=> else: cmd not specified, wait for now...
  395. }
  396. if (argv.version) {
  397. return console.log(`${bin}, ${this.ver}`);
  398. }
  399. if (argv.help) {
  400. return this.help(!isVoid && name);
  401. }
  402. if (cmd === void 0) {
  403. return $.error(bin, 'No command specified.');
  404. }
  405. let all = this.tree[ALL$1];
  406. // merge all objects :: params > command > all
  407. opts.alias = Object.assign(all.alias, cmd.alias, opts.alias);
  408. opts.default = Object.assign(all.default, cmd.default, opts.default);
  409. let vals = mri(arr.slice(offset), opts);
  410. let segs = cmd.usage.split(/\s+/);
  411. let reqs = segs.filter(x => x.charAt(0)==='<');
  412. let args = vals._.splice(0, reqs.length);
  413. if (args.length < reqs.length) {
  414. name && (bin += ` ${name}`); // for help text
  415. return $.error(bin, 'Insufficient arguments!');
  416. }
  417. segs.filter(x => x.charAt(0)==='[').forEach(_ => {
  418. args.push(vals._.pop()); // adds `undefined` per [slot] if no more
  419. });
  420. args.push(vals); // flags & co are last
  421. let handler = cmd.handler;
  422. return opts.lazy ? { args, name, handler } : handler.apply(null, args);
  423. }
  424. help(str) {
  425. console.log(
  426. $.help(this.name, this.tree, str || DEF$1)
  427. );
  428. }
  429. }
  430. var lib$2 = str => new Sade(str);
  431. var version = "2.6.5";
  432. const prog = lib$2('svelte').version(version);
  433. prog
  434. .command('compile <input>')
  435. .option('-o, --output', 'Output (if absent, prints to stdout)')
  436. .option('-f, --format', 'Type of output (amd, cjs, es, iife, umd)')
  437. .option('-g, --globals', 'Comma-separate list of `module ID:Global` pairs')
  438. .option('-n, --name', 'Name for IIFE/UMD export (inferred from filename by default)')
  439. .option('-m, --sourcemap', 'Generate sourcemap (`-m inline` for inline map)')
  440. .option('-d, --dev', 'Add dev mode warnings and errors')
  441. .option('--amdId', 'ID for AMD module (default is anonymous)')
  442. .option('--generate', 'Change generate format between `dom` and `ssr`')
  443. .option('--no-css', `Don't include CSS (useful with SSR)`)
  444. .option('--immutable', 'Support immutable data structures')
  445. .example('compile App.html > App.js')
  446. .example('compile src -o dest')
  447. .example('compile -f umd MyComponent.html > MyComponent.js')
  448. .action((input, opts) => {
  449. Promise.resolve(require("./compile.ts.js")).then(({ compile }) => {
  450. compile(input, opts);
  451. });
  452. })
  453. .parse(process.argv);