Created
November 4, 2013 01:58
-
-
Save davidchambers/7297030 to your computer and use it in GitHub Desktop.
Determine whether a JavaScript file is an AMD module
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env coffee | |
esprima = require 'esprima' | |
isModule = (source) -> | |
esprima.parse(source).body.some (node) -> | |
node.type is 'ExpressionStatement' and | |
node.expression.type is 'CallExpression' and | |
node.expression.callee.type is 'Identifier' and | |
node.expression.callee.name is 'define' | |
process.stdin.resume() | |
process.stdin.setEncoding('utf8') | |
source = '' | |
process.stdin.on 'data', (chunk) -> source += chunk | |
process.stdin.on 'end', -> process.stdout.write "#{isModule source}\n" |
Author
davidchambers
commented
Nov 4, 2013
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment