Пример #1
0
var recreateTestdata = function() {
    if (!testdata.exists()) {
        log.debug("Creating new directory: " + testdata.path);
        testdata.mkdirs();
    } else {
        log.debug("Recreating directory: " + testdata.path);
        testdata.rmtree();
        testdata.mkdirs();
    }
}
Пример #2
0
 testGetPackageFile: function() {
     var location = "getjs/tests/packages/index.json";
     var destination = testdata.join("build");
     var r = new Repository(location);
     var pack = r.getPackageInfo("skewer");
     var sourceFile = r.getPackageSource(pack);
     r.getPackageFile(sourceFile, pack, destination);
     testing.truthy(destination.exists());
 }
Пример #3
0
 testInstallPackage: function() {
     var env = new WorkingEnv(testdata);
     env.clearRepositories();
     env.addRepository("getjs/tests/packages/index.json");
     var installer = new install.Installer(env);
     var downloadinfo = installer.download("skewer");
     installer.install(downloadinfo.pack, 
                         downloadinfo.packFile,
                         downloadinfo.sourceFile);
     
     var packfile = testdata.join("build", "Skewer-0.6.jspkg");
     testing.truthy(packfile.exists(), "build/Skewer-0.6.jspkg should exist");
     var goodfile = testdata.join("lib", "skewer.js");
     testing.truthy(goodfile.exists(), "lib/skewer.js should have been installed");
     
     var dontwant = testdata.join("package.json");
     testing.falsy(dontwant.exists(), 
         "package.json should not be installed at the root");
     
     var packagesDir = testdata.join(".getjs", "packages");
     var packageMeta = packagesDir.join("Skewer.json");
     testing.truthy(packageMeta.exists(), "Expected Skewer.json to be installed");
     
     var packageFilelist = packagesDir.join("Skewer.filelist");
     testing.truthy(packageFilelist.exists(), "Expected file list to be created");
     
     var rawdata = packageFilelist.read();
     var filelist = json.decode(rawdata.toString());
     testing.equal(4, filelist.length);
     testing.equal(".getjs/packages/Skewer.filelist", filelist[3]);
     
     var packages = env.getInstalledPackages();
     testing.equal("Skewer", packages.skewer.name);
     testing.itemsAreEqual([0,6], packages.skewer['version'].numeric);
     
 }
Пример #4
0
var File = require('file').Path,
    Seethrough = require('jsdocs/seethrough.js').Template;

var thisFile = new File(require.fileName)
    thisDir = thisFile.join('..');

jsUnity.attachAssertions();
exports.PublishTests = {
    setUp: function() {},
    tearDown: function() {},
    'test - read template files': function() {
        var cssText = thisDir.join('styles.css').read().toString();
        var ieFixText = thisDir.join('ieFix.css').read().toString();
        var indexText = thisDir.join('index.xhtml').read().toString();
        var listText = thisDir.join('list.xhtml').read().toString();
        var classText = thisDir.join('class.xhtml').read().toString();
        var codeText = thisDir.join('code.xhtml').read().toString();
        
        assertTrue(cssText.length > 0);
        assertTrue(ieFixText.length > 0);
        assertTrue(indexText.length > 0);
        assertTrue(listText.length > 0);
        assertTrue(classText.length > 0);
        assertTrue(codeText.length > 0);
    },
    'test - creating templates': function() {
        var cssText = thisDir.join('styles.css').read().toString();
        var ieFixText = thisDir.join('ieFix.css').read().toString();
        var indexText = thisDir.join('index.xhtml').read().toString();
        var listText = thisDir.join('list.xhtml').read().toString();
        var classText = thisDir.join('class.xhtml').read().toString();
Пример #5
0
 config.sourcesPaths.forEach(function(path) {
     try {
         var file = new File(path);
         if (file.exists()) sourceFiles.push(file);
     } catch(e) {}
 });
Пример #6
0
var document = exports.document = function(config) {
    try {
        if (config.configPath) {
            Log.debug('Extending configs with configs from file specified');
            var configFile = new File(configPath);
            var baseConfig = JSON.decode(configFile.read().toString());
            for (var member in baseConfig)
                if (!config[member]) config[member] = baseConfig[member];
        }
    } catch(e) {
        Log.warn('Failed to get configs from a file : ' + config.configPath + ' : ' + e.message);
    }
    if (config.sourcesPaths instanceof Array) {
        Log.debug('Getting sources to document');
        var sourceFiles = [];
        config.sourcesPaths.forEach(function(path) {
            try {
                var file = new File(path);
                if (file.exists()) sourceFiles.push(file);
            } catch(e) {}
        });
    } else throw new Error('No source files to document.');
    Log.debug('Trying to get a template directory');
    try {
        var template;
        if (config.templatePath) template = new File(path).absolute();
        else template = Catalog['jsdocs'].directory.join(defaults.templatePath);
        if (!template.exists()) throw new Error('Template path doesn\'t exists : ' + template);
    } catch(e) {
        Log.error(e.message);
        throw new Error('Bad template path was provided : ' + template);
    }
    Log.debug('Trying to require publish.js from template directory');
    try {
        var publish = require(template.join('publish').toString()).publish;
    } catch(e) {
        Log.error(e.message);
        throw new Error('Bad template, template folder should contain publisher.js with exports.publish function in it : ' + template);
    }
    Log.debug('Trying to get folder where documentations will be saved');
    try {
        var path = config.destinationPath || defaults.destinationPath;
        var destination = new File(path).absolute();
        if (!destination.exists()) destination.mkdirs();
        if (!destination.isDirectory()) throw new Error('Destination should be a directory : ' + path);
    } catch (e) {
        throw new Error('Bad destination path ' + path + ' : ' + e.message);
    }
    Log.debug('Trying to get file to log results');
    var log = null;
    try {
        if (config.logPath) {
            var log = new File(config.logPath).absolute();
            if (!log.exists()) destination.touch();
            if (!log.isFile() || !log.isWritable)
                throw new Error('Log path should point to a writable file : ' + config.logPath);
        }
    } catch(e) {
        throw new Error('Bad log path : ' + config.logPath + ' : ' + e.message);
    }
    // TODO: add assertor to a logger to log to the log file
    var includeUndocumented = config.includeUndocumented || defaults.includeUndocumented;
    var includePrivates = config.includePrivates || defaults.includePrivates;
    var encoding = config.encoding || defaults.encoding;
    var nocode = config.nocode || defaults.nocode;
    var depth = config.depth || defaults.depth;
    var verbose = config.verbose || defaults.verbose;
    var fileExtensions = config.fileExtensions || defaults.fileExtensions;
    // Getting all the sources to be documented
    var sources = _getSourceFiles(sourceFiles, fileExtensions, depth);
    if (sources.length == 0) throw new Error('There is nothing to be documented');

    Log.debug('Exposing Plugins for template');
    var Plugins = {
        // Class for geneartion of the plugins
        Template: function(path) {
            return new Seethrough(template.join(path).read());
        },
        getContent: function(path) {
            return template.join(path).read().toString()
        },
        syntaxHighlight: function(code, language) {
            if (code instanceof File) code = code.read().toString();
            return SyntaxStroop.highlight(code, language);
        },
        publish: function(files) {
            Object.keys(files).forEach(function(path) {
                destination.join(path).write(files[path]);
            });
        }
    };
    global.Log = Log;

    // Have to dill with JSDOCS and all this mess so far :(
    // I know lines below makes no sense and I'm going to get rid of them a tsome point :)
    JSDOC.opt = {
        srcFiles: sources,
        n: nocode,
        p: includePrivates,
        a: includeUndocumented,
        e: encoding
    };

    Log.info("JSDocs started at " + new Date());
    Log.debug("With options: ");
    for (var o in JSDOC.opt) Log.debug("    " + o + ": " + JSDOC.opt[o]);

    // get a plugins
    // TODO: Need to use better way for this
    require('./plugins').plug(JSDOC);

    JSDOC.handlers = {};
    JSDOC.JsDoc = {};
    Log.debug('Start parseing source files');
    _parseSourceFiles(sources);
    JSDOC.JsDoc.symbolSet = JSDOC.Parser.symbols;
    Log.debug('Start publishing docs');
    publish(JSDOC.JsDoc.symbolSet, sources, Plugins);
    Log.debug('Finished publishing docs');
};