Commit fa381086 by Иван Кубота

halfway

parent 4ae2b78d
......@@ -24,24 +24,26 @@ var cache = {};
const serveBundle = async function(tpl, res){
var fileName = dir(pack.src, pack.entry.js);
var posixName = path.posix.join(pack.src, pack.entry.js);
console.log(fileName)
fs.readFile(fileName, function(err, data) {
fs.readFile(fileName, function(err, jsx) {
if(err){
return res.end(err.message);
}
const cacheEntry = +new Date()+'_'+Math.random().toString(36).substr(2)
const cacheEntry = posixName;//+new Date()+'_'+Math.random().toString(36).substr(2)
res.end(tpl
.replace('$DATA$', JSON.stringify(data))
.replace('$BUNDLE$',
'<script src="'+cacheEntry+'.js"></script>')
'<script src="'+cacheEntry+'"></script>')
);
transformJSX(data+'', path.join(pack.src, pack.entry.js), function(err, result) {
transformJSX(jsx+'', path.posix.join(pack.src, pack.entry.js), function(err, result) {
debugger
if(err){
console.error(err)
cache[ '/' + cacheEntry + '.js' ] = JSON.stringify(err, null,2);
cache[ '/' + cacheEntry ] = JSON.stringify(err, null,2);
}else
cache['/'+cacheEntry+'.js'] = result.code;
cache['/'+cacheEntry] = result.code;
});
});
......@@ -50,7 +52,7 @@ const serveBundle = async function(tpl, res){
var path = require('path');
var bCore = require( "@babel/core" );
var b = require('@babel/plugin-transform-modules-amd')
var transformJSX = function(code, fileName, cb) {
bCore.transform(
code,
......@@ -61,11 +63,22 @@ var transformJSX = function(code, fileName, cb) {
"pragmaFrag": "D.f", // default is React.Fragment
"throwIfNamespace": false // defaults to true
} ],
["babel-plugin-async-import"]
//["@babel/plugin-transform-modules-commonjs"]
['@babel/plugin-transform-modules-amd']
/* ["@babel/plugin-transform-modules-commonjs", { "synchronousImport": true }],
['func-wrap', {
/!* use a named export *!/
name: 'library',
/!* assign arguments to the function *!/
args: ['fileName="'+fileName+'"'],
/!* export as CommonJS *!/
format: 'cjs'
}]*/
],
sourceMaps: 'both',
sourceFileName: fileName
sourceFileName: fileName,
moduleId: fileName
}, function( c, d, e ){
if(c){
cb(c);
......@@ -135,9 +148,9 @@ var transformServe = function(dir) {
};
app.use(transformServe('public'));
app.use(App.static(dir(pack.public)))
var lives = [];
app.use('/', function(req, res, next) {
console.log(req.originalUrl)
if(req.originalUrl === '/'){
fs.readFile(dir(pack.src, pack.entry.html), function(err, data) {
if(err){
......@@ -153,9 +166,14 @@ app.use('/', function(req, res, next) {
}else{
if(req.originalUrl in cache){
res( cache[ req.originalUrl ] );
}else{
next();
}
}
});
app.use(App.static(dir(pack.public)))
app.use(App.static(dir(pack.src)))
......
......@@ -19,8 +19,10 @@
},
"devDependencies": {
"@babel/core": "^7.8.3",
"@babel/plugin-transform-modules-amd": "^7.8.3",
"@babel/plugin-transform-react-jsx": "^7.8.3",
"babel-plugin-async-import": "ssh://git@github.com:bernardmcmanus/babel-plugin-async-import.git"
"babel-plugin-async-import": "ssh://git@github.com:bernardmcmanus/babel-plugin-async-import.git",
"babel-plugin-func-wrap": "^1.1.0"
},
"plugins": [
"@babel/plugin-transform-react-jsx"
......
;(function() {
'use strict';
var splitPathRe =
/^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;
var Path = {
dirname: function(path) {
var result = Path.posixSplitPath(path),
root = result[0],
dir = result[1];
if (!root && !dir) {
// No dirname whatsoever
return '.';
}
if (dir) {
// It has a dirname, strip trailing slash
dir = dir.substr(0, dir.length - 1);
}
return root + dir;
},
resolve: function() {
var resolvedPath = '',
resolvedAbsolute = false;
for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
var path = (i >= 0) ? arguments[i] : '/';
// Skip empty and invalid entries
if (typeof path !== 'string') {
throw new TypeError('Arguments to path.resolve must be strings');
} else if (!path) {
continue;
}
resolvedPath = path + '/' + resolvedPath;
resolvedAbsolute = path[0] === '/';
}
// At this point the path should be resolved to a full absolute path, but
// handle relative paths to be safe (might happen when process.cwd() fails)
// Normalize the path
resolvedPath = Path.normalizeArray(resolvedPath.split('/'),
!resolvedAbsolute).join('/');
var result = ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.';
if(result[0]==='/')
return result.substr(1);
return result;
},
normalizeArray: function(parts, allowAboveRoot) {
var res = [];
for (var i = 0; i < parts.length; i++) {
var p = parts[i];
// ignore empty parts
if (!p || p === '.')
continue;
if (p === '..') {
if (res.length && res[res.length - 1] !== '..') {
res.pop();
} else if (allowAboveRoot) {
res.push('..');
}
} else {
res.push(p);
}
}
return res;
},
join: function(){
var path = '';
for( var i = 0; i < arguments.length; i++ ){
var segment = arguments[ i ];
if( typeof segment !== 'string' ){
throw new TypeError( 'Arguments to path.join must be strings' );
}
if( segment ){
if( !path ){
path += segment;
}else{
path += '/' + segment;
}
}
}
return Path.normalize( path );
},
basename: function(path, ext) {
var f = Path.posixSplitPath(path)[2];
// TODO: make this comparison case-insensitive on windows?
if (ext && f.substr(-1 * ext.length) === ext) {
f = f.substr(0, f.length - ext.length);
}
return f;
},
posixSplitPath: function(filename) {
return splitPathRe.exec(filename).slice(1);
},
normalize: function( path ){
var isAbsolute = Path.isAbsolute( path ),
trailingSlash = path && path[ path.length - 1 ] === '/';
// Normalize the path
path = Path.normalizeArray( path.split( '/' ), !isAbsolute ).join( '/' );
if( !path && !isAbsolute ){
path = '.';
}
if( path && trailingSlash ){
path += '/';
}
return ( isAbsolute ? '/' : '' ) + path;
},
// posix version
isAbsolute: function( path ){
return path.charAt( 0 ) === '/';
}
};
var log = function() {
console.log.apply(console, ['Define'].concat([].slice.call(arguments)));
};
var head = document.getElementsByTagName('head')[0];
var cssLoader = function(fileName) {
var link = document.createElement('link');
link.setAttribute('rel', 'stylesheet');
link.setAttribute('type', 'text/css');
link.setAttribute('href', fileName);
head.appendChild(link);
};
var InstantLoaders = [
{name: '.scss', loader: cssLoader},
{name: '.css', loader: cssLoader},
];
var Ready = function() {}; Ready.prototype = {ready: true};
var Wait = function(fileName) {this.fileName = fileName; this.wait = [];};
Wait.prototype = {
fileName: '',
ready: false,
resolving: 0,
checkInstantLoad: function() {
for( var i = 0, _i = InstantLoaders.length; i < _i; i++ ){
const instantLoader = InstantLoaders[ i ];
if(this.fileName.substr(-instantLoader.name.length).toLowerCase()===instantLoader.name){
instantLoader.loader(this.fileName);
return true;
}
}
return false;
}
};
var wait = {
exports: Ready()
};
var defined = {
};
var resolve = function(base, file) {
return Path.resolve(Path.dirname(base), file);
};
var exec = function(def) {
var exports = {};
defined[def.fileName] = def.fn.apply(null, def.deps.map(function(dep) {
if(dep === 'exports'){
return exports;
}
return defined[resolve(def.fileName, dep)];
}));
wait[def.fileName] = new Ready();
for( var i = 0, _i = wait.length; i < _i; i++ ){
var waitElement = wait[ i ];
waitElement.resolving--;
}
for( var i = 0, _i = wait.length; i < _i; i++ ){
if(waitElement.resolving === 0){
exec(waitElement.def)
}
}
};
window.define = function(fileName, deps, fn) {
defined[fileName] = {fileName:fileName, deps: deps, fn:fn};
var unresolved = deps.filter(function(dep) {
if(dep === 'exports'){
return false;
}
var resolvedName = resolve(fileName, dep);
var waiter = wait[resolvedName];
if(!wait[resolvedName]){
waiter = wait[resolvedName] = new Wait(resolvedName)
}
if(!waiter.ready){
waiter.wait.push( fileName );
if( waiter.checkInstantLoad() ){
wait[ resolvedName ] = new Ready();
}
}
return !wait[resolvedName].ready;
});
if(unresolved.length === 0){
log(fileName, 'deps fullfilled');
exec(defined[fileName])
}else{
log(fileName, 'is waiting for', unresolved);
var waiter = wait[fileName] = new Wait(fileName);
for( var i = 0, _i = unresolved.length; i < _i; i++ ){
var unresolvedElement = unresolved[ i ];
waiter.wait.push(resolve(fileName, unresolvedElement));
waiter.resolving++;
}
}
};
})();
\ No newline at end of file
......@@ -3,6 +3,7 @@
<head>
<title>Category mapper</title>
<meta charset="utf-8" />
<script src="controller/require.js"></script>
<script src="livest-reloading.js"></script>
<script src="js/releasable-observer.js"></script>
......@@ -55,6 +56,15 @@
<link type="text/css" rel="stylesheet" href="src/main.css">-->
</head>
<body>
<script>initDataProvider($DATA$);init();</script>
<script>
initDataProvider($DATA$);
debugger
define('begin', ['src/main.jsx'], function(main) {
debugger
main();
});
</script>
</body>
</html>
\ No newline at end of file
data = null;
import './main.scss';
import {a,b} from './js/pcg-dom-util'
a(3)
const init = function() {
export default function() {
let tagField, exportEl;
div({
......
......@@ -140,6 +140,15 @@
dependencies:
"@babel/helper-plugin-utils" "^7.8.3"
"@babel/plugin-transform-modules-amd@^7.8.3":
version "7.8.3"
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-modules-amd/-/plugin-transform-modules-amd-7.8.3.tgz#65606d44616b50225e76f5578f33c568a0b876a5"
integrity sha512-MadJiU3rLKclzT5kBH4yxdry96odTUwuqrZM+GllFI/VhxfPz+k9MshJM+MwhfkCdxxclSbSBbUGciBngR+kEQ==
dependencies:
"@babel/helper-module-transforms" "^7.8.3"
"@babel/helper-plugin-utils" "^7.8.3"
babel-plugin-dynamic-import-node "^2.3.0"
"@babel/plugin-transform-modules-commonjs@^7.8.3":
version "7.8.3"
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-modules-commonjs/-/plugin-transform-modules-commonjs-7.8.3.tgz#df251706ec331bd058a34bdd72613915f82928a5"
......@@ -372,6 +381,11 @@ babel-plugin-dynamic-import-node@^2.3.0:
dependencies:
object.assign "^4.1.0"
babel-plugin-func-wrap@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/babel-plugin-func-wrap/-/babel-plugin-func-wrap-1.1.0.tgz#302e479eb9cc15ddb3db2c65f4b48a748b6e69a1"
integrity sha512-C6e8mUVg3c/o9LwGk3tYvRq8MlyZdqimtQHzcZdsb2nEywlOkmp3zlCllo8QAmcsnwSB30iEcZ6rr2AhhTwO3w==
balanced-match@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment