(function ()()

in tools/release.js [47:126]


(function () {
    var config, matched, version, devVersion, registry;

    config = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf-8'));
    devVersion = config.version;
    matched = devVersion.match(/^(\d+\.\d+\.\d+(-\d+)?)$/);
    if (!matched) {
        console.error('version style "' + devVersion + '" is not matched to X.X.X[-X].');
        process.exit(1);
    }

    version = matched[1];
    config.version = version;

    registry = new RegistryClient();

    function ping(memo, name) {
        return new Promise(function (resolve, reject) {
            var pattern;
            console.log('[' + name + '] ' + 'send ping');

            pattern = config.dependencies[name];

            registry.lookup(name, function (err, entry) {
                var i, iz, version;

                if (err) {
                    console.error('[' + name + '] ' + err.message + '. skip this dependency');
                    return;
                }

                console.log('[' + name + '] ' + 'received result');
                memo[name] = pattern;
                resolve();
            });
        });
    }

    exec('git branch -D ' + version)
    .then(function () {
        return exec('git checkout -b ' + version);
    })
    .then(function generateConfigs() {
        var dependencies = {},
            optionalDependencies = {},
            promises;
        fs.writeFileSync(path.join(root, 'package.json'), JSON.stringify(config, null, 4), 'utf-8');

        // generate component.json
        promises =
            Object.keys(config.dependencies).map(ping.bind(null, dependencies)).concat(
                Object.keys(config.optionalDependencies).map(ping.bind(null, optionalDependencies)));
        return Promise.all(promises).then(function () {
            config.dependencies = dependencies;
            config.optionalDependencies = optionalDependencies;
            fs.writeFileSync(path.join(root, 'component.json'), JSON.stringify(config, null, 4), 'utf-8');
        });
    })
    .then(function browserify() {
        return exec('npm run-script build');
    })
    .then(function browserify() {
        return exec('npm run-script build-min');
    })
    .then(function gitAdd() {
        return exec('git add "' + root + '"');
    })
    .then(function gitCommit() {
        return exec('git commit -m "Bump version ' + version + '"');
    })
    .then(function gitDeleteTag() {
        return exec('git tag -d ' + version);
    })
    .then(function gitAddTag() {
        return exec('git tag -a ' + version + ' -m "version ' + version + '"');
    })
    .then(function () {
        console.log('Finally you should execute npm publish and git push --tags');
    });
}());