diff --git a/gulpfile.js b/gulpfile.js index 2a1d2439b6..e1e0a41239 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -21,13 +21,15 @@ require('./tasks/gulp/prepare-files.js') require('./tasks/gulp/demo-build.js') require('./tasks/gulp/preview-component-list.js') require('./tasks/gulp/preview-docs.js') +// new tasks +require('./tasks/gulp/copy-to-destination.js') // Build packages task ----------------- // Prepare package folder for publishing // ------------------------------------- -gulp.task('build:packages', cb => { - runsequence('test', 'prepare:files', 'packages:update', cb) -}) +// gulp.task('build:packages', cb => { +// runsequence('test', 'prepare:files', 'packages:update', cb) +// }) // Build dist task ---------------------- // Create temp files, update packages @@ -104,6 +106,13 @@ gulp.task('serve', ['watch'], () => { }) }) +// Build packages task ----------------- +// Prepare package folder for publishing +// ------------------------------------- +gulp.task('build:packages', cb => { + runsequence('copy-files', cb) +}) + // Default task ------------------------- // Lists out available tasks. // -------------------------------------- diff --git a/package.json b/package.json index 6008389580..c2a37a2a6e 100644 --- a/package.json +++ b/package.json @@ -15,8 +15,9 @@ "homepage": "https://github.com/alphagov/govuk-frontend#readme", "scripts": { "start": "gulp dev --destination 'public'", - "test": "standard && gulp compile:components --destination 'public' && gulp test", - "heroku": "gulp compile:components --destination 'public' && gulp copy-assets --destination 'public' && node app.js" + "test": "standard && gulp test", + "heroku": "gulp compile:components --destination 'public' && gulp copy-assets --destination 'public' && node app.js", + "build:packages": "gulp build:packages --destination 'packages' --production" }, "devDependencies": { "autoprefixer": "^7.1.1", diff --git a/tasks/gulp/copy-to-destination.js b/tasks/gulp/copy-to-destination.js new file mode 100644 index 0000000000..e3d13cb541 --- /dev/null +++ b/tasks/gulp/copy-to-destination.js @@ -0,0 +1,65 @@ +'use strict' + +const gulp = require('gulp') +const paths = require('../../config/paths.json') +const postcss = require('gulp-postcss') +const autoprefixer = require('autoprefixer') +const taskArguments = require('./task-arguments') +const replace = require('gulp-replace') +const filter = require('gulp-filter') +const flatten = require('gulp-flatten') +const rename = require('gulp-rename') + +let scssFiles = filter([paths.src + '**/*.scss'], {restore: true}) +let icons = filter([paths.src + 'globals/icons/*'], {restore: true}) +let components = filter([paths.src + 'components/**/*'], {restore: true}) +let globals = filter([paths.src + 'globals/scss/**/*'], {restore: true}) + +gulp.task('copy-files', () => { + return gulp.src([ + paths.src + '**/*', + '!' + paths.src + 'components/_component-example/**/*', + '!' + paths.src + 'globals/icons', + '!' + paths.src + 'globals/scss', + '!' + paths.src + 'globals', + '!' + paths.src + 'views', + '!' + paths.src + 'components', + '!' + paths.src + 'views/**', + '!' + paths.src + 'examples', + '!' + paths.src + 'examples/**', + '!' + paths.src + 'globals/scss/govuk-frontend-oldie.scss' + ]) + .pipe(scssFiles) + .pipe(replace('//start:devonly', '/*start:devonly')) + .pipe(replace('//end:devonly', 'end:devonly*/')) + .pipe(postcss([ + // postcssnormalize, + autoprefixer, + require('postcss-nested') + ], {syntax: require('postcss-scss')})) + .pipe(scssFiles.restore) + .pipe(icons) + .pipe(flatten({includeParents: -1})) + .pipe(icons.restore) + .pipe(globals) // replace import in scss files and bring globals/ up one level + .pipe(replace('../../components', '@govuk-frontend')) + .pipe(replace('../../globals', '@govuk-frontend')) + .pipe(replace('./node_modules/', '')) + .pipe(flatten({ + subPath: [2, 3], + newPath: 'globals' + })) + .pipe(rename((path) => { + if (path.basename + path.extname === 'govuk-frontend.scss') { + path.dirname = 'all' + path.basename = '_all' + } + })) + .pipe(globals.restore) + .pipe(components) // replace import in scss files and flatten folder (e.g remove components/) + .pipe(replace('../../globals/scss', '@govuk-frontend/globals')) + .pipe(replace('../', '@govuk-frontend/')) + .pipe(flatten({includeParents: -1})) + .pipe(components.restore) + .pipe(gulp.dest(taskArguments.destination + '/')) +})