From f41585447371716a9675744f14abc732803d9712 Mon Sep 17 00:00:00 2001 From: Blackbaud-TimPepper Date: Tue, 25 Sep 2018 12:35:33 -0400 Subject: [PATCH 1/8] add 'logSkyuxVersion' property --- README.md | 1 + lib/settings.js | 5 +++-- lib/utils.js | 1 + test/lib-settings.spec.js | 28 ++++++++++++++++++++++++++-- 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 494ef4f..2d247b7 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,7 @@ 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" | diff --git a/lib/settings.js b/lib/settings.js index 0b23dfe..a0dec03 100644 --- a/lib/settings.js +++ b/lib/settings.js @@ -56,15 +56,16 @@ 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' diff --git a/lib/utils.js b/lib/utils.js index 9eb6dd4..2f9c88f 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -45,6 +45,7 @@ function validate(assets, settings) { 'name', 'version', 'skyuxVersion', + 'logSkyuxVersion', 'azureStorageAccount', 'azureStorageAccessKey', 'azureStorageTableName' diff --git a/test/lib-settings.spec.js b/test/lib-settings.spec.js index f4aa5a5..7a55ad8 100644 --- a/test/lib-settings.spec.js +++ b/test/lib-settings.spec.js @@ -59,7 +59,7 @@ describe('skyux-deploy lib settings', () => { ); }); - function setupPackageJson(_requested) { + function setupPackageJson(_requested, argv) { const skyuxInstalledPath = path.join( process.cwd(), 'node_modules', @@ -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({ From c6b5e4061f41ccacb2553abb6d1da35cfabe168b Mon Sep 17 00:00:00 2001 From: Blackbaud-TimPepper Date: Wed, 17 Oct 2018 08:14:37 -0400 Subject: [PATCH 2/8] add ability to run deploy on static client --- README.md | 1 + lib/assets.js | 13 ++++++++-- lib/deploy.js | 4 +-- lib/settings.js | 3 ++- lib/utils.js | 3 ++- test/lib-assets.spec.js | 57 +++++++++++++++++++++++++++++++++++++++++ 6 files changed, 75 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 2d247b7..0c6fbe3 100644 --- a/README.md +++ b/README.md @@ -28,5 +28,6 @@ All of the following options are required and overridable via the CLI. For exam | `azureStorageAccount` | `null` | | `azureStorageAccessKey` | `null` | | `azureStorageTableName` | "spa" | +| `isStaticClient` | `false` | `null` values are typically supplied by the CI process. diff --git a/lib/assets.js b/lib/assets.js index a6e23e1..c630585 100644 --- a/lib/assets.js +++ b/lib/assets.js @@ -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')); + if (bundle.length) { + metadataPath = bundle[0]; + } + } if (fs.existsSync(metadataPath)) { const metadata = require(metadataPath); diff --git a/lib/deploy.js b/lib/deploy.js index c66f446..b33655d 100644 --- a/lib/deploy.js +++ b/lib/deploy.js @@ -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); diff --git a/lib/settings.js b/lib/settings.js index a0dec03..7bac18b 100644 --- a/lib/settings.js +++ b/lib/settings.js @@ -68,7 +68,8 @@ function getSettings(argv = {}) { skyuxVersion: logSkyuxVersion ? getSkyuxVersion() : '', packageConfig: packageConfig, skyuxConfig: skyuxConfig, - azureStorageTableName: 'spa' + azureStorageTableName: 'spa', + isStaticClient: false }; // Merges in all packageConfig, really only care about name + version diff --git a/lib/utils.js b/lib/utils.js index 2f9c88f..45139f0 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -48,7 +48,8 @@ function validate(assets, settings) { 'logSkyuxVersion', 'azureStorageAccount', 'azureStorageAccessKey', - 'azureStorageTableName' + 'azureStorageTableName', + 'isStaticClient' ]; let success = true; diff --git a/test/lib-assets.spec.js b/test/lib-assets.spec.js index a8a4aa8..494cdf0 100644 --- a/test/lib-assets.spec.js +++ b/test/lib-assets.spec.js @@ -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', () => { From e4b17e0b6b133197c35a9000d05ae083c302fd13 Mon Sep 17 00:00:00 2001 From: Blackbaud-TimPepper Date: Wed, 17 Oct 2018 14:58:34 -0400 Subject: [PATCH 3/8] allow multiple bundle files --- lib/assets.js | 59 ++++++++++++++++++++++++++++------------- test/lib-assets.spec.js | 39 +++++---------------------- 2 files changed, 47 insertions(+), 51 deletions(-) diff --git a/lib/assets.js b/lib/assets.js index c630585..c03c791 100644 --- a/lib/assets.js +++ b/lib/assets.js @@ -37,34 +37,57 @@ const getDistAssets = (includeContent, isStaticClient) => { if (isStaticClient) { // This should just return the single project bundle - const bundle = glob.sync(path.join(dist, 'bundles', '*.js')); - if (bundle.length) { - metadataPath = bundle[0]; - } + console.log('3', 'glorb'); + return glob.sync(path.join(dist, 'bundles', '*.js')) + .map(bundle => { + const bundlePath = bundle.split('/'); + return formatAssets( + includeContent, + isStaticClient, + { name: bundlePath[bundlePath.length - 1] } + ); + }); } if (fs.existsSync(metadataPath)) { const metadata = require(metadataPath); + console.log('2', metadata); + return metadata.map((asset) => + formatAssets(includeContent, isStaticClient, asset)); + } - return metadata.map((asset) => { - const parsed = path.parse(asset.name); - const content = fs.readFileSync(path.join(dist, asset.name), readOptions); - const hash = getHash(content, 'md5', 'hex'); + console.log('1', []); + return []; +}; - let newProperties = { - name: parsed.name + '.' + hash + parsed.ext, - sri: sriAlgorithm + '-' + getHash(content, sriAlgorithm, 'base64') - }; +const formatAssets = (includeContent, isStaticContent, asset) => { + console.log('DATA', asset); + const parsed = path.parse(asset.name); - if (includeContent) { - newProperties.content = content; - } + let content; + if (isStaticContent) { + content = fs.readFileSync( + path.join(dist, 'bundles', asset.name), + readOptions); + } else { + content = fs.readFileSync( + path.join(dist, asset.name), + readOptions); + } - return merge({}, asset, newProperties); - }); + const hash = getHash(content, 'md5', 'hex'); + + let newProperties = { + name: parsed.name + '.' + hash + parsed.ext, + sri: sriAlgorithm + '-' + getHash(content, sriAlgorithm, 'base64') + }; + + if (includeContent) { + newProperties.content = content; } - return []; + console.log('MERGE', merge({}, asset, newProperties)); + return merge({}, asset, newProperties); }; /** diff --git a/test/lib-assets.spec.js b/test/lib-assets.spec.js index 494cdf0..dd15d64 100644 --- a/test/lib-assets.spec.js +++ b/test/lib-assets.spec.js @@ -84,6 +84,8 @@ describe('skyux-deploy lib assets', () => { const readFileSync = fs.readFileSync; spyOn(fs, 'existsSync').and.returnValue(true); spyOn(fs, 'readFileSync').and.callFake((file, options) => { + console.log('FILE', file); + if (file.indexOf('custom-name.js') > -1) { return 'my-custom-content3'; } else { @@ -108,12 +110,13 @@ describe('skyux-deploy lib assets', () => { 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) { + console.log('FILE', file); + if (file.indexOf('test.umd.js') > -1) { return 'my-custom-content3'; } else { return readFileSync(file, options); @@ -128,40 +131,10 @@ describe('skyux-deploy lib assets', () => { ]; 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); + expect(assetsWithContent[0].content).toEqual('my-custom-content3'); }); }); From 7c2630a4ff12fcbf5f23cccb2efa35f205fa74fd Mon Sep 17 00:00:00 2001 From: Blackbaud-TimPepper Date: Wed, 17 Oct 2018 15:01:45 -0400 Subject: [PATCH 4/8] remove debugging code and add function docs --- lib/assets.js | 14 ++++++++------ test/lib-assets.spec.js | 2 -- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/assets.js b/lib/assets.js index c03c791..9032f60 100644 --- a/lib/assets.js +++ b/lib/assets.js @@ -36,8 +36,6 @@ const getDistAssets = (includeContent, isStaticClient) => { let metadataPath = path.join(dist, 'metadata.json'); if (isStaticClient) { - // This should just return the single project bundle - console.log('3', 'glorb'); return glob.sync(path.join(dist, 'bundles', '*.js')) .map(bundle => { const bundlePath = bundle.split('/'); @@ -51,17 +49,22 @@ const getDistAssets = (includeContent, isStaticClient) => { if (fs.existsSync(metadataPath)) { const metadata = require(metadataPath); - console.log('2', metadata); return metadata.map((asset) => formatAssets(includeContent, isStaticClient, asset)); } - console.log('1', []); return []; }; +/** + * Formats individual assets + * @name formatAssets + * @param {boolean} includeContent + * @param {boolean} isStaticContent + * @param {object} asset + * @returns {object} asset + */ const formatAssets = (includeContent, isStaticContent, asset) => { - console.log('DATA', asset); const parsed = path.parse(asset.name); let content; @@ -86,7 +89,6 @@ const formatAssets = (includeContent, isStaticContent, asset) => { newProperties.content = content; } - console.log('MERGE', merge({}, asset, newProperties)); return merge({}, asset, newProperties); }; diff --git a/test/lib-assets.spec.js b/test/lib-assets.spec.js index dd15d64..825c445 100644 --- a/test/lib-assets.spec.js +++ b/test/lib-assets.spec.js @@ -84,7 +84,6 @@ describe('skyux-deploy lib assets', () => { const readFileSync = fs.readFileSync; spyOn(fs, 'existsSync').and.returnValue(true); spyOn(fs, 'readFileSync').and.callFake((file, options) => { - console.log('FILE', file); if (file.indexOf('custom-name.js') > -1) { return 'my-custom-content3'; @@ -115,7 +114,6 @@ describe('skyux-deploy lib assets', () => { path.join(process.cwd(), 'dist', 'bundles', 'test.umd.js') ]); spyOn(fs, 'readFileSync').and.callFake((file, options) => { - console.log('FILE', file); if (file.indexOf('test.umd.js') > -1) { return 'my-custom-content3'; } else { From 43f55d12794e3bc9cd75ab67e456cb99ef3e7399 Mon Sep 17 00:00:00 2001 From: Blackbaud-TimPepper Date: Thu, 18 Oct 2018 14:38:51 -0400 Subject: [PATCH 5/8] clean up logic --- lib/assets.js | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/lib/assets.js b/lib/assets.js index 9032f60..eb22c86 100644 --- a/lib/assets.js +++ b/lib/assets.js @@ -37,14 +37,11 @@ const getDistAssets = (includeContent, isStaticClient) => { if (isStaticClient) { return glob.sync(path.join(dist, 'bundles', '*.js')) - .map(bundle => { - const bundlePath = bundle.split('/'); - return formatAssets( - includeContent, - isStaticClient, - { name: bundlePath[bundlePath.length - 1] } - ); - }); + .map(bundle => formatAssets( + includeContent, + isStaticClient, + { name: path.basename(bundle) } + )); } if (fs.existsSync(metadataPath)) { From 50bc96448def4f0d689fea477b5b66a557f7cbab Mon Sep 17 00:00:00 2001 From: Blackbaud-TimPepper Date: Thu, 25 Oct 2018 09:39:17 -0400 Subject: [PATCH 6/8] update url name convention --- lib/assets.js | 23 +++++++++++++++++------ lib/deploy.js | 12 ++++++++++-- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/lib/assets.js b/lib/assets.js index eb22c86..6beda3f 100644 --- a/lib/assets.js +++ b/lib/assets.js @@ -32,7 +32,7 @@ const getEmittedAssets = () => glob * @param {boolean} isStaticClient * @returns {Array} assets */ -const getDistAssets = (includeContent, isStaticClient) => { +const getDistAssets = (includeContent, isStaticClient, version) => { let metadataPath = path.join(dist, 'metadata.json'); if (isStaticClient) { @@ -40,7 +40,10 @@ const getDistAssets = (includeContent, isStaticClient) => { .map(bundle => formatAssets( includeContent, isStaticClient, - { name: path.basename(bundle) } + { + name: path.basename(bundle), + version: version + } )); } @@ -57,15 +60,15 @@ const getDistAssets = (includeContent, isStaticClient) => { * Formats individual assets * @name formatAssets * @param {boolean} includeContent - * @param {boolean} isStaticContent + * @param {boolean} isStaticClient * @param {object} asset * @returns {object} asset */ -const formatAssets = (includeContent, isStaticContent, asset) => { +const formatAssets = (includeContent, isStaticClient, asset) => { const parsed = path.parse(asset.name); let content; - if (isStaticContent) { + if (isStaticClient) { content = fs.readFileSync( path.join(dist, 'bundles', asset.name), readOptions); @@ -77,8 +80,16 @@ const formatAssets = (includeContent, isStaticContent, asset) => { const hash = getHash(content, 'md5', 'hex'); + let name; + + if (isStaticClient) { + name = asset.version + '/' + parsed.name; + } else { + name = parsed.name + '.' + hash + parsed.ext; + } + let newProperties = { - name: parsed.name + '.' + hash + parsed.ext, + name: name, sri: sriAlgorithm + '-' + getHash(content, sriAlgorithm, 'base64') }; diff --git a/lib/deploy.js b/lib/deploy.js index b33655d..def8752 100644 --- a/lib/deploy.js +++ b/lib/deploy.js @@ -6,8 +6,16 @@ const assets = require('./assets'); const azure = require('./azure'); module.exports = (settings) => { - const assetsWithContent = assets.getDistAssets(true, settings.isStaticClient); - const assetsWithoutContent = assets.getDistAssets(false, settings.isStaticClient); + const assetsWithContent = assets.getDistAssets( + true, + settings.isStaticClient, + settings.version + ); + const assetsWithoutContent = assets.getDistAssets( + false, + settings.isStaticClient, + settings.version + ); const assetsEmitted = assets.getEmittedAssets(); const assetsCombined = assetsWithContent.concat(assetsEmitted); From 6ff0651cdfbe8d54087c563e3046986d0be1c581 Mon Sep 17 00:00:00 2001 From: Blackbaud-TimPepper Date: Tue, 13 Nov 2018 12:06:44 -0500 Subject: [PATCH 7/8] fix extension issue --- lib/assets.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/assets.js b/lib/assets.js index 6beda3f..e64fc4d 100644 --- a/lib/assets.js +++ b/lib/assets.js @@ -83,7 +83,7 @@ const formatAssets = (includeContent, isStaticClient, asset) => { let name; if (isStaticClient) { - name = asset.version + '/' + parsed.name; + name = asset.version + '/' + parsed.base; } else { name = parsed.name + '.' + hash + parsed.ext; } From de87543c78d03843d4aeb918ee50673fe0c774d1 Mon Sep 17 00:00:00 2001 From: Bobby Earl Date: Tue, 5 Feb 2019 14:56:02 -0500 Subject: [PATCH 8/8] Saving bundles path. --- lib/assets.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/assets.js b/lib/assets.js index e64fc4d..f6dd52f 100644 --- a/lib/assets.js +++ b/lib/assets.js @@ -10,6 +10,7 @@ const glob = require('glob'); const cwd = process.cwd(); const dist = path.join(cwd, 'dist'); const assets = path.join(dist, 'assets'); +const bundles = path.join(dist, 'bundles'); const sriAlgorithm = 'sha384'; const readOptions = { encoding: 'utf8' }; @@ -36,7 +37,7 @@ const getDistAssets = (includeContent, isStaticClient, version) => { let metadataPath = path.join(dist, 'metadata.json'); if (isStaticClient) { - return glob.sync(path.join(dist, 'bundles', '*.js')) + return glob.sync(path.join(bundles, '*.js')) .map(bundle => formatAssets( includeContent, isStaticClient, @@ -70,7 +71,7 @@ const formatAssets = (includeContent, isStaticClient, asset) => { let content; if (isStaticClient) { content = fs.readFileSync( - path.join(dist, 'bundles', asset.name), + path.join(bundles, asset.name), readOptions); } else { content = fs.readFileSync(