Skip to content
This repository was archived by the owner on Apr 22, 2020. It is now read-only.

Commit 8913c2f

Browse files
alex-milanovmikesamuel
authored andcommitted
small changes so that it can be used directly in a npm pipeline (#476)
* added module.exports * modified module.exports to incl. prettyPrintOne * added include paths for css preprocessor support * fix window not defined issue with browserify * Change to prettify.js for better React support * moved node logic to js-modules/node_prettify, modified grunt tasks * remvoed redundant closure-compiler flag
1 parent f425d31 commit 8913c2f

7 files changed

+2033
-271
lines changed

Gruntfile.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ module.exports = function (grunt) {
3636
},
3737
src: 'js-modules/run_prettify.js',
3838
dest: 'src/run_prettify.js'
39+
},
40+
nodeprettify: {
41+
options: {
42+
context: {
43+
RUN_PRETTIFY: true
44+
}
45+
},
46+
src: 'js-modules/node_prettify.js',
47+
dest: 'src/node_prettify.js'
3948
}
4049
},
4150

@@ -50,7 +59,8 @@ module.exports = function (grunt) {
5059
},
5160
files: [
5261
{src: 'src/prettify.js', dest: 'src/prettify.js'},
53-
{src: 'src/run_prettify.js', dest: 'src/run_prettify.js'}
62+
{src: 'src/run_prettify.js', dest: 'src/run_prettify.js'},
63+
{src: 'src/node_prettify.js', dest: 'src/node_prettify.js'}
5464
]
5565
},
5666
langs: {
@@ -144,7 +154,7 @@ module.exports = function (grunt) {
144154
warning_level: 'VERBOSE',
145155
language_in: 'ECMASCRIPT5',
146156
compilation_level: 'ADVANCED',
147-
charset: 'US-ASCII',
157+
charset: 'US-ASCII'
148158
},
149159
prettify: {
150160
options: {

js-modules/node_prettify.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
var IN_GLOBAL_SCOPE = false;
3+
4+
/* @include prettify.js */
5+
6+
var path = require('path');
7+
8+
module.exports = {
9+
prettyPrint: prettyPrint,
10+
prettyPrintOne: prettyPrintOne,
11+
// include paths for css preprocessor support
12+
includePaths: [
13+
__dirname,
14+
path.resolve(__dirname, '../styles')
15+
]
16+
};

js-modules/prettify.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,10 @@ var PR;
9191
* UI events.
9292
* If set to {@code false}, {@code prettyPrint()} is synchronous.
9393
*/
94-
window['PR_SHOULD_USE_CONTINUATION'] = true;
94+
var PR_SHOULD_USE_CONTINUATION = true
95+
if (typeof window !== 'undefined') {
96+
window['PR_SHOULD_USE_CONTINUATION'] = PR_SHOULD_USE_CONTINUATION;
97+
}
9598

9699
/**
97100
* Pretty print a chunk of code.
@@ -116,7 +119,7 @@ var prettyPrint;
116119

117120

118121
(function () {
119-
var win = window;
122+
var win = (typeof window !== 'undefined') ? window : {};
120123
// Keyword lists for various languages.
121124
// We use things that coerce to strings to make them compact when minified
122125
// and to defeat aggressive optimizers that fold large string constants.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"contributors": [
2828
2929
],
30-
"main": "src/prettify.js",
30+
"main": "src/node_prettify.js",
3131
"directories": {
3232
"lib": "src",
3333
"doc": "docs",

0 commit comments

Comments
 (0)