Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

add ability to run deploy on static client #30

Merged
merged 11 commits into from
Feb 6, 2019
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ All of the following options are required and overridable via the CLI. For exam
| `name` | `null` |
| `version` | `version` property in `package.json` |
| `skyuxVersion` | `_requested.spec` in the `package.json` file in `./node_modules/blackbaud-skyux2/` |
| `logSkyuxVersion` | `true` |
| `azureStorageAccount` | `null` |
| `azureStorageAccessKey` | `null` |
| `azureStorageTableName` | "spa" |
| `isStaticClient` | `false` |

`null` values are typically supplied by the CI process.
13 changes: 11 additions & 2 deletions lib/assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,19 @@ const getEmittedAssets = () => glob
* Returns an array of assets (files + metadata).
* @name getDistAssets
* @param {boolean} includeContent
* @param {boolean} isStaticClient
* @returns {Array} assets
*/
const getDistAssets = (includeContent) => {
const metadataPath = path.join(dist, 'metadata.json');
const getDistAssets = (includeContent, isStaticClient) => {
let metadataPath = path.join(dist, 'metadata.json');

if (isStaticClient) {
// This should just return the single project bundle
const bundle = glob.sync(path.join(dist, 'bundles', '*.js'));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of our bundles definitely have multiple files (regular vs minified). I would adjust this to publish anything *.* inside the bundles folder.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would we want all the files? Currently the following logic receives a single path. What would be the best path forward for handling multiple files?

if (bundle.length) {
metadataPath = bundle[0];
}
}

if (fs.existsSync(metadataPath)) {
const metadata = require(metadataPath);
Expand Down
4 changes: 2 additions & 2 deletions lib/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ const assets = require('./assets');
const azure = require('./azure');

module.exports = (settings) => {
const assetsWithContent = assets.getDistAssets(true);
const assetsWithoutContent = assets.getDistAssets(false);
const assetsWithContent = assets.getDistAssets(true, settings.isStaticClient);
const assetsWithoutContent = assets.getDistAssets(false, settings.isStaticClient);
const assetsEmitted = assets.getEmittedAssets();
const assetsCombined = assetsWithContent.concat(assetsEmitted);

Expand Down
8 changes: 5 additions & 3 deletions lib/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,20 @@ function getSkyuxVersion() {
* @name getSettings
* @returns {Object} settings
*/
function getSettings(argv) {
function getSettings(argv = {}) {

const packageConfig = getLocalConfig('package.json');
const skyuxConfig = getLocalConfig('skyuxconfig.json');
const logSkyuxVersion = argv.logSkyuxVersion !== 'false' && argv.logSkyuxVersion !== false;

const defaults = {
name: '',
version: '',
skyuxVersion: getSkyuxVersion(),
skyuxVersion: logSkyuxVersion ? getSkyuxVersion() : '',
packageConfig: packageConfig,
skyuxConfig: skyuxConfig,
azureStorageTableName: 'spa'
azureStorageTableName: 'spa',
isStaticClient: false
};

// Merges in all packageConfig, really only care about name + version
Expand Down
4 changes: 3 additions & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ function validate(assets, settings) {
'name',
'version',
'skyuxVersion',
'logSkyuxVersion',
'azureStorageAccount',
'azureStorageAccessKey',
'azureStorageTableName'
'azureStorageTableName',
'isStaticClient'
];
let success = true;

Expand Down
57 changes: 57 additions & 0 deletions test/lib-assets.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,63 @@ describe('skyux-deploy lib assets', () => {
expect(assetsWithoutContent[0].content).not.toBeDefined();
});

it('should evaluate static client assets', () => {
const readFileSync = fs.readFileSync;
spyOn(glob, 'sync').and.returnValue([
path.join(process.cwd(), 'dist', 'bundles', 'test.umd.js')
]);
spyOn(fs, 'existsSync').and.returnValue(true);
spyOn(fs, 'readFileSync').and.callFake((file, options) => {
if (file.indexOf('custom-name.js') > -1) {
return 'my-custom-content3';
} else {
return readFileSync(file, options);
}
});

let stubs = {};
stubs[path.join(process.cwd(), 'dist', 'bundles', 'test.umd.js')] = [
{
name: 'custom-name.js'
}
];

const lib = proxyquire('../lib/assets', stubs);
const assetsWithContent = lib.getDistAssets(true, true);

expect(fs.existsSync).toHaveBeenCalledWith(
'/Users/tim.pepper/Development/bb_repos/skyux-deploy/dist/bundles/test.umd.js'
);
expect(assetsWithContent[0].content).toEqual('my-custom-content3');
});

it('should evaluate static client assets with no bundle', () => {
const readFileSync = fs.readFileSync;
spyOn(glob, 'sync').and.returnValue([]);
spyOn(fs, 'existsSync').and.returnValue(false);
spyOn(fs, 'readFileSync').and.callFake((file, options) => {
if (file.indexOf('custom-name.js') > -1) {
return 'my-custom-content3';
} else {
return readFileSync(file, options);
}
});

let stubs = {};
stubs[path.join(process.cwd(), 'dist', 'bundles', 'test.umd.js')] = [
{
name: 'custom-name.js'
}
];

const lib = proxyquire('../lib/assets', stubs);
const assetsWithContent = lib.getDistAssets(true, true);

expect(fs.existsSync).toHaveBeenCalledWith(
'/Users/tim.pepper/Development/bb_repos/skyux-deploy/dist/metadata.json'
);
expect(assetsWithContent.length).toEqual(0);
});
});

describe('getEmittedAssets', () => {
Expand Down
28 changes: 26 additions & 2 deletions test/lib-settings.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe('skyux-deploy lib settings', () => {
);
});

function setupPackageJson(_requested) {
function setupPackageJson(_requested, argv) {
const skyuxInstalledPath = path.join(
process.cwd(),
'node_modules',
Expand All @@ -81,12 +81,36 @@ describe('skyux-deploy lib settings', () => {
});

const lib = require('../lib/settings');
const settings = lib.getSettings();
const settings = lib.getSettings(argv);

expect(logger.error).not.toHaveBeenCalled();
return settings;
}

it('should return the default skyux version if logSkyuxVersion is set to false', () => {
const version = 'custom-skyux-version-npm3';
const settings = setupPackageJson(
{
spec: version
},
{
logSkyuxVersion: false
});
expect(settings.skyuxVersion).toEqual('');
});

it('should return the default skyux version if logSkyuxVersion is set to `false`', () => {
const version = 'custom-skyux-version-npm3';
const settings = setupPackageJson(
{
spec: version
},
{
logSkyuxVersion: 'false'
});
expect(settings.skyuxVersion).toEqual('');
});

it('should read the skyux version if it is installed (npm < 5)', () => {
const version = 'custom-skyux-version-npm3';
const settings = setupPackageJson({
Expand Down