Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Client componentisation #3

Merged
merged 9 commits into from
Jan 28, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 32 additions & 5 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

var fs = require('fs-extra');
var path = require('path');
var semver = require('semver');
var uglifyJs = require('uglify-js');

module.exports = function(grunt) {
Expand Down Expand Up @@ -38,14 +39,40 @@ module.exports = function(grunt) {
// custom tasks
grunt.registerTask('build-web-client', 'Builds and minifies the web-client.js', function(){

var done = this.async();
var handlebars = fs.readFileSync(path.join(__dirname, 'registry/public/handlebars.1.3.0.js')).toString();
var ocClient = fs.readFileSync(path.join(__dirname, 'registry/public/oc-client.js')).toString();
var done = this.async(),
handlebars = fs.readFileSync(path.join(__dirname, 'components/oc-client/src/handlebars.1.3.0.js')).toString(),
ocClient = fs.readFileSync(path.join(__dirname, 'components/oc-client/src/oc-client.js')).toString(),
version = 'oc.clientVersion=\'' + taskObject.pkg.version + '\';',
bundle = handlebars + '\n' + ocClient + '\n' + version,
ocClientPackageInfo = require('./components/oc-client/package.json');

fs.writeFile(path.join(__dirname, 'registry/public/oc-client.min.js'), uglifyJs.minify(handlebars + '\n' + ocClient, {fromString: true}).code, function(err, res){
grunt.log.ok('Web-client created.');
ocClientPackageInfo.version = taskObject.pkg.version;

fs.writeJsonSync(path.join(__dirname, 'components/oc-client/package.json'), ocClientPackageInfo);
fs.writeFileSync(path.join(__dirname, 'components/oc-client/src/oc-client.min.js'), uglifyJs.minify(bundle, {fromString: true}).code);

var Local = require('./cli/domain/local'),
local = new Local();

local.package(path.join(__dirname, 'components/oc-client'), function(err, res){
grunt.log[!!err ? 'error' : 'ok'](!!err ? err : 'Client has been built and packaged');
done();
});
});

// used for version patching
grunt.registerTask('version', 'Does the version upgrade', function(versionType){

taskObject.pkg.version = semver.inc(taskObject.pkg.version, versionType);

grunt.log.ok('Package version upgrading to: ' + taskObject.pkg.version);

fs.writeJsonSync('package.json', taskObject.pkg);

grunt.task.run([
'test',
'build'
]);
});

};
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,11 @@ oc dev . 3030
Then you may want to create a blank html page to start playing with it and see how it looks:
```html
<html>
<head>
<script src="http://localhost:3030/scripts/oc-client.min.js"></script>
</head>
<body>
<oc-component href="http://localhost:3030/hello-world">
Optionally, some failover text here
</oc-component>
<script src="http://localhost:3030/oc-client/client.js" />
</body>
</html>
```
Expand Down Expand Up @@ -229,8 +227,8 @@ This is all you need:
<html>
<head></head>
<body>
<script src="http://my-components-registry.mydomain.com/scripts/oc-client.min.js"></script>
<oc-component href="http://my-components-registry.mydomain.com/hello-world/1.X.X"></oc-component>
<script src="http://my-components-registry.mydomain.com/oc-client/client.js" />
</body>
</html>
```
Expand Down
2 changes: 1 addition & 1 deletion cli/base-component/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "ComponentName",
"description": "",
"version": "1.0.0",
"dependencies": [],
"dependencies": {},
"repository": "",
"oc": {
"parameters": {},
Expand Down
2 changes: 1 addition & 1 deletion client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ var Client = function(conf){
return callback(errorDescription, '');
}

fs.readFile(path.resolve(__dirname, '../registry/public/oc-client.min.js'), 'utf-8', function(err, clientJs){
fs.readFile(path.resolve(__dirname, '../components/oc-client/src/oc-client.min.js'), 'utf-8', function(err, clientJs){
var clientSideHtml = format('<script class="ocClientScript">{0}</script>{1}', clientJs, self.renderer.getUnrenderedComponent(href));
return callback(errorDescription, clientSideHtml);
});
Expand Down
2 changes: 2 additions & 0 deletions components/oc-client/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
package.tar.gz
node_modules
2 changes: 2 additions & 0 deletions components/oc-client/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
package.tar.gz
node_modules
25 changes: 25 additions & 0 deletions components/oc-client/_package/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "oc-client",
"description": "",
"version": "0.1.0",
"dependencies": {},
"repository": "",
"oc": {
"parameters": {},
"files": {
"template": {
"type": "handlebars",
"hashKey": "389d92b88e4fc9bed8f0d8329a8a9b488ef3def1",
"src": "template.js"
},
"static": [
"src"
],
"dataProvider": {
"type": "node.js",
"haskey": "5650391178d095f6097963605cef19b5a77353cd",
"src": "server.js"
}
}
}
}
5 changes: 5 additions & 0 deletions components/oc-client/_package/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

module.exports.data = function(req, callback){
callback(null, { staticPath: req.staticPath });
};

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions components/oc-client/_package/template.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions components/oc-client/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "oc-client",
"description": "",
"version": "0.1.0",
"dependencies": {},
"repository": "",
"oc": {
"parameters": {},
"files": {
"data": "server.js",
"template": {
"src": "template.html",
"type": "handlebars"
},
"static": [
"src"
]
}
}
}
5 changes: 5 additions & 0 deletions components/oc-client/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

module.exports.data = function(req, callback){
callback(null, { staticPath: req.staticPath });
};
Loading