Skip to content

Commit

Permalink
Merge remote-tracking branch 'es6-hello-world/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
zaggino committed Mar 6, 2015
1 parent c2a1726 commit 4f5acd1
Show file tree
Hide file tree
Showing 10 changed files with 165 additions and 59 deletions.
5 changes: 3 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ rules:
#Strict Mode
global-strict: 0 #deprecated
no-extra-strict: 0 #deprecated
strict: [2, "global"] #controls location of Use Strict Directives
strict: [2, "function"] #controls location of Use Strict Directives

#Variables
no-catch-shadow: 2 #disallow the catch clause parameter name being the same as a variable in the outer scope
Expand Down Expand Up @@ -171,11 +171,12 @@ rules:

#Legacy
max-depth: [2, 5] #specify the maximum depth that blocks can be nested
max-len: [1, 80] #specify the maximum length of a line in your program
max-len: [1, 100] #specify the maximum length of a line in your program
max-params: [2, 5] #limits the number of parameters that can be used in the function declaration.
max-statements: [1, 50] #specify the maximum number of statement allowed in a function
no-bitwise: 2 #disallow use of bitwise operators
no-plusplus: 0 #disallow use of unary operators, ++ and --

globals:
brackets: false
define: false
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
# https://help.github.com/articles/ignoring-files
# Example .gitignore files: https://github.com/github/gitignore
/bower_components/
/node_modules/
/node_modules/
/dist/
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
The MIT License (MIT)

Copyright (c) 2015 Martin Zagora

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# brackets-es6-hello-world
Boilerplate for a Brackets extension written in ES6

## gulp tasks

`gulp test` - lint your sources with ESLint

`gulp build` - build your ES6 files into ES5 so Brackets is able to run them

`gulp watch` - watch files for changes and compile them as you go
52 changes: 48 additions & 4 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
/*eslint strict: [2, "global"]*/

'use strict';

var fs = require('fs');
var path = require('path');
var gulp = require('gulp');
var gutil = require('gulp-util');
var eslint = require('gulp-eslint');
var through = require('through2');
var sourcemaps = require('gulp-sourcemaps');
var babel = require('gulp-babel');

var MAIN_FILES = './*.js';
var SRC_FILES = './src/**/*.js';
var DIST_DIR = './dist/';

// options for transpiling es6 to es5
var babelOptions = {
// generators are available in Brackets' shell and also break sourcemaps
blacklist: ['regenerator']
};

// provides pipe to log stuff to console when certain task finishes
function logPipe(str) {
return through.obj(function (file, enc, cb) {
cb();
Expand All @@ -15,6 +31,24 @@ function logPipe(str) {
});
}

// helper for transpiling es6 files to es5
function doBabel(globs, singleFile) {
if (singleFile) {
gutil.log(gutil.colors.cyan('Start Babel ' + globs[0]));
}

var task = gulp.src(globs, {base: path.resolve(__dirname, 'src')})
.pipe(sourcemaps.init())
.pipe(babel(babelOptions))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(DIST_DIR));

return singleFile ?
task.pipe(logPipe(gutil.colors.cyan('Finish Babel ' + globs[0]))) :
task;
}

// helper for linting files
function doEslint(globs, singleFile) {
if (singleFile) {
gutil.log(gutil.colors.magenta('Start ESLint ' + globs[0]));
Expand All @@ -29,14 +63,24 @@ function doEslint(globs, singleFile) {
task.pipe(eslint.failAfterError());
}

gulp.task('babel', function () {
return doBabel([SRC_FILES], false);
});

gulp.task('eslint', function () {
return doEslint(['./**/*.js'], false);
return doEslint([MAIN_FILES, SRC_FILES], false);
});

gulp.task('watch', function () {
gulp.watch('./**/*.js').on('change', function (event) {
doEslint([path.relative(__dirname, event.path)], true);
gulp.watch([SRC_FILES]).on('change', function (event) {
var filePath = path.relative(__dirname, event.path);
if (fs.statSync(filePath).isFile()) {
doEslint([filePath], true);
doBabel([filePath], true);
}
});
});

gulp.task('default', ['eslint']);
gulp.task('build', ['babel']);
gulp.task('test', ['eslint']);
gulp.task('default', ['build', 'test']);
16 changes: 6 additions & 10 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
/*globals define*/

'use strict';

define(function (require, exports, module) {
'use strict';

// styling
var ExtensionUtils = brackets.getModule('utils/ExtensionUtils');
ExtensionUtils.loadStyleSheet(module, 'styles/main.less');


// require('dist/browser-polyfill');
// require('dist/main')();
// launch compiled js code
require('dist/main');

/*
if (window.isBracketsTestWindow) {
}
// TODO: provide base for writing unit tests
if (window.isBracketsTestWindow) { }
*/

});
39 changes: 18 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,40 +1,37 @@
{
"name": "brackets-npm-registry",
"version": "0.0.1",
"description": "Download extensions from NPM",
"keywords": [
"extensions",
"npm"
],
"main": "main.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"name": "brackets-es6-hello-world",
"version": "0.0.2",
"description": "Boilerplate for a Brackets extension written in ES6",
"keywords": ["brackets-extension", "boilerplate", "hello-world"],
"homepage": "https://github.com/zaggino/brackets-es6-hello-world",
"bugs": "https://github.com/zaggino/brackets-es6-hello-world/issues",
"license": "MIT",
"author": {
"name": "Martin Zagora",
"email": "zaggino@gmail.com",
"url": "https://github.com/zaggino"
},
"homepage": "https://github.com/zaggino/brackets-npm-registry",
"repository": {
"type": "git",
"url": "https://github.com/zaggino/brackets-git.git"
"url": "https://github.com/zaggino/brackets-es6-hello-world.git"
},
"license": "MIT",
"engines": {
"brackets": ">=1.1.0"
"scripts": {
"test": "gulp test",
"install": "gulp build"
},
"dependencies": {
"bluebird": "^2.9.13",
"npm": "^2.6.1"
},
"devDependencies": {
"babelify": "^5.0.4",
"browserify": "^9.0.3",
"babel-core": "^4.6.6",
"eslint": "^0.15.1",
"esprima-fb": "^13001.1.0-dev-harmony-fb",
"gulp": "^3.8.11",
"gulp-babel": "^4.0.0",
"gulp-eslint": "^0.5.0",
"gulp-sourcemaps": "^1.5.0",
"gulp-util": "^3.0.4",
"through2": "^0.6.3"
},
"engines": {
"brackets": ">=1.2.0"
}
}
5 changes: 5 additions & 0 deletions requirejs-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"paths": {
"bluebird": "./node_modules/bluebird/js/browser/bluebird.min"
}
}
48 changes: 27 additions & 21 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
'use strict';
define(function (require) {
'use strict';

let co = require('bluebird').coroutine;
let SUCCESS = Symbol();
let AppInit = brackets.getModule('utils/AppInit');
let co = require('bluebird').coroutine;
let Logger = require('./utils/Logger');
let SUCCESS = Symbol();

function promiseResponse() {
return new Promise(function (resolve) {
setTimeout(function () {
resolve(SUCCESS);
}, 1);
function promiseResponse() {
return new Promise(function (resolve) {
setTimeout(function () {
resolve(SUCCESS);
}, 1);
});
}

let tryGenerators = co(function* () {
let response = yield promiseResponse();
if (response === SUCCESS) {
Logger.log('Hello world!');
} else {
throw new Error('Response has unexpected value: ' + response);
}
});
}

let tryGenerators = co(function* () {
var response = yield promiseResponse();
if (response === SUCCESS) {
console.log('ES6 generators work!');
} else {
console.error('ES6 generators failed...');
}
});
AppInit.appReady(function () {
// co functions return promises
tryGenerators()
.catch(e => Logger.error(e));
});

module.exports = function () {
console.log('brackets-npm-registry is starting...');
tryGenerators();
};
});
24 changes: 24 additions & 0 deletions src/utils/Logger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
define(function (require, exports, module) {
'use strict';

let packageInfo = JSON.parse(require('text!../../package.json'));

class Logger {

constructor() {
this.prefix = `[${packageInfo.name}] `;
}

log(...args) {
console.log(this.prefix + args.join(' '));
}

error(...args) {
console.error(this.prefix + args.join(' '));
}

}

module.exports = new Logger();

});

0 comments on commit 4f5acd1

Please sign in to comment.