@puls-atlas/cli
Version:
The Puls Atlas CLI tool for managing Atlas projects
48 lines • 1.13 kB
JavaScript
import fs from 'fs';
import * as parser from '@babel/parser';
import traverse from '@babel/traverse';
export default path => {
if (!fs.existsSync(path)) {
throw new Error(`File does not exist: ${path}`);
}
const code = fs.readFileSync(path).toString();
const node = parser.parse(code, {
sourceType: 'module'
});
const output = {
exports: []
};
traverse.default(node, {
enter: path => {
const {
node
} = path;
if (node.type === 'Identifier' && node.name === 'exports') {
const {
parent
} = path;
if (parent.type === 'MemberExpression') {
const {
property
} = parent;
if (property.type === 'Identifier') {
output.exports.push(property.name);
}
}
} else if (path.isExportNamedDeclaration()) {
const {
declaration
} = node;
if (declaration) {
const {
id
} = declaration;
if (id) {
output.exports.push(id.name);
}
}
}
}
});
return output.exports;
};