Skip to content

Commit

Permalink
Merge pull request #3382 from thongredweb/gulp_libraries
Browse files Browse the repository at this point in the history
[Gulp] Add missing admin language. Optimize process for libraries
  • Loading branch information
Thong Tran Quang committed May 5, 2017
2 parents f0c69bc + 4bcce73 commit f6ab758
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 46 deletions.
39 changes: 34 additions & 5 deletions jgulp/components/redshop.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,12 @@ gulp.task('watch:' + baseTask + ':frontend:files', function (cb) {
*/
// Admin: COPY
gulp.task('copy:' + baseTask + ':backend',
['copy:' + baseTask + ':backend:redshop.xml', 'copy:' + baseTask + ':backend:install.php', 'copy:' + baseTask + ':backend:admin']
[
'copy:' + baseTask + ':backend:redshop.xml',
'copy:' + baseTask + ':backend:install.php',
'copy:' + baseTask + ':backend:files',
'copy:' + baseTask + ':backend:lang'
]
);
// Admin: Clean backend, will clean components from Administrator
gulp.task('clean:' + baseTask + ':backend', function () {
Expand All @@ -229,9 +234,27 @@ gulp.task('clean:' + baseTask + ':backend', function () {
});
// Admin: Watch
gulp.task('watch:' + baseTask + ':backend',
['watch:' + baseTask + ':backend:redshop.xml', 'watch:' + baseTask + ':backend:install.php', 'watch:' + baseTask + ':backend:admin']
[
'watch:' + baseTask + ':backend:redshop.xml',
'watch:' + baseTask + ':backend:install.php',
'watch:' + baseTask + ':backend:files',
'watch:' + baseTask + ':backend:lang'
]
);

// Copy: Admin language
gulp.task('copy:' + baseTask + ':backend:lang', ['clean:' + baseTask + ':backend:lang'], function () {
return gulp.src(extPath + '/component/admin/language/**')
.pipe(gulp.dest(config.wwwDir + '/administrator/language'));
});
// Clean: Admin language
gulp.task('clean:' + baseTask + ':backend:lang', function () {
return del(config.wwwDir + '/administrator/language/**/*.' + componentName + '.*', {force: true});
});
// Watch: Admin language
gulp.task('watch:' + baseTask + ':backend:lang', function () {
gulp.watch(extPath + '/component/admin/language/**', ['copy:' + baseTask + ':backend:lang']);
});

// Copy: redSHOP.xml file
gulp.task('copy:' + baseTask + ':backend:redshop.xml', ['clean:' + baseTask + ':backend:redshop.xml'], function () {
Expand Down Expand Up @@ -264,12 +287,18 @@ gulp.task('clean:' + baseTask + ':backend:install.php', function () {


// Copy: copy redSHOP Backend files
gulp.task('copy:' + baseTask + ':backend:admin', function () {
return gulp.src(extPath + '/component/admin/**/*')
gulp.task('copy:' + baseTask + ':backend:files', function () {
return gulp.src(
[
extPath + '/component/admin/**/*',
'!' + extPath + '/component/admin/language',
'!' + extPath + '/component/admin/language/**'
]
)
.pipe(gulp.dest(config.wwwDir + '/administrator/components/' + componentName));
});
// Watch: redSHOP Backend files
gulp.task('watch:' + baseTask + ':backend:admin', function (cb) {
gulp.task('watch:' + baseTask + ':backend:files', function (cb) {
gulp.watch(extPath + '/component/admin/**/*')
.on("change", function (file) {
var destinationPath = path.join(config.wwwDir, "administrator", "components", componentName);
Expand Down
96 changes: 55 additions & 41 deletions jgulp/libraries/redshop.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,35 @@ var config = require('../../gulp-config.json');

// Dependencies
var browserSync = require('browser-sync');
var concat = require('gulp-concat');
var composer = require('gulp-composer');
var del = require('del');
var fs = require('fs');
var rename = require('gulp-rename');
var xml2js = require('xml2js');
var parser = new xml2js.Parser({explicitArray : false});
var concat = require('gulp-concat');
var composer = require('gulp-composer');
var del = require('del');
var fs = require('fs');
var rename = require('gulp-rename');
var xml2js = require('xml2js');
var parser = new xml2js.Parser({explicitArray: false});
var path = require('path');

var libraryName = 'redshop';

var baseTask = 'libraries.' + libraryName;
var extPath = './libraries/' + libraryName;
var baseTask = 'libraries.' + libraryName;
var extPath = './libraries/' + libraryName;
var manifestFile = libraryName + '.xml';
var wwwPath = config.wwwDir + '/libraries/' + libraryName;
var wwwPath = config.wwwDir + '/libraries/' + libraryName;
var libraryFiles = [];

// Clean
gulp.task('clean:' + baseTask,
[
'clean:' + baseTask + ':library',
'clean:' + baseTask + ':manifest'
],
function() {
}
);
gulp.task('clean:' + baseTask, ['clean:' + baseTask + ':library', 'clean:' + baseTask + ':manifest'], function () {
});

// Clean: library
gulp.task('clean:' + baseTask + ':library', function() {
return del(wwwPath, {force : true});
gulp.task('clean:' + baseTask + ':library', function () {
return del(wwwPath, {force: true});
});

// Clean: manifest
gulp.task('clean:' + baseTask + ':manifest', function() {
return del(config.wwwDir + '/administrator/manifests/libraries/' + manifestFile, {force : true});
gulp.task('clean:' + baseTask + ':manifest', function () {
return del(config.wwwDir + '/administrator/manifests/libraries/' + manifestFile, {force: true});
});

// Copy
Expand All @@ -46,17 +41,17 @@ gulp.task('copy:' + baseTask,
'copy:' + baseTask + ':library',
'copy:' + baseTask + ':manifest'
],
function() {
function () {
}
);

// Copy: manifest
gulp.task('copy:' + baseTask + ':manifest', ['clean:' + baseTask + ':manifest'], function() {
gulp.task('copy:' + baseTask + ':manifest', ['clean:' + baseTask + ':manifest'], function () {
return gulp.src(extPath + '/' + manifestFile)
.pipe(gulp.dest(config.wwwDir + '/administrator/manifests/libraries'));
});

gulp.task('copy:' + baseTask + ':vendor', function() {
gulp.task('copy:' + baseTask + ':vendor', function () {
return gulp.src([
extPath + '/vendor/**',
'!' + extPath + '/vendor/**/docs',
Expand All @@ -78,7 +73,7 @@ gulp.task('copy:' + baseTask + ':vendor', function() {
'!' + extPath + '/vendor/**/Vagrant*',
'!' + extPath + '/vendor/**/.*.yml',
'!' + extPath + '/vendor/**/.editorconfig'
], { base: extPath })
], {base: extPath})
.pipe(gulp.dest(wwwPath));
});

Expand All @@ -95,7 +90,7 @@ function getLibraryFiles(callback) {
return callback(libraryFiles);
}

fs.readFile(extPath + '/' + libraryName + '.xml', function(err, data) {
fs.readFile(extPath + '/' + libraryName + '.xml', function (err, data) {
parser.parseString(data, function (err, result) {
var folders = result.extension.files.folder;
var files = result.extension.files.filename;
Expand All @@ -116,14 +111,14 @@ function getLibraryFiles(callback) {
}

// Composer
gulp.task('composer:' + baseTask, function(cb) {
composer({ cwd: extPath, bin: 'php ./composer.phar'}).on('end', cb);
gulp.task('composer:' + baseTask, function (cb) {
composer({cwd: extPath, bin: 'php ./composer.phar'}).on('end', cb);
});

// Copy: library
gulp.task('copy:' + baseTask + ':library', ['composer:' + baseTask], function(cb) {
getLibraryFiles(function(src){
return gulp.src(src,{ base: extPath })
gulp.task('copy:' + baseTask + ':library', ['composer:' + baseTask], function (cb) {
getLibraryFiles(function (src) {
return gulp.src(src, {base: extPath})
.pipe(gulp.dest(wwwPath))
.on('end', cb);
});
Expand All @@ -135,20 +130,39 @@ gulp.task('watch:' + baseTask,
'watch:' + baseTask + ':library',
'watch:' + baseTask + ':manifest'
],
function() {
function () {
});

// Watch: library
gulp.task('watch:' + baseTask + ':library', function() {
gulp.watch([
extPath + '/**/*',
'!' + extPath + '/vendor',
'!' + extPath + '/vendor/**/*',
'!' + extPath + '/' + manifestFile
], ['copy:' + baseTask + ':library', browserSync.reload]);
gulp.task('watch:' + baseTask + ':library', function () {
gulp.watch(
[
extPath,
extPath + '/**',
extPath + '/**!/*',
'!' + extPath + '/vendor',
'!' + extPath + '/vendor/!**!/!*',
'!' + extPath + '/' + manifestFile
],
function (event) {
var folder = 'libraries/redshop';
var deployFile = path.join(wwwPath, event.path.substring(event.path.indexOf("libraries") + folder.length, event.path.length));

if (event.type == "changed") {
// Copy files
gulp.src(event.path).pipe(gulp.dest(path.dirname(deployFile)));
}
else if (event.type == "deleted") {
// Delete files
del(deployFile, {force: true});
}

browserSync.reload();
}
);
});

// Watch: manifest
gulp.task('watch:' + baseTask + ':manifest', function() {
gulp.task('watch:' + baseTask + ':manifest', function () {
gulp.watch(extPath + '/' + manifestFile, ['copy:' + baseTask + ':manifest', browserSync.reload]);
});

0 comments on commit f6ab758

Please sign in to comment.