Skip to content
This repository has been archived by the owner on Apr 29, 2021. It is now read-only.

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
j-rewerts committed Sep 22, 2016
2 parents eba2f38 + cab40fa commit 3e95134
Show file tree
Hide file tree
Showing 18 changed files with 1,912 additions and 1,014 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ coverage
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release
build/*

# Dependency directories
# https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git
Expand Down
4 changes: 4 additions & 0 deletions .jscsrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"preset": "google",
"maximumLineLength": 120
}
4 changes: 2 additions & 2 deletions gapps.config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"path": "src",
"path": "build/gas",
"fileId": "1GJIHQGKlDsooooj5FMmi_E4yNvrUCuR1GK0l-pH8JwR-1G7lbX6rXiyp"
}
}
214 changes: 211 additions & 3 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,213 @@
// NPM packages
var browserify = require('browserify');
var gjslint = require('gulp-gjslint');
var gulp = require('gulp');
var gutil = require('gulp-util');
var source = require('vinyl-source-stream');
var htmlProcessor = require('gulp-htmlprocessor');
var sass = require('gulp-sass');

gulp.task('default', function() {
// place code for your default task here
});
// Node modules
var exec = require('child_process').exec;
var fs = require('fs');

// These are the primary tasks
gulp.task('test-gas', ['deploy-gas'], openGAS);
gulp.task('test-web', ['build-web'], openWeb);

// General
gulp.task('lint-all', closureLint);
gulp.task('fix-all', closureFix);
gulp.task('browserify', browserifyBundle);
gulp.task('compile-sass', compileSASS);

// Web specific
gulp.task('build-web', ['browserify', 'compile-sass'], buildWeb);

// GAS specific
gulp.task('deploy-gas', ['swap-tags'], deployGAS);
gulp.task('swap-tags', ['build-gas'], replaceTags);
gulp.task('build-gas', ['browserify', 'compile-sass'], buildGAS);


/**
* Bundles up client.js (and all required functionality) and places it in a build directory.
*
* @return {stream} the stream as the completion hint to the gulp engine
*/
function browserifyBundle() {
return browserify('./src/client/js/client.js')
.bundle()
.on('error', function(e) {
gutil.log(e);
})
.pipe(source('bundle.js'))
.pipe(gulp.dest('./build/common'));
}


/**
* Builds the project for GAS.
* GAS doesn't allow seperate CSS or JS, so both need to be injected into the main HTML.
*
* @return {stream} the stream as the completion hint to the gulp engine
*/
function buildGAS() {

gulp.src('./src/client/html/**', {
base: './src/client'
})
.pipe(gulp.dest('./build/gas'));

// GAS
return gulp.src('./src/GAS/*')
.pipe(gulp.dest('./build/gas/GAS'));
}


/**
* Replaces all script tags and css links.
* Note: This is done relative to this gulpfile.
* All swap tags are relative to this gulpfile.
*
* @return {stream} the stream as the completion hint to the gulp engine
*/
function replaceTags() {
return gulp.src('./build/gas/html/*.html')
.pipe(htmlProcessor({
includeBase: './'
}))
.pipe(gulp.dest('./build/gas/html/'));
}


/**
* Builds the project for the web.
*
* @return {stream} the stream as the completion hint to the gulp engine
*/
function buildWeb() {
gulp.src('./build/common/bundle.js')
.pipe(gulp.dest('./build/web/client/js'));

gulp.src('./src/client/css/*')
.pipe(gulp.dest('./build/web/client/css'));

gulp.src('./src/client/html/*')
.pipe(gulp.dest('./build/web/client/html'));

gulp.src('./src/client/images/*')
.pipe(gulp.dest('./build/web/client/images'));

gulp.src('./build/common/css/*')
.pipe(gulp.dest('./build/web/client/css'));

return gulp.src('./src/GAS/*')
.pipe(gulp.dest('./build/web/GAS'));
}


/**
* Deploys the GAS code up to the project.
* Calls browserifyBundle, then buildGAS.
*
* @param {callback} cb - a callback so the engine knows when it'll be done
* @return {stream} the stream as the completion hint to the gulp engine
*/
function deployGAS(cb) {
return exec('gapps push', function(err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
});
}


/**
* Opens up the project in GAS in chrome.
* Calls browserifyBundle, then buildGAS, then deployGAS.
*
* @param {callback} cb - a callback so the engine knows when it'll be done
* @return {stream} the stream as the completion hint to the gulp engine
*/
function openGAS(cb) {
// Open the project in chrome
var key = JSON.parse(fs.readFileSync('gapps.config.json', 'utf8')).fileId;

var chrome = 'start chrome https://script.google.com/a/edmonton.ca/d/' + key + '/edit';
return exec(chrome, function(err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
});
}


/**
* Opens up the project in chrome.
* Calls browserifyBundle, then buildWeb.
*
* @param {callback} cb - a callback so the engine knows when it'll be done
* @return {stream} the stream as the completion hint to the gulp engine
*/
function openWeb(cb) {
var chrome = 'start chrome ./build/web/client/html/ListSetupSidebar.html';
return exec(chrome, function(err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
});
}


/**
* Runs Google's own Closure Linter on the JS destined for the web
*
* @return {stream} the stream as the completion hint to the gulp engine
*/
function closureLint() {
// flags: https://github.com/jmendiara/node-closure-linter-wrapper#flags
var lintOptions = {
flags: ['--max_line_length 120', '--strict']
};

// Output all failures to the console, and \then fail.
return gulp.src(['./src/**/*.js'])
.pipe(gjslint(lintOptions))
.pipe(gjslint.reporter('console'));
}


/**
* Attempts to automatically fix many of the errors that gjslint checks for.
* Runs a shell command.
*
* @param {callback} cb - a callback so the engine knows when it'll be done
* @return {stream} the stream as the completion hint to the gulp engine
*/
function closureFix(cb) {

var fixJS = 'fixjsstyle --strict --max_line_length 120 -r ./src';

return exec(fixJS, function(err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
});
}


/**
* Compiles SASS (?) ¯\_(ツ)_/¯
*
* @return {stream} the stream as the completion hint to the gulp engine
*/
function compileSASS() {
return gulp.src('./src/client/sass/*.scss')
.pipe(sass().on('error', function(error) {
var message = new gutil.PluginError('sass', error.messageFormatted).toString();
process.stderr.write(message + '\n');
process.exit(1);
}))
.pipe(gulp.dest('./build/common/css'));
}
14 changes: 13 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,19 @@
"dependencies": {
"gasify": "^0.1.0"
},
"devDependencies": {},
"devDependencies": {
"browserify": "^13.1.0",
"gulp-gjslint": "^0.1.5",
"gulp-htmlprocessor": "^0.1.1",
"gulp-replace": "^0.5.4",
"gulp-sass": "^2.3.2",
"gulp-uglify": "^2.0.0",
"gulp-util": "^3.0.7",
"gulp": "^3.9.1",
"jquery": "^3.1.0",
"uglify-js": "^1.3.5",
"vinyl-source-stream": "^1.1.0"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
Expand Down
2 changes: 1 addition & 1 deletion src/Comparison.js → src/GAS/Comparison.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

Comparison = {
'Text is exactly' : textIsExactly
'Text is exactly': textIsExactly
};

function textIsExactly(text, mustBe) {
Expand Down
13 changes: 7 additions & 6 deletions src/Events.js → src/GAS/Events.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,22 @@ function onInstall(e) {

function onOpen(e) {
SpreadsheetApp.getUi()
.createAddonMenu()//'Defect Tracker'
.addItem('Set Up Email List', 'openListSetUpSidebar')
.addToUi();
.createAddonMenu() //'Defect Tracker'
.addItem('Set Up Email List', 'openListSetUpSidebar')
.addToUi();

PropertiesService.getDocumentProperties().setProperty(PROPERTY_SS_ID, SpreadsheetApp.getActiveSpreadsheet().getId());
PropertiesService.getDocumentProperties().setProperty(PROPERTY_SS_ID, SpreadsheetApp.getActiveSpreadsheet().getId());
}


/**
* Creates an HTML sidebar for creating/viewing mailman rules.
*
*/
function openListSetUpSidebar() {
var ui = HtmlService.createHtmlOutputFromFile('ListSetupSidebar')
.setTitle('Set Up Email List')
.setSandboxMode(HtmlService.SandboxMode.IFRAME);
.setTitle('Set Up Email List')
.setSandboxMode(HtmlService.SandboxMode.IFRAME);

SpreadsheetApp.getUi().showSidebar(ui);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Global Variables.js → src/GAS/Global Variables.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var PROPERTY_RULE = 'RULE';
var PROPERTY_SS_ID = 'SPREADSHEET_ID';

var SPREADSHEET_ID = null;
var SPREADSHEET_ID = null;
49 changes: 49 additions & 0 deletions src/GAS/Server Callbacks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* Called from the client-side. Returns the current selection in A1 notation.
* @return {string} The sheets selection in A1 notation.
*/
function getSheetSelection() {
var column = columnToLetter(SpreadsheetApp.getActiveRange().getColumn());
var sheet = SpreadsheetApp.getActiveRange().getSheet().getName();

return sheet + '!' + column + ':' + column;
}


/**
* The ultimate output of the client-side html form.
* Used to create a new rule to check.
*
* @param {string} to The A1 notation for the column containing the primary recipients
* @param {string} cc The A1 notation for the column containing the cc recipients
* @param {string} bcc The A1 notation for the column containing the bcc recipients
* @param {string} subject The A1 notation for the column containing the subject
* @param {string} body The A1 notation for the body column
* @param {string} range The A1 notation for the range to be searched/emailed
* @param {string} comparison The type of comparison (TODO only supports Text is exactly...)
* @param {string} value The value corresponding to the comparison
* @param {string} previous The last time this row sent an email
* @return {string} Success value that informs users of issues/success
*/
function createRule(to, cc, bcc, subject, body, range, comparison, value, previous) {
// Test all the values

var rule = {
'to': to,
'cc': cc,
'bcc': bcc,
'subject': subject,
'body': body,
'range': range,
'comparison': comparison,
'value': value,
'previous': previous
};

PropertiesService.getDocumentProperties().setProperty(PROPERTY_RULE, JSON.stringify(rule));

Logger.log(rule);

// TEMP
onTrigger();
}
Loading

0 comments on commit 3e95134

Please sign in to comment.