jetc 0.4.4 → 0.4.5
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/build.js +1 -1
- package/bin/server.js +7 -7
- package/index.js +17 -17
- package/license.txt +1 -1
- package/package.json +6 -4
package/bin/build.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
'use strict';const c=require("fs"),d=require("path"),{parser:e}=require("jeti"),f=d.join(process.cwd(),"./build.js");function g(){let a=null;try{const b=c.readFileSync(f,"utf8"),h="(function() {\nconst module = {exports: {}};\nlet exports = module.exports;\n"+e(b)+"return module.exports;})()";a=eval(h)}catch(b){console.error(b),process.exit(1)}return a&&a.default||a}require.main===module&&c.existsSync(f)&&g()();
|
|
2
|
+
'use strict';const c=require("fs"),d=require("path"),{parser:e}=require("jeti"),f=d.join(process.cwd(),process.argv[2]||"./build.js");function g(){let a=null;try{const b=c.readFileSync(f,"utf8"),h="(function() {\nconst module = {exports: {}};\nlet exports = module.exports;\n"+e(b)+"return module.exports;})()";a=eval(h)}catch(b){console.error(b),process.exit(1)}return a&&a.default||a}require.main===module&&c.existsSync(f)&&g()();
|
package/bin/server.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
'use strict';function
|
|
3
|
-
function
|
|
4
|
-
function
|
|
5
|
-
(c=c[c.length-1],a[c])?{"Content-Type":a[c]}:null}const
|
|
6
|
-
function
|
|
7
|
-
|
|
8
|
-
|
|
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 A(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])?{"Content-Type":a[c]}:null}const n=require("fs"),B=require("http");function C(){var a=process.argv;let c=!1,b="",f=3E3;const g=a.length;for(let k=2;k<g;k++){const d=a[k];d.startsWith("--port=")?f=parseInt(d.slice(7),10):"--all"===d?c=!0:k===g-1&&(b=d)}return{a:c,folder:b,port:f}}function D(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}
|
|
6
|
+
function E(){const {a,folder:c,port:b}=C(),f=B.createServer((g,k)=>{{var d=g.url.split("?")[0];var e=process.cwd().replace(/\\/g,"/");var m=c?t(e,c):e,p=t(m,"index.html");const q=t(m,d),y=t(q,"index.html");var h="";e="";if(r(q))h=q,e=d;else if(r(y))h=y,e=t(d,"index.html");else if(0===d.indexOf("/node_modules/")){if(d=d.split("/node_modules/"),p=D(m),m=d.pop(),p&&m&&(h=t(p,d.join("/node_modules/")),h=u(m,{paths:[h]})))d=h.split("/node_modules/"),d[0]="",e=d.join("/node_modules/")}else(h=u(t(".",d),
|
|
7
|
+
{paths:[m]}))?e=h.slice(m.length):(h=u(d.slice(1),{paths:[m]}))&&(e=t("/node_modules/",h.split("/node_modules/").pop())),h||!a||1<d.split("/").pop().split(".").length||!r(p)||(h=p,e=t("/index.html"));e={filename:h,location:e}}const {filename:z,location:x}=e;e="";if(z){try{e=n.readFileSync(z,"binary")}catch(q){e=q;g=g.url;k.writeHead(500,A(".txt"));k.write(e+"\n");k.end();console.log(w(),g+" "+v(31,500));return}g=g.url;h=Object.assign({},{Location:x},A(x),{"Cache-Control":"max-age=0, no-cache, must-revalidate, proxy-revalidate",
|
|
8
|
+
Expires:"Thu, 01 Jan 1970 00:00:00 GMT","Last-Modified":(new Date).toUTCString()});k.writeHead(200,h);k.write(e,"binary");k.end();console.log(w(),g+" 200 "+e.length+" "+x)}else g=g.url,k.writeHead(404,A(".txt")),k.write("404 Not Found\n"),k.end(),console.log(w(),g+" "+v(31,404))});f.on("error",g=>console.error(g));f.listen(b,"localhost");console.log("Development server is running at http://localhost:"+b+"/\nPress Ctrl + C to shutdown.\n")}require.main===module&&E();
|
package/index.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
'use strict';const
|
|
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
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}
|
|
3
|
-
class B{constructor(a){this.path=a;this.a=this.path.split("/");this.
|
|
3
|
+
class B{constructor(a){this.path=a;this.a=this.path.split("/");this.g=this.a.pop();this.folder=this.a.join("/");this.ext=this.name=null;a=this.g.split(".");this.ext=1<a.length&&(a[0]||2<a.length)?a.pop():"";this.name=a.join(".")}b(){return 0===this.a.length||-1===["",".",".."].indexOf(this.a[0])}mimeType(){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 C(a){return"application/javascript"===a}
|
|
5
5
|
const D={comment:"less exclamation dash dash *!(dash dash more) dash dash more","single-string":"single-quote *((escape any) | !single-quote) single-quote","double-string":"double-quote *((escape any) | !double-quote) double-quote",string:"single-string | double-string","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)",
|
|
6
6
|
"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)","start-head":"less head tag-body more","end-head":"less slash head more","content-head":"*(tag-script | !end-head)","start-script":"less script tag-body more","end-script":"less slash script more","content-script":"*!end-script","tag-head":"start-head content-head end-head","tag-script":"start-script content-script end-script",tag:"tag-head | tag-script | any-tag",
|
|
7
7
|
grammar:"*(tag | comment | any)"},E={"single-comment":"slash slash *!end-line end-line","multi-comment":"slash star *!(star slash) star slash",comment:"single-comment | multi-comment","single-string":"single-quote *((escape any) | !single-quote) single-quote","double-string":"double-quote *((escape any) | !double-quote) double-quote","back-string":"back-quote *((escape any) | (dollar context) | !back-quote) back-quote",string:"single-string | double-string | back-string","import-source":"single-string | double-string",
|
|
8
8
|
"module-require":"require *space lparen import-source rparen",code:"module-require | comment | string",grammar:"*(code | any)"},H={attribute:null,"content-head":null,"content-script":null,"end-head":null,"start-head":null,"tag-head":F,"tag-script":G},J={"import-source":null,"module-require":I};
|
|
9
|
-
function F(a,b){var c=
|
|
10
|
-
function I(a,b){const c=
|
|
11
|
-
function G(a,b){const c=
|
|
12
|
-
'<script src="'+
|
|
13
|
-
class M{constructor(a,b,c){this.content=
|
|
14
|
-
|
|
15
|
-
"utf8"))}parse(){if("text/html"===this.mimeType){var a=this.content,b=this.request;var c=u(this.root);c.name=(new B(b)).name;a=v(a,D,H);
|
|
16
|
-
function N(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[]}class O{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 P{create(a,b){return this[a]=new O(a,b)}get(a){return this[a]}}
|
|
17
|
-
function Q(a,b,c,d){const
|
|
18
|
-
class R{constructor(a,b,c){this.content=[];this.deps=c;this.name=a;this.mimeType=b}
|
|
19
|
-
class T{constructor(){this["application/javascript"]=this.
|
|
20
|
-
function U(a,b){const c=a.
|
|
21
|
-
|
|
22
|
-
module.exports={entry:function(a){return new L((b,c)=>{try{const {
|
|
23
|
-
return a}};
|
|
9
|
+
function F(a,b){var c=t(),{href:d}=c||{};c=' <link href="'+z("/",d)+'" rel="stylesheet">\n ';const e=b.length;let f="",g="",h="";if(d){for(d=0;d<e;d+=2){const k=b[d],n=b[d+1];"start-head"===k?g=n:"end-head"===k?h=n:"content-head"===k&&(f=n)}return[a,g+f+c+h]}return[a,b.filter((k,n)=>1===n%2).join("")]}
|
|
10
|
+
function I(a,b){const c=t(),{aliases:d}=c||{},e=b.length;let f=null;for(let g=0;g<e;g+=2){const h=b[g+1];"import-source"===b[g]&&(c?(f=h.slice(1,-1),f=d[f]||f,f=h[0]+f+h[h.length-1]):f=h)}return[a,"require("+f+")"]}
|
|
11
|
+
function G(a,b){const c=t(),{folder:d,name:e}=c||{},f=b.length;let g="",h="",k="",n=!1;c&&!c.deps&&(c.deps=[]);for(let l=0;l<f;l+=2){const m=b[l],p=b[l+1];"attribute"===m?"src="===p.slice(0,4).toLowerCase()?(h=p.slice(5,-1),n="jeti"===h.slice(-4)||"jeti/index.js"===h.slice(-13)):"type="===p.slice(0,5).toLowerCase()&&(k=p.slice(6,-1).toLowerCase()):"content-script"===m&&(g=p)}if("application/jet"===k){if(!h&&!g)return[a,""];c&&(!h&&e&&(b=c.deps.map(l=>l.request),h=y(d,e,"js",b)),c.deps.push({content:g,
|
|
12
|
+
request:h}));return[a,'<script src="'+z("/",h)+'">\x3c/script>']}return n?[a,""]:[a,b.filter((l,m)=>1===m%2).join("")]}function K(a,b){u().href=b;a=v(a,D,H);r();return a}class L extends Promise{config(a){return this.then(b=>{Object.assign(b.config,a);return b})}save(a){return this.then(b=>{{const c=b.fragments;w(a)&&q.rmSync(a,{recursive:!0});for(let d in c){const e=c[d].content,f=z(a,d),g=(new B(f)).folder;w(g)||q.mkdirSync(g,{recursive:!0});q.writeFileSync(f,e)}}return b})}}
|
|
13
|
+
class M{constructor(a,b,c,d){this.f=null;this.config=a;this.content=d;this.deps=[];this.root=this.request=this.path=this.name=this.module=this.mimeType=null;if("undefined"===typeof this.content)if(a=b.root,d=new B(c),!d.b()){d=z(a,c);d=x(d)?c.slice(1):null;if(!d){d=a;var e=new B(d);e=0<e.a.length&&""===e.a[0];var f=z(e?"":".",d,c);if(f=A(f)){const g=process.cwd().replace(/\\/g,"/");d=e?d:z(g,d);d=f.slice(d.length)}else d=null}if(this.request=d)this.root=a}else{if(d.b()){a:{if(a=A(c,{paths:[a]})){const [g,
|
|
14
|
+
h]=N(a);if(h){d=require(h);a=[d.name+"@"+d.version,g,a.slice(g.length)];break a}}a=null}a&&([this.module,this.root,this.request]=a)}}else this.request="/"+c,this.root=b.root;if(this.request)this.name=z(this.module||b.name,this.request),this.config.namespace&&(this.f=this.config.namespace+":"+("./"===this.name.slice(0,2)?this.name.slice(2):this.name)),this.path=z(this.root,this.request),this.request="."+this.request,b=new B(this.request),this.folder=b.folder,this.mimeType=b.mimeType();else throw Error("Cannot find "+
|
|
15
|
+
c);}b(){return-1<this.root.indexOf("node_modules/")}load(){this.content||(this.content=q.readFileSync(this.path,"utf8"))}parse(){if("text/html"===this.mimeType){var a=this.content,b=this.request;var c=u(this.root);c.name=(new B(b)).name;a=v(a,D,H);r();c=[a,c.deps];[this.content,this.deps]=c}else C(this.mimeType)&&(a=this.content,c=u(this.folder),a=v(a),r(),c=[a,c.deps],[this.content,this.deps]=c)}c(){return{content:this.content,deps:this.deps,mimeType:this.mimeType}}translate(a){if(C(this.mimeType)){var b=
|
|
16
|
+
this.content;u().aliases=a;a=v(b,E,J);r();this.content=a}}}function N(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[]}class O{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 P{create(a,b){return this[a]=new O(a,b)}get(a){return this[a]}}
|
|
17
|
+
function Q(a,b,c,d){const e=a.config,f=a.fragments,g=a.modules,h=a.namespaces;d=new M(e,b,c,d);const k=e.externs&&e.externs.indexOf(c)+1?c:d.f||d.name;b.set(c,k);if(!f[k]&&!g[k]){let n=!1;d.load();"jete"!==c&&d.parse();if(d.b()){g[k]={};c=d.module;const m=d.root;c&&(b=h.get(c)||h.create(c,m))}else f[k]={};const l=[];d.deps.length&&(n=!0,d.deps.forEach(m=>{if(!(e.module&&e.externs&&e.externs.indexOf(m)+1)){var p=null;"string"===typeof m?(p=b.get(m))||(p=Q(a,b,m)):m&&m.request&&(p=Q(a,b,m.request,m.content));
|
|
18
|
+
l.push(p)}}),d.deps=l);n&&d.translate(b.aliases);d.b()?g[k]=d.c():f[k]=d.c()}return k}class R{constructor(a,b,c){this.content=[];this.deps=c;this.name=a;this.mimeType=b}c(){const a=this.deps,b=this.mimeType;return{content:this.content.join(""),deps:a,mimeType:b}}}class S{constructor(){this.all=[]}close(a){delete this[a]}create(a,b,c){this[b]=new R(a,b,c);this.all.push(this[b]);return this[b]}get(a){return this[a]}getAll(){return this.all}}
|
|
19
|
+
class T{constructor(){this["application/javascript"]=this.i={}}close(a){delete this[a]}get(a){this[a]||(this[a]={});return this[a]}has(a,b){a=this.get(a);return this.i[b]||a[b]}put(a,b){this.get(a)[b]=!0}}
|
|
20
|
+
function U(a,b){const c=a.config,d=a.h;var e=a.modules;const f=a.register;var g=c.root;e=a.fragments[b]||e[b];if(!e)throw Error("Fragment not found "+b);var h=e.deps;const k=e.mimeType;if(!f.has(k,b)){const l=d.get(k)||d.create(b,k,"text/html"===k?h:[]);C(k)&&(e.content="require('"+b+"', function(module, exports) {\n"+e.content+"});\n",f["application/javascript"]!==f.i||l.name!==b||c.module||l.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=>c.text()).then(c=>{{const f=document.createElement(a);f.appendChild(document.createTextNode(c));document.head.appendChild(f)}})};'object'!==typeof window||window.require||(window.require=e)})();\n"));
|
|
21
|
+
f.put(k,b);h.forEach(m=>{var p;if(p="text/html"===k)p=0!==Object.keys(f["application/javascript"]).length;p&&(f.close("application/javascript"),d.close("application/javascript"));U(a,m)});if("text/html"===k&&(h=d.get("text/css"))){var {name:n}=new B(b);g=y(g,n,"css");n=z(".",g);e.content=K(e.content,g);l.deps.push(n);h.name=n}l.content.push(e.content);C(k)&&l.name===b&&!c.module&&l.content.push("'object'===typeof window&&window.addEventListener('DOMContentLoaded',function(){require('"+b+"')});\n")}}
|
|
22
|
+
module.exports={entry:function(a){return new L((b,c)=>{try{const {g:d,folder:e}=new B(a),f={config:{root:z(process.cwd(),e),entries:[d]},fragments:{},modules:{}};b(f)}catch(d){c(d)}})},pack:function(a){const b=a.config.entries,c=new S,d=new T;a.h=c;a.register=d;b.forEach(f=>U(a,f));const e={};c.getAll().forEach(f=>{const g=f.name;g&&(e[g]=f.c())});a.fragments=e;a.modules={};delete a.h;delete a.register;return a},parse:function(a){const b=a.config,c=b.entries,d=new P,e=d.create(".",b.root);a.namespaces=
|
|
23
|
+
d;b.entries=c.map(f=>Q(a,e,f,""));delete a.namespaces;return a}};
|
package/license.txt
CHANGED
package/package.json
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jetc",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.5",
|
|
4
4
|
"description": "Jet.js Compiler and Server.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"postinstall": "node postinstall"
|
|
7
|
+
"postinstall": "node postinstall",
|
|
8
|
+
"start": "jetc-server",
|
|
9
|
+
"build": "jetc-build"
|
|
8
10
|
},
|
|
9
11
|
"files": [
|
|
10
12
|
"bin/",
|
|
@@ -20,6 +22,6 @@
|
|
|
20
22
|
"author": "Oleksandr Krayilo",
|
|
21
23
|
"license": "ISC",
|
|
22
24
|
"dependencies": {
|
|
23
|
-
"jeti": "^0.
|
|
25
|
+
"jeti": "^0.8.0"
|
|
24
26
|
}
|
|
25
|
-
}
|
|
27
|
+
}
|