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

Add support for style sheet assets #77

Merged
merged 5 commits into from
Mar 29, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Publish

on:
push:
tags:
- '*.*.*'

jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
# Setup .npmrc file to publish to npm
- uses: actions/setup-node@v1
with:
node-version: '12.x'
registry-url: 'https://registry.npmjs.org'
- name: Build
run: |
npm install
- name: Publish
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
20 changes: 20 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Test

on:
pull_request:
push:
branches:
- master

jobs:
coverage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 5
- name: Install and run tests
run: |
npm ci
npm test
bash <(curl -s https://codecov.io/bash)
10 changes: 0 additions & 10 deletions .travis.yml

This file was deleted.

2 changes: 2 additions & 0 deletions lib/assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ const formatAssets = (includeContent, isStaticClient, asset, hashFileNames = tru
props.content = content;
}

props.type = asset.type || 'script';

return merge({}, asset, props);
};

Expand Down
9 changes: 8 additions & 1 deletion lib/deploy-spa.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,20 @@ async function deploy(settings) {
settings.hashFileNames
);

const scripts = assetsWithoutContent.filter(x => x.type === 'script');
const styleSheets = assetsWithoutContent.filter(x => x.type === 'styleSheet');

const spa = {
name: settings.name,
package_config: settings.packageConfig,
scripts: assetsWithoutContent,
scripts,
sky_ux_config: settings.skyuxConfig
};

if (styleSheets.length) {
Blackbaud-SteveBrush marked this conversation as resolved.
Show resolved Hide resolved
spa.styleSheets = styleSheets;
}

if (settings.rootElementTagName) {
spa.root_element_tag_name = settings.rootElementTagName;
}
Expand Down
9 changes: 8 additions & 1 deletion lib/deploy-static.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,21 @@ async function register(settings, versionAssets, versionRowKey) {
versionAssets
);

const scripts = assetsWithoutContent.filter(x => x.type === 'script');
const styleSheets = assetsWithoutContent.filter(x => x.type === 'styleSheet');

const entity = {
PartitionKey: azure.generator.String(settings.name),
RowKey: azure.generator.String(versionRowKey),
Scripts: azure.generator.String(JSON.stringify(assetsWithoutContent)),
Scripts: azure.generator.String(JSON.stringify(scripts)),
PackageConfig: azure.generator.String(JSON.stringify(settings.packageConfig)),
SkyUXConfig: azure.generator.String(JSON.stringify(settings.skyuxConfig))
};

if (styleSheets.length) {
entity.StyleSheets = azure.generator.String(JSON.stringify(styleSheets));
}

logger.info(`Registering ${versionAssets} as ${versionRowKey}.`);
return await azure.registerEntityToTable(settings, entity);
}
Expand Down
22 changes: 22 additions & 0 deletions test/lib-assets.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,28 @@ describe('skyux-deploy lib assets', () => {
expect(fs.statSync).toHaveBeenCalled();
});

it('should set the asset type to "script" by default', () => {
spyOn(fs, 'existsSync').and.returnValue(true);
spyOn(fs, 'readFileSync').and.returnValue('');

let stubs = {};
stubs[path.join(process.cwd(), 'dist', 'metadata.json')] = [
{
name: 'custom-name.js'
},
{
name: 'styles.css',
type: 'styleSheet'
}
];

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

expect(assets[0].type).toEqual('script');
expect(assets[1].type).toEqual('styleSheet');
});

it('should allow disabling the file name hash', () => {
const readFileSync = fs.readFileSync;
spyOn(fs, 'existsSync').and.returnValue(true);
Expand Down
43 changes: 36 additions & 7 deletions test/lib-deploy-spa.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,24 @@ describe('skyux-deploy lib deploy SPA', () => {
let assetsMock;
let portalMock;
let lib;
let mockAssets;

beforeEach(() => {
spyOn(logger, 'error');
spyOn(logger, 'info');

mockAssets = [
{
name: 'my-asset.js',
content: 'my-content',
type: 'script'
}
];

assetsMock = {
getDistAssets: jasmine.createSpy('getDistAssets')
.and
.returnValue([
{
name: 'my-asset.js',
content: 'my-content'
}
]),
.returnValue(mockAssets),
};

portalMock = {
Expand Down Expand Up @@ -62,7 +66,8 @@ describe('skyux-deploy lib deploy SPA', () => {
scripts: [
{
name: 'my-asset.js',
content: 'my-content'
content: 'my-content',
type: 'script'
}
]
},
Expand All @@ -89,4 +94,28 @@ describe('skyux-deploy lib deploy SPA', () => {
expect(actualTagName).toEqual('app-root');
});

it('should call deploySpa with style sheets', async () => {
mockAssets.push({
name: 'styles.css',
type: 'styleSheet'
});

await lib(
{
azureStorageAccessKey: 'abc',
name: 'custom-name2',
version: 'custom-version2',
skyuxConfig: { test1: true },
packageConfig: { test2: true }
}
);

expect(portalMock.deploySpa.calls.mostRecent().args[1].styleSheets).toEqual([
{
name: 'styles.css',
type: 'styleSheet'
}
]);
});

});
38 changes: 31 additions & 7 deletions test/lib-deploy-static.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@ describe('skyux-deploy lib deploy static', () => {
const mock = require('mock-require');
const logger = require('@blackbaud/skyux-logger');

const distAsset = [
{
name: 'my-asset.js',
content: 'my-content'
}
];

let distAsset;
let assetsMock;
let azureMock;
let lib;
Expand All @@ -20,6 +14,14 @@ describe('skyux-deploy lib deploy static', () => {
spyOn(logger, 'error');
spyOn(logger, 'info');

distAsset = [
{
name: 'my-asset.js',
content: 'my-content',
type: 'script'
}
];

assetsMock = {
getDistAssets: jasmine.createSpy('getDistAssets').and.returnValue(distAsset)
};
Expand Down Expand Up @@ -65,6 +67,28 @@ describe('skyux-deploy lib deploy static', () => {
);
});

it('should call registerEntityToTable with style sheets if they exist', async () => {
distAsset.push({
name: 'styles.css',
type: 'styleSheet'
});

const settings = {
azureStorageAccessKey: 'abc',
isStaticClient: true,
name: 'custom-name2',
version: 'custom-version2',
skyuxConfig: { test1: true },
packageConfig: { test2: true }
};

await lib(settings);

expect(azureMock.registerEntityToTable.calls.mostRecent().args[1].StyleSheets).toEqual(
'[{"name":"styles.css","type":"styleSheet"}]'
);
});

it('should log a warning if version is invalid', async () => {
const settings = {
version: 'INVALID_VERSION'
Expand Down