Match xplat/yoga/javascript prettier conventions

Summary:
Match Prettier config to match other Meta OSS projects

Didn't update the test generator to use this form yet.

Reviewed By: yungsters

Differential Revision: D45570415

fbshipit-source-id: d5fd791b047debf41c28aecac75fb8dde16da3e3
This commit is contained in:
Nick Gerleman
2023-05-09 15:35:42 -07:00
committed by Facebook GitHub Bot
parent 0cb4a49d38
commit 0a6a581936
29 changed files with 197 additions and 199 deletions

View File

@@ -20,81 +20,78 @@ import {
spawn,
task,
tscTask,
} from "just-scripts";
} from 'just-scripts';
import glob from "glob";
import path from "path";
import which from "which";
import glob from 'glob';
import path from 'path';
import which from 'which';
const node = process.execPath;
option("fix");
option('fix');
task("clean", cleanTask({ paths: ["build", "dist"] }));
task('clean', cleanTask({paths: ['build', 'dist']}));
task(
"prepare-for-build",
'prepare-for-build',
parallel(
babelTransformTask({ paths: ["src_js"], dest: "dist" }),
copyTask({ paths: ["src_js/**/*.d.ts"], dest: "dist" }),
emcmakeGenerateTask()
)
babelTransformTask({paths: ['src_js'], dest: 'dist'}),
copyTask({paths: ['src_js/**/*.d.ts'], dest: 'dist'}),
emcmakeGenerateTask(),
),
);
function defineFlavor(flavor: string, env: NodeJS.ProcessEnv) {
task(`cmake-build:${flavor}`, cmakeBuildTask({ targets: [flavor] }));
task(`cmake-build:${flavor}`, cmakeBuildTask({targets: [flavor]}));
task(
`jest:${flavor}`,
jestTask({ config: path.join(__dirname, "jest.config.ts"), env })
jestTask({config: path.join(__dirname, 'jest.config.ts'), env}),
);
task(
`test:${flavor}`,
series("prepare-for-build", `cmake-build:${flavor}`, `jest:${flavor}`)
series('prepare-for-build', `cmake-build:${flavor}`, `jest:${flavor}`),
);
}
defineFlavor("asmjs-async", { WASM: "0", SYNC: "0" });
defineFlavor("asmjs-sync", { WASM: "0", SYNC: "1" });
defineFlavor("wasm-async", { WASM: "1", SYNC: "0" });
defineFlavor("wasm-sync", { WASM: "1", SYNC: "1" });
defineFlavor('asmjs-async', {WASM: '0', SYNC: '0'});
defineFlavor('asmjs-sync', {WASM: '0', SYNC: '1'});
defineFlavor('wasm-async', {WASM: '1', SYNC: '0'});
defineFlavor('wasm-sync', {WASM: '1', SYNC: '1'});
task("cmake-build:all", cmakeBuildTask());
task('cmake-build:all', cmakeBuildTask());
task(
"cmake-build:async",
cmakeBuildTask({ targets: ["asmjs-async", "wasm-async"] })
'cmake-build:async',
cmakeBuildTask({targets: ['asmjs-async', 'wasm-async']}),
);
task(
"cmake-build:sync",
cmakeBuildTask({ targets: ["asmjs-sync", "wasm-sync"] })
'cmake-build:sync',
cmakeBuildTask({targets: ['asmjs-sync', 'wasm-sync']}),
);
task("build", series("prepare-for-build", "cmake-build:all"));
task('build', series('prepare-for-build', 'cmake-build:all'));
task(
"test",
'test',
series(
"prepare-for-build",
series("cmake-build:asmjs-async", "jest:asmjs-async"),
series("cmake-build:asmjs-sync", "jest:asmjs-sync"),
series("cmake-build:wasm-async", "jest:wasm-async"),
series("cmake-build:wasm-sync", "jest:wasm-sync")
)
'prepare-for-build',
series('cmake-build:asmjs-async', 'jest:asmjs-async'),
series('cmake-build:asmjs-sync', 'jest:asmjs-sync'),
series('cmake-build:wasm-async', 'jest:wasm-async'),
series('cmake-build:wasm-sync', 'jest:wasm-sync'),
),
);
task(
"benchmark",
series("prepare-for-build", "cmake-build:sync", runBenchTask())
'benchmark',
series('prepare-for-build', 'cmake-build:sync', runBenchTask()),
);
task(
"lint",
'lint',
parallel(
tscTask(),
series(
eslintTask({ fix: argv().fix }),
clangFormatTask({ fix: argv().fix })
)
)
series(eslintTask({fix: argv().fix}), clangFormatTask({fix: argv().fix})),
),
);
function babelTransformTask(opts: {
@@ -102,68 +99,68 @@ function babelTransformTask(opts: {
dest: string;
}) {
return () => {
const args = [...opts.paths, "--source-maps", "--out-dir", opts.dest];
logger.info(`Transforming [${opts.paths.join(",")}] to '${opts.dest}'`);
const args = [...opts.paths, '--source-maps', '--out-dir', opts.dest];
logger.info(`Transforming [${opts.paths.join(',')}] to '${opts.dest}'`);
return spawn(node, [require.resolve("@babel/cli/bin/babel"), ...args]);
return spawn(node, [require.resolve('@babel/cli/bin/babel'), ...args]);
};
}
function runBenchTask() {
return () => {
const files = glob.sync("./tests/Benchmarks/**/*");
const args = ["./tests/bin/run-bench.ts", ...files];
logger.info(args.join(" "));
const files = glob.sync('./tests/Benchmarks/**/*');
const args = ['./tests/bin/run-bench.ts', ...files];
logger.info(args.join(' '));
return spawn(node, args, {
stdio: "inherit",
env: { NODE_OPTIONS: "-r ts-node/register" },
stdio: 'inherit',
env: {NODE_OPTIONS: '-r ts-node/register'},
});
};
}
function emcmakeGenerateTask() {
return () => {
const emcmake = which.sync("emcmake");
const ninja = which.sync("ninja", { nothrow: true });
const emcmake = which.sync('emcmake');
const ninja = which.sync('ninja', {nothrow: true});
const args = [
"cmake",
"-S",
".",
"-B",
"build",
...(ninja ? ["-G", "Ninja"] : []),
'cmake',
'-S',
'.',
'-B',
'build',
...(ninja ? ['-G', 'Ninja'] : []),
];
logger.info(["emcmake", ...args].join(" "));
logger.info(['emcmake', ...args].join(' '));
return spawn(emcmake, args);
};
}
function cmakeBuildTask(opts?: { targets?: ReadonlyArray<string> }) {
function cmakeBuildTask(opts?: {targets?: ReadonlyArray<string>}) {
return () => {
const cmake = which.sync("cmake");
const cmake = which.sync('cmake');
const args = [
"--build",
"build",
...(opts?.targets ? ["--target", ...opts.targets] : []),
'--build',
'build',
...(opts?.targets ? ['--target', ...opts.targets] : []),
];
logger.info(["cmake", ...args].join(" "));
logger.info(['cmake', ...args].join(' '));
return spawn(cmake, args, { stdio: "inherit" });
return spawn(cmake, args, {stdio: 'inherit'});
};
}
function clangFormatTask(opts?: { fix?: boolean }) {
function clangFormatTask(opts?: {fix?: boolean}) {
return () => {
const args = [
...(opts?.fix ? ["-i"] : ["--dry-run", "--Werror"]),
...glob.sync("**/*.{h,hh,hpp,c,cpp,cc,m,mm}"),
...(opts?.fix ? ['-i'] : ['--dry-run', '--Werror']),
...glob.sync('**/*.{h,hh,hpp,c,cpp,cc,m,mm}'),
];
logger.info(["clang-format", ...args].join(" "));
logger.info(['clang-format', ...args].join(' '));
return spawn(node, [require.resolve("clang-format"), ...args], {
stdio: "inherit",
return spawn(node, [require.resolve('clang-format'), ...args], {
stdio: 'inherit',
});
};
}