lib/version.js
function discoverVersion() {
    // try to understand package name and current version
    // from package.json or bower.json
    let packageFile;
    let packageFileExtension;
    let packageType;
    let results = {
        name: '',
        currentVersion: ''
    };
    let possiblePackageFiles = ['package.json', 'bower.json', 'package.js'];

    for (possiblePackageFile of possiblePackageFiles) {
        if (fs.existsSync(possiblePackageFile)) {
            packageFile = possiblePackageFile;
            break;
        }
    }

    packageFileExtension = packageFile.substr(packageFile.lastIndexOf('.') + 1);

    if (packageFile) {
        let packageData;

        if (packageFileExtension === 'json') {
            packageData = jsonReader(packageFile);
        }
        if (packageFileExtension === 'js') {
            let tmpData = fs.readFileSync(packageFile).toString().split('\n');
            let nameFound = false;
            let versionFound = false;

            packageData = {};

            for (line of tmpData) {
                if (line.indexOf('name:') >= 0) {
                    nameFound = true;
                    packageData.name = line.split(' ').pop().replace(/'/g, '').replace(/,/g, '');
                }
                if (line.indexOf('version:') >= 0) {
                    versionFound = true;
                    packageData.version = line.split(' ').pop().replace(/'/g, '').replace(/,/g, '');
                }

                if (nameFound && versionFound) {
                    break;
                }
            }
        }

        debugLog('Reading packageFile for init:');
        debugLog('Discovered pacakge name: ' + packageData.name + ' - discovered package version ' + packageData.version);

        if (packageData.name) {
            results.name = packageData.name;
        }
        else {
            print('Can\'t discover package name automatically', 'msgWarning', 'spaced22');
        }

        if (packageData.version) {
            results.currentVersion = packageData.version;
        }
        else {
            print('Can\'t discover package\'s currentVersion automatically', 'msgWarning', 'spaced22');
        }
    }
    else {
        print('Can\'t discover package name and/or currentVersion automatically', 'msgWarning', 'spaced22');
        print('Please fill .versionFilesList.json with the missing informations', 'msgWarning', 'spaced22');
    }

    return results;
}
function discoverVersion() {
    // try to understand package name and current version
    // from package.json or bower.json
    let packageFile;
    let packageFileExtension;
    let packageType;
    let results = {
        name: '',
        currentVersion: ''
    };
    let possiblePackageFiles = ['package.json', 'bower.json', 'package.js'];

    for (possiblePackageFile of possiblePackageFiles) {
        if (fs.existsSync(possiblePackageFile)) {
            packageFile = possiblePackageFile;
            break;
        }
    }

    packageFileExtension = packageFile.substr(packageFile.lastIndexOf('.') + 1);

    if (packageFile) {
        let packageData;

        if (packageFileExtension === 'json') {
            packageData = jsonReader(packageFile);
        }
        if (packageFileExtension === 'js') {
            let tmpData = fs.readFileSync(packageFile).toString().split('\n');
            let nameFound = false;
            let versionFound = false;

            packageData = {};

            for (line of tmpData) {
                if (line.indexOf('name:') >= 0) {
                    nameFound = true;
                    packageData.name = line.split(' ').pop().replace(/'/g, '').replace(/,/g, '');
                }
                if (line.indexOf('version:') >= 0) {
                    versionFound = true;
                    packageData.version = line.split(' ').pop().replace(/'/g, '').replace(/,/g, '');
                }

                if (nameFound && versionFound) {
                    break;
                }
            }
        }

        debugLog('Reading packageFile for init:');
        debugLog('Discovered pacakge name: ' + packageData.name + ' - discovered package version ' + packageData.version);

        if (packageData.name) {
            results.name = packageData.name;
        }
        else {
            print('Can\'t discover package name automatically', 'msgWarning', 'spaced22');
        }

        if (packageData.version) {
            results.currentVersion = packageData.version;
        }
        else {
            print('Can\'t discover package\'s currentVersion automatically', 'msgWarning', 'spaced22');
        }
    }
    else {
        print('Can\'t discover package name and/or currentVersion automatically', 'msgWarning', 'spaced22');
        print('Please fill .versionFilesList.json with the missing informations', 'msgWarning', 'spaced22');
    }

    return results;
}
function discoverVersion ( ) { // try to understand package name and current version // from package.json or bower.json let packageFile ; let packageFileExtension ; let packageType ; let results = { name : '' , currentVersion : '' } ; let possiblePackageFiles = [ 'package.json' , 'bower.json' , 'package.js' ] ; for ( possiblePackageFile of possiblePackageFiles ) { if ( fs . existsSync ( possiblePackageFile ) ) { packageFile = possiblePackageFile ; break ; } } packageFileExtension = packageFile . substr ( packageFile . lastIndexOf ( '.' ) + 1 ) ; if ( packageFile ) { let packageData ; if ( packageFileExtension === 'json' ) { packageData = jsonReader ( packageFile ) ; } if ( packageFileExtension === 'js' ) { let tmpData = fs . readFileSync ( packageFile ) . toString ( ) . split ( '\n' ) ; let nameFound = false ; let versionFound = false ; packageData = { } ; for ( line of tmpData ) { if ( line . indexOf ( 'name:' ) >= 0 ) { nameFound = true ; packageData . name = line . split ( ' ' ) . pop ( ) . replace ( / ' / g , '' ) . replace ( / , / g , '' ) ; } if ( line . indexOf ( 'version:' ) >= 0 ) { versionFound = true ; packageData . version = line . split ( ' ' ) . pop ( ) . replace ( / ' / g , '' ) . replace ( / , / g , '' ) ; } if ( nameFound && versionFound ) { break ; } } } debugLog ( 'Reading packageFile for init:' ) ; debugLog ( 'Discovered pacakge name: ' + packageData . name + ' - discovered package version ' + packageData . version ) ; if ( packageData . name ) { results . name = packageData . name ; } else { print ( 'Can\'t discover package name automatically' , 'msgWarning' , 'spaced22' ) ; } if ( packageData . version ) { results . currentVersion = packageData . version ; } else { print ( 'Can\'t discover package\'s currentVersion automatically' , 'msgWarning' , 'spaced22' ) ; } } else { print ( 'Can\'t discover package name and/or currentVersion automatically' , 'msgWarning' , 'spaced22' ) ; print ( 'Please fill .versionFilesList.json with the missing informations' , 'msgWarning' , 'spaced22' ) ; } return results ; }
discover project version
discover project version