Skip to content

Commit 94a687c

Browse files
committed
Minor changes to make sigma publishable to NPM
Fixing jacomyal#186. Here are some more details about the commit itself: - Updated conrad.js - Added a dirty script to fix exports: sigma.export.js - Fixed last references to window - Added the npmPrePublish Grunt task, and linked it to `npm prepublish` - Added .npmignore rules and fixed some in .gitignore - Updated package.json, changing the name from "sigma-js" to "sigma"
1 parent 57874b9 commit 94a687c

File tree

9 files changed

+58
-27
lines changed

9 files changed

+58
-27
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
node_modules/*
22
build/*
3+
*.tgz

.npmignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
build/*
2+
!build/sigma.require.js
3+
!build/sigma.min.js
4+
!build/plugins/*
5+
test/*
6+
node_modules/*
7+
examples/*
8+
Gruntfile.js
9+
CHANGELOG.md
10+
.travis.yml
11+
.gitignore
12+
*.tgz
13+
*.log

Gruntfile.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ module.exports = function(grunt) {
4949
'src/misc/sigma.misc.drawHovers.js'
5050
];
5151

52+
var npmJsFiles = coreJsFiles.slice(0);
53+
npmJsFiles.splice(2, 0, 'src/sigma.export.js');
54+
5255
var pluginFiles = [
5356
'plugins/sigma.layout.forceAtlas2/*.js',
5457
'plugins/sigma.parsers.gexf/*.js',
@@ -110,11 +113,15 @@ module.exports = function(grunt) {
110113
},
111114
concat: {
112115
options: {
113-
separator: ';'
116+
separator: '\n'
114117
},
115118
dist: {
116119
src: coreJsFiles,
117120
dest: 'build/sigma.js'
121+
},
122+
require: {
123+
src: npmJsFiles,
124+
dest: 'build/sigma.require.js'
118125
}
119126
},
120127
sed: {
@@ -147,6 +154,7 @@ module.exports = function(grunt) {
147154
// By default, will check lint, hint, test and minify:
148155
grunt.registerTask('default', ['closureLint', 'jshint', 'qunit', 'sed', 'uglify']);
149156
grunt.registerTask('release', ['closureLint', 'jshint', 'qunit', 'sed', 'uglify', 'zip']);
157+
grunt.registerTask('npmPrePublish', ['uglify:plugins', 'concat:require']);
150158

151159
// For travis-ci.org, only launch tests:
152160
grunt.registerTask('travis', ['qunit']);

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "sigma-js",
2+
"name": "sigma",
33
"version": "1.0.2",
44
"description": "A JavaScript library dedicated to graph drawing.",
55
"homepage": "http://sigmajs.org",
@@ -9,6 +9,7 @@
99
"url": "http://github.com/jacomyal/sigma.js.git"
1010
},
1111
"license": "MIT",
12+
"main": "build/sigma.require.js",
1213
"devDependencies": {
1314
"grunt-cli": "^0.1.13",
1415
"grunt": "~0.4.4",
@@ -25,6 +26,7 @@
2526
"scripts": {
2627
"start": "http-server -p 8000",
2728
"test": "grunt travis",
28-
"build": "grunt uglify"
29+
"build": "grunt uglify",
30+
"prepublish": "grunt npmPrePublish"
2931
}
3032
}

src/conrad.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -979,6 +979,6 @@
979979
if (typeof module !== 'undefined' && module.exports)
980980
exports = module.exports = conrad;
981981
exports.conrad = conrad;
982-
} else
983-
global.conrad = conrad;
982+
}
983+
global.conrad = conrad;
984984
})(this);

src/renderers/sigma.renderers.def.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
;(function(undefined) {
1+
;(function(global) {
22
'use strict';
33

44
if (typeof sigma === 'undefined')
@@ -9,7 +9,7 @@
99

1010
// Check if WebGL is enabled:
1111
var canvas,
12-
webgl = !!window.WebGLRenderingContext;
12+
webgl = !!global.WebGLRenderingContext;
1313
if (webgl) {
1414
canvas = document.createElement('canvas');
1515
webgl = !!(
@@ -22,4 +22,4 @@
2222
sigma.renderers.def = webgl ?
2323
sigma.renderers.webgl :
2424
sigma.renderers.canvas;
25-
}).call(this);
25+
})(this);

src/sigma.core.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -647,11 +647,7 @@
647647
*/
648648
if (typeof this.sigma !== 'undefined')
649649
throw 'An object called sigma is already in the global scope.';
650-
else if (typeof exports !== 'undefined') {
651-
if (typeof module !== 'undefined' && module.exports)
652-
exports = module.exports = sigma;
653-
exports.sigma = sigma;
654-
} else
655-
this.sigma = sigma;
650+
651+
this.sigma = sigma;
656652

657653
}).call(this);

src/sigma.export.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Hardcoded export for the node.js version:
2+
var sigma = this.sigma,
3+
conrad = this.conrad;
4+
5+
sigma.conrad = conrad;
6+
7+
if (typeof exports !== 'undefined') {
8+
if (typeof module !== 'undefined' && module.exports)
9+
exports = module.exports = sigma;
10+
exports.sigma = sigma;
11+
}

src/utils/sigma.polyfills.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
;(function(undefined) {
1+
;(function(global) {
22
'use strict';
33

44
/**
@@ -12,19 +12,19 @@
1212
lastTime = 0,
1313
vendors = ['ms', 'moz', 'webkit', 'o'];
1414

15-
for (x = 0; x < vendors.length && !window.requestAnimationFrame; x++) {
16-
window.requestAnimationFrame =
17-
window[vendors[x] + 'RequestAnimationFrame'];
18-
window.cancelAnimationFrame =
19-
window[vendors[x] + 'CancelAnimationFrame'] ||
20-
window[vendors[x] + 'CancelRequestAnimationFrame'];
15+
for (x = 0; x < vendors.length && !global.requestAnimationFrame; x++) {
16+
global.requestAnimationFrame =
17+
global[vendors[x] + 'RequestAnimationFrame'];
18+
global.cancelAnimationFrame =
19+
global[vendors[x] + 'CancelAnimationFrame'] ||
20+
global[vendors[x] + 'CancelRequestAnimationFrame'];
2121
}
2222

23-
if (!window.requestAnimationFrame)
24-
window.requestAnimationFrame = function(callback, element) {
23+
if (!global.requestAnimationFrame)
24+
global.requestAnimationFrame = function(callback, element) {
2525
var currTime = new Date().getTime(),
2626
timeToCall = Math.max(0, 16 - (currTime - lastTime)),
27-
id = window.setTimeout(
27+
id = global.setTimeout(
2828
function() {
2929
callback(currTime + timeToCall);
3030
},
@@ -35,8 +35,8 @@
3535
return id;
3636
};
3737

38-
if (!window.cancelAnimationFrame)
39-
window.cancelAnimationFrame = function(id) {
38+
if (!global.cancelAnimationFrame)
39+
global.cancelAnimationFrame = function(id) {
4040
clearTimeout(id);
4141
};
4242

@@ -74,4 +74,4 @@
7474

7575
return fBound;
7676
};
77-
}).call(this);
77+
})(this);

0 commit comments

Comments
 (0)