-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(css): Allow independent css builds
- move a lot of logic from bin/mastarm into a util file to allow testing - add test case for build script - add tests for util functions
- Loading branch information
1 parent
4edf0b2
commit 6314bb9
Showing
7 changed files
with
189 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
const pkg = require('../lib/pkg') | ||
|
||
exports.getCssFiles = (options) => { | ||
let files = [] | ||
if (options.css) { | ||
if (options.cssFiles) { | ||
files = files.concat(options.cssFiles.split(' ')) | ||
} else { | ||
files.push('lib/styles.css:assets/index.css') | ||
} | ||
} | ||
return files | ||
} | ||
|
||
exports.makeGetFn = (targets) => { | ||
return (item) => { | ||
const ts = targets.filter((t) => t[item] !== undefined) | ||
if (ts.length > 0) return ts[0][item] | ||
} | ||
} | ||
|
||
exports.parseEntries = function (entries, get) { | ||
const files = entries.map((entry) => { | ||
entry = entry.split(':') | ||
if (entry.length === 1) { | ||
entry.push(`assets/${entry[0]}`) | ||
} | ||
return entry | ||
}) | ||
|
||
if (files.length === 0) { | ||
files.push([ | ||
get('entry') || pkg.main || 'index.js', | ||
get('outfile') || 'assets/index.js' | ||
]) | ||
} | ||
|
||
return files | ||
} | ||
|
||
/** | ||
* A lot of subcommands utilize exact argument lengths. Pop mastarm to handle it. | ||
*/ | ||
exports.popMastarmFromArgv = function () { | ||
process.argv = process.argv.slice(0, 1).concat(process.argv.slice(2)) | ||
} | ||
|
||
exports.updateDependencies = function () { | ||
const checkDependenciesSync = require('check-dependencies').sync | ||
const results = checkDependenciesSync({ | ||
install: true, | ||
packageDir: process.cwd() | ||
}) | ||
if (results.status !== 0) { | ||
console.error(results.error) | ||
process.exit(results.status) | ||
} else if (!results.depsWereOk) { | ||
console.log('Updated out of date dependencies found in package.json. Please try running the command again.') | ||
process.exit(results.status) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
exports[`util.js getCssFiles should return correct results 1`] = `Array []`; | ||
|
||
exports[`util.js getCssFiles should return correct results 2`] = ` | ||
Array [ | ||
"lib/styles.css:assets/index.css" | ||
] | ||
`; | ||
|
||
exports[`util.js getCssFiles should return correct results 3`] = ` | ||
Array [ | ||
"a:b", | ||
"c" | ||
] | ||
`; | ||
|
||
exports[`util.js parseEntries should return default file paths 1`] = ` | ||
Array [ | ||
Array [ | ||
"bin/mastarm", | ||
"assets/index.js" | ||
] | ||
] | ||
`; | ||
|
||
exports[`util.js parseEntries should return inputted file paths 1`] = ` | ||
Array [ | ||
Array [ | ||
"a", | ||
"b" | ||
], | ||
Array [ | ||
"c", | ||
"assets/c" | ||
] | ||
] | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* globals describe, expect, it, jest */ | ||
|
||
const mockSyncFn = jest.fn(() => { return { status: 0, depsWereOk: true } }) | ||
jest.mock('check-dependencies', () => { return { sync: mockSyncFn } }) | ||
|
||
const util = require('../../lib/util') | ||
|
||
describe('util.js', () => { | ||
describe('getCssFiles', () => { | ||
it('should return correct results', () => { | ||
expect(util.getCssFiles({ css: false })).toMatchSnapshot() | ||
expect(util.getCssFiles({ css: true })).toMatchSnapshot() | ||
expect(util.getCssFiles({ css: true, cssFiles: 'a:b c' })).toMatchSnapshot() | ||
}) | ||
}) | ||
|
||
it('makeGetFn should find the right value', () => { | ||
expect(util.makeGetFn([{ a: 1 }, { a: 2 }])('a')).toEqual(1) | ||
}) | ||
|
||
describe('parseEntries', () => { | ||
it('should return default file paths', () => { | ||
expect(util.parseEntries([], () => null)).toMatchSnapshot() | ||
}) | ||
|
||
it('should return inputted file paths', () => { | ||
expect(util.parseEntries(['a:b', 'c'])).toMatchSnapshot() | ||
}) | ||
}) | ||
|
||
it('popMastarmFromArgv should remove the mastarm command', () => { | ||
const argv1 = process.argv[1] | ||
expect(argv1).toContain('mastarm') | ||
util.popMastarmFromArgv() | ||
expect(process.argv[1]).not.toBe(argv1) | ||
}) | ||
|
||
it('updateDependencies should run check-dependencies package', () => { | ||
util.updateDependencies() | ||
expect(mockSyncFn).toBeCalled() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.criticalClass { | ||
font-weight: bold !important; | ||
} |