Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

saving a helpful debug utility #549

Merged
merged 3 commits into from
Sep 25, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions packages/core/tests/babel-debug-util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { transform, TransformOptions } from '@babel/core';
import { readJSONSync, readFileSync } from 'fs-extra';
import { join } from 'path';
import { argv } from 'process';

export async function transpile(appDir: string, fileLocalPath: string): Promise<string> {
let pkg = readJSONSync(join(appDir, 'package.json'));
let config = (await import(join(appDir, pkg['ember-addon'].babel.filename))).default;
let filename = join(appDir, fileLocalPath);
let src = readFileSync(filename, 'utf8');
return transform(src, Object.assign({ filename }, config) as TransformOptions)!.code!;
}

if (require.main === module) {
if (argv.length < 4) {
console.log(
`
Usage:
node babel-debug-util.js [pathToAppOutputDir] [localPathToFile]

Given an app that has been prepared by Embroider (the stage2 output)
and the local path to a JS file within that app, run the app's babel
config on that file and print the results.
`
);
process.exit(-1);
}

transpile(process.argv[2], process.argv[3])
.then(src => {
console.log(src);
})
.catch(err => {
console.log(err);
process.exit(-1);
});
}