Permalink
Browse files

Use `shelljs` for Windows interoperability

Summary:
We can't run the `manfiest.js` util in Windows as is, since it relies on `find` and `grep` utilities.  So bring in the `shelljs` package to perform this.

We should consider revisiting this in the future should this solution be too slow.  As it is, this should be a performance hit compared to `find | grep` as we're essentially performing `fs.readFileSync(...)` over and over.

Reviewed By: w1106c

Differential Revision: D13625762

fbshipit-source-id: 30bec8dd80b7a1ed3e3353dfed719ee505eedb7f
  • Loading branch information...
jrwats authored and facebook-github-bot committed Jan 11, 2019
1 parent a3929dd commit 87aae58324da771eeeaab21286d3ac41e1b35125
Showing with 2,917 additions and 29 deletions.
  1. +2 −1 demo-app/package.json
  2. +20 −2 demo-app/yarn.lock
  3. +2 −1 package.json
  4. +10 −25 transform/babel-plugin-fbt/bin/manifest.js
  5. +2,883 −0 yarn.lock
@@ -69,6 +69,7 @@
"fbjs": "1.0.0",
"lodash": "4.17.11",
"npm": "^6.4.1",
"optimist": "^0.6.1"
"optimist": "^0.6.1",
"shelljs": "^0.8.3"
}
}

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -25,6 +25,7 @@
"babel-plugin-minify-replace": "0.5.0",
"fbjs": "1.0.0",
"npm": "^6.4.1",
"optimist": "^0.6.1"
"optimist": "^0.6.1",
"shelljs": "^0.8.3"
}
}
@@ -21,6 +21,7 @@ const {execSync} = require('child_process');
const fs = require('fs');
const optimist = require('optimist');
const path = require('path');
const shell = require('shelljs');

const argv = optimist
.usage(
@@ -35,12 +36,6 @@ const argv = optimist
'The source folder in which to look for JS source containing fbt and ' +
'files with the $FbtEnum.js suffix. Defaults to CWD',
)
.default('root', process.cwd())
.describe(
'root',
'The folder from which to make source paths relative. ' +
"e.g. '/' for absolute paths. Defaults to CWD",
)
.default('enum-manifest', '.enum_manifest.json')
.describe(
'enum-manifest',
@@ -64,36 +59,26 @@ require('@babel/register')({
],
});

// Take newline delimitted output and return an array of lines
const lines = newlined =>
newlined
.toString()
.trim()
.split('\n');

// Find enum files
const enumFiles = lines(
execSync("find . -type f -iname '*$FbtEnum.js'", {
cwd: argv.src,
}),
);
const enumFiles = shell
.find(argv.src)
.filter(path => /\$FbtEnum\.js/i.test(path));

// Write enum manfiest
const enumManifest = {};
for (const filepath of enumFiles) {
// Infer module name from filename.
const name = path.parse(filepath).name;
enumManifest[name] = require(path.resolve(argv.src, filepath));
enumManifest[name] = require(path.resolve(filepath));
}
fs.writeFileSync(argv['enum-manifest'], JSON.stringify(enumManifest));

// Find source files that are fbt-containing candidates
const srcFiles = lines(
execSync(
"find . -type f -iname '*.js' | xargs grep -E -l '\\b[Ff]b[st]\\b'",
{cwd: argv.src},
),
).map(relpath => path.relative(argv.root, path.resolve(argv.src, relpath)));
const jsFiles = shell.find(argv.src).filter(path => /\.js$/.test(path));
const srcFiles = shell
.grep('-l', '\\b[Ff]b[st]\\b', jsFiles)
.trim()
.split('\n');

fs.writeFileSync(
argv['src-manifest'],
Oops, something went wrong.

0 comments on commit 87aae58

Please sign in to comment.