Skip to content

Commit 0506e2e

Browse files
author
Ryan A. Johnson
committed
build: use gulp tasks to generate tgz downloads
* Update Copyright year to "2017-2019" range
1 parent ab7445d commit 0506e2e

File tree

11 files changed

+332
-51
lines changed

11 files changed

+332
-51
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright 2019 Rackspace US, Inc.
1+
Copyright 2017-2019 Rackspace US, Inc.
22

33
Licensed under the Apache License, Version 2.0 (the "License");
44
you may not use this file except in compliance with the License.

gulpfile.esm.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
1-
import { task } from 'gulp';
2-
3-
import { bundle } from './tasks/bundle';
4-
5-
task('default', bundle);
1+
export * from './tasks';
2+
export { bundle as default } from './tasks';

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"gh-pages": "^2.0.0",
3333
"globby": "10.x",
3434
"gulp": "^4.0.2",
35+
"gulp-tar": "^3.1.0",
3536
"highlight.js": "^9.12.0",
3637
"jsdoc": "^3.5.5",
3738
"jsdom": "^12.2.0",

scripts/_config/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ CONFIG.sourceDir = 'src';
1111
CONFIG.docsDir = 'docs';
1212
CONFIG.testDir = 'test';
1313
CONFIG.distDir = 'dist';
14+
CONFIG.tmpDir = '_tmp';
1415

1516
// Component Explorer configuration
1617
// Used directly for "site" rendering context

scripts/_generate/index.js

Lines changed: 8 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ const SASS = require('node-sass');
1010
const path = require('path');
1111
const tar = require('tar');
1212
const webpack = require('webpack');
13-
const { copy, ensureDir, ensureDirSync, remove } = require('fs-extra');
13+
const { ensureDir, ensureDirSync } = require('fs-extra');
14+
const { src, dest } = require('gulp');
1415

15-
const pkg = require('../../package.json');
1616
const CONFIG = require('../_config');
1717
const { exec, readFile, writeFile } = require('../_util');
1818

@@ -120,42 +120,15 @@ async function generateJSON () {
120120
* Generates downloadable *.tgz assets
121121
*/
122122
async function generateDownloads () {
123-
let destDir = `${CONFIG.publicDir}/downloads`;
123+
console.log('Generate *.tgz Downloads');
124+
await exec(`yarn gulp archive`, { cwd: CONFIG.root });
124125

125-
let downloads = [
126-
{
127-
src: CONFIG.distDir,
128-
name: `helix-ui-${pkg.version}`,
129-
},
130-
{
131-
src: `${CONFIG.sourceDir}/images/icons`,
132-
name: `helix-ui-${pkg.version}-icons`,
133-
}
126+
let globs = [
127+
`${CONFIG.tmpDir}/*.tgz`,
134128
];
135129

136-
// Make sure destination exists
137-
await ensureDir(destDir);
138-
139-
downloads.forEach(async function (dl) {
140-
console.log(`Generating ${dl.name}.tgz`);
141-
let tmpDir = `_tmp/${dl.name}`;
142-
143-
// Ensure a clean slate
144-
await remove(tmpDir);
145-
146-
// Create temporary directory so we can customize
147-
// the name of the uncompressed output.
148-
await ensureDir(tmpDir);
149-
150-
await copy(dl.src, tmpDir);
151-
await tar.create({
152-
file: `${destDir}/${dl.name}.tgz`,
153-
gzip: true,
154-
}, [tmpDir]);
155-
156-
// Cleanup temporary files
157-
await remove(tmpDir);
158-
});
130+
return src(globs)
131+
.pipe(dest(`${CONFIG.publicDir}/downloads`));
159132
}//generateDownloads
160133

161134
/**

tasks/archive/helix-ui.js

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/**
2+
* dist/** --> {tmpDir}/{pkg.name}-{pkg.version}/** --> {tmpDir}/{pkg.name}-{pkg.version}.tgz
3+
*/
4+
import { ensureDir, readFile, remove, writeFile } from 'fs-extra';
5+
import { dest, parallel, series, src } from 'gulp';
6+
import tar from 'gulp-tar';
7+
import path from 'path';
8+
9+
import { pkg, rootDir, tmpDir } from '../config';
10+
11+
12+
// target destination for the tarball
13+
const FILEPATH = `${tmpDir}/${pkg.name}-${pkg.version}.tgz`;
14+
// where to build tarball contents
15+
const TMP_DIR = `${tmpDir}/package`;
16+
// name of the tarball
17+
const FILENAME = path.basename(FILEPATH); // "{NAME}-{VERSION}.tgz"
18+
// target directory
19+
const DEST_DIR = path.dirname(FILEPATH); // "{tmpDir}"
20+
/*
21+
* Collect globs for bundled dependency assets
22+
* (as configured via "bundledDependencies" in package.json)
23+
*/
24+
const BUNDLED = pkg.bundledDependencies.map(dep => `node_modules/${dep}/**/*`);
25+
/*
26+
* Define globs for all assets to be included in the package.
27+
* (relative to the root of the project)
28+
*/
29+
const GLOBS = [
30+
'LICENSE',
31+
'README.md',
32+
// extra files
33+
'dist/**/*', // TODO: use config vars to compose this glob
34+
...BUNDLED,
35+
];
36+
37+
38+
async function writePackageJSON () {
39+
let raw = await readFile(`${rootDir}/package.json`);
40+
let data = JSON.parse(raw);
41+
42+
data.files = '*'; // include everything in {TMP_DIR} in the tarball
43+
44+
// remove unnecessary keys
45+
delete data.scripts;
46+
delete data.nyc;
47+
48+
await ensureDir(TMP_DIR);
49+
await writeFile(`${TMP_DIR}/package.json`, JSON.stringify(data, null, 2));
50+
}
51+
52+
function copyGlobFiles () {
53+
return src(GLOBS, { base: '.' })
54+
.pipe(dest(TMP_DIR));
55+
}
56+
57+
58+
async function _prepare () {
59+
await remove(TMP_DIR);
60+
await remove(FILEPATH);
61+
}
62+
63+
64+
/*
65+
* Package asset bundles into tarball.
66+
*
67+
* This is similar to how NPM works via `npm pack`,
68+
* but it allows us to have more control of the
69+
* directory structure within the tarball.
70+
*
71+
* NOTE: bundles MUST be generated beforehand
72+
*/
73+
function createArchive () {
74+
return src(`${TMP_DIR}/**/*`)
75+
.pipe(tar(FILENAME, { gzip: true })) // archive...
76+
.pipe(dest(DEST_DIR)); // write tarball to destination
77+
}
78+
79+
const collectFiles = parallel(
80+
copyGlobFiles,
81+
writePackageJSON,
82+
);
83+
84+
const archiveHelixUI = series(
85+
_prepare,
86+
collectFiles,
87+
createArchive,
88+
);
89+
90+
export {
91+
FILEPATH,
92+
archiveHelixUI,
93+
};

tasks/archive/icons.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { src, dest } from 'gulp';
2+
import tar from 'gulp-tar';
3+
import path from 'path';
4+
5+
import {
6+
pkg,
7+
pubDir,
8+
site as siteCfg,
9+
srcDir,
10+
tmpDir,
11+
} from '../config';
12+
13+
// what to include in the tarball
14+
const GLOBS = [
15+
'LICENSE',
16+
`${srcDir}/images/icons/*.svg`,
17+
];
18+
// path of generated tarball (relative to project root)
19+
const FILEPATH = `${tmpDir}/${pkg.name}-${pkg.version}-icons.tgz`;
20+
// where to build tarball contents
21+
const TMP_DIR = `${tmpDir}/icons`;
22+
// name of tarball (sans directory paths)
23+
const FILENAME = path.basename(FILEPATH);
24+
// where to place the tarball
25+
const DEST_DIR = path.dirname(FILEPATH);
26+
27+
async function archiveIcons () {
28+
return src(GLOBS)
29+
.pipe(dest(TMP_DIR))
30+
.pipe(tar(FILENAME, { gzip: true }))
31+
.pipe(dest(DEST_DIR))
32+
}
33+
34+
export {
35+
FILEPATH,
36+
archiveIcons,
37+
};

tasks/archive/index.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* Create _tmp/*.tgz files
3+
*/
4+
import { parallel } from 'gulp';
5+
import { archiveHelixUI } from './helix-ui';
6+
import { archiveIcons } from './icons';
7+
8+
// FYI: requires `gulp bundle --prod`
9+
const archive = parallel(
10+
archiveHelixUI,
11+
archiveIcons,
12+
);
13+
14+
export {
15+
archive,
16+
archiveHelixUI,
17+
archiveIcons,
18+
};

tasks/config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export const docsDir = 'docs'
99
export const pubDir = 'public';
1010
export const srcDir = 'src';
1111
export const testDir = 'test';
12+
export const tmpDir = '_tmp';
1213

1314
// Component Explorer Docs Configuration
1415
// Used directly for "site" rendering context

tasks/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './archive';
2+
export { bundle } from './bundle';

0 commit comments

Comments
 (0)