Skip to content
This repository was archived by the owner on Jun 14, 2024. It is now read-only.

Commit 3aafe01

Browse files
committed
checkin toy sample closure app
1 parent 322a71f commit 3aafe01

File tree

7 files changed

+125
-0
lines changed

7 files changed

+125
-0
lines changed

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ node_modules
33
.DS_Store
44
externs/pom.xml
55
test
6+
samples

samples/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dist/

samples/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
This folder contains a toy project that compiles with the Closure Compiler in JS.
2+
3+
You'll need `gulp`.
4+
If you don't have it, run `npm install -g gulp`.
5+
Then, check out this repo, install the dependencies, and run the Gulp tool-
6+
7+
```bash
8+
$ git clone https://github.com/google/closure-compiler-js.git
9+
$ cd closure-compiler-js/samples
10+
$ npm install
11+
$ gulp
12+
```
13+
14+
This will generate an output file and source map inside `dist`.
15+
You can run the `output.min.js` file with Node, or inside a browser.

samples/gulpfile.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2016 The Closure Compiler Authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/**
18+
* @fileoverview Gulpfile to compile with Closure Compiler in JS.
19+
*/
20+
21+
const compiler = require('google-closure-compiler-js').gulp();
22+
const gulp = require('gulp');
23+
const sourcemaps = require('gulp-sourcemaps');
24+
25+
gulp.task('default', function() {
26+
return gulp.src(['helper.js', 'index.js'])
27+
.pipe(sourcemaps.init())
28+
.pipe(compiler({
29+
jsOutputFile: 'output.min.js', // filename returned to gulp
30+
compilationLevel: 'ADVANCED', // as opposed to 'SIMPLE', the default
31+
warningLevel: 'VERBOSE', // complain loudly on errors
32+
createSourceMap: true, // create output source map
33+
processCommonJsModules: true, // needed to support require()
34+
}))
35+
.pipe(sourcemaps.write('/'))
36+
.pipe(gulp.dest('./dist'));
37+
});

samples/helper.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright 2016 The Closure Compiler Authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/**
18+
* @fileoverview Demo library for an application compiled with Closure.
19+
*/
20+
21+
let value = 0;
22+
23+
module.exports = function() {
24+
return `I've been called ${++value} times`;
25+
};

samples/index.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2016 The Closure Compiler Authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/**
18+
* @fileoverview Demo entry point for an application compiled with Closure.
19+
*/
20+
21+
'use strict';
22+
23+
const helperModule = require('./helper');
24+
25+
let authors = 'The Closure Compiler Authors';
26+
console.info(`I'm a test module by ${authors}.`);
27+
28+
if (typeof document !== 'undefined') {
29+
const h1 = document.createElement('h1');
30+
h1.textContent = 'Loud heading is loud';
31+
document.body.appendChild(h1);
32+
}
33+
34+
console.warn('Output from helperModule: ' + helperModule());
35+
console.warn('Some more output from helperModule: ' + helperModule());

samples/package.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "google-closure-compiler-js_samples",
3+
"version": "1.0.0",
4+
"main": "index.js",
5+
"author": "The Closure Compiler Authors",
6+
"private": true,
7+
"license": "Apache-2.0",
8+
"dependencies": {
9+
"google-closure-compiler-js": "latest"
10+
}
11+
}

0 commit comments

Comments
 (0)