Skip to content

Commit

Permalink
Merge branch 'master' of github.com:clay/claycli into clayhandlebars_…
Browse files Browse the repository at this point in the history
…pin_hbs
  • Loading branch information
jpope19 committed Mar 17, 2021
2 parents 65b851b + 4e3100f commit e2f75b2
Show file tree
Hide file tree
Showing 8 changed files with 4,810 additions and 1,541 deletions.
4 changes: 2 additions & 2 deletions cli/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function handler(argv) {
// if we're pointed at an elastic prefix, run a query to fetch pages
if (isPrefix) {
return h(getStdin()
.then(yaml.safeLoad)
.then(yaml.load)
.then((query) => {
return exporter.fromQuery(url, query, {
key: argv.key,
Expand All @@ -80,7 +80,7 @@ function handler(argv) {
.stopOnError((e) => fatalError(e, argv))
.map((res) => {
const rootKey = Object.keys(res)[0], // could be unprefixed uri OR type of thing (if exporting a bootstrap)
str = argv.yaml ? yaml.safeDump(res) : `${JSON.stringify(res)}\n`;
str = argv.yaml ? yaml.dump(res) : `${JSON.stringify(res)}\n`;

process.stdout.write(str); // pipe stringified exported stuff to stdout
if (argv.yaml) {
Expand Down
6 changes: 3 additions & 3 deletions lib/cmd/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ function importItems(str, url, options = {}) {

return h(bootstraps);
})
.map(yaml.safeLoad)
.map(yaml.load)
.errors((e, push) => {
push(null, { type: 'error', message: `YAML syntax error: ${e.message.slice(0, e.message.indexOf(':'))}` });
})
Expand All @@ -169,7 +169,7 @@ function importItems(str, url, options = {}) {
return _.isString(res) ? JSON.parse(res) : res; // allow strings or objects
} catch (e) {
try {
yaml.safeLoad(res);
yaml.load(res);
// user accidentally tried to import dispatches from a yaml file!
return { type: 'error', message: 'Cannot import dispatch from yaml', details: 'Please use the --yaml argument to import from bootstraps' };
} catch (otherE) {
Expand Down Expand Up @@ -199,7 +199,7 @@ function parseBootstrap(str, url) {
const prefix = config.get('url', url);

return h.of(str)
.map(yaml.safeLoad)
.map(yaml.load)
.errors((e, push) => push(new Error(`YAML syntax error: ${e.message.slice(0, e.message.indexOf(':'))}`)))
.flatMap((obj) => formatting.toDispatch(h.of(obj)))
.flatMap((dispatch) => prefixes.add(dispatch, prefix));
Expand Down
25 changes: 14 additions & 11 deletions lib/cmd/import.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,25 @@ describe('import', () => {
});

it('returns error if bad YAML', () => {
return lib(yaml.safeDump({ a: 'hi' }) + 'a', url, { yaml: true }).toPromise(Promise).then((res) => {
expect(res).toEqual({ type: 'error', message: 'YAML syntax error: can not read a block mapping entry; a multiline key may not be an implicit key at line 3, column 1' });
return lib(yaml.dump({ a: 'hi' }) + 'a', url, { yaml: true }).toPromise(Promise).then((res) => {
expect(res).toMatchObject({
message: expect.stringMatching(/^YAML syntax error/),
type: 'error',
});
});
});

it('imports bootstrap from stream', () => {
fetch.mockResponseOnce('{}');
return lib(h.of(yaml.safeDump({ _components: { a: { b: 'c' }} })), url, { yaml: true, key, concurrency }).collect().toPromise(Promise).then((res) => {
return lib(h.of(yaml.dump({ _components: { a: { b: 'c' }} })), url, { yaml: true, key, concurrency }).collect().toPromise(Promise).then((res) => {
expect(res).toEqual([{ type: 'success', message: 'http://domain.com/_components/a' }]);
});
});

it('adds warning when importing @published item', () => {
fetch.mockResponseOnce('{}');
fetch.mockResponseOnce('{}');
return lib(h.of(yaml.safeDump({ _components: { a: { instances: { 'b@published': { c: 'd' }} }} })), url, { yaml: true, publish: true, key, concurrency }).collect().toPromise(Promise).then((res) => {
return lib(h.of(yaml.dump({ _components: { a: { instances: { 'b@published': { c: 'd' }} }} })), url, { yaml: true, publish: true, key, concurrency }).collect().toPromise(Promise).then((res) => {
expect(res).toEqual([{ type: 'success', message: 'http://domain.com/_components/a/instances/b' }, { type: 'success', message: 'http://domain.com/_components/a/instances/b@published' }, { type: 'warning', message: 'Generated latest data for @published item', details: 'http://domain.com/_components/a/instances/b@published' }]);
});
});
Expand Down Expand Up @@ -81,23 +84,23 @@ describe('import', () => {
it('allows multiple files with `tail -n +1 filenames` splitter', () => {
fetch.mockResponseOnce('{}');
fetch.mockResponseOnce('{}');
return lib('\n==> ../path/to/doc2.yml <==\n' + yaml.safeDump({ _components: { a: { b: 'c' }} }) + '\n==> ../path/to/doc2.yml <==\n' + yaml.safeDump({ _components: { b: { c: 'd' }} }), url, { yaml: true, key, concurrency }).collect().toPromise(Promise).then((res) => {
return lib('\n==> ../path/to/doc2.yml <==\n' + yaml.dump({ _components: { a: { b: 'c' }} }) + '\n==> ../path/to/doc2.yml <==\n' + yaml.dump({ _components: { b: { c: 'd' }} }), url, { yaml: true, key, concurrency }).collect().toPromise(Promise).then((res) => {
expect(res).toEqual([{ type: 'success', message: 'http://domain.com/_components/a' }, { type: 'success', message: 'http://domain.com/_components/b' }]);
});
});

it('allows multiple files with duplicate bootstrap keys', () => {
fetch.mockResponseOnce('{}');
fetch.mockResponseOnce('{}');
return lib(yaml.safeDump({ _components: { a: { b: 'c' }} }) + yaml.safeDump({ _components: { b: { c: 'd' }} }), url, { yaml: true, key, concurrency }).collect().toPromise(Promise).then((res) => {
return lib(yaml.dump({ _components: { a: { b: 'c' }} }) + yaml.dump({ _components: { b: { c: 'd' }} }), url, { yaml: true, key, concurrency }).collect().toPromise(Promise).then((res) => {
expect(res).toEqual([{ type: 'success', message: 'http://domain.com/_components/a' }, { type: 'success', message: 'http://domain.com/_components/b' }]);
});
});

it('imports bootstrap', () => {
fetch.mockResponseOnce('{}');
fetch.mockResponseOnce('{}');
return lib(yaml.safeDump({
return lib(yaml.dump({
_layouts: {
abc: {
a: 'b'
Expand Down Expand Up @@ -182,19 +185,19 @@ describe('import', () => {
const fn = lib.parseBootstrap;

it('returns error if bad YAML', () => {
return fn(yaml.safeDump({ a: 'hi' }) + 'a', url).toPromise(Promise).catch((e) => {
expect(e.message).toBe('YAML syntax error: can not read a block mapping entry; a multiline key may not be an implicit key at line 3, column 1');
return fn(yaml.dump({ a: 'hi' }) + 'a', url).toPromise(Promise).catch((e) => {
expect(e.message).toMatch(/^YAML syntax error/);
});
});

it('parses single bootstrap into dispatch, adding prefixes', () => {
return fn(yaml.safeDump({ _components: { a: { b: 'c' }} }), url).collect().toPromise(Promise).then((res) => {
return fn(yaml.dump({ _components: { a: { b: 'c' }} }), url).collect().toPromise(Promise).then((res) => {
expect(res).toEqual([ { 'domain.com/_components/a': { b: 'c' } } ]);
});
});

it('parses single bootstrap with child components into dispatch, adding prefixes', () => {
return fn(yaml.safeDump({
return fn(yaml.dump({
_components: {
a: {
a: 'b',
Expand Down
2 changes: 1 addition & 1 deletion lib/cmd/lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ function nonexistentGroupFields(obj) {
*/
function lintSchema(str) {
return h([str])
.map(yaml.safeLoad)
.map(yaml.load)
.errors((e, push) => {
push(null, { type: 'error', message: `YAML syntax error: ${e.message.slice(0, e.message.indexOf(':'))}` });
}).flatMap((obj) => {
Expand Down
16 changes: 8 additions & 8 deletions lib/cmd/lint.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,43 +221,43 @@ describe('lint', () => {

describe('lintSchema', () => {
it('returns error if yaml syntax error', () => {
return lib.lintSchema(yaml.safeDump({ _description: 'hi' }) + 'a').toPromise(Promise).then((res) => {
expect(res).toEqual({ type: 'error', message: 'YAML syntax error: can not read a block mapping entry; a multiline key may not be an implicit key at line 3, column 1' });
return lib.lintSchema(yaml.dump({ _description: 'hi' }) + 'a').toPromise(Promise).then((res) => {
expect(res).toMatchObject({ type: 'error', message: expect.stringMatching(/^YAML syntax error/) });
});
});

it('returns error if no _description', () => {
return lib.lintSchema(yaml.safeDump({ foo: { _has: 'bar' } })).collect().toPromise(Promise).then((res) => {
return lib.lintSchema(yaml.dump({ foo: { _has: 'bar' } })).collect().toPromise(Promise).then((res) => {
expect(res).toEqual([{ type: 'error', message: 'Schema has no _description' }]);
});
});

it('lints _description', () => {
return lib.lintSchema(yaml.safeDump({ _description: 'hi' })).toPromise(Promise).then((res) => {
return lib.lintSchema(yaml.dump({ _description: 'hi' })).toPromise(Promise).then((res) => {
expect(res).toEqual({ type: 'success' });
});
});

it('returns error if non-camelCased prop', () => {
return lib.lintSchema(yaml.safeDump({ _description: 'hi', 'foo-bar': { _has: 'baz' } })).collect().toPromise(Promise).then((res) => {
return lib.lintSchema(yaml.dump({ _description: 'hi', 'foo-bar': { _has: 'baz' } })).collect().toPromise(Promise).then((res) => {
expect(res).toEqual([{ type: 'error', message: 'Properties must be camelCased', details: 'foo-bar' }]);
});
});

it('lints camelCased prop', () => {
return lib.lintSchema(yaml.safeDump({ _description: 'hi', fooBar: { _has: 'baz' } })).toPromise(Promise).then((res) => {
return lib.lintSchema(yaml.dump({ _description: 'hi', fooBar: { _has: 'baz' } })).toPromise(Promise).then((res) => {
expect(res).toEqual({ type: 'success' });
});
});

it('returns error if non-existant group fields', () => {
return lib.lintSchema(yaml.safeDump({ _description: 'hi', _groups: { foo: { fields: ['bar'] } } })).collect().toPromise(Promise).then((res) => {
return lib.lintSchema(yaml.dump({ _description: 'hi', _groups: { foo: { fields: ['bar'] } } })).collect().toPromise(Promise).then((res) => {
expect(res).toEqual([{ type: 'error', message: 'Fields referenced by groups don\'t exist', details: 'foo » bar' }]);
});
});

it('lints existing group fields', () => {
return lib.lintSchema(yaml.safeDump({ _description: 'hi', bar: { _has: 'baz' }, _groups: { foo: { fields: ['bar'] } } })).toPromise(Promise).then((res) => {
return lib.lintSchema(yaml.dump({ _description: 'hi', bar: { _has: 'baz' }, _groups: { foo: { fields: ['bar'] } } })).toPromise(Promise).then((res) => {
expect(res).toEqual({ type: 'success' });
});
});
Expand Down
6 changes: 3 additions & 3 deletions lib/compilation-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ function time(t2, t1) {

if (diff > 1000 * 60) {
// more than a minute (60,000ms)
return format(new Date(diff), 'm[m] s.SS[s]');
return format(new Date(diff), "m'm' s.SS's'");
} else {
// less than a minute
return format(new Date(diff), 's.SS[s]');
return format(new Date(diff), "s.SS's'");
}
}

Expand Down Expand Up @@ -188,7 +188,7 @@ module.exports.unbucket = unbucket;
module.exports.generateBundles = generateBundles;
module.exports.hasChanged = hasChanged;
module.exports.transformPath = transformPath;
module.exports.browserslist = { browsers: ['> 3%', 'not and_uc > 0'] }; // used by styles, and vueify, and babel/preset-env
module.exports.browserslist = { overrideBrowserslist: ['> 3%', 'not and_uc > 0'] }; // used by styles, and vueify, and babel/preset-env
module.exports.determinePostCSSPlugins = determinePostCSSPlugins;
module.exports.getConfigFileOrBrowsersList = getConfigFileOrBrowsersList;
module.exports.getConfigFileValue = getConfigFileValue;
Expand Down

0 comments on commit e2f75b2

Please sign in to comment.