lib/main.js
function(url, onProgress) {
        onProgress = onProgress || function(){};
        return injectGlobalCatalogs()
            .then(function() {
                library.commit();
               return request.read(url);
            })
            .then(function(response) {
                // disable saves for better performance
                library.autosave(false);
                // index projects and source languages
                if (response.status !== 200) return Promise.reject(response);

                let projects;
                try {
                    projects = JSON.parse(response.data);
                } catch (err) {
                    return Promise.reject(err);
                }

                return promiseUtils.chain(downloadSourceLanguages, function(err, data) {
                    if(err instanceof Error) return Promise.reject(err);
                    console.log(err);
                    return false;
                }, {compact: true, onProgress: onProgress.bind(null, 'projects')})(projects);
            })
            .then(function(projects) {
                // index resources
                library.commit();
                if(!projects) return Promise.reject('No projects found');
                let list = [];
                for(let project of projects) {
                    for(let localizedProject of project) {
                        list.push({
                            id: localizedProject.id,
                            slug: localizedProject.slug,
                            source_language_id: localizedProject.source_language_id,
                            resourceUrl: localizedProject.resourceUrl
                        });
                    }
                }

                return promiseUtils.chain(downloadSourceResources, function(err, data) {
                    if(err instanceof Error) return Promise.reject(err);
                    console.log(err);
                    return false;
                }, {compact: true, onProgress: onProgress.bind(null, 'resources')})(list);
            }).then(function() {
                // keep the promise args clean
                library.commit();
                library.autosave(true);
                return Promise.resolve();
            }).catch(function(err) {
                library.autosave(true);
                return Promise.reject(err);
            });
    }
function(url, onProgress) {
        onProgress = onProgress || function(){};
        return injectGlobalCatalogs()
            .then(function() {
                library.commit();
               return request.read(url);
            })
            .then(function(response) {
                // disable saves for better performance
                library.autosave(false);
                // index projects and source languages
                if (response.status !== 200) return Promise.reject(response);

                let projects;
                try {
                    projects = JSON.parse(response.data);
                } catch (err) {
                    return Promise.reject(err);
                }

                return promiseUtils.chain(downloadSourceLanguages, function(err, data) {
                    if(err instanceof Error) return Promise.reject(err);
                    console.log(err);
                    return false;
                }, {compact: true, onProgress: onProgress.bind(null, 'projects')})(projects);
            })
            .then(function(projects) {
                // index resources
                library.commit();
                if(!projects) return Promise.reject('No projects found');
                let list = [];
                for(let project of projects) {
                    for(let localizedProject of project) {
                        list.push({
                            id: localizedProject.id,
                            slug: localizedProject.slug,
                            source_language_id: localizedProject.source_language_id,
                            resourceUrl: localizedProject.resourceUrl
                        });
                    }
                }

                return promiseUtils.chain(downloadSourceResources, function(err, data) {
                    if(err instanceof Error) return Promise.reject(err);
                    console.log(err);
                    return false;
                }, {compact: true, onProgress: onProgress.bind(null, 'resources')})(list);
            }).then(function() {
                // keep the promise args clean
                library.commit();
                library.autosave(true);
                return Promise.resolve();
            }).catch(function(err) {
                library.autosave(true);
                return Promise.reject(err);
            });
    }
function ( url , onProgress ) { onProgress = onProgress || function ( ) { } ; return injectGlobalCatalogs ( ) . then ( function ( ) { library . commit ( ) ; return request . read ( url ) ; } ) . then ( function ( response ) { // disable saves for better performance library . autosave ( false ) ; // index projects and source languages if ( response . status !== 200 ) return Promise . reject ( response ) ; let projects ; try { projects = JSON . parse ( response . data ) ; } catch ( err ) { return Promise . reject ( err ) ; } return promiseUtils . chain ( downloadSourceLanguages , function ( err , data ) { if ( err instanceof Error ) return Promise . reject ( err ) ; console . log ( err ) ; return false ; } , { compact : true , onProgress : onProgress . bind ( null , 'projects' ) } ) ( projects ) ; } ) . then ( function ( projects ) { // index resources library . commit ( ) ; if ( ! projects ) return Promise . reject ( 'No projects found' ) ; let list = [ ] ; for ( let project of projects ) { for ( let localizedProject of project ) { list . push ( { id : localizedProject . id , slug : localizedProject . slug , source_language_id : localizedProject . source_language_id , resourceUrl : localizedProject . resourceUrl } ) ; } } return promiseUtils . chain ( downloadSourceResources , function ( err , data ) { if ( err instanceof Error ) return Promise . reject ( err ) ; console . log ( err ) ; return false ; } , { compact : true , onProgress : onProgress . bind ( null , 'resources' ) } ) ( list ) ; } ) . then ( function ( ) { // keep the promise args clean library . commit ( ) ; library . autosave ( true ) ; return Promise . resolve ( ) ; } ) . catch ( function ( err ) { library . autosave ( true ) ; return Promise . reject ( err ) ; } ) ; }
Indexes the languages, projects, and resources from the api

@param url {string} the entry resource api catalog
@param onProgress {function} an optional progress listener. This should receive progress id, total, completed
@returns {Promise}
Indexes the languages projects and resources from the api