@react-native/codegen
Advanced tools
Comparing version 0.74.0-nightly-20231121-a6964b362 to 0.74.0-nightly-20231122-d4399c5f1
@@ -14,9 +14,7 @@ /** | ||
const combine = require('./combine-js-to-schema'); | ||
const _require = require('./combine-utils'), | ||
filterJSFile = _require.filterJSFile, | ||
parseArgs = _require.parseArgs; | ||
const fs = require('fs'); | ||
const glob = require('glob'); | ||
const path = require('path'); | ||
const _require = require('./combine-js-to-schema'), | ||
combineSchemasInFileListAndWriteToFile = | ||
_require.combineSchemasInFileListAndWriteToFile; | ||
const _require2 = require('./combine-utils'), | ||
parseArgs = _require2.parseArgs; | ||
const _parseArgs = parseArgs(process.argv), | ||
@@ -26,33 +24,2 @@ platform = _parseArgs.platform, | ||
fileList = _parseArgs.fileList; | ||
const allFiles = []; | ||
fileList.forEach(file => { | ||
if (fs.lstatSync(file).isDirectory()) { | ||
const filePattern = path.sep === '\\' ? file.replace(/\\/g, '/') : file; | ||
const dirFiles = glob | ||
.sync(`${filePattern}/**/*.{js,ts,tsx}`, { | ||
nodir: true, | ||
// TODO: This will remove the need of slash substitution above for Windows, | ||
// but it requires glob@v9+; with the package currenlty relying on | ||
// glob@7.1.1; and flow-typed repo not having definitions for glob@9+. | ||
// windowsPathsNoEscape: true, | ||
}) | ||
.filter(element => filterJSFile(element, platform)); | ||
allFiles.push(...dirFiles); | ||
} else if (filterJSFile(file)) { | ||
allFiles.push(file); | ||
} | ||
}); | ||
const combined = combine(allFiles); | ||
// Warn users if there is no modules to process | ||
if (Object.keys(combined.modules).length === 0) { | ||
console.error( | ||
'No modules to process in combine-js-to-schema-cli. If this is unexpected, please check if you set up your NativeComponent correctly. See combine-js-to-schema.js for how codegen finds modules.', | ||
); | ||
} | ||
const formattedSchema = JSON.stringify(combined, null, 2); | ||
if (outfile != null) { | ||
fs.writeFileSync(outfile, formattedSchema); | ||
} else { | ||
console.log(formattedSchema); | ||
} | ||
combineSchemasInFileListAndWriteToFile(fileList, platform, outfile); |
@@ -79,3 +79,6 @@ /** | ||
TypeScriptParser = _require2.TypeScriptParser; | ||
const _require3 = require('./combine-utils'), | ||
filterJSFile = _require3.filterJSFile; | ||
const fs = require('fs'); | ||
const glob = require('glob'); | ||
const path = require('path'); | ||
@@ -111,2 +114,38 @@ const flowParser = new FlowParser(); | ||
} | ||
module.exports = combineSchemas; | ||
function expandDirectoriesIntoFiles(fileList, platform) { | ||
return fileList | ||
.flatMap(file => { | ||
if (!fs.lstatSync(file).isDirectory()) { | ||
return [file]; | ||
} | ||
const filePattern = path.sep === '\\' ? file.replace(/\\/g, '/') : file; | ||
return glob.sync(`${filePattern}/**/*.{js,ts,tsx}`, { | ||
nodir: true, | ||
// TODO: This will remove the need of slash substitution above for Windows, | ||
// but it requires glob@v9+; with the package currenlty relying on | ||
// glob@7.1.1; and flow-typed repo not having definitions for glob@9+. | ||
// windowsPathsNoEscape: true, | ||
}); | ||
}) | ||
.filter(element => filterJSFile(element, platform)); | ||
} | ||
function combineSchemasInFileList(fileList, platform) { | ||
const expandedFileList = expandDirectoriesIntoFiles(fileList, platform); | ||
const combined = combineSchemas(expandedFileList); | ||
if (Object.keys(combined.modules).length === 0) { | ||
console.error( | ||
'No modules to process in combine-js-to-schema-cli. If this is unexpected, please check if you set up your NativeComponent correctly. See combine-js-to-schema.js for how codegen finds modules.', | ||
); | ||
} | ||
return combined; | ||
} | ||
function combineSchemasInFileListAndWriteToFile(fileList, platform, outfile) { | ||
const combined = combineSchemasInFileList(fileList, platform); | ||
const formattedSchema = JSON.stringify(combined, null, 2); | ||
fs.writeFileSync(outfile, formattedSchema); | ||
} | ||
module.exports = { | ||
combineSchemas, | ||
combineSchemasInFileList, | ||
combineSchemasInFileListAndWriteToFile, | ||
}; |
{ | ||
"name": "@react-native/codegen", | ||
"version": "0.74.0-nightly-20231121-a6964b362", | ||
"version": "0.74.0-nightly-20231122-d4399c5f1", | ||
"description": "Code generation tools for React Native", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1523393
24527
6