mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-22 17:40:22 +00:00
Couple of changes into angular.scenario runner: - add autotest config (runs tests when document ready) - update ObjectModel (forwards events) - use only one ObjectModel instance for all outputters - expose error msg and line number in ObjectModel.Spec and ObjectModel.Step - fix generating spec.ids - fix 'html' output so that it does not mutate ObjectModel Couple of changes into docs / generator: - rename copy -> copyTpl - move docs/static into docs/examples (to avoid conflict with jstd proxy) Running all docs e2e tests: ======================================================== 1/ compile angular-scenario, jstd-scenario-adapter >> rake compile 2/ build docs >> rake docs 3/ start jstd server >> ./server-scenario.sh 4/ capture some browser 5/ run node server to serve static content >> node ../lib/nodeserver/server.js 6/ run tests >> ./test-scenario.sh
74 lines
1.8 KiB
JavaScript
74 lines
1.8 KiB
JavaScript
/**
|
|
* All writing related code here. This is so that we can separate the async code from sync code
|
|
* for testability
|
|
*/
|
|
require.paths.push(__dirname);
|
|
var fs = require('fs');
|
|
var OUTPUT_DIR = "build/docs/";
|
|
|
|
function output(docs, content, callback){
|
|
callback();
|
|
}
|
|
|
|
exports.output = function(file, content, callback){
|
|
//console.log('writing', OUTPUT_DIR + file, '...');
|
|
fs.writeFile(
|
|
OUTPUT_DIR + file,
|
|
exports.toString(content),
|
|
callback);
|
|
};
|
|
|
|
|
|
exports.toString = function toString(obj){
|
|
switch (typeof obj) {
|
|
case 'string':
|
|
return obj;
|
|
case 'object':
|
|
if (obj instanceof Array) {
|
|
obj.forEach(function (value, key){
|
|
obj[key] = toString(value);
|
|
});
|
|
return obj.join('');
|
|
} else {
|
|
return JSON.stringify(obj);
|
|
}
|
|
}
|
|
return obj;
|
|
};
|
|
|
|
exports.makeDir = function (path, callback) {
|
|
var parts = path.split(/\//);
|
|
path = '.';
|
|
(function next(){
|
|
if (parts.length) {
|
|
path += '/' + parts.shift();
|
|
fs.mkdir(path, 0777, next);
|
|
} else {
|
|
callback();
|
|
}
|
|
})();
|
|
};
|
|
|
|
exports.copyTpl = function(filename, callback) {
|
|
copy('docs/src/templates/' + filename, OUTPUT_DIR + filename, callback);
|
|
};
|
|
|
|
function copy(from, to, callback) {
|
|
//console.log('writing', to, '...');
|
|
fs.readFile(from, function(err, content){
|
|
if (err) return callback.error(err);
|
|
fs.writeFile(to, content, callback);
|
|
});
|
|
}
|
|
|
|
exports.copyDir = function(dir, callback) {
|
|
exports.makeDir(OUTPUT_DIR + '/' + dir, callback.waitFor(function(){
|
|
fs.readdir('docs/' + dir, callback.waitFor(function(err, files){
|
|
if (err) return this.error(err);
|
|
files.forEach(function(file){
|
|
copy('docs/' + dir + '/' + file, OUTPUT_DIR + '/' + dir + '/' + file, callback.waitFor());
|
|
});
|
|
callback();
|
|
}));
|
|
}));
|
|
};
|