@adhd/decompile-cli 0.1.7
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/README.md +175 -0
- package/bin/decompile.d.ts +2 -0
- package/bin/decompile.js +89 -0
- package/bin/decompile.js.map +1 -0
- package/package.json +35 -0
- package/src/index.d.ts +1 -0
- package/src/index.js +2 -0
- package/src/index.js.map +1 -0
- package/src/lib/extractors/index.d.ts +10 -0
- package/src/lib/extractors/index.js +228 -0
- package/src/lib/extractors/index.js.map +1 -0
- package/src/lib/extractors/local-file.d.ts +5 -0
- package/src/lib/extractors/local-file.js +22 -0
- package/src/lib/extractors/local-file.js.map +1 -0
- package/src/lib/extractors/map.d.ts +6 -0
- package/src/lib/extractors/map.js +74 -0
- package/src/lib/extractors/map.js.map +1 -0
- package/src/lib/extractors/raw-html.d.ts +7 -0
- package/src/lib/extractors/raw-html.js +93 -0
- package/src/lib/extractors/raw-html.js.map +1 -0
- package/src/lib/extractors/site.d.ts +34 -0
- package/src/lib/extractors/site.js +96 -0
- package/src/lib/extractors/site.js.map +1 -0
- package/src/lib/index.d.ts +8 -0
- package/src/lib/index.js +6 -0
- package/src/lib/index.js.map +1 -0
- package/src/lib/pipeline/index.d.ts +1 -0
- package/src/lib/pipeline/index.js +2 -0
- package/src/lib/pipeline/index.js.map +1 -0
- package/src/lib/pipeline/pipes/resolver/actions.d.ts +14 -0
- package/src/lib/pipeline/pipes/resolver/actions.js +50 -0
- package/src/lib/pipeline/pipes/resolver/actions.js.map +1 -0
- package/src/lib/pipeline/pipes/resolver/index.d.ts +1 -0
- package/src/lib/pipeline/pipes/resolver/index.js +2 -0
- package/src/lib/pipeline/pipes/resolver/index.js.map +1 -0
- package/src/lib/pipeline/stack.d.ts +23 -0
- package/src/lib/pipeline/stack.js +45 -0
- package/src/lib/pipeline/stack.js.map +1 -0
- package/src/lib/store/build.d.ts +2 -0
- package/src/lib/store/build.js +50 -0
- package/src/lib/store/build.js.map +1 -0
- package/src/lib/store/index.d.ts +92 -0
- package/src/lib/store/index.js +127 -0
- package/src/lib/store/index.js.map +1 -0
- package/src/lib/store/package.d.ts +60 -0
- package/src/lib/store/package.js +114 -0
- package/src/lib/store/package.js.map +1 -0
- package/src/lib/store/templates.d.ts +84 -0
- package/src/lib/store/templates.js +78 -0
- package/src/lib/store/templates.js.map +1 -0
- package/src/lib/store/utils.d.ts +3 -0
- package/src/lib/store/utils.js +8 -0
- package/src/lib/store/utils.js.map +1 -0
- package/src/lib/validators/index.d.ts +2 -0
- package/src/lib/validators/index.js +7 -0
- package/src/lib/validators/index.js.map +1 -0
- package/src/lib/validators/local/index.d.ts +31 -0
- package/src/lib/validators/local/index.js +93 -0
- package/src/lib/validators/local/index.js.map +1 -0
- package/src/lib/validators/local/isBase64.d.ts +2 -0
- package/src/lib/validators/local/isBase64.js +11 -0
- package/src/lib/validators/local/isBase64.js.map +1 -0
- package/src/lib/validators/local/isCSS.d.ts +2 -0
- package/src/lib/validators/local/isCSS.js +15 -0
- package/src/lib/validators/local/isCSS.js.map +1 -0
- package/src/lib/validators/local/isHTML.d.ts +2 -0
- package/src/lib/validators/local/isHTML.js +13 -0
- package/src/lib/validators/local/isHTML.js.map +1 -0
- package/src/lib/validators/local/isJS.d.ts +2 -0
- package/src/lib/validators/local/isJS.js +28 -0
- package/src/lib/validators/local/isJS.js.map +1 -0
- package/src/lib/validators/local/isJson.d.ts +2 -0
- package/src/lib/validators/local/isJson.js +40 -0
- package/src/lib/validators/local/isJson.js.map +1 -0
- package/src/lib/validators/local/isSourceMap.d.ts +11 -0
- package/src/lib/validators/local/isSourceMap.js +57 -0
- package/src/lib/validators/local/isSourceMap.js.map +1 -0
- package/src/lib/validators/url/errors.d.ts +9 -0
- package/src/lib/validators/url/errors.js +36 -0
- package/src/lib/validators/url/errors.js.map +1 -0
- package/src/lib/validators/url/index.d.ts +32 -0
- package/src/lib/validators/url/index.js +231 -0
- package/src/lib/validators/url/index.js.map +1 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import 'babel-polyfill';
|
|
2
|
+
import sourceMap from 'source-map';
|
|
3
|
+
const formatName = (f) => {
|
|
4
|
+
return f.replace('webpack:///', '');
|
|
5
|
+
};
|
|
6
|
+
const SOURCEMAP_URL_REGEX = /sourceMappingURL=([/a-zA-Z._0-9-]+\.map)/gim;
|
|
7
|
+
export const extractMapLink = (raw) => {
|
|
8
|
+
const { path, data } = raw;
|
|
9
|
+
console.log({ path });
|
|
10
|
+
// TODO: should allow [?] ?
|
|
11
|
+
let mfiles = (data.match(SOURCEMAP_URL_REGEX) || [])
|
|
12
|
+
.filter((e) => !!e)
|
|
13
|
+
.map((s) => s.split('=')[1]);
|
|
14
|
+
if (mfiles.length) {
|
|
15
|
+
mfiles = [mfiles[mfiles.length - 1]];
|
|
16
|
+
return mfiles.map((mfile) => {
|
|
17
|
+
if (mfile.startsWith('http')) {
|
|
18
|
+
return mfile;
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
const newp = path.split('/');
|
|
22
|
+
newp[newp.length - 1] = mfile;
|
|
23
|
+
return newp.join('/');
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
// type SourceType = { path: string; data: string | null };
|
|
29
|
+
export const extractSource = async (rawMap) => {
|
|
30
|
+
try {
|
|
31
|
+
const consumer = await new sourceMap.SourceMapConsumer(rawMap);
|
|
32
|
+
const sources = {};
|
|
33
|
+
consumer.eachMapping((m) => {
|
|
34
|
+
const s = m.source;
|
|
35
|
+
const outFile = formatName(s);
|
|
36
|
+
if (m.source && !sources[outFile]) {
|
|
37
|
+
const content = consumer.sourceContentFor(s, true);
|
|
38
|
+
if (!(outFile.startsWith('external ') || outFile.startsWith('(webpack)'))) {
|
|
39
|
+
// TODO: can depcheck check raw text for dependencies?
|
|
40
|
+
// NOTE: this may remove chunked content, consider content hashing
|
|
41
|
+
sources[outFile] = { path: outFile, data: content || '' };
|
|
42
|
+
console.log('extractSource', { path: outFile });
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
return Object.values(sources).filter((e) => !!e);
|
|
47
|
+
// return await Promise.all(consumer.sources.map((s) => {
|
|
48
|
+
// const outFile = formatName(s);
|
|
49
|
+
// const content = consumer.sourceContentFor(s) || '';
|
|
50
|
+
// if (
|
|
51
|
+
// !(outFile.startsWith('external ') ||
|
|
52
|
+
// outFile.startsWith('(webpack)'))
|
|
53
|
+
// ) {
|
|
54
|
+
// // TODO: can depcheck check raw text for dependencies?
|
|
55
|
+
// return { name: outFile, data: content };
|
|
56
|
+
// } else {
|
|
57
|
+
// return null;
|
|
58
|
+
// }
|
|
59
|
+
// })).then((r) => {
|
|
60
|
+
// // consumer.destroy();
|
|
61
|
+
// return r;
|
|
62
|
+
// }).catch((e) => {
|
|
63
|
+
// console.error(e);
|
|
64
|
+
// // consumer.destroy();
|
|
65
|
+
// return null;
|
|
66
|
+
// });
|
|
67
|
+
}
|
|
68
|
+
catch (e) {
|
|
69
|
+
console.error('ERROR[extractSource]', e);
|
|
70
|
+
return [];
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
export default extractSource;
|
|
74
|
+
//# sourceMappingURL=map.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"map.js","sourceRoot":"","sources":["../../../../src/lib/extractors/map.ts"],"names":[],"mappings":"AAAA,OAAO,gBAAgB,CAAC;AACxB,OAAO,SAA2B,MAAM,YAAY,CAAC;AAErD,MAAM,UAAU,GAAG,CAAC,CAAS,EAAE,EAAE;IAC/B,OAAO,CAAC,CAAC,OAAO,CAAC,aAAa,EAAE,EAAE,CAAC,CAAC;AACtC,CAAC,CAAC;AAEF,MAAM,mBAAmB,GAAG,6CAA6C,CAAC;AAE1E,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,GAAc,EAAE,EAAE;IAC/C,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,GAAG,CAAC;IAC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Map } from 'source-map';\nimport { StackItem } from '../pipeline/stack';\nconst formatName = (f: string) => {\n return f.replace('webpack:///', '');\n};\n\nconst SOURCEMAP_URL_REGEX = /sourceMappingURL=([/a-zA-Z._0-9-]+\\.map)/gim;\n\nexport const extractMapLink = (raw: StackItem) => {\n const { path, data } = raw;\n console.log({ path });\n // TODO: should allow [?] ?\n let mfiles = ((data as string).match(SOURCEMAP_URL_REGEX) || [])\n .filter((e) => !!e)\n .map((s) => s.split('=')[1]);\n if (mfiles.length) {\n mfiles = [mfiles[mfiles.length - 1]];\n return mfiles.map((mfile: string) => {\n if (mfile.startsWith('http')) {\n return mfile;\n } else {\n const newp = path.split('/');\n newp[newp.length - 1] = mfile;\n return newp.join('/');\n }\n });\n }\n};\n\n// type SourceType = { path: string; data: string | null };\nexport const extractSource = async (rawMap: RawSourceMap) => {\n try {\n const consumer = await new sourceMap.SourceMapConsumer(rawMap);\n const sources: Record<string, StackItem> = {};\n consumer.eachMapping((m) => {\n const s = m.source;\n const outFile = formatName(s);\n if (m.source && !sources[outFile]) {\n const content = consumer.sourceContentFor(s, true);\n if (\n !(outFile.startsWith('external ') || outFile.startsWith('(webpack)'))\n ) {\n // TODO: can depcheck check raw text for dependencies?\n // NOTE: this may remove chunked content, consider content hashing\n sources[outFile] = { path: outFile, data: content || '' };\n console.log('extractSource', { path: outFile });\n }\n }\n });\n return Object.values(sources).filter((e) => !!e);\n // return await Promise.all(consumer.sources.map((s) => {\n // const outFile = formatName(s);\n // const content = consumer.sourceContentFor(s) || '';\n // if (\n // !(outFile.startsWith('external ') ||\n // outFile.startsWith('(webpack)'))\n // ) {\n // // TODO: can depcheck check raw text for dependencies?\n // return { name: outFile, data: content };\n // } else {\n // return null;\n // }\n // })).then((r) => {\n // // consumer.destroy();\n // return r;\n // }).catch((e) => {\n // console.error(e);\n // // consumer.destroy();\n // return null;\n // });\n } catch (e) {\n console.error('ERROR[extractSource]', e);\n return [];\n }\n};\n\nexport default extractSource;\n"]}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { load } from 'cheerio';
|
|
2
|
+
const selectors = {
|
|
3
|
+
stylesheets: {
|
|
4
|
+
selector: 'link[rel="stylesheet"]',
|
|
5
|
+
attribute: 'href',
|
|
6
|
+
},
|
|
7
|
+
scripts: {
|
|
8
|
+
selector: 'script',
|
|
9
|
+
attribute: 'src',
|
|
10
|
+
},
|
|
11
|
+
imports: {
|
|
12
|
+
selector: 'link[rel="import"]',
|
|
13
|
+
attribute: 'href',
|
|
14
|
+
},
|
|
15
|
+
preloadScripts: {
|
|
16
|
+
selector: 'link[rel="preload"][as="script"]',
|
|
17
|
+
attribute: 'href',
|
|
18
|
+
},
|
|
19
|
+
preload: {
|
|
20
|
+
selector: 'link[rel="preload"][as="style"]',
|
|
21
|
+
attribute: 'href',
|
|
22
|
+
},
|
|
23
|
+
links: {
|
|
24
|
+
selector: 'a',
|
|
25
|
+
attribute: 'href',
|
|
26
|
+
},
|
|
27
|
+
images: {
|
|
28
|
+
selector: 'img',
|
|
29
|
+
attribute: 'src',
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
const loadExtract = (src, types = []) => {
|
|
33
|
+
if (types.length == 0) {
|
|
34
|
+
return [];
|
|
35
|
+
}
|
|
36
|
+
const $ = load(src.data);
|
|
37
|
+
console.log({ types });
|
|
38
|
+
const results = types.map((t) => {
|
|
39
|
+
const chosenType = selectors[t];
|
|
40
|
+
const resSel = $(chosenType.selector);
|
|
41
|
+
if (resSel) {
|
|
42
|
+
// `Array.prototype.map.call(...)` is untypable by TS: the generic `this` is lost,
|
|
43
|
+
// so it returns `unknown[]`. Chaining `.reduce((r: string[], l: string) => …)`
|
|
44
|
+
// off that array therefore failed to match any overload (TS2769) once `any` was
|
|
45
|
+
// swept to `unknown`. Assert the element type ONCE, here at the boundary where
|
|
46
|
+
// the callback demonstrably returns `string`, then let `reduce` be properly typed.
|
|
47
|
+
const links = Array.prototype.map.call(resSel, (el) => {
|
|
48
|
+
const $el = $(el);
|
|
49
|
+
const r = new URL($el.attr(chosenType.attribute), src.path).toString();
|
|
50
|
+
console.log('lnk', r);
|
|
51
|
+
return r.replace(/[?].*/, '');
|
|
52
|
+
});
|
|
53
|
+
// Dedupe, dropping entries whose URL resolution produced a trailing "undefined".
|
|
54
|
+
return links.reduce((r, l) => (r.includes(l) || l.endsWith('undefined') ? r : [...r, l]), []);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
return [];
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
return results.reduce((r, a) => r.concat(a), []);
|
|
61
|
+
};
|
|
62
|
+
export const extractSourceLinks = (raw) => {
|
|
63
|
+
const re = /(http[s]?:\/\/)?[^\s(["<,>]*\.[^\s[",><]*/gim;
|
|
64
|
+
return raw.match(re)?.filter((m) => /http.*\.(js|css)$/.test(m));
|
|
65
|
+
};
|
|
66
|
+
// export const oust = (src, type) => {
|
|
67
|
+
// if (!src || !type) {
|
|
68
|
+
// throw new Error('`src` and `type` required');
|
|
69
|
+
// }
|
|
70
|
+
// const validTypes = Object.keys(types);
|
|
71
|
+
// if (!validTypes.includes(type)) {
|
|
72
|
+
// throw new Error(
|
|
73
|
+
// `Invalid \`type\` value "${type}". `+
|
|
74
|
+
// `Choose one of: ${validTypes.join(', ')}`,
|
|
75
|
+
// );
|
|
76
|
+
// }
|
|
77
|
+
// return loadExtract(src, [type]);
|
|
78
|
+
// };
|
|
79
|
+
export const extractRawHtml = (src) => {
|
|
80
|
+
return loadExtract(src, [
|
|
81
|
+
'stylesheets',
|
|
82
|
+
'scripts',
|
|
83
|
+
'imports',
|
|
84
|
+
'preloadScripts',
|
|
85
|
+
'preload',
|
|
86
|
+
]);
|
|
87
|
+
};
|
|
88
|
+
export const isHtml = (s) => {
|
|
89
|
+
// eslint-disable-next-line max-len
|
|
90
|
+
return /<(br|basefont|hr|input|source|frame|param|area|meta|!--|col|link|option|base|img|wbr|!DOCTYPE).*?>|<(a|abbr|acronym|address|applet|article|aside|audio|b|bdi|bdo|big|blockquote|body|button|canvas|caption|center|cite|code|colgroup|command|datalist|dd|del|details|dfn|dialog|dir|div|dl|dt|em|embed|fieldset|figcaption|figure|font|footer|form|frameset|head|header|hgroup|h1|h2|h3|h4|h5|h6|html|i|iframe|ins|kbd|keygen|label|legend|li|map|mark|menu|meter|nav|noframes|noscript|object|ol|optgroup|output|p|pre|progress|q|rp|rt|ruby|s|samp|script|section|select|small|span|strike|strong|style|sub|summary|sup|table|tbody|td|textarea|tfoot|th|thead|time|title|tr|track|tt|u|ul|var|video).*?<\/\2>/i.test(s);
|
|
91
|
+
};
|
|
92
|
+
export default extractRawHtml;
|
|
93
|
+
//# sourceMappingURL=raw-html.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"raw-html.js","sourceRoot":"","sources":["../../../../src/lib/extractors/raw-html.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAe/B,MAAM,SAAS,GAAgB;IAC7B,WAAW,EAAE;QACX,QAAQ,EAAE,wBAAwB;QAClC,SAAS,EAAE,MAAM;KAClB;IACD,OAAO,EAAE;QACP,QAAQ,EAAE,QAAQ;QAClB,SAAS,EAAE,KAAK;KACjB;IACD,OAAO,EAAE;QACP,QAAQ,EAAE,oBAAoB;QAC9B,SAAS,EAAE,MAAM;KAClB;IACD,cAAc,EAAE;QACd,QAAQ,EAAE,kCAAkC;QAC5C,SAAS,EAAE,MAAM;KAClB;IACD,OAAO,EAAE;QACP,QAAQ,EAAE,iCAAiC;QAC3C,SAAS,EAAE,MAAM;KAClB;IACD,KAAK,EAAE;QACL,QAAQ,EAAE,GAAG;QACb,SAAS,EAAE,MAAM;KAClB;IACD,MAAM,EAAE;QACN,QAAQ,EAAE,KAAK;QACf,SAAS,EAAE,KAAK;KACjB;CACF,CAAC;AAEF,MAAM,WAAW,GAAG,CAAC,GAAc,EAAE,QAAyB,EAAE,EAAE,EAAE;IAClE,IAAI,KAAK,CAAC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CAAC;QACJ,CAAC;aAAM,CAAC;YACN,OAAO,EAAc,CAAC;QACxB,CAAC;IACH,CAAC,CAAC,CAAC;IACH,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAa,CAAC;AAC/D,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,GAAW,EAAE,EAAE;IAChD,MAAM,EAAE,GAAG,8CAA8C,CAAC;IAC1D,OAAO,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,mBAAmB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AACnE,CAAC,CAAC;AAEF,uCAAuC;AACvC,yBAAyB;AACzB,oDAAoD;AACpD,MAAM;AAEN,2CAA2C;AAE3C,sCAAsC;AACtC,uBAAuB;AACvB,gDAAgD;AAChD,qDAAqD;AACrD,SAAS;AACT,MAAM;AAEN,qCAAqC;AACrC,KAAK;AAEL,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,GAAmC,EAAE,EAAE;IACpE,OAAO,WAAW,CAAC,GAAG,EAAE;QACtB,aAAa;QACb,SAAS;QACT,SAAS;QACT,gBAAgB;QAChB,SAAS;KACV,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,CAAS,EAAE,EAAE;IAClC,mCAAmC;IACnC,OAAO,mrBAAmrB,CAAC,IAAI,CAC7rB,CAAC,CACF,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,cAAc,CAAC","sourcesContent":["import { load } from 'cheerio';\nimport { StackItem } from '../pipeline/stack';\ntype SelectorTypes =\n | 'stylesheets'\n | 'scripts'\n | 'imports'\n | 'preloadScripts'\n | 'preload'\n | 'links'\n | 'images';\ntype SelectorAccessor = {\n selector: string;\n attribute: 'href' | 'src';\n};\ntype SelectorMap = Record<SelectorTypes, SelectorAccessor>;\nconst selectors: SelectorMap = {\n stylesheets: {\n selector: 'link[rel=\"stylesheet\"]',\n attribute: 'href',\n },\n scripts: {\n selector: 'script',\n attribute: 'src',\n },\n imports: {\n selector: 'link[rel=\"import\"]',\n attribute: 'href',\n },\n preloadScripts: {\n selector: 'link[rel=\"preload\"][as=\"script\"]',\n attribute: 'href',\n },\n preload: {\n selector: 'link[rel=\"preload\"][as=\"style\"]',\n attribute: 'href',\n },\n links: {\n selector: 'a',\n attribute: 'href',\n },\n images: {\n selector: 'img',\n attribute: 'src',\n },\n};\n\nconst loadExtract = (src: StackItem, types: SelectorTypes[] = []) => {\n if (types.length == 0) {\n return [];\n }\n const $ = load(src.data);\n console.log({ types });\n const results = types.map((t) => {\n const chosenType = selectors[t];\n const resSel = $(chosenType.selector);\n if (resSel) {\n // `Array.prototype.map.call(...)` is untypable by TS: the generic `this` is lost,\n // so it returns `unknown[]`. Chaining `.reduce((r: string[], l: string) => …)`\n // off that array therefore failed to match any overload (TS2769) once `any` was\n // swept to `unknown`. Assert the element type ONCE, here at the boundary where\n // the callback demonstrably returns `string`, then let `reduce` be properly typed.\n const links = Array.prototype.map.call(resSel, (el: unknown): string => {\n const $el = $(el as never);\n const r = new URL(\n $el.attr(chosenType.attribute) as string,\n src.path\n ).toString();\n console.log('lnk', r);\n return r.replace(/[?].*/, '');\n }) as string[];\n\n // Dedupe, dropping entries whose URL resolution produced a trailing \"undefined\".\n return links.reduce<string[]>(\n (r, l) => (r.includes(l) || l.endsWith('undefined') ? r : [...r, l]),\n []\n );\n } else {\n return [] as string[];\n }\n });\n return results.reduce((r, a) => r.concat(a), []) as string[];\n};\n\nexport const extractSourceLinks = (raw: string) => {\n const re = /(http[s]?:\\/\\/)?[^\\s([\"<,>]*\\.[^\\s[\",><]*/gim;\n return raw.match(re)?.filter((m) => /http.*\\.(js|css)$/.test(m));\n};\n\n// export const oust = (src, type) => {\n// if (!src || !type) {\n// throw new Error('`src` and `type` required');\n// }\n\n// const validTypes = Object.keys(types);\n\n// if (!validTypes.includes(type)) {\n// throw new Error(\n// `Invalid \\`type\\` value \"${type}\". `+\n// `Choose one of: ${validTypes.join(', ')}`,\n// );\n// }\n\n// return loadExtract(src, [type]);\n// };\n\nexport const extractRawHtml = (src: { data: string; path: string }) => {\n return loadExtract(src, [\n 'stylesheets',\n 'scripts',\n 'imports',\n 'preloadScripts',\n 'preload',\n ]);\n};\n\nexport const isHtml = (s: string) => {\n // eslint-disable-next-line max-len\n return /<(br|basefont|hr|input|source|frame|param|area|meta|!--|col|link|option|base|img|wbr|!DOCTYPE).*?>|<(a|abbr|acronym|address|applet|article|aside|audio|b|bdi|bdo|big|blockquote|body|button|canvas|caption|center|cite|code|colgroup|command|datalist|dd|del|details|dfn|dialog|dir|div|dl|dt|em|embed|fieldset|figcaption|figure|font|footer|form|frameset|head|header|hgroup|h1|h2|h3|h4|h5|h6|html|i|iframe|ins|kbd|keygen|label|legend|li|map|mark|menu|meter|nav|noframes|noscript|object|ol|optgroup|output|p|pre|progress|q|rp|rt|ruby|s|samp|script|section|select|small|span|strike|strong|style|sub|summary|sup|table|tbody|td|textarea|tfoot|th|thead|time|title|tr|track|tt|u|ul|var|video).*?<\\/\\2>/i.test(\n s\n );\n};\n\nexport default extractRawHtml;\n"]}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
type RequestOptions = {
|
|
2
|
+
method?: 'GET' | 'POST' | 'PUT' | 'DELETE';
|
|
3
|
+
headers?: Record<string, string>;
|
|
4
|
+
body?: unknown;
|
|
5
|
+
json?: boolean;
|
|
6
|
+
referer?: string;
|
|
7
|
+
};
|
|
8
|
+
export declare class BrowserClient {
|
|
9
|
+
private jar;
|
|
10
|
+
private lastUrl?;
|
|
11
|
+
private agent;
|
|
12
|
+
private defaultHeaders;
|
|
13
|
+
fetch(url: string, options?: RequestOptions): Promise<{
|
|
14
|
+
status: any;
|
|
15
|
+
headers: any;
|
|
16
|
+
body: any;
|
|
17
|
+
}>;
|
|
18
|
+
get(url: string): Promise<{
|
|
19
|
+
status: any;
|
|
20
|
+
headers: any;
|
|
21
|
+
body: any;
|
|
22
|
+
}>;
|
|
23
|
+
post(url: string, body: unknown): Promise<{
|
|
24
|
+
status: any;
|
|
25
|
+
headers: any;
|
|
26
|
+
body: any;
|
|
27
|
+
}>;
|
|
28
|
+
getCookies(url: string): Promise<string[]>;
|
|
29
|
+
}
|
|
30
|
+
export declare const extractSite: (_url: string) => Promise<{
|
|
31
|
+
path: string;
|
|
32
|
+
data: any;
|
|
33
|
+
} | null>;
|
|
34
|
+
export default extractSite;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import request from 'async-request';
|
|
2
|
+
import https from 'https';
|
|
3
|
+
import { CookieJar } from 'tough-cookie';
|
|
4
|
+
import { url } from '../validators/index.js';
|
|
5
|
+
export class BrowserClient {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.jar = new CookieJar();
|
|
8
|
+
this.agent = new https.Agent({
|
|
9
|
+
keepAlive: true,
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
defaultHeaders(_url) {
|
|
13
|
+
return {
|
|
14
|
+
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36',
|
|
15
|
+
Accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8',
|
|
16
|
+
'Accept-Language': 'en-US,en;q=0.9',
|
|
17
|
+
'Accept-Encoding': 'gzip, deflate, br',
|
|
18
|
+
Connection: 'keep-alive',
|
|
19
|
+
'Upgrade-Insecure-Requests': '1',
|
|
20
|
+
...(this.lastUrl ? { Referer: this.lastUrl } : {}),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
async fetch(url, options = {}) {
|
|
24
|
+
const method = options.method || 'GET';
|
|
25
|
+
const headers = {
|
|
26
|
+
...this.defaultHeaders(url),
|
|
27
|
+
...(options.headers || {}),
|
|
28
|
+
...(options.referer ? { Referer: options.referer } : {}),
|
|
29
|
+
};
|
|
30
|
+
const res = await request(url, {
|
|
31
|
+
method,
|
|
32
|
+
headers,
|
|
33
|
+
data: options.body,
|
|
34
|
+
// json: options.json,
|
|
35
|
+
jar: this.jar,
|
|
36
|
+
agent: this.agent,
|
|
37
|
+
followRedirect: true,
|
|
38
|
+
maxRedirects: 10,
|
|
39
|
+
});
|
|
40
|
+
this.lastUrl = url;
|
|
41
|
+
return {
|
|
42
|
+
status: res.statusCode,
|
|
43
|
+
headers: res.headers,
|
|
44
|
+
body: res.body,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
async get(url) {
|
|
48
|
+
return this.fetch(url);
|
|
49
|
+
}
|
|
50
|
+
async post(url, body) {
|
|
51
|
+
return this.fetch(url, {
|
|
52
|
+
method: 'POST',
|
|
53
|
+
body,
|
|
54
|
+
headers: {
|
|
55
|
+
'Content-Type': 'application/json',
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
getCookies(url) {
|
|
60
|
+
return new Promise((resolve, reject) => {
|
|
61
|
+
this.jar.getCookies(url, (err, cookies) => {
|
|
62
|
+
if (err)
|
|
63
|
+
return reject(err);
|
|
64
|
+
resolve(cookies.map((c) => c.cookieString()));
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
const client = new BrowserClient();
|
|
70
|
+
export const extractSite = async (_url) => {
|
|
71
|
+
// console.log({_url})
|
|
72
|
+
// if (_url.startsWith('//')){
|
|
73
|
+
// url=`https:${_url}`
|
|
74
|
+
// }
|
|
75
|
+
const assetUrl = url.ensure(_url).toString();
|
|
76
|
+
console.log('extractSite', assetUrl);
|
|
77
|
+
let res = null;
|
|
78
|
+
try {
|
|
79
|
+
res = await client.fetch(assetUrl, {
|
|
80
|
+
headers: {
|
|
81
|
+
Accept: 'text/html,application/xhtml+xml,application/xml;',
|
|
82
|
+
'Accept-Language': 'en-US,en;q=0.9',
|
|
83
|
+
'user-agent': `Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) ` +
|
|
84
|
+
`AppleWebKit/537.36 (KHTML, like Gecko) ` +
|
|
85
|
+
`Chrome/80.0.3987.163 Safari/537.36`,
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
return { path: assetUrl, data: res.body };
|
|
89
|
+
}
|
|
90
|
+
catch (e) {
|
|
91
|
+
console.error(e);
|
|
92
|
+
}
|
|
93
|
+
return null;
|
|
94
|
+
};
|
|
95
|
+
export default extractSite;
|
|
96
|
+
//# sourceMappingURL=site.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"site.js","sourceRoot":"","sources":["../../../../src/lib/extractors/site.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,eAAe,CAAC;AACpC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,GAAG,EAAE,MAAM,wBAAwB,CAAC;AAU7C,MAAM,OAAO,aAAa;IAA1B;QACU,QAAG,GAAG,IAAI,SAAS,EAAE,CAAC;QAGtB,UAAK,GAAG,IAAI,KAAK,CAAC,KAAK,CAAC;YAC9B,SAAS,EAAE,IAAI;SAChB,CAAC,CAAC;IAmEL,CAAC;IAjES,cAAc,CAAC,IAAY;QACjC,OAAO;YACL,YAAY,EACV,uHAAuH;YACzH,MAAM,EACJ,uFAAuF;YACzF,iBAAiB,EAAE,gBAAgB;YACnC,iBAAiB,EAAE,mBAAmB;YACtC,UAAU,EAAE,YAAY;YACxB,2BAA2B,EAAE,GAAG;YAChC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SACnD,CAAC;IACJ,CAAC;IAED,KAA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I,CAAC,GAAG,CAAC,UAAU,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,EAAE;gBACxC,IAAI,GAAG;oBAAE,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;gBAC5B,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC;YAChD,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAED,MAAM,MAAM,GAAG,IAAI,aAAa,EAAE,CAAC;AAEnC,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,EAAE,IAAY,EAAE,EAAE;IAChD,sBAAsB;IACtB,8BAA8B;IAC9B,wBAAwB;IACxB,IAAI;IACJ,MAAM,QAAQ,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,CAAC;IAC7C,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,QAAQ,CAAC,CAAC;IACrC,IAAI,GAAG,GAAG,IAAI,CAAC;IACf,IAAI,CAAC;QACH,GAAG,GAAG,MAAM,MAAM,CAAC,KAAK,CAAC,QAAQ,EAAE;YACjC,OAAO,EAAE;gBACP,MAAM,EAAE,kDAAkD;gBAC1D,iBAAiB,EAAE,gBAAgB;gBACnC,YAAY,EACV,kDAAkD;oBAClD,yCAAyC;oBACzC,oCAAoC;aACvC;SACF,CAAC,CAAC;QACH,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,CAAC;IAC5C,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACnB,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAEF,eAAe,WAAW,CAAC","sourcesContent":["import request from 'async-request';\nimport https from 'https';\nimport { CookieJar } from 'tough-cookie';\nimport { url } from '../validators/index.js';\n\ntype RequestOptions = {\n method?: 'GET' | 'POST' | 'PUT' | 'DELETE';\n headers?: Record<string, string>;\n body?: unknown;\n json?: boolean;\n referer?: string;\n};\n\nexport class BrowserClient {\n private jar = new CookieJar();\n private lastUrl?: string;\n\n private agent = new https.Agent({\n keepAlive: true,\n });\n\n private defaultHeaders(_url: string): Record<string, string> {\n return {\n 'User-Agent':\n 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36',\n Accept:\n 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8',\n 'Accept-Language': 'en-US,en;q=0.9',\n 'Accept-Encoding': 'gzip, deflate, br',\n Connection: 'keep-alive',\n 'Upgrade-Insecure-Requests': '1',\n ...(this.lastUrl ? { Referer: this.lastUrl } : {}),\n };\n }\n\n async fetch(url: string, options: RequestOptions = {}) {\n const method = options.method || 'GET';\n\n const headers = {\n ...this.defaultHeaders(url),\n ...(options.headers || {}),\n ...(options.referer ? { Referer: options.referer } : {}),\n };\n\n const res = await request(url, {\n method,\n headers,\n data: options.body,\n // json: options.json,\n jar: this.jar,\n agent: this.agent,\n followRedirect: true,\n maxRedirects: 10,\n });\n\n this.lastUrl = url;\n\n return {\n status: res.statusCode,\n headers: res.headers,\n body: res.body,\n };\n }\n\n async get(url: string) {\n return this.fetch(url);\n }\n\n async post(url: string, body: unknown) {\n return this.fetch(url, {\n method: 'POST',\n body,\n headers: {\n 'Content-Type': 'application/json',\n },\n });\n }\n\n getCookies(url: string) {\n return new Promise<string[]>((resolve, reject) => {\n this.jar.getCookies(url, (err, cookies) => {\n if (err) return reject(err);\n resolve(cookies.map((c) => c.cookieString()));\n });\n });\n }\n}\n\nconst client = new BrowserClient();\n\nexport const extractSite = async (_url: string) => {\n // console.log({_url})\n // if (_url.startsWith('//')){\n // url=`https:${_url}`\n // }\n const assetUrl = url.ensure(_url).toString();\n console.log('extractSite', assetUrl);\n let res = null;\n try {\n res = await client.fetch(assetUrl, {\n headers: {\n Accept: 'text/html,application/xhtml+xml,application/xml;',\n 'Accept-Language': 'en-US,en;q=0.9',\n 'user-agent':\n `Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) ` +\n `AppleWebKit/537.36 (KHTML, like Gecko) ` +\n `Chrome/80.0.3987.163 Safari/537.36`,\n },\n });\n return { path: assetUrl, data: res.body };\n } catch (e) {\n console.error(e);\n }\n return null;\n};\n\nexport default extractSite;\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { FileStore as FS } from './store/index.js';
|
|
2
|
+
export declare const Extractors: {
|
|
3
|
+
testpipeline: (files: string[], prefix: string) => Promise<import("./store/index.js").WriteOperations[]>;
|
|
4
|
+
pipeline: (input: string, prefix?: string) => Promise<import("./store/index.js").WriteOperations>;
|
|
5
|
+
extract: (callStack: import("./pipeline/stack.js").PipelineStack) => Promise<void>;
|
|
6
|
+
};
|
|
7
|
+
export declare const Store: FS;
|
|
8
|
+
export declare const FileStore: typeof FS;
|
package/src/lib/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,uBAAuB,CAAC;AACtC,OAAO,EAAE,SAAS,IAAI,EAAE,EAAE,KAAK,IAAI,CAAC,EAAE,MAAM,kBAAkB,CAAC;AAC/D,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,CAAC;AAC5B,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,CAAC;AACvB,MAAM,CAAC,MAAM,SAAS,GAAG,EAAE,CAAC","sourcesContent":["import E from './extractors/index.js';\nimport { FileStore as FS, Store as S } from './store/index.js';\nexport const Extractors = E;\nexport const Store = S;\nexport const FileStore = FS;\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { PipelineStack as Stack } from './stack.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/lib/pipeline/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,IAAI,KAAK,EAAE,MAAM,YAAY,CAAC","sourcesContent":["export { PipelineStack as Stack } from './stack.js';\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
type ActionEnum = 'site' | 'local' | 'raw' | 'link' | 'source' | 'map' | 'write';
|
|
2
|
+
type ActionType = {
|
|
3
|
+
pipe: 'resolver';
|
|
4
|
+
type: ActionEnum;
|
|
5
|
+
[key: string]: unknown;
|
|
6
|
+
};
|
|
7
|
+
export declare const getSiteAction: (props: Partial<ActionType>) => ActionType;
|
|
8
|
+
export declare const getLocalAction: (props: Partial<ActionType>) => ActionType;
|
|
9
|
+
export declare const getRawAction: (props: Partial<ActionType>) => ActionType;
|
|
10
|
+
export declare const getLinkAction: (props: Partial<ActionType>) => ActionType;
|
|
11
|
+
export declare const getSourceAction: (props: Partial<ActionType>) => ActionType;
|
|
12
|
+
export declare const getMapAction: (props: Partial<ActionType>) => ActionType;
|
|
13
|
+
export declare const getWriteAction: (props: Partial<ActionType>) => ActionType;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export const getSiteAction = (props) => {
|
|
2
|
+
return {
|
|
3
|
+
pipe: 'resolver',
|
|
4
|
+
type: 'site',
|
|
5
|
+
...props,
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
export const getLocalAction = (props) => {
|
|
9
|
+
return {
|
|
10
|
+
pipe: 'resolver',
|
|
11
|
+
type: 'local',
|
|
12
|
+
...props,
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
export const getRawAction = (props) => {
|
|
16
|
+
return {
|
|
17
|
+
pipe: 'resolver',
|
|
18
|
+
type: 'raw',
|
|
19
|
+
...props,
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
export const getLinkAction = (props) => {
|
|
23
|
+
return {
|
|
24
|
+
pipe: 'resolver',
|
|
25
|
+
type: 'link',
|
|
26
|
+
...props,
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
export const getSourceAction = (props) => {
|
|
30
|
+
return {
|
|
31
|
+
pipe: 'resolver',
|
|
32
|
+
type: 'source',
|
|
33
|
+
...props,
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
export const getMapAction = (props) => {
|
|
37
|
+
return {
|
|
38
|
+
pipe: 'resolver',
|
|
39
|
+
type: 'map',
|
|
40
|
+
...props,
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
export const getWriteAction = (props) => {
|
|
44
|
+
return {
|
|
45
|
+
pipe: 'resolver',
|
|
46
|
+
type: 'write',
|
|
47
|
+
...props,
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
//# sourceMappingURL=actions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actions.js","sourceRoot":"","sources":["../../../../../../src/lib/pipeline/pipes/resolver/actions.ts"],"names":[],"mappings":"AAaA,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,KAA0B,EAAE,EAAE;IAC1D,OAAO;QACL,IAAI,EAAE,UAAU;QAChB,IAAI,EAAE,MAAM;QACZ,GAAG,KAAK;KACK,CAAC;AAClB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,KAA0B,EAAE,EAAE;IAC3D,OAAO;QACL,IAAI,EAAE,UAAU;QAChB,IAAI,EAAE,OAAO;QACb,GAAG,KAAK;KACK,CAAC;AAClB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,KAA0B,EAAE,EAAE;IACzD,OAAO;QACL,IAAI,EAAE,UAAU;QAChB,IAAI,EAAE,KAAK;QACX,GAAG,KAAK;KACK,CAAC;AAClB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,KAA0B,EAAE,EAAE;IAC1D,OAAO;QACL,IAAI,EAAE,UAAU;QAChB,IAAI,EAAE,MAAM;QACZ,GAAG,KAAK;KACK,CAAC;AAClB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,KAA0B,EAAE,EAAE;IAC5D,OAAO;QACL,IAAI,EAAE,UAAU;QAChB,IAAI,EAAE,QAAQ;QACd,GAAG,KAAK;KACK,CAAC;AAClB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,KAA0B,EAAE,EAAE;IACzD,OAAO;QACL,IAAI,EAAE,UAAU;QAChB,IAAI,EAAE,KAAK;QACX,GAAG,KAAK;KACK,CAAC;AAClB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,KAA0B,EAAE,EAAE;IAC3D,OAAO;QACL,IAAI,EAAE,UAAU;QAChB,IAAI,EAAE,OAAO;QACb,GAAG,KAAK;KACK,CAAC;AAClB,CAAC,CAAC","sourcesContent":["type ActionEnum =\n | 'site'\n | 'local'\n | 'raw'\n | 'link'\n | 'source'\n | 'map'\n | 'write';\ntype ActionType = {\n pipe: 'resolver';\n type: ActionEnum;\n [key: string]: unknown;\n};\nexport const getSiteAction = (props: Partial<ActionType>) => {\n return {\n pipe: 'resolver',\n type: 'site',\n ...props,\n } as ActionType;\n};\n\nexport const getLocalAction = (props: Partial<ActionType>) => {\n return {\n pipe: 'resolver',\n type: 'local',\n ...props,\n } as ActionType;\n};\n\nexport const getRawAction = (props: Partial<ActionType>) => {\n return {\n pipe: 'resolver',\n type: 'raw',\n ...props,\n } as ActionType;\n};\n\nexport const getLinkAction = (props: Partial<ActionType>) => {\n return {\n pipe: 'resolver',\n type: 'link',\n ...props,\n } as ActionType;\n};\n\nexport const getSourceAction = (props: Partial<ActionType>) => {\n return {\n pipe: 'resolver',\n type: 'source',\n ...props,\n } as ActionType;\n};\n\nexport const getMapAction = (props: Partial<ActionType>) => {\n return {\n pipe: 'resolver',\n type: 'map',\n ...props,\n } as ActionType;\n};\n\nexport const getWriteAction = (props: Partial<ActionType>) => {\n return {\n pipe: 'resolver',\n type: 'write',\n ...props,\n } as ActionType;\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { getLinkAction, getLocalAction, getMapAction, getRawAction, getSiteAction, getSourceAction, getWriteAction, } from './actions.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../src/lib/pipeline/pipes/resolver/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,cAAc,EACd,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,eAAe,EACf,cAAc,GACf,MAAM,cAAc,CAAC","sourcesContent":["export {\n getLinkAction,\n getLocalAction,\n getMapAction,\n getRawAction,\n getSiteAction,\n getSourceAction,\n getWriteAction,\n} from './actions.js';\n"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { RawSourceMap } from 'source-map';
|
|
2
|
+
export type StackItem = {
|
|
3
|
+
path: string;
|
|
4
|
+
data: string;
|
|
5
|
+
mapping?: RawSourceMap;
|
|
6
|
+
};
|
|
7
|
+
export declare class PipelineStack {
|
|
8
|
+
private _stack;
|
|
9
|
+
private _counter;
|
|
10
|
+
constructor();
|
|
11
|
+
/**
|
|
12
|
+
* Get current counter state showing active items by type.
|
|
13
|
+
*/
|
|
14
|
+
get counters(): Record<string, number>;
|
|
15
|
+
push(type: string, value: StackItem): void;
|
|
16
|
+
pop(): [string, StackItem] | null;
|
|
17
|
+
hasMore(): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Check if stack is empty (no active items).
|
|
20
|
+
*/
|
|
21
|
+
isEmpty(): boolean;
|
|
22
|
+
}
|
|
23
|
+
export default PipelineStack;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Transform } from '@adhd/data-base-transforms';
|
|
2
|
+
/**
|
|
3
|
+
* Pipeline stack for tracking decompiled objects by type.
|
|
4
|
+
* Tracks items through site, local, raw, link, map, source, and write stages.
|
|
5
|
+
* Counter tracks active items in the stack by type.
|
|
6
|
+
*/
|
|
7
|
+
const { Stack, Counter } = Transform;
|
|
8
|
+
export class PipelineStack {
|
|
9
|
+
constructor() {
|
|
10
|
+
this._counter = new Counter((value) => {
|
|
11
|
+
// Extract type from [type, value] tuple
|
|
12
|
+
return Array.isArray(value) ? value[0] : 'unknown';
|
|
13
|
+
});
|
|
14
|
+
this._stack = new Stack({
|
|
15
|
+
onPush: (value) => this._counter.increment(value),
|
|
16
|
+
onPop: (value) => {
|
|
17
|
+
value !== undefined && this._counter.decrement(value);
|
|
18
|
+
},
|
|
19
|
+
onClear: () => this._counter.clear(),
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Get current counter state showing active items by type.
|
|
24
|
+
*/
|
|
25
|
+
get counters() {
|
|
26
|
+
return this._counter.toJson();
|
|
27
|
+
}
|
|
28
|
+
push(type, value) {
|
|
29
|
+
this._stack.push([type, value]);
|
|
30
|
+
}
|
|
31
|
+
pop() {
|
|
32
|
+
return this._stack.pop() ?? null;
|
|
33
|
+
}
|
|
34
|
+
hasMore() {
|
|
35
|
+
return !this._stack.isEmpty;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Check if stack is empty (no active items).
|
|
39
|
+
*/
|
|
40
|
+
isEmpty() {
|
|
41
|
+
return this._stack.isEmpty;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
export default PipelineStack;
|
|
45
|
+
//# sourceMappingURL=stack.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stack.js","sourceRoot":"","sources":["../../../../src/lib/pipeline/stack.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAEvD;;;;GAIG;AACH,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,SAAS,CAAC;AAGrC,MAAM,OAAO,aAAa;IAIxB;QACE,IAAI,CAAC,QAAQ,GAAG,IAAI,OAAO,CAAsB,CAAC,KAAK,EAAE,EAAE;YACzD,wCAAwC;YACxC,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAE,KAAK,CAAC,CAAC,CAAY,CAAC,CAAC,CAAC,SAAS,CAAC;QACjE,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,MAAM,GAAG,IAAI,KAAK,CAAsB;YAC3C,MAAM,EAAE,CAAC,KAAK,EAAQ,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,KAAK,CAAC;YACvD,KAAK,EAAE,CAAC,KAAK,EAAQ,EAAE;gBACrB,KAAK,KAAK,SAAS,IAAI,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;YACxD,CAAC;YACD,OAAO,EAAE,GAAS,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE;SAC3C,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACH,IAAW,QAAQ;QACjB,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC;IAChC,CAAC;IAEM,IAAI,CAAC,IAAY,EAAE,KAAgB;QACxC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;IAClC,CAAC;IAEM,GAAG;QACR,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC;IACnC,CAAC;IAEM,OAAO;QACZ,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC;IAC9B,CAAC;IAED;;OAEG;IACI,OAAO;QACZ,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC;IAC7B,CAAC;CACF;AAED,eAAe,aAAa,CAAC","sourcesContent":["import { Transform } from '@adhd/data-base-transforms';\nimport { RawSourceMap } from 'source-map';\n/**\n * Pipeline stack for tracking decompiled objects by type.\n * Tracks items through site, local, raw, link, map, source, and write stages.\n * Counter tracks active items in the stack by type.\n */\nconst { Stack, Counter } = Transform;\nexport type StackItem = { path: string; data: string; mapping?: RawSourceMap };\n\nexport class PipelineStack {\n private _stack: InstanceType<typeof Stack<[string, StackItem]>>;\n private _counter: InstanceType<typeof Counter<[string, StackItem]>>;\n\n constructor() {\n this._counter = new Counter<[string, StackItem]>((value) => {\n // Extract type from [type, value] tuple\n return Array.isArray(value) ? (value[0] as string) : 'unknown';\n });\n\n this._stack = new Stack<[string, StackItem]>({\n onPush: (value): void => this._counter.increment(value),\n onPop: (value): void => {\n value !== undefined && this._counter.decrement(value);\n },\n onClear: (): void => this._counter.clear(),\n });\n }\n\n /**\n * Get current counter state showing active items by type.\n */\n public get counters(): Record<string, number> {\n return this._counter.toJson();\n }\n\n public push(type: string, value: StackItem): void {\n this._stack.push([type, value]);\n }\n\n public pop(): [string, StackItem] | null {\n return this._stack.pop() ?? null;\n }\n\n public hasMore(): boolean {\n return !this._stack.isEmpty;\n }\n\n /**\n * Check if stack is empty (no active items).\n */\n public isEmpty(): boolean {\n return this._stack.isEmpty;\n }\n}\n\nexport default PipelineStack;\n"]}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import _ from 'lodash';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import extractSources from '../extractors/map.js';
|
|
5
|
+
import Store from './index.js';
|
|
6
|
+
import { buildPackage } from './package.js';
|
|
7
|
+
import { BABELRC, BLANK_PACKAGE } from './templates.js';
|
|
8
|
+
import { read_map } from './utils.js';
|
|
9
|
+
export const buildConsumer = async (_outname, mapPath) => {
|
|
10
|
+
// const outputDir = path.resolve(`./${outname}`);
|
|
11
|
+
const rawMap = read_map(mapPath);
|
|
12
|
+
const sources = await extractSources(rawMap);
|
|
13
|
+
sources
|
|
14
|
+
.filter((s) => !!s)
|
|
15
|
+
.forEach(({ path, data }) => {
|
|
16
|
+
Store.addToImports(path);
|
|
17
|
+
Store.addFile(path, data);
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
export const build = (project, map_dir = `./maps`, prefix = 'build/', _type = 'dir') => {
|
|
21
|
+
const PROJECT = project; // process.env.PROJECT || 'patreon'
|
|
22
|
+
const PREFIX = prefix;
|
|
23
|
+
const PACKAGE = `${PROJECT}.${Date.now()}`;
|
|
24
|
+
const OUTPUT_NAME = path.resolve(`${PREFIX}${PACKAGE}`);
|
|
25
|
+
// const OUTPUT_PATH = `${OUTPUT_NAME}.zip`;
|
|
26
|
+
const buildWithPrefix = _.partial(buildConsumer, OUTPUT_NAME);
|
|
27
|
+
const INPUT_DIR = map_dir;
|
|
28
|
+
const promisedMaps = fs
|
|
29
|
+
.readdirSync(INPUT_DIR)
|
|
30
|
+
.filter((file) => {
|
|
31
|
+
return file.endsWith('.map');
|
|
32
|
+
})
|
|
33
|
+
.map((f) => `${INPUT_DIR}/${f}`)
|
|
34
|
+
.map(buildWithPrefix);
|
|
35
|
+
promisedMaps.push(Store.addFile('package.json', JSON.stringify(BLANK_PACKAGE, null, 4)));
|
|
36
|
+
promisedMaps.push(Store.addFile('.babelrc', JSON.stringify(BABELRC, null, 4)));
|
|
37
|
+
Promise.all(promisedMaps)
|
|
38
|
+
.then(() => Store.addFile('index.js', Store.main_file))
|
|
39
|
+
.then(() => buildPackage(OUTPUT_NAME))
|
|
40
|
+
.then((_deps) => {
|
|
41
|
+
const deps = _.uniq(_deps).map((p) => ({ [p]: '*' }));
|
|
42
|
+
BLANK_PACKAGE.dependencies = Object.assign({}, ...deps);
|
|
43
|
+
const packagejson = JSON.stringify(BLANK_PACKAGE, null, 4);
|
|
44
|
+
return Store.addFile('package.json', packagejson);
|
|
45
|
+
})
|
|
46
|
+
.catch((e) => {
|
|
47
|
+
console.error(e);
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
//# sourceMappingURL=build.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build.js","sourceR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MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,GAAG,IAAI,CAAC,CAAC;QACxD,MAAM,WAAW,GAAG,IAAI,CAAC,SAAS,CAAC,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;QAC3D,OAAO,KAAK,CAAC,OAAO,CAAC,cAAc,EAAE,WAAW,CAAC,CAAC;IACpD,CAAC,CAAC;SACD,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;QACX,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACnB,CAAC,CAAC,CAAC;AACP,CAAC,CAAC","sourcesContent":["import fs from 'fs';\nimport _ from 'lodash';\nimport path from 'path';\nimport extractSources from '../extractors/map.js';\nimport Store from './index.js';\nimport { buildPackage } from './package.js';\nimport { BABELRC, BLANK_PACKAGE } from './templates.js';\nimport { read_map } from './utils.js';\n\nexport const buildConsumer = async (_outname: string, mapPath: string) => {\n // const outputDir = path.resolve(`./${outname}`);\n const rawMap = read_map(mapPath);\n\n const sources = await extractSources(rawMap);\n sources\n .filter((s) => !!s)\n .forEach(({ path, data }) => {\n Store.addToImports(path);\n Store.addFile(path, data);\n });\n};\n\nexport const build = (\n project: string,\n map_dir = `./maps`,\n prefix = 'build/',\n _type = 'dir'\n) => {\n const PROJECT = project; // process.env.PROJECT || 'patreon'\n const PREFIX = prefix;\n const PACKAGE = `${PROJECT}.${Date.now()}`;\n const OUTPUT_NAME = path.resolve(`${PREFIX}${PACKAGE}`);\n // const OUTPUT_PATH = `${OUTPUT_NAME}.zip`;\n\n const buildWithPrefix = _.partial(buildConsumer, OUTPUT_NAME);\n const INPUT_DIR = map_dir;\n const promisedMaps = fs\n .readdirSync(INPUT_DIR)\n .filter((file) => {\n return file.endsWith('.map');\n })\n .map((f) => `${INPUT_DIR}/${f}`)\n .map(buildWithPrefix);\n\n promisedMaps.push(\n Store.addFile('package.json', JSON.stringify(BLANK_PACKAGE, null, 4))\n );\n promisedMaps.push(\n Store.addFile('.babelrc', JSON.stringify(BABELRC, null, 4))\n );\n Promise.all(promisedMaps)\n .then(() => Store.addFile('index.js', Store.main_file))\n .then(() => buildPackage(OUTPUT_NAME))\n .then((_deps) => {\n const deps = _.uniq(_deps).map((p) => ({ [p]: '*' }));\n BLANK_PACKAGE.dependencies = Object.assign({}, ...deps);\n const packagejson = JSON.stringify(BLANK_PACKAGE, null, 4);\n return Store.addFile('package.json', packagejson);\n })\n .catch((e) => {\n console.error(e);\n });\n};\n"]}
|