Skip to content

Commit

Permalink
Create copy task and add it to npm run
Browse files Browse the repository at this point in the history
  • Loading branch information
Jani Kraner committed Sep 13, 2017
1 parent 7721ec6 commit 542e7ec
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 5 deletions.
15 changes: 12 additions & 3 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
// --------------------------------------
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
65 changes: 65 additions & 0 deletions tasks/gulp/copy-to-destination.js
Original file line number Diff line number Diff line change
@@ -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 + '/'))
})

0 comments on commit 542e7ec

Please sign in to comment.