support both old system and imports in the pipeline
This commit is contained in:
parent
33711c8db2
commit
3d36aaaeb3
|
@ -227,7 +227,11 @@ Config.prototype.loadEmbarkConfigFile = function() {
|
|||
Config.prototype.loadPipelineConfigFile = function() {
|
||||
var assets = this.embarkConfig.app;
|
||||
for(var targetFile in assets) {
|
||||
this.assetFiles[targetFile] = this.loadFiles(assets[targetFile]);
|
||||
if (typeof(assets[targetFile]) === 'string' || (Array.isArray(assets[targetFile]) && (assets[targetFile].length === 1))) {
|
||||
this.assetFiles[targetFile] = this.loadFile(assets[targetFile]);
|
||||
} else {
|
||||
this.assetFiles[targetFile] = this.loadFiles(assets[targetFile]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -245,6 +249,101 @@ Config.prototype.loadChainTrackerFile = function() {
|
|||
this.chainTracker = chainTracker;
|
||||
};
|
||||
|
||||
Config.prototype.loadFile = function(files) {
|
||||
var self = this;
|
||||
var originalFiles = utils.filesMatchingPattern(files);
|
||||
var readFiles = [];
|
||||
|
||||
// get plugins
|
||||
var filesFromPlugins = [];
|
||||
|
||||
var filePlugins = self.plugins.getPluginsFor('pipelineFiles');
|
||||
|
||||
if (filePlugins.length > 0) {
|
||||
filePlugins.forEach(function(plugin) {
|
||||
try {
|
||||
var fileObjects = plugin.runFilePipeline();
|
||||
for (var i=0; i < fileObjects.length; i++) {
|
||||
var fileObject = fileObjects[i];
|
||||
filesFromPlugins.push(fileObject);
|
||||
}
|
||||
}
|
||||
catch(err) {
|
||||
self.logger.error(err.message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
filesFromPlugins.filter(function(file) {
|
||||
if (utils.fileMatchesPattern(files, file.intendedPath)) {
|
||||
readFiles.push(file);
|
||||
}
|
||||
});
|
||||
|
||||
// get user files
|
||||
originalFiles.filter(function(file) {
|
||||
return file.indexOf('.') >= 0;
|
||||
}).filter(function(file) {
|
||||
if (file === 'embark.js') {
|
||||
return;
|
||||
} else if (file.indexOf("web3-") === 0) {
|
||||
return;
|
||||
} else if (file.indexOf("web3") === 0) {
|
||||
return;
|
||||
//} else if (file === 'abi.js') {
|
||||
// readFiles.push({filename: file, content: "", path: file});
|
||||
} else {
|
||||
|
||||
if (file.indexOf('.js') >= 0) {
|
||||
//if (file.indexOf('.js') >= 0) {
|
||||
readFiles.push(new File({filename: file, type: "custom", path: file, resolver: function(callback) {
|
||||
console.log("---");
|
||||
console.log(fs.dappPath());
|
||||
console.log(file);
|
||||
console.log("---");
|
||||
webpack({
|
||||
entry: utils.joinPath(fs.dappPath(), file),
|
||||
output: {
|
||||
//libraryTarget: 'umd',
|
||||
path: utils.joinPath(fs.dappPath(), '.embark'),
|
||||
//filename: 'my-first-webpack.bundle.js'
|
||||
filename: file
|
||||
},
|
||||
externals: function(context, request, callback) {
|
||||
if (request == "MyLib") {
|
||||
console.log("MyLib Detected!");
|
||||
return callback(null, "{foo: 'hello'}");
|
||||
}
|
||||
callback();
|
||||
},
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.css$/,
|
||||
use: [
|
||||
{ loader: "style-loader" },
|
||||
{ loader: "css-loader" }
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}).run((err, stats) => {
|
||||
console.log(err, stats);
|
||||
//return callback(fs.readFileSync('./.embark/my-first-webpack.bundle.js').toString());
|
||||
return callback(fs.readFileSync('./.embark/' + file).toString());
|
||||
});
|
||||
}}));
|
||||
} else {
|
||||
readFiles.push(new File({filename: file, type: "dapp_file", path: file}));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
return readFiles;
|
||||
};
|
||||
|
||||
Config.prototype.loadFiles = function(files) {
|
||||
var self = this;
|
||||
var originalFiles = utils.filesMatchingPattern(files);
|
||||
|
@ -335,55 +434,7 @@ Config.prototype.loadFiles = function(files) {
|
|||
//} else if (file === 'abi.js') {
|
||||
// readFiles.push({filename: file, content: "", path: file});
|
||||
} else {
|
||||
|
||||
if (file.indexOf('index.js') >= 0) {
|
||||
//if (file.indexOf('.js') >= 0) {
|
||||
readFiles.push(new File({filename: file, type: "custom", path: file, resolver: function(callback) {
|
||||
console.log("---");
|
||||
console.log(fs.dappPath());
|
||||
console.log(file);
|
||||
console.log("---");
|
||||
webpack({
|
||||
entry: utils.joinPath(fs.dappPath(), file),
|
||||
output: {
|
||||
//libraryTarget: 'umd',
|
||||
path: utils.joinPath(fs.dappPath(), '.embark'),
|
||||
//filename: 'my-first-webpack.bundle.js'
|
||||
filename: file
|
||||
},
|
||||
externals: function(context, request, callback) {
|
||||
if (request == "MyLib") {
|
||||
console.log("MyLib Detected!");
|
||||
return callback(null, "{foo: 'hello'}");
|
||||
}
|
||||
callback();
|
||||
},
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.css$/,
|
||||
use: [
|
||||
{ loader: "style-loader" },
|
||||
{ loader: "css-loader" }
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}).run((err, stats) => {
|
||||
console.log(err, stats);
|
||||
//return callback(fs.readFileSync('./.embark/my-first-webpack.bundle.js').toString());
|
||||
return callback(fs.readFileSync('./.embark/' + file).toString());
|
||||
});
|
||||
}}));
|
||||
} else {
|
||||
readFiles.push(new File({filename: file, type: "dapp_file", path: file}));
|
||||
}
|
||||
|
||||
//if (file.indexOf('.') >= 0) {
|
||||
// readFiles.push(new File({filename: file, type: "dapp_file", path: file}));
|
||||
//} else if (file[0] === '$') {
|
||||
// //readFiles.push(new File({filename: file, type: 'embark_internal', path: file}));
|
||||
//}
|
||||
readFiles.push(new File({filename: file, type: "dapp_file", path: file}));
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -1,12 +1,5 @@
|
|||
/*globals $, SimpleStorage, document*/
|
||||
|
||||
import Test2 from 'MyLib';
|
||||
|
||||
import test3 from './foo';
|
||||
import './foo.css';
|
||||
|
||||
window.test_3 = test3;
|
||||
|
||||
var addToLog = function(id, txt) {
|
||||
$(id + " .logs").append("<br>" + txt);
|
||||
};
|
||||
|
@ -15,9 +8,6 @@ var addToLog = function(id, txt) {
|
|||
// Blockchain example
|
||||
// ===========================
|
||||
$(document).ready(function() {
|
||||
console.log([1,2,3].map(v => v + 1));
|
||||
alert('hello');
|
||||
window.test_2 = Test2;
|
||||
|
||||
$("#blockchain button.set").click(function() {
|
||||
var value = parseInt($("#blockchain input.text").val(), 10);
|
||||
|
|
|
@ -0,0 +1,166 @@
|
|||
/*globals $, SimpleStorage, document*/
|
||||
|
||||
import $ from './_vendor/jquery.min';
|
||||
//import EmbarkJS from 'Embark/EmbarkJS';
|
||||
|
||||
import Test2 from 'MyLib';
|
||||
|
||||
import test3 from './foo';
|
||||
import './foo.css';
|
||||
|
||||
window.test_3 = test3;
|
||||
|
||||
var addToLog = function(id, txt) {
|
||||
$(id + " .logs").append("<br>" + txt);
|
||||
};
|
||||
|
||||
// ===========================
|
||||
// Blockchain example
|
||||
// ===========================
|
||||
$(document).ready(function() {
|
||||
console.log([1,2,3].map(v => v + 1));
|
||||
alert('hello');
|
||||
window.test_2 = Test2;
|
||||
|
||||
$("#blockchain button.set").click(function() {
|
||||
var value = parseInt($("#blockchain input.text").val(), 10);
|
||||
|
||||
// If web3.js 1.0 is being used
|
||||
if (EmbarkJS.isNewWeb3()) {
|
||||
SimpleStorage.methods.set(value).send({from: web3.eth.defaultAccount});
|
||||
addToLog("#blockchain", "SimpleStorage.methods.set(value).send({from: web3.eth.defaultAccount})");
|
||||
} else {
|
||||
SimpleStorage.set(value);
|
||||
addToLog("#blockchain", "SimpleStorage.set(" + value + ")");
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
$("#blockchain button.get").click(function() {
|
||||
// If web3.js 1.0 is being used
|
||||
if (EmbarkJS.isNewWeb3()) {
|
||||
SimpleStorage.methods.get().call(function(err, value) {
|
||||
$("#blockchain .value").html(value);
|
||||
});
|
||||
addToLog("#blockchain", "SimpleStorage.methods.get(console.log)");
|
||||
} else {
|
||||
SimpleStorage.get().then(function(value) {
|
||||
$("#blockchain .value").html(value.toNumber());
|
||||
});
|
||||
addToLog("#blockchain", "SimpleStorage.get()");
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
// ===========================
|
||||
// Storage (IPFS) example
|
||||
// ===========================
|
||||
$(document).ready(function() {
|
||||
// automatic set if config/storage.json has "enabled": true and "provider": "ipfs"
|
||||
//EmbarkJS.Storage.setProvider('ipfs',{server: 'localhost', port: '5001'});
|
||||
|
||||
$("#storage .error").hide();
|
||||
EmbarkJS.Storage.ipfsConnection.ping()
|
||||
.then(function(){
|
||||
$("#status-storage").addClass('status-online');
|
||||
$("#storage-controls").show();
|
||||
})
|
||||
.catch(function(err) {
|
||||
if(err){
|
||||
console.log("IPFS Connection Error => " + err.message);
|
||||
$("#storage .error").show();
|
||||
$("#status-storage").addClass('status-offline');
|
||||
$("#storage-controls").hide();
|
||||
}
|
||||
});
|
||||
|
||||
$("#storage button.setIpfsText").click(function() {
|
||||
var value = $("#storage input.ipfsText").val();
|
||||
EmbarkJS.Storage.saveText(value).then(function(hash) {
|
||||
$("span.textHash").html(hash);
|
||||
$("input.textHash").val(hash);
|
||||
addToLog("#storage", "EmbarkJS.Storage.saveText('" + value + "').then(function(hash) { })");
|
||||
})
|
||||
.catch(function(err) {
|
||||
if(err){
|
||||
console.log("IPFS saveText Error => " + err.message);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$("#storage button.loadIpfsHash").click(function() {
|
||||
var value = $("#storage input.textHash").val();
|
||||
EmbarkJS.Storage.get(value).then(function(content) {
|
||||
$("span.ipfsText").html(content);
|
||||
addToLog("#storage", "EmbarkJS.Storage.get('" + value + "').then(function(content) { })");
|
||||
})
|
||||
.catch(function(err) {
|
||||
if(err){
|
||||
console.log("IPFS get Error => " + err.message);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$("#storage button.uploadFile").click(function() {
|
||||
var input = $("#storage input[type=file]");
|
||||
EmbarkJS.Storage.uploadFile(input).then(function(hash) {
|
||||
$("span.fileIpfsHash").html(hash);
|
||||
$("input.fileIpfsHash").val(hash);
|
||||
addToLog("#storage", "EmbarkJS.Storage.uploadFile($('input[type=file]')).then(function(hash) { })");
|
||||
})
|
||||
.catch(function(err) {
|
||||
if(err){
|
||||
console.log("IPFS uploadFile Error => " + err.message);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$("#storage button.loadIpfsFile").click(function() {
|
||||
var hash = $("#storage input.fileIpfsHash").val();
|
||||
var url = EmbarkJS.Storage.getUrl(hash);
|
||||
var link = '<a href="' + url + '" target="_blank">' + url + '</a>';
|
||||
$("span.ipfsFileUrl").html(link);
|
||||
$(".ipfsImage").attr('src', url);
|
||||
addToLog("#storage", "EmbarkJS.Storage.getUrl('" + hash + "')");
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
// ===========================
|
||||
// Communication (Whisper) example
|
||||
// ===========================
|
||||
$(document).ready(function() {
|
||||
|
||||
$("#communication .error").hide();
|
||||
$("#communication .errorVersion").hide();
|
||||
if (EmbarkJS.Messages.providerName === 'whisper') {
|
||||
EmbarkJS.Messages.getWhisperVersion(function(err, version) {
|
||||
if (err) {
|
||||
$("#communication .error").show();
|
||||
$("#communication-controls").hide();
|
||||
$("#status-communication").addClass('status-offline');
|
||||
} else {
|
||||
EmbarkJS.Messages.setProvider('whisper');
|
||||
$("#status-communication").addClass('status-online');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$("#communication button.listenToChannel").click(function() {
|
||||
var channel = $("#communication .listen input.channel").val();
|
||||
$("#communication #subscribeList").append("<br> subscribed to " + channel + " now try sending a message");
|
||||
EmbarkJS.Messages.listenTo({topic: [channel]}).then(function(message) {
|
||||
$("#communication #messagesList").append("<br> channel: " + channel + " message: " + message);
|
||||
});
|
||||
addToLog("#communication", "EmbarkJS.Messages.listenTo({topic: ['" + channel + "']}).then(function(message) {})");
|
||||
});
|
||||
|
||||
$("#communication button.sendMessage").click(function() {
|
||||
var channel = $("#communication .send input.channel").val();
|
||||
var message = $("#communication .send input.message").val();
|
||||
EmbarkJS.Messages.sendMessage({topic: channel, data: message});
|
||||
addToLog("#communication", "EmbarkJS.Messages.sendMessage({topic: '" + channel + "', data: '" + message + "'})");
|
||||
});
|
||||
|
||||
});
|
|
@ -0,0 +1,107 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>Embark - SimpleStorage Demo</title>
|
||||
<link rel="stylesheet" href="css/app.css">
|
||||
<script src="js/new_app.js"></script>
|
||||
</head>
|
||||
<body class="container">
|
||||
<h3>Embark - Usage Example</h3>
|
||||
|
||||
<ul class="nav nav-tabs" role="tablist" id="myTabs">
|
||||
<li role="presentation" class="active"><a href="#blockchain" aria-controls="blockchain" role="tab" data-toggle="tab">Blockchain</a></li>
|
||||
<li role="presentation"><a href="#storage" aria-controls="storage" role="tab" data-toggle="tab">Decentralized Storage (IPFS)<span class="pull-right" id="status-storage"></a></li>
|
||||
<li role="presentation"><a href="#communication" aria-controls="communication" role="tab" data-toggle="tab">P2P communication (Whisper/Orbit)<span class="pull-right" id="status-communication"></span></a></li>
|
||||
</ul>
|
||||
|
||||
<div class="tab-content">
|
||||
<div role="tabpanel" class="tab-pane active" id="blockchain">
|
||||
<h3> 1. Set the value in the blockchain</h3>
|
||||
<div class="form-group form-inline">
|
||||
<input type="text" class="text form-control" value="10">
|
||||
<button class="set btn btn-primary">Set Value</button>
|
||||
<p>Once you set the value, the transaction will need to be mined and then the value will be updated on the blockchain.</p>
|
||||
</div>
|
||||
|
||||
<h3> 2. Get the current value</h3>
|
||||
<div class="form-group">
|
||||
<div>
|
||||
current value is <span class="value"></span>
|
||||
</div>
|
||||
<button class="get btn btn-primary">Get Value</button>
|
||||
<p>Click the button to get the current value. The initial value is 100.</p>
|
||||
</div>
|
||||
|
||||
<h3> 3. Contract Calls </h3>
|
||||
<p>Javascript calls being made: </p>
|
||||
<div class="logs">
|
||||
</div>
|
||||
</div>
|
||||
<div role="tabpanel" class="tab-pane" id="storage">
|
||||
<div class="error alert alert-danger" role="alert">The node you are using does not support IPFS. Please ensure <a href="https://github.com/ipfs/js-ipfs-api#cors" target="_blank">CORS</a> is setup for the IPFS node.</div>
|
||||
<div id="storage-controls">
|
||||
|
||||
<h3>Save text to IPFS</h3>
|
||||
<div class="form-group form-inline">
|
||||
<input type="text" class="ipfsText text form-control" value="hello world!">
|
||||
<button class="setIpfsText btn btn-primary">Save</button>
|
||||
<p>generated Hash: <span class="textHash"></span></p>
|
||||
</div>
|
||||
|
||||
<h3>Load text from IPFS given an hash</h3>
|
||||
<div class="form-group form-inline">
|
||||
<input type="text" class="textHash text form-control" size="60">
|
||||
<button class="loadIpfsHash set btn btn-primary">Load</button>
|
||||
<p>result: <span class="ipfsText"></span></p>
|
||||
</div>
|
||||
|
||||
<h3>upload file to ipfs</h3>
|
||||
<div class="form-group form-inline">
|
||||
<input type="file" class="form-control">
|
||||
<button class="uploadFile set btn btn-primary">upload</button>
|
||||
<p>generated hash: <span class="fileIpfsHash"></span></p>
|
||||
</div>
|
||||
|
||||
<h3>Get file or image from ipfs</h3>
|
||||
<div class="form-group form-inline">
|
||||
<input type="text" class="fileIpfsHash form-control" size="60">
|
||||
<button class="loadIpfsFile set btn btn-primary">Load</button>
|
||||
<p>file available at: <span class="ipfsFileUrl"></span></p>
|
||||
<p><img class="ipfsImage" src=""></p>
|
||||
</div>
|
||||
|
||||
<p>Javascript calls being made: </p>
|
||||
<div class="logs">
|
||||
<br> EmbarkJS.Storage.setProvider('ipfs',{server: 'localhost', port: '5001'})
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div role="tabpanel" class="tab-pane" id="communication">
|
||||
<div class="error alert alert-danger" role="alert">The node you are using does not support Whisper</div>
|
||||
<div class="errorVersion alert alert-danger" role="alert">The node uses an unsupported version of Whisper</div>
|
||||
<div id="communication-controls">
|
||||
<h3>Listen To channel</h3>
|
||||
<div class="form-group form-inline listen">
|
||||
<input type="text" class="channel text form-control" placeholder="channel">
|
||||
<button class="listenToChannel set btn btn-primary">Start Listening</button>
|
||||
<div id="subscribeList"></div>
|
||||
<p>messages received:<p>
|
||||
<div id="messagesList"></div>
|
||||
</div>
|
||||
|
||||
<h3>Send Message</h3>
|
||||
<div class="form-group form-inline send">
|
||||
<input type="text" class="channel text form-control" placeholder="channel">
|
||||
<input type="text" class="message text form-control" placeholder="message">
|
||||
<button class="sendMessage set btn btn-primary">Send Message</button>
|
||||
</div>
|
||||
|
||||
<p>Javascript calls being made: </p>
|
||||
<div class="logs">
|
||||
<br> EmbarkJS.Messages.setProvider('whisper')
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
|
@ -4,12 +4,14 @@
|
|||
"js/webpack_test.js": "app/js/index.js",
|
||||
"css/app.css": ["app/css/**"],
|
||||
"images/": ["app/images/**"],
|
||||
"js/app.js": ["embark.js", "app/js/_vendor/jquery.min.js", "app/js/_vendor/bootstrap.min.js", "app/js/**", "!app/js/test.js", "!app/js/foo.js", "!app/js/foo.css"],
|
||||
"js/app.js": ["embark.js", "app/js/_vendor/jquery.min.js", "app/js/_vendor/bootstrap.min.js", "app/js/**", "!app/js/test.js", "!app/js/foo.js", "!app/js/foo.css", "!app/js/new_index.js"],
|
||||
"js/new_app.js": ["app/js/new_index.js"],
|
||||
"js/embark.js": ["embark.js"],
|
||||
"js/abi.js": "abi.js",
|
||||
"js/test.js": ["embark.js", "app/js/_vendor/jquery.min.js", "app/js/_vendor/async.min.js", "app/js/test.js"],
|
||||
"js/mytoken.js": ["$MyToken", "app/js/token_test.js"],
|
||||
"index.html": "app/index.html",
|
||||
"new_index.html": "app/new_index.html",
|
||||
"test.html": "app/test.html",
|
||||
"test2.html": "app/test2.html",
|
||||
"js/myweb3.js": "web3-0.18.js",
|
||||
|
|
Loading…
Reference in New Issue