-
Notifications
You must be signed in to change notification settings - Fork 24.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update script to parse all specs in folder
Summary: Updates the combine-js-to-schema to expose a cli and combine all passed files into a single schema output Note: as far as I could tell, there isn't a way for buck to pass a glob of directories, so instead of accepting a dir and crawling it, this update accepts a list of files and combines them. Which makes sense, since buck is good at crawling already Reviewed By: TheSavior Differential Revision: D14007193 fbshipit-source-id: dbc209bb8d1cadd381269e9f70dc71a90f77878e
- Loading branch information
1 parent
17e1694
commit 34763bf
Showing
5 changed files
with
105 additions
and
21 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
...react-native-codegen/buck_tests/__tests__/__snapshots__/combine-js-to-schema-test.js.snap
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,14 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`should combine files 1`] = ` | ||
Object { | ||
"modules": Object { | ||
"ComponentOne": Object { | ||
"foo": "baz", | ||
}, | ||
"ComponentTwo": Object { | ||
"foo": "bar", | ||
}, | ||
}, | ||
} | ||
`; |
48 changes: 48 additions & 0 deletions
48
packages/react-native-codegen/buck_tests/__tests__/combine-js-to-schema-test.js
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,48 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @emails oncall+react_native | ||
* @flow strict-local | ||
* @format | ||
*/ | ||
|
||
import combine from '../combine-js-to-schema'; | ||
|
||
jest.mock( | ||
'/test/module/SchemaOne', | ||
() => ({ | ||
modules: { | ||
ComponentOne: { | ||
foo: 'baz', | ||
}, | ||
}, | ||
}), | ||
{virtual: true}, | ||
); | ||
|
||
jest.mock( | ||
'/test/module/SchemaTwo', | ||
() => ({ | ||
modules: { | ||
ComponentTwo: { | ||
foo: 'bar', | ||
}, | ||
}, | ||
}), | ||
{virtual: true}, | ||
); | ||
|
||
test('should combine files', () => { | ||
const files = ['/test/module/SchemaOne', '/test/module/SchemaTwo']; | ||
expect(combine(files)).toMatchSnapshot(); | ||
}); | ||
|
||
test('should throw for failed require', () => { | ||
const files = ['/test/module/does/not/exist']; | ||
expect(() => combine(files)).toThrow( | ||
"Can't require file at /test/module/does/not/exist", | ||
); | ||
}); |
24 changes: 24 additions & 0 deletions
24
packages/react-native-codegen/buck_tests/combine-js-to-schema-cli.js
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,24 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @emails oncall+react_native | ||
* @flow | ||
* @format | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const combine = require('./combine-js-to-schema'); | ||
const fs = require('fs'); | ||
|
||
const [outfile, ...fileList] = process.argv.slice(2); | ||
|
||
const formattedSchema = JSON.stringify(combine(fileList), null, 2); | ||
if (outfile != null) { | ||
fs.writeFileSync(outfile, formattedSchema); | ||
} else { | ||
console.log(formattedSchema); | ||
} |
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