mcfly-io / generator-sublime

Yeoman generator for scaffolfding the standard configuration root files like .gitignore, .jshintrc, .jscsrc etc...
8 stars 10 forks source link

Fix ionic.js task #300

Closed jskrzypek closed 8 years ago

jskrzypek commented 8 years ago

The suffix was handled incorrectly. It needs to get used with gulp-rename and not in building the ionicBundleSrc.

in constants.js

ionicPlatform: {
                installer: 'node_modules', // or 'bower_components'
                moduleName: 'ionic-platform-web-client',
                bundleSrc: 'dist',
                bundleFiles: ['ionic.io.bundle.js', 'ionic.io.bundle.min.js'],
                bundleDest: './' + clientFolder + '/scripts/',
                settingsReplaceStart: '\\\"IONIC_SETTINGS_STRING_START\\\";',
                settingsReplaceEnd: '\\\"IONIC_SETTINGS_STRING_END\\\"',
                settingsReplaceString: 'return { get: function(setting) { if (settings[setting]) { return settings[setting]; } return null; } };'
            },

in ionic.js, require gulp-rename, and then taskPlatformCopy() should be:

var taskIonicPlatformCopy = function(constants) {
    if (!helper.isMobile(constants)) {
        return Promise.resolve(null);
    }

    var ionicPlatform = constants.ionic.ionicPlatform;

    var ionicPlatformSrc = ionicPlatform.bundleFiles.map(function(fileName) {
        return path.join('.',
            ionicPlatform.installer,
            ionicPlatform.moduleName,
            ionicPlatform.bundleSrc,
            fileName);
    });

    var ionicPlatformDest = path.join(constants.dist.distFolder, 'www', ionicPlatform.bundleDest);

    gutil.log('Copying ' + gutil.colors.cyan(ionicPlatformSrc) + ' to ' + gutil.colors.cyan(ionicPlatformDest));

    // The following is based on http://blog.samuelbrown.io/2015/10/08/upgrading-ionic-io-services-tips-and-tricks/
    return taskIonicProject(constants)
        .then(function(configData) {
            var replacementString = 'var settings = ' + JSON.stringify(configData) + '; ' + ionicPlatform.settingsReplaceString;
            return gulp.src(ionicPlatformSrc)
                .pipe(replace(new RegExp('(' + ionicPlatform.settingsReplaceStart + ')(.*?)(' + ionicPlatform.settingsReplaceEnd + ')', 'g'), '$1' + replacementString + '$3'))
                .pipe(rename(function(path){
                    path.basename += constants.targetSuffix;
                }))
                .pipe(gulp.dest(ionicPlatformDest));
        });
};