jetc 0.5.4 → 0.5.6
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/bin/server.js +7 -6
- package/index.js +12 -13
- package/package.json +2 -2
package/bin/server.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
'use strict';function l(a){return n.existsSync(a)&&n.statSync(a).isDirectory()}function r(a){return n.existsSync(a)&&n.statSync(a).isFile()}function t(...a){a=a.join("/").split("/");let c=a.length;for(let b=1;b<c;b++)0<b&&b<c-1&&!a[b]?(a.splice(b,1),--c,--b):0<b&&"."===a[b]?(a.splice(b,1),--c,--b):1===b&&".."===a[b]&&"."===a[b-1]?(a.splice(b-1,1),--c,--b):0<b&&".."===a[b]&&"."!==a[b-1]&&".."!==a[b-1]&&(a.splice(b-1,2),c-=2,b-=2);return a.join("/")}
|
|
3
|
-
function u(a,c){try{return require.resolve(a,c).replace(/\\/g,"/")}catch(b){}return null}function v(a,c){return"\u001b["+a+"m"+c+"\u001b[39m"}function w(){return v(90,"["+(new Date).toLocaleString("en-US")+"]")}
|
|
4
|
-
function
|
|
5
|
-
(c=c[c.length-1],a[c])?
|
|
6
|
-
function
|
|
7
|
-
{
|
|
8
|
-
|
|
3
|
+
function u(a,c){try{return require.resolve(a,c).replace(/\\/g,"/")}catch(b){}return null}function v(a,c){return"\u001b["+a+"m"+c+"\u001b[39m"}function w(){return v(90,"["+(new Date).toLocaleString("en-US")+"]")}function z(a){return(a=B(a))?{"Content-Type":a}:null}
|
|
4
|
+
function B(a){a=a.split("/");var c=a[a.length-1].split(".");a={css:"text/css",csv:"text/csv",eot:"application/vnd.ms-fontobject",gif:"image/gif",htm:"text/html",html:"text/html",ico:"image/vnd.microsoft.icon",jpeg:"image/jpeg",jpg:"image/jpeg",js:"application/javascript",json:"application/json",otf:"font/otf",pdf:"application/pdf",png:"image/png",svg:"image/svg+xml",tif:"image/tiff",tiff:"image/tiff",ttf:"font/ttf",txt:"text/plain",woff:"font/woff",woff2:"font/woff2",xml:"text/xml"};return 1<c.length&&
|
|
5
|
+
(c=c[c.length-1],a[c])?a[c]:null}const n=require("fs"),C=require("http");function D(){var a=process.argv;let c=!1,b="",f=3E3;const d=a.length;for(let k=2;k<d;k++){const e=a[k];e.startsWith("--port=")?f=parseInt(e.slice(7),10):"--all"===e?c=!0:k===d-1&&(b=e)}return{a:c,folder:b,port:f}}function E(a,c){a=a.headers.accept;let b=!0;if(a){const f=B(c);b=!1;a.split(",").forEach(d=>{d=d.split(";")[0].trim();if(d===f||"*/*"===d)b=!0})}return b}
|
|
6
|
+
function F(a){let c="";a=a.split("/").map(f=>{f=c+f;c=f+"/";return[f,f+"/node_modules"]}).reverse();const b=a.length;for(let f=0;f<b;f++)if(l(a[f][1]))return a[f][0];return null}
|
|
7
|
+
function G(){const {a,folder:c,port:b}=D(),f=C.createServer((d,k)=>{{var e=d.url.split("?")[0];var g=process.cwd().replace(/\\/g,"/");var m=c?t(g,c):g,p=t(m,"index.html");const q=t(m,e),A=t(q,"index.html");var h="";g="";if(r(q))h=q,g=e;else if(r(A))h=A,g=t(e,"index.html");else if(0===e.indexOf("/node_modules/")){if(e=e.split("/node_modules/"),p=F(m),m=e.pop(),p&&m&&(h=t(p,e.join("/node_modules/")),h=u(m,{paths:[h]})))e=h.split("/node_modules/"),e[0]="",g=e.join("/node_modules/")}else(h=u(t(".",e),
|
|
8
|
+
{paths:[m]}))?g=h.slice(m.length):(h=u(e.slice(1),{paths:[m]}))&&(g=t("/node_modules/",h.split("/node_modules/").pop())),h||!a||1<e.split("/").pop().split(".").length||!r(p)||(h=p,g=t("/index.html"));g={filename:h,location:g}}const {filename:x,location:y}=g;g="";if(x&&E(d,x)){try{g=n.readFileSync(x,"binary")}catch(q){g=q;d=d.url;k.writeHead(500,z(".txt"));k.write("500 Internal Server Error\n");k.end();console.log(w(),d+" "+v(31,500)+" "+g);return}d=d.url;h=Object.assign({},{Location:y},z(y),{"Cache-Control":"max-age=0, no-cache, must-revalidate, proxy-revalidate",
|
|
9
|
+
Expires:"Thu, 01 Jan 1970 00:00:00 GMT","Last-Modified":(new Date).toUTCString()});k.writeHead(200,h);k.write(g,"binary");k.end();console.log(w(),d+" 200 "+g.length+" "+y)}else d=d.url,k.writeHead(404,z(".txt")),k.write("404 Not Found\n"),k.end(),console.log(w(),d+" "+v(31,404))});f.on("error",d=>console.error(d));f.listen(b,"localhost");console.log("Development server is running at http://localhost:"+b+"/\nPress Ctrl + C to shutdown.\n")}require.main===module&&G();
|
package/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';const q=require("fs"),{closeContext:r,getContext:t,openContext:u,parser:v}=require("jeti");function w(a){return q.existsSync(a)&&q.statSync(a).isDirectory()}function x(a){return q.existsSync(a)&&q.statSync(a).isFile()}function y(a,b,c,d){let e;for(let f=1;e=b+(1<f?f:"")+"."+c,q.existsSync(z(a,e))||-1!==(d||[]).indexOf(e);f++);return e}
|
|
2
|
-
function z(...a){a=a.join("/").split("/");let b=a.length;for(let c=1;c<b;c++)0<c&&c<b-1&&!a[c]?(a.splice(c,1),--b,--c):0<c&&"."===a[c]?(a.splice(c,1),--b,--c):1===c&&".."===a[c]&&"."===a[c-1]?(a.splice(c-1,1),--b,--c):0<c&&".."===a[c]&&"."!==a[c-1]&&".."!==a[c-1]&&(a.splice(c-1,2),b-=2,c-=2);return a.join("/")}function A(a,b){try{return require.resolve(a,b).replace(/\\/g,"/")}catch(c){}return null}function B(a){return 0<a.
|
|
3
|
-
class C{constructor(a){this.path=a;this.
|
|
2
|
+
function z(...a){a=a.join("/").split("/");let b=a.length;for(let c=1;c<b;c++)0<c&&c<b-1&&!a[c]?(a.splice(c,1),--b,--c):0<c&&"."===a[c]?(a.splice(c,1),--b,--c):1===c&&".."===a[c]&&"."===a[c-1]?(a.splice(c-1,1),--b,--c):0<c&&".."===a[c]&&"."!==a[c-1]&&".."!==a[c-1]&&(a.splice(c-1,2),b-=2,c-=2);return a.join("/")}function A(a,b){try{return require.resolve(a,b).replace(/\\/g,"/")}catch(c){}return null}function B(a){return 0<a.b.length&&""===a.b[0]}
|
|
3
|
+
class C{constructor(a){this.path=a;this.b=this.path.split("/");this.filename=this.b.pop();this.folder=this.b.join("/");this.ext=this.name=null;a=this.filename.split(".");this.ext=1<a.length&&(a[0]||2<a.length)?a.pop():"";this.name=a.join(".")}a(){return{css:"text/css",htm:"text/html",html:"text/html",js:"application/javascript",json:"application/json",scss:"text/scss",txt:"text/plain",xml:"text/xml"}[this.ext]||""}toString(){return this.path}}
|
|
4
4
|
function D(a,b,c){({name:b}=new C(b));a=y(a,b,"css");b=z(".",a);c.name=b;return{href:a,filename:b}}function E(a){return a&&"'jet module';"===a.slice(0,13)}function F(a){return"application/javascript"===a}var G={"single-comment":"slash slash *!end-line end-line","multi-comment":"slash star *!(star slash) star slash",comment:"single-comment | multi-comment"},H={"single-string":"single-quote *((escape any) | !single-quote) single-quote"},I={"double-string":"double-quote *((escape any) | !double-quote) double-quote"};
|
|
5
5
|
const J={...G,...H,...I,string:"single-string | double-string",whitespace:"+(space | comment)",bracket:"lbrace | rbrace | lparen | rparen | lbracket | rbracket","extended-symbol":"symbol | punctuation | bracket",delimiter:"extended-symbol | string",compress:"*whitespace +delimiter *whitespace",grammar:"*(compress | whitespace | any)"},K={...G,...H,...I,string:"single-string | double-string",whitespace:"+(space | comment)",delimiter:"comma | colon | semicolon | lbrace | rbrace",compress:"*whitespace +delimiter *whitespace",
|
|
6
6
|
grammar:"*(compress | string | whitespace | any)"},L={comment:"less exclamation dash dash *!(dash dash more) dash dash more",...H,...I,"attribute-name":"letter *(letter | digit | dash)","attribute-value":"single-string | double-string",attribute:"attribute-name ?(equal attribute-value)","tag-name":"letter *(letter | digit | dash)","tag-body":"*(space | attribute)","any-tag":"less ?slash tag-name tag-body more",head:"(H | h) (E | e) (A | a) (D | d)",script:"(S | s) (C | c) (R | r) (I | i) (P | p) (T | t)",
|
|
@@ -11,16 +11,15 @@ function T(a,b){const c=t(),{aliases:d}=c||{},e=b.length;let f=null;for(let g=0;
|
|
|
11
11
|
function R(a,b){const c=t(),{folder:d,name:e}=c||{},f=b.length;let g="",h="",l="",m=!1;c&&!c.deps&&(c.deps=[]);for(let n=0;n<f;n+=2){const k=b[n],p=b[n+1];"attribute"===k?"src="===p.slice(0,4).toLowerCase()?(h=p.slice(5,-1),m="jeti"===h.slice(-4)||"jeti/index.js"===h.slice(-13)):"type="===p.slice(0,5).toLowerCase()&&(l=p.slice(6,-1).toLowerCase()):"content-script"===k&&(g=p)}if("application/jet"===l){if(!h&&!g)return[a,""];c&&(!h&&e&&(b=c.deps.map(n=>n.path),h=y(d,e,"js",b)),c.deps.push({content:g,
|
|
12
12
|
path:h}));return[a,'<script src="'+z("/",h)+'">\x3c/script>']}return m?[a,""]:[a,b.filter((n,k)=>1===k%2).join("")]}function N(a){return[a," "]}function V(a,b){u({path:b});a=v(a,L,S);r();return a}class W extends Promise{config(a){return this.then(b=>{Object.assign(b.config,a);return b})}save(a,b){return this.then(c=>X(a,c,b))}}
|
|
13
13
|
function X(a,b,c){const d=b.fragments;(c||{}).remove&&w(a)&&q.rmSync(a,{recursive:!0});Object.keys(d).forEach(e=>{const f=d[e].content;e=z(a,e);const g=(new C(e)).folder;w(g)||q.mkdirSync(g,{recursive:!0});q.writeFileSync(e,f)});return b}
|
|
14
|
-
class aa{constructor(a,b,c,d){({resolve:d}=d||{});this.content=c||"";this.deps=[];this.root=this.path=this.name=this.module=this.
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
class aa{constructor(a,b,c,d){({resolve:d}=d||{});this.content=c||"";this.deps=[];this.root=this.path=this.name=this.module=this.a=this.location=null;if(d)if(c=a.root,d=new C(b),B(d)||0<d.b.length&&("."===d.b[0]||".."===d.b[0])){d=z(c,b);d=x(d)?b.slice(1):null;if(!d){{d=c;const f=B(new C(d));var e=z(f?"":".",d,b);if(e=A(e)){const g=process.cwd().replace(/\\/g,"/");d=f?d:z(g,d);d=e.slice(d.length)}else d=null}}if(this.path=d)this.root=c}else{a:{if(c=A(b,{paths:[c]})){const [f,g]=ba(c);if(g){d=require(g);
|
|
15
|
+
c=[d.name+"@"+d.version,f,c.slice(f.length)];break a}}c=null}c&&([this.module,this.root,this.path]=c)}else this.path="/"+b,this.root=a.root;if(this.path)this.name=z(this.module||a.name,this.path),this.location=z(this.root,this.path),this.path="."+this.path,a=new C(this.path),this.folder=a.folder,this.a=a.a();else throw Error("Cannot find "+b);}load(){this.content||(this.content=q.readFileSync(this.location,"utf8"))}parse(){if("text/html"===this.a){var a=this.content;var b=u({folder:this.root,name:(new C(this.path)).name});
|
|
16
|
+
a=v(a,L,S);r();b=[a,b.deps];[this.content,this.deps]=b}else F(this.a)&&(a=this.content,b=u({folder:this.folder}),a=v(a),r(),b=[a,b.deps],[this.content,this.deps]=b)}c(){return{content:this.content,deps:this.deps,a:this.a}}translate(a){if(F(this.a)){var b=this.content;u({aliases:a});a=v(b,M,U);r();this.content=a}}}function ba(a){a=a.split("/");let b="";a.pop();a=a.map(d=>{d=b+d;b=d+"/";return[d,d+"/package.json"]}).reverse();const c=a.length;for(let d=0;d<c;d++)if(x(a[d][1]))return a[d];return[]}
|
|
17
|
+
class ca{constructor(a,b){this.aliases={};this.name=a;this.root=b}get(a){return this.aliases[a]}set(a,b){this.aliases[a]=b}}class da{create(a,b){return this[a]=new ca(a,b)}get(a){return this[a]}}
|
|
18
18
|
function Y(a,b,c,d,e){const f=a.config,g=a.fragments,h=a.modules,l=a.namespaces;({resolve:e}=e||{});d=new aa(b,c,d,{resolve:e});e=d.name;var m=f&&f["module-name"];f&&f.externs&&-1<f.externs.indexOf(c)?e=c:!(f&&f.entries&&-1<f.entries.indexOf(c))&&m&&(e=m+"/"+("./"===e.slice(0,2)?e.slice(2):e));b.set(c,e);if(!g[e]&&!h[e]){m=!1;d.load();E(d.content)?(e=c,b.set(c,e)):"jete"===c||d.parse();if(-1<d.root.indexOf("node_modules/")){h[e]={};c=d.root;const k=d.module;k&&(b=l.get(k)||l.create(k,c))}else g[e]=
|
|
19
|
-
{};const n=[];d.deps.length&&(m=!0,d.deps.forEach(k=>{if(!(f&&f.externs&&-1<f.externs.indexOf(k))||f&&f["include-externs"]){var p=null;"string"===typeof k?(p=b.get(k))||(p=Y(a,b,k,"",{resolve:!0})):k&&k.path&&(p=Y(a,b,k.path,k.content));n.push(p)}}),d.deps=n);m&&d.translate(b.aliases);-1<d.root.indexOf("node_modules/")?h[e]=d.
|
|
20
|
-
class ea{constructor(a,b,c){this.content=[];this.deps=c;this.name=a;this.
|
|
21
|
-
|
|
22
|
-
function Z(a,b){var c=a.config;const d=a.c;var e=a.modules;const f=a.register,g=c.root;e=a.fragments[b]||e[b];if(!e)throw Error("Fragment not found "+b);var h=e.deps;const l=e.mimeType;if(!f.has(l,b)){const m=d.get(l)||d.create(b,l,"text/html"===l?h:[]),n=m.name===b&&F(l);c=c&&c["module-name"];if(F(l)){const k=n&&c?c:b;e.content=E(e.content)?e.content.slice(13):"require('"+k+"', function(module, exports) {\n"+e.content+"});\n"}n&&!c&&m.content.push("(function(){function e(b,a){if('function'===typeof a)b=d[b]=a;else{a=d[b];if('function'===typeof a){{const c={exports:{}};a(c,c.exports);a=c}a=d[b]=a}b=a?a.exports:null}return b}const d={};e.load=function(b){const a=b.indexOf('.css')===b.length-4?'style':'script';return fetch(b).then(c=>200===c.status?c.text():'').then(c=>{if(c){const f=document.createElement(a);f.appendChild(document.createTextNode(c));document.head.appendChild(f)}})};'object'!==typeof window||window.require||(window.require=e)})();\n");
|
|
19
|
+
{};const n=[];d.deps.length&&(m=!0,d.deps.forEach(k=>{if(!(f&&f.externs&&-1<f.externs.indexOf(k))||f&&f["include-externs"]){var p=null;"string"===typeof k?(p=b.get(k))||(p=Y(a,b,k,"",{resolve:!0})):k&&k.path&&(p=Y(a,b,k.path,k.content));n.push(p)}}),d.deps=n);m&&d.translate(b.aliases);-1<d.root.indexOf("node_modules/")?h[e]=d.c():g[e]=d.c()}return e}
|
|
20
|
+
class ea{constructor(a,b,c){this.content=[];this.deps=c;this.name=a;this.a=b}c(){const a=this.deps,b=this.a;return{content:this.content.join(""),deps:a,a:b}}}class fa{constructor(){this.all=[]}close(a){this[a]&&delete this[a]}create(a,b,c){this[b]=new ea(a,b,c);this.all.push(this[b]);return this[b]}get(a){return this[a]}getAll(){return this.all}}class ha{close(a){this[a]&&delete this[a]}get(a){this[a]||(this[a]={});return this[a]}has(a,b){return(this[a]||{})[b]}put(a,b){this.get(a)[b]=!0}}
|
|
21
|
+
function Z(a,b){var c=a.config;const d=a.f;var e=a.modules;const f=a.register,g=c.root;e=a.fragments[b]||e[b];if(!e)throw Error("Fragment not found "+b);var h=e.deps;const l=e.a;if(!f.has(l,b)){const m=d.get(l)||d.create(b,l,"text/html"===l?h:[]),n=m.name===b&&F(l);c=c&&c["module-name"];if(F(l)){const k=n&&c?c:b;e.content=E(e.content)?e.content.slice(13):"require('"+k+"', function(module, exports) {\n"+e.content+"});\n"}n&&!c&&m.content.push("(function(){function e(b,a){if('function'===typeof a)b=d[b]=a;else{a=d[b];if('function'===typeof a){{const c={exports:{}};a(c,c.exports);a=c}a=d[b]=a}b=a?a.exports:null}return b}const d={};e.load=function(b){const a=b.indexOf('.css')===b.length-4?'style':'script';return fetch(b).then(c=>200===c.status?c.text():'').then(c=>{if(c){const f=document.createElement(a);f.appendChild(document.createTextNode(c));document.head.appendChild(f)}})};'object'!==typeof window||window.require||(window.require=e)})();\n");
|
|
23
22
|
f.put(l,b);h.forEach(k=>{"text/html"===l&&(f.close("application/javascript"),d.close("application/javascript"));Z(a,k)});F(l)&&n&&0===Object.keys(f["text/html"]||{}).length&&(h=d.get("text/css"))&&D(g,b,h);if("text/html"===l&&(h=d.get("text/css"))){const {href:k,filename:p}=D(g,b,h);e.content=V(e.content,k);m.deps.push(p)}m.content.push(e.content);n&&!c&&m.content.push("'object'===typeof window&&window.addEventListener('DOMContentLoaded',function(){require('"+b+"')});\n")}}
|
|
24
|
-
function ia(a,b,c){const d=c[b];if(!F(d.
|
|
25
|
-
module.exports={compress:function(a){const b=a.fragments;Object.keys(b).forEach(c=>{c=b[c];const d=c.content,e=c.
|
|
26
|
-
d.map(f=>ia(e,f,c));return a},pack:function(a){const b=a.config.entries,c=new fa,d=new ha;a.
|
|
23
|
+
function ia(a,b,c){const d=c[b];if(!F(d.a))throw Error("Entry must be a JavaScript to make a module");Object.keys(c).forEach(e=>{const f=c[e],g=f.content;"text/css"===f.a&&(d.content="if('object'===typeof document){const a=document.createElement('style');"+(a?"a.id='"+a+"';":"")+"a.appendChild(document.createTextNode('"+g.replace(/\\/g,"\\\\").replace(/[']/g,"\\'")+"'));document.head.appendChild(a);}"+d.content,delete c[e])});d.content="'jet module';"+d.content}
|
|
24
|
+
module.exports={compress:function(a){const b=a.fragments;Object.keys(b).forEach(c=>{c=b[c];const d=c.content,e=c.a;if(F(e)||"text/css"===e)c.content=v(d,"text/css"===e?K:J,P).trim()});return a},entry:function(a){return new W((b,c)=>{try{const {filename:d,folder:e}=new C(a),f={config:{root:z(process.cwd(),e),entries:[d]},fragments:{},modules:{}};b(f)}catch(d){c(d)}})},makemod:function(a){const b=a.config,c=a.fragments,d=b.entries,e=b&&b["module-name"];if(!e)throw Error("Config must include 'module-name' to make a module");
|
|
25
|
+
d.map(f=>ia(e,f,c));return a},pack:function(a){const b=a.config.entries,c=new fa,d=new ha;a.f=c;a.register=d;b.forEach(f=>Z(a,f));const e={};c.getAll().forEach(f=>{const g=f.name;g&&(e[g]=f.c())});a.fragments=e;a.modules={};delete a.f;delete a.register;return a},parse:function(a){const b=a.config,c=b.entries,d=new da,e=d.create(".",b.root);a.namespaces=d;b.entries=c.map(f=>Y(a,e,f));delete a.namespaces;return a}};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jetc",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.6",
|
|
4
4
|
"description": "Jet.js Compiler and Server.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -22,6 +22,6 @@
|
|
|
22
22
|
"author": "Oleksandr Krayilo",
|
|
23
23
|
"license": "ISC",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"jeti": "^0.8.
|
|
25
|
+
"jeti": "^0.8.4"
|
|
26
26
|
}
|
|
27
27
|
}
|