Skip to content

Commit

Permalink
Rewrite unit tests to not change the process's CWD, replace Traceur w…
Browse files Browse the repository at this point in the history
…ith 6to5

Closes #86
Closes #87
Paving the way for #96 (allow APIs to receive a sitePath argument)

TODO check if build's copySrc is copying files which have been negated by globs before being re-included
TODO check why build task takes so long to finish when passing an absolute sitePath argument and CWD != sitePath (the `harmonic build`  in the unit test takes about 11 seconds to finish in Windows)
  • Loading branch information
UltCombo committed Dec 24, 2014
1 parent b105641 commit 6989c05
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 1,474 deletions.
5 changes: 3 additions & 2 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
module.exports = {
srcBase: 'src/',
src: {
js: ['**/*.js', '!bin/skeleton/**', '!bin/client/**']
// handleCopy should copy the negated files here but it is apparently not working
js: ['**/*.js', '!bin/skeleton/**/*.js']
},
distBase: 'dist/',
config: {
jscs: { configPath: '.jscsrc', esnext: true },
'6to5': { blacklist: ['generators'] },
mocha: { bail: true, timeout: 5000 }
mocha: { bail: true, timeout: 20000 }
}
};
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,14 @@
"permalinks": "^0.2.1",
"rimraf": "^2.2.8",
"stylus": "^0.45.1",
"traceur": "0.0.49",
"underscore": "^1.6.0",
"v8-argv": "^0.2.0"
},
"devDependencies": {
"chalk": "^0.5.1",
"gulp": "^3.8.10",
"gulp-batch": "^1.0.4",
"gulp-filter": "^1.0.2",
"gulp-filter": "^2.0.0",
"gulp-jscs": "^1.3.1",
"gulp-jshint": "^1.9.0",
"gulp-load-plugins": "^0.8.0",
Expand Down
29 changes: 16 additions & 13 deletions src/bin/cli/program.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,37 +28,40 @@ program
});

program
.command('build')
.command('build [path]')
.description('Build your static website')
.action(() => {
// [BUG] https://github.com/jshint/jshint/issues/1849 - can't use arrow function
.action(function(path = '.') {
let core = require('../core');
core.init();
core.init(path);
});

program
.command('new_post ["title"]')
.command('new_post ["title"] [path]')
.description('Create a new post')
.action((title) => {
newFile('post', title);
// [BUG] https://github.com/jshint/jshint/issues/1849 - can't use arrow function
.action(function(title, path = '.') {
newFile(path, 'post', title);
});

program
.command('new_page ["title"]')
.command('new_page ["title"] [path]')
.description('Create a new page')
.action((title) => {
newFile('page', title);
// [BUG] https://github.com/jshint/jshint/issues/1849 - can't use arrow function
.action(function(title, path = '.') {
newFile(path, 'page', title);
});

program
.command('run [port]')
.command('run [port] [path]')
.description('Run you static site locally. Port is optional')
// [BUG] https://github.com/jshint/jshint/issues/1849 - can't use arrow function
.action(function(port = 9356) {
.action(function(port = 9356, path = '.') {
let core = require('../core'),
build = core.init();
build = core.init(path);
if (build) {
build.then(function() {
run(port);
run(path, port);
});
}
});
Expand Down
17 changes: 9 additions & 8 deletions src/bin/cli/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ function config(sitePath) {
* @param {string} type - The new file's type. Can be either 'post' or 'page'.
* @param {string} title - The new file's title.
*/
function newFile(type, title) {
function newFile(sitePath, type, title) {
var clc = cliColor(),
langs = getConfig().i18n.languages,
langs = getConfig(sitePath).i18n.languages,
template = '<!--\n' +
'layout: ' + type + '\n' +
'title: ' + title + '\n' +
Expand All @@ -131,14 +131,15 @@ function newFile(type, title) {
'categories:\n' +
'-->\n' +
'# ' + title,
path = type === 'post' ? postspath : pagespath,
filedir = path.join(sitePath, type === 'post' ? postspath : pagespath),
filename = titleToFilename(title);

langs.forEach((lang) => {
if (!fs.existsSync(path + lang)) {
fs.mkdirSync(path + lang);
let fileLangDir = path.join(filedir, lang);
if (!fs.existsSync(fileLangDir)) {
fs.mkdirSync(fileLangDir);
}
fs.writeFileSync(path + lang + '/' + filename, template);
fs.writeFileSync(path.join(fileLangDir, filename), template);
});

console.log(clc.info(
Expand All @@ -147,9 +148,9 @@ function newFile(type, title) {
));
}

function run(port) {
function run(sitePath, port) {
let clc = cliColor();
let file = new staticServer.Server(path.join(process.cwd(), 'public'));
let file = new staticServer.Server(path.join(sitePath, 'public'));

console.log(clc.info('Harmonic site is running on http://localhost:' + port));

Expand Down
Loading

0 comments on commit 6989c05

Please sign in to comment.