Ejemplo n.º 1
0
    it('json', () => {
        assert.equal(json.encode({
            a: 100,
            b: 200
        }), '{"a":100,"b":200}');

        assert.equal(json.encode(json.decode('{"a":100,"b":200}')),
            '{"a":100,"b":200}');

        var buf = new Buffer('test');
        var j = json.encode(buf);

        assert.isTrue(Buffer.isBuffer(json.decode(j)));
    });
Ejemplo n.º 2
0
 sessionSetup : function() {
   if (this.cookies['kupo_session']) {
     this.session = JSON.decode(this.cookies['kupo_session']);
   } else {
     this.session = {}
   }
 },
Ejemplo n.º 3
0
 sourcePackagesPath.listPaths().forEach(function(item) {
     if(item.join("package.json").exists()) {
         if(!UTIL.has(JSON.decode(item.join("package.json").read().toString()), "uid")) {
             item.symlink(targetPackagesPath.join(item.basename()));
         }
     }
 });
Ejemplo n.º 4
0
	get: function(key) {
		var o = memcached.get(this.handle, key);
		if (o.rc !== 0) {
			return false;
		}
		return o.flags === 0 ? Json.decode(o.value) : o.value;
	},
Ejemplo n.º 5
0
exports.readNotes = function () {
    var notesPath = exports.getNotesPath();
    if (!notesPath.isFile())
        return {};
    return json.decode(notesPath.read(
        {charset: 'utf-8'}
    ));
};
Ejemplo n.º 6
0
 it("argv utf8", () => {
     assert.deepEqual(json.decode(process.open(cmd, [
         path.join(__dirname, "process", "exec2.js"),
         "参数1",
         "参数2"
     ]).readLine()), [
         cmd, path.join(__dirname, "process", "exec2.js"), "参数1", "参数2"
     ]);
 });
Ejemplo n.º 7
0
        function (name, source) {
            var info;

            if (source['package.json'])
                info = util.copy(source['package.json']);

            if (source.type == "inline") {
                if (!info) {
                    self.print(
                        "\0red(dropped:\0) " + name + 
                        " \0blue(because it did not provide a " +
                        "package.json inline.\0)"
                    );
                    return;
                }

            } else if (source.type == "github") {

                var githubName = source.name || name,
                    githubRef = source.ref || "master";
                if (!source.user)
                    throw new Error("package source " + util.enquote(name) + " did not have a github user name");
                var project = source.user + '/' + githubName;
                var url = "http://github.com/" + project + "/raw/" + githubRef + "/package.json";

                // download package.json if not already provided
                if (!info) {
                    try {
                        var text = http.read(url).toString('utf-8');
                    } catch (exception) {
                        self.print("\0red(dropped:\0) " + name + " \0blue(because of an HTTP error\0)");
                        return;
                    }
                    try {
                        info = json.decode(text);
                    } catch (exception) {
                        self.print("\0red(dropped:\0) " + name + " \0blue(because of a JSON error\0)");
                        return;
                    }
                }

                info.githubName = githubName;
                info.type = "zip";
                info.location = 'http://github.com/' + source.user + '/' + githubName + '/zipball/' + githubRef;

            } else {
                throw new Error(
                    "Project " + util.enquote(name) +
                    " has an urecognized type: " +
                    util.enquote(source.type)
                );
            }

            self.print('\0green(' + name + '\0)');
            packages[name] = info;
        }
Ejemplo n.º 8
0
 start: function() {
     // read the session file
     var content = fs.readFile(this.file);
     if (content) {
         // file exists, deserialize it
         this.data = Json.decode(content);
     }
     // flag that the session.data should be serialized and written to disk
     // by end()
     this.started = true;
 },
Ejemplo n.º 9
0
var App = exports.App = function (packageName) {
    
    if (!(this instanceof exports.App)) {
        return new exports.App(packageName);
    }

    if(!UTIL.has(PACKAGES.uidCatalog, packageName)) {
        if(!UTIL.has(PACKAGES.usingCatalog, packageName)) {
            throw new AppError("App package not found: " + packageName);
        } else {
        this.path = PACKAGES.usingCatalog[packageName].directory;
        }
    } else {
        this.path = PACKAGES.usingCatalog[PACKAGES.uidCatalog[packageName].id].directory;
    }


    var manifestPath = this.path.join("package.json");
    if(!manifestPath.exists()) {
        throw new AppError("no manifest found at: " + manifestPath);
    }
    this.manifest = JSON.decode(manifestPath.read({charset:"utf-8"}));
    
    PACKAGE.resolvePackageInfoVariables(this.manifest);
    
    this.protocolHandler = this.registerProtocolHandler();
    
    this.resourceURLs = {
        path: {},
        key: {}
    };

    this.status = false;
    
    // keep the app package handy    
    this.pkg = PACKAGE.Package(this.path).setAppInfo(this.manifest.narwhalrunner);
    this.pkgVars = this.pkg.getTemplateVariables();

    // routes for packages - THIS IS THE NEW MODEL
    this.routes = {};

    // populate package reference ID map to package ID
    this.refIdMap = {};
    var self = this;
        
    UTIL.keys(PACKAGES.usingCatalog).forEach(function(id) {
        self.registerPackage(PACKAGE.Package(PACKAGES.usingCatalog[id].directory, id));//, id);
    });

    this.cache = CACHE.Cache(this.getProfilePath().join("Cache", this.getInternalName()));

    this.programTransportListeners = {};
    this.protocolCache = null;
}
Ejemplo n.º 10
0
 it("argv 1", () => {
     assert.deepEqual(json.decode(process.open(cmd, [
         "--use_strict",
         "--test1",
         path.join(__dirname, "process", "exec2.js"),
         "arg1",
         "arg2"
     ]).readLine()), [
         cmd, path.join(__dirname, "process", "exec2.js"), "arg1", "arg2"
     ]);
 });
Ejemplo n.º 11
0
exports.readCatalog = function () {
    var catalogPath = exports.getCatalogPath();
    if (!catalogPath.exists())
        throw new Error(catalogPath + " does not exist.");
    if (!catalogPath.isFile())
        throw new Error(catalogPath + " is not a file.");
    var catalog = json.decode(catalogPath.read({charset: 'utf-8'}));
    if (catalog.version === undefined || +catalog.version < exports.minCatalogVersion)
        throw new Error("catalog is out of date.  use tusk update or create-catalog");
    packages.normalize(catalog.packages);
    return catalog;
};
Ejemplo n.º 12
0
    it("env1", () => {
        var env = json.decode(process.open(cmd, [
            path.join(__dirname, "process", "exec4.js")
        ], {
            env: {
                abcd: "234"
            }
        }).readLine());

        assert.isUndefined(env.abc);
        assert.equal(env.abcd, "234");
    });
Ejemplo n.º 13
0
exports.sourceToDescriptor = function (name, source, catalog, useCache, log) {

    source.packageName = name;

    // normalize the source, based on its type
    sourceTypes[source.type](source);

    // download a package descriptor if necessary
    if (source.descriptor) {
        descriptor = UTIL.deepCopy(source.descriptor);
    } else {
        var httpStore = TUSK.getHttpStore();

        if (!useCache) {
            try {
                log.downloading(source.descriptorUrl);
                httpStore.download(source.descriptorUrl);
            } catch (exception) {
                log.error(
                    "Unable to download a fresh copy of " +
                    source.descriptorUrl +
                    ".  Trying to use cache.  Reason: " +
                    exception
                );
            }
        }

        try {
            var json = httpStore.read(source.descriptorUrl, {"charset": "UTF-8"});
        } catch (exception) {
            log.error("Unable to read " + source.descriptorUrl + ".");
            return;
        }

        try {
            descriptor = JSON.decode(json);
        } catch (exception) {
            log.error("Unable to parse " + source.descriptorUrl + ".");
            return;
        }
    }

    descriptor.name = name;
    descriptor.descriptorUrl = source.descriptorUrl;
    descriptor.packageUrl = source.url;
    descriptor.packageArchive = source.archive;
    descriptor.source = source;
    delete descriptor.source.descriptor;

    return descriptor;

};
Ejemplo n.º 14
0
exports.getSources = function () {
    // read .tusk/sources.json
    // create .tusk/sources.json from default if necessary
    var tuskDirectory = TUSK.getTuskDirectory();
    var sourcesFile = tuskDirectory.join('sources.json').canonical();
    if (!sourcesFile.exists()) {
        sources = exports.defaultSources;
    } else {
        sources = JSON.decode(sourcesFile.read({"charset": "UTF-8"}));
    }
    sources.url = URI.pathToUri(sourcesFile);
    return sources;
};
Ejemplo n.º 15
0
var PackageDescriptor = exports.PackageDescriptor = function(path) {
    if (!(this instanceof exports.PackageDescriptor))
        return new exports.PackageDescriptor(path);

    if(path instanceof FILE.Path) {
        this.path = path;

        if(!path.exists()) {
            throw new PackageDescriptorError("No package descriptor found at: " + path);
        }
        try {
            this.spec = JSON.decode(path.read());
        } catch(e) {
            throw new PackageDescriptorError("Error parsing package descriptor"+((this.path)?(" at: " + this.path):""));
        }

        // overlay local spec
        if(path.dirname().join("package.local.json").exists()) {
            this.localSpec = JSON.decode(path.dirname().join("package.local.json").read());
            this.globalSpec = UTIL.deepCopy(this.spec);
            this.spec = UTIL.deepCopy(this.globalSpec);
            UTIL.deepUpdate(this.spec, this.localSpec);
        }

    } else {
        this.spec = path;
    }
    
    if(!this.globalSpec) {
        this.globalSpec = UTIL.deepCopy(this.spec);
    } 
    
    if(!this.spec) {
        throw new PackageDescriptorError("Empty package descriptor"+((this.path)?(" at: " + this.path):""));
    }
    if(!this.spec.name) {
        throw new PackageDescriptorError("No 'name' property in package descriptor"+((this.path)?(" at: " + this.path):""));
    }
}
Ejemplo n.º 16
0
exports.readSources = function () {
    var sources = json.decode(exports.getSourcesPath().read(
        {charset: 'utf-8'}
    ));
    if (
        sources.version === undefined ||
        +sources.version < exports.minCatalogVersion
    )
        throw new Error(
            "sources file is out of date.  version " +
            exports.minCatalogVersion + " is required."
        );
    sources.sources = sources.sources || {};
    return sources;
};
Ejemplo n.º 17
0
JsonStore.prototype.load = function(force) {
    if(this.dirty && !force) {
        throw new JsonStoreError("Cannot load store. Unsaved data present.");
    }
    if(!this.exists()) {
        throw new JsonStoreError("Cannot load store. Store does not exist on disk at: " + this.file);
    }
    if(this.hasFileChanged()) {
        try {
            this.data = JSON.decode(this.file.read());
        } catch(e) {
            throw new JsonStoreError("Error parsing JSON from file: " + this.file);
        }
        this.fileMtime = this.file.mtime();
    }
    this.dirty = false;
};
Ejemplo n.º 18
0
    (catalog.includes || []).forEach(function (url) {
        url = URI.resolve(catalog.url, url);

        if (UTIL.has(catalogs, url))
            return;
        var include;

        if (!useCache) {
            // try to download a fresh copy
            try {
                log.downloading(url);
                httpStore.download(url);
            } catch (exception) {
                // use an old one if it's no longer available
                log.error("Unable to download a fresh copy of catalog " + url + ".");
            }
        }

        // try to read the downloaded or stale copy
        try {
            var json = httpStore.read(url, {"charset": "UTF-8"});
        } catch (exception) {
            log.error("HttpError getting " + url + ".");
            return;
        }

        // try to parse the source file
        try {
            include = JSON.decode(json);
        } catch (exception) {
            log.error("SyntaxError in " + url + ".");
            return;
        }

        if (include.version < TUSK.minCatalogVersion) {
            log.error("Catalog at " + url + " is obsolete.");
            return;
        }

        catalogs[url] = include;
        include.url = url;
        // validate the catalog
        // transitively grab sub-catalogs
        exports.getCatalogs(include, catalogs, order, useCache, log);
    });
Ejemplo n.º 19
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);
     
 }
Ejemplo n.º 20
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');
};
Ejemplo n.º 21
0
exports.readCatalog = function (catalogPath) {
    return JSON.decode(exports.getCatalogPath(catalogPath).read({"charset": "UTF-8"}));
};
Ejemplo n.º 22
0
Cache.prototype.getObject = function(key) {
    var str = this.getString(key);
    if(!str) return false;
    return JSON.decode(str);
}
Ejemplo n.º 23
0
 it("env", () => {
     process.env.abc = 123;
     assert.equal(json.decode(process.open(cmd, [
         path.join(__dirname, "process", "exec4.js")
     ]).readLine()).abc, "123");
 });
Ejemplo n.º 24
0
		res.each(function(value, key) {
			if (value.rc !== 0) {
				o[key] = value.flags === 0 ? Json.decode(value.value) : value.value;
			}
		});
Ejemplo n.º 25
0
ProgramBuilder.prototype.buildProgramPackage = function(sourcePackage, options) {

    options = options || {};
    var self = this;
    
    var sourceBasePath = this.sourcePackage.getPath(),
        targetBasePath = this.targetPackage.getPath();
    targetBasePath.mkdirs();

    var sourceDescriptor = this.sourcePackage.getDescriptor();

    // write package.json file (merged with package.local.json if avaiable)
    var file = targetBasePath.join("package.json");
    // set version
    var descriptor = sourceDescriptor.getSpec(),
        locator = this.sourcePackage.getLocator();
        
    // determine version for release        
    // TODO: Use provided version instead (if applicable)
    var time = new Date()
    descriptor.version = [
        "0.0.0" + locator.getRevision(),
        (""+time.getFullYear()).substr(2,2),
        UTIL.padBegin(time.getMonth()+1, 2),
        UTIL.padBegin(time.getDate(), 2),
        UTIL.padBegin(time.getHours(), 2),
        UTIL.padBegin(time.getMinutes(), 2)
    ].join("");
    file.write(JSON.encode(descriptor, null, "    "));
    

    // HACK: write program file first above, then modify below
    // add options
    // TODO: Remove old builders when done
    var programOptions = this.getTargetOptions(options.target);
    descriptor['implements']['http://registry.pinf.org/cadorn.org/github/pinf/@meta/program/package/0.1.0'].options = programOptions;
    file.write(JSON.encode(descriptor, null, "    "));


    var buildPackage = PACKAGE.Package(this.sourcePackage.getBuildPath().join("raw"), this.sourcePackage.getLocator());

    // write package.json after updating version
    var descriptor = JSON.decode(sourceBasePath.join("package.json").read());
    // HACK: merge local on top
    if(sourceBasePath.join("package.local.json").exists()) {
        UTIL.update(descriptor, JSON.decode(sourceBasePath.join("package.local.json").read()));
    }
    descriptor.version = this.targetPackage.getDescriptor().getVersion();
    descriptor['implements']['http://registry.pinf.org/cadorn.org/github/pinf/@meta/program/package/0.1.0'].options = programOptions;
    buildPackage.getPath().join("package.json").write(JSON.encode(descriptor, null, "  "));
    
//        sourceBasePath.join("package.json").copy(buildBasePath.join("package.json"));





    // instanciate program descriptor objects from source package
    // which will be updated during build process
    var remoteProgramDescriptor = JSON_STORE.JsonStore(sourceBasePath.join("program.json")),
        localProgramDescriptor = JSON_STORE.JsonStore(sourceBasePath.join("program.local.json")),
        programDescriptor = localProgramDescriptor;

    // select the appropriate program descriptor for our build
    if(options.remoteDependencies) {
        programDescriptor = remoteProgramDescriptor;
    }
    if(!programDescriptor.exists()) {
        programDescriptor.init();
    }


    var path;


    self.traversePackages(programDescriptor, sourceDescriptor, buildPackage, options);
    
    
/*
    // link all system and using packages to desired versions
    options.uidLocators = {};
    UTIL.every({
        "system": {
            "iterator": "traverseEveryDependency",
            "directory": "packages",
            "property": "dependencies",
            "id": "getName"
        },
        "using": {
            "iterator": "traverseEveryUsing",
            "directory": "using",
            "property": "using",
            "id": "getTopLevelId"
        }
    }, function(type) {

        var locatorRewriteInfo = [];
        sourceDescriptor[type[1].iterator](function(parentPackage, name, locator, stacks, property) {
            if(!locator) {
                return;
            }

            var key = ["packages", type[0]].concat(stacks.names).concat([name, "@"]);
print(key);
            if(options.remoteProgram) {
                if(!programDescriptor.has(key)) {
                    throw new Error("remote program.json is missing a locator for key: " + key.join(" -> "));
                }
                // overwite locator with the one from the program config
                locator = LOCATOR.PackageLocator(programDescriptor.get(key).locator);
            }

            if(options.remoteDependencies) {
                locator.setForceRemote(true);
            }

            var pkg = PINF.getPackageForLocator(locator);

            // linked packages do not contain 'version' properties
            if(pkg.getVersion()) {
                locator.pinAtVersion(pkg.getVersion());
            }
            
            // when traversing dependencies, using packages are traversed as well
            if(property!=type[1]["property"]) {
                return locator;
            }

//            if(type[0]=="system") {
//                path = rawBuildPath.join(type[1].directory, stacks.names.concat(name).join("."));
//            } else
//            if(type[0]=="using") {
//                path = rawBuildPath.join(type[1].directory, pkg.getTopLevelId());
                
                
//                path = targetBasePath.join("using", pkg.getTopLevelId());
                path = targetPackage.getPath().join("using", pkg.getTopLevelId());

                
//            }

            // update info in program.json file
            var info =  {};
            if(pkg.hasUid()) {
                info["uid"] = pkg.getUid();

                options.uidLocators[info["uid"]] = locator;
            }
            info["locator"] = locator.getSpec(true);
            programDescriptor.set(key, info);

print("id: "+pkg.getTopLevelId());
dump(options.monitor.built);            

            // only build package if not already built for program
            if(!UTIL.has(options.monitor.built, pkg.getTopLevelId())) {

                options.monitor.built[pkg.getTopLevelId()] = true;
            
                self.buildPackage(pkg, options);
    
    
                // if package has a version we need to copy it, otherwise we can link it (as it is likely a sources overlay)
                if(pkg.getVersion()) {
                    if(!path.exists()) {
                        path.dirname().mkdirs();
    print("COPY "+pkg.getPath()+" to "+path);                    
                        FILE.copyTree(pkg.getPath(), path);
                    }
                    // since we copied it to a specific version we need to update all package locators
                    // to include the exact version
                    if(!pkg.hasUid())
                    locatorRewriteInfo.push({
                        "id": parentPackage[type[1].id](),
                        "name": name,
                        "revision": pkg.getVersion()
                    });
                } else
                if(!path.exists() && !path.join("package.json").exists()) {
                    path.dirname().mkdirs();
    print("LINK "+pkg.getPath()+" to "+path);                    
                    pkg.getPath().symlink(path);
                }
    
                if(type[0]=="system") {
    //print("link system package from " + path + " to " + targetPackage.getPath().join("using", "packages", name));                
                                  
                    targetPackage.getPath().join("packages").mkdirs();
                    path.symlink(targetPackage.getPath().join("packages", name));
                }
            } else {
                return false;
            }

            return locator;
        }, {
            "packageStore": PINF.getDatabase().getPackageStore(),
            "package": self.sourcePackage
        });

        locatorRewriteInfo.forEach(function(info) {
            if(info.id==self.sourcePackage[type[1].id]()) {
                path = targetPackage.getPath().join("package.json");
            } else {
                path = targetPackage.getPath().join(type[1].directory, info.id).join("package.json");
            }

            // ensure we only update copied package.json files!
            if(targetPackage.getPath().join("using").relative(path.canonical()).valueOf().substring(0,1)==".") {
                // don't update as package.json file is not within built using directory
            } else {
                JSON_STORE.JsonStore(path).set([type[1].property, info.name, "revision"], info.revision);
            }
        });
    });
*/    
    
    // copy updated program descriptor
    programDescriptor.getFile().copy(targetBasePath.join("program.json"));

    
    // link all packages with no UID property which are packages that are managed as part of the sourcePackage
    // if a UID is present the package will end up in /using/ based on dependency declarations
    var sourcePackagesPath = sourceBasePath.join("packages"),
        targetPackagesPath = targetBasePath.join("packages");
    if(sourcePackagesPath.exists()) {
        targetPackagesPath.mkdirs();
        sourcePackagesPath.listPaths().forEach(function(item) {
            if(item.join("package.json").exists()) {
                if(!UTIL.has(JSON.decode(item.join("package.json").read().toString()), "uid")) {
                    item.symlink(targetPackagesPath.join(item.basename()));
                }
            }
        });
    };

/*

    // build tester
/*
TODO: This shoul happen dynamically when a test is executed

    var spec = descriptor.getPinfSpec();
    if(spec && spec.tester) {
        var pkg = PINF.getPackageForLocator(LOCATOR.PackageLocator(spec.tester));
        options.testPackage = pkg;
        pkg.getBuilder().triggerBuild(PACKAGE.Package(rawBuildPath), options);
    }
*/

}
Ejemplo n.º 26
0
 ].forEach(function(name) {
     file = filesPath.join(name, "package.json");
     var descriptor = JSON.decode(file.read());
     delete descriptor.uid;
     file.write(JSON.encode(descriptor, null, '    '));
 });
Ejemplo n.º 27
0
App.prototype.getVersion = function() {
    if(!version) {
        version = JSON.decode(FILE.Path(this.getProgram().sea).join("package.json").read()).version;
    }
    return version;
}
Ejemplo n.º 28
0
exports.testBasicRegistration = function() {
    
    var file,
        rev;

    tusk.command("pinf --db " + tmpDBPath + " register-namespace http://127.0.0.1:8080/test@pinf.org/public/");
    
    
    
    tusk.command("pinf --db " + tmpDBPath + " register-package test@pinf.org/public " + filesPath.join("test-package-1").valueOf());
    
    ASSERT.deepEqual(
        JSON.decode(filesPath.join("test-package-1", "package.json").read()),
        {
            "uid": "http://127.0.0.1:8080/test@pinf.org/public/test-package-1/",
            "name": "test-package-1"
        }
    );
    
    file = filesPath.join("test-package-1");
    OS.command("cd " + file.valueOf() + "; git add . ; git commit -m 'registered' ; git tag v0.2.0");

    tusk.command("pinf --db " + tmpDBPath + " announce-release " + file.valueOf());

        

    file = filesPath.join("test-package-2");
    OS.command("cd " + file.valueOf() + "; git branch test; git checkout test");

    tusk.command("pinf --db " + tmpDBPath + " register-package test@pinf.org/public " + filesPath.join("test-package-2").valueOf());

    file = filesPath.join("test-package-2");
    OS.command("cd " + file.valueOf() + "; git add . ; git commit -m 'registered'");
    
    tusk.command("pinf --db " + tmpDBPath + " announce-release --branch test " + file.valueOf());
    
    rev = GIT.Git(file).getLatestRevisionForBranch("test");

    ASSERT.deepEqual(
        JSON.decode(HTTP.read("http://127.0.0.1:8080/test@pinf.org/public/catalog.json").decodeToString()),
        {
          "uid": "http://127.0.0.1:8080/test@pinf.org/public/catalog.json",
          "packages": {
            "test-package-1": {
              "0": {
                "uid": "http://127.0.0.1:8080/test@pinf.org/public/test-package-1/",
                "name": "test-package-1",
                "version": "0.2.0"
              }
            },
            "test-package-2": {
              "test": {
                "uid": "http://127.0.0.1:8080/test@pinf.org/public/test-package-2/",
                "name": "test-package-2",
                "version": "0.0.0rev-" + rev
              }
            }
          }
        }
    );

    ASSERT.deepEqual(
        JSON.decode(HTTP.read("http://127.0.0.1:8080/test@pinf.org/public/test-package-1/").decodeToString()),
        {
          "name": "test-package-1",
          "versions": {
            "0": {
              "uid": "http://127.0.0.1:8080/test@pinf.org/public/test-package-1/",
              "name": "test-package-1",
              "version": "0.2.0"
            }
          }
        }
    );

    ASSERT.deepEqual(
        JSON.decode(HTTP.read("http://127.0.0.1:8080/test@pinf.org/public/test-package-2/").decodeToString()),
        {
          "name": "test-package-2",
          "branches": {
            "test": {
              "uid": "http://127.0.0.1:8080/test@pinf.org/public/test-package-2/",
              "name": "test-package-2",
              "version": "0.0.0rev-" + rev
            }
          }
        }
    );
    

    file = filesPath.join("test-package-5");
    
    tusk.command("pinf --db " + tmpDBPath + " register-package test@pinf.org/public " + file.valueOf());
    tusk.command("pinf --db " + tmpDBPath + " announce-release --branch master " + file.valueOf());

    rev = GIT.Git(file).getLatestRevisionForBranch("master");

    ASSERT.deepEqual(
        JSON.decode(HTTP.read("http://127.0.0.1:8080/test@pinf.org/public/test-package-5/").decodeToString()),
        {
          "name": "test-package-5",
          "branches": {
            "master": {
              "uid": "http://127.0.0.1:8080/test@pinf.org/public/test-package-5/",
              "name": "test-package-5",
              "repositories": [
                  {
                      "type": "git", 
                      "url": "git://github.com/cadorn/pinf.git",
                      "path": "packages/cli/tests/registry-server/_files/test-package-5",
                      "raw": "http://github.com/cadorn/pinf/raw/{rev}/packages/cli/tests/registry-server/_files/test-package-5/{path}",
                      "download": {
                        "type": "zip",
                        "url": "http://github.com/cadorn/pinf/zipball/{rev}/"
                      }
                  }
              ],
              "version": "0.0.0rev-" + rev
            }
          }
        }
    );
    
    
    tusk.command("pinf --db " + tmpDBPath + " register-namespace http://127.0.0.1:8080/test@pinf.org/public/subset/");

    tusk.command("pinf --db " + tmpDBPath + " register-package --name renamed-test-package-5 test@pinf.org/public/subset http://127.0.0.1:8080/test@pinf.org/public/test-package-5/");
    
    ASSERT.deepEqual(
        JSON.decode(HTTP.read("http://127.0.0.1:8080/test@pinf.org/public/subset/catalog.json").decodeToString()),
        {
          "uid": "http://127.0.0.1:8080/test@pinf.org/public/subset/catalog.json",
          "packages": {
            "renamed-test-package-5": {
              "*": {
                "name": "test-package-5",
                "repositories": [
                   {
                      "type": "git",
                      "url": "git://github.com/cadorn/pinf.git",
                      "path": "packages/cli/tests/registry-server/_files/test-package-5",
                      "raw": "http://github.com/cadorn/pinf/raw/{rev}/packages/cli/tests/registry-server/_files/test-package-5/{path}",
                      "download": {
                         "type": "zip",
                         "url": "http://github.com/cadorn/pinf/zipball/{rev}/"
                      }
                   }
                ]
              },
              "master": {
                "uid": "http://127.0.0.1:8080/test@pinf.org/public/test-package-5/",
                "name": "test-package-5",
                "repositories": [
                  {
                    "type": "git",
                    "url": "git://github.com/cadorn/pinf.git",
                    "path": "packages/cli/tests/registry-server/_files/test-package-5",
                    "raw": "http://github.com/cadorn/pinf/raw/{rev}/packages/cli/tests/registry-server/_files/test-package-5/{path}",
                    "download": {
                      "type": "zip",
                      "url": "http://github.com/cadorn/pinf/zipball/{rev}/"
                    }
                  }
                ],
                "version": "0.0.0rev-" + rev
              }
            }
          }
        }
    );


    file = filesPath.join("test-package-1");
    OS.command("cd " + file.valueOf() + "; git tag v0.2.1rc1");

    tusk.command("pinf --db " + tmpDBPath + " announce-release " + file.valueOf());

    ASSERT.deepEqual(
        JSON.decode(HTTP.read("http://127.0.0.1:8080/test@pinf.org/public/test-package-1/").decodeToString()),
        {
          "name": "test-package-1",
          "versions": {
            "0": {
              "uid": "http://127.0.0.1:8080/test@pinf.org/public/test-package-1/",
              "name": "test-package-1",
              "version": "0.2.0"
            },
            "0.2.1rc": {
              "uid": "http://127.0.0.1:8080/test@pinf.org/public/test-package-1/",
              "name": "test-package-1",
              "version": "0.2.1rc1"
            }
          }
        }
    );

    resetFiles({"skipUIDRemoval": true});
}