| 1 |
#!/usr/bin/env node |
| 2 |
|
| 3 |
require("commoner").resolve(function(id) { |
| 4 |
var context = this; |
| 5 |
|
| 6 |
return context.getProvidedP().then(function(idToPath) { |
| 7 |
// If a module declares its own identifier using @providesModule |
| 8 |
// then that identifier will be a key in the idToPath object. |
| 9 |
if (idToPath.hasOwnProperty(id)) |
| 10 |
return context.readFileP(idToPath[id]); |
| 11 |
}); |
| 12 |
|
| 13 |
}, function(id) { |
| 14 |
// Otherwise assume the identifier maps directly to a filesystem path. |
| 15 |
return this.readModuleP(id); |
| 16 |
|
| 17 |
}).process(function(id, source) { |
| 18 |
// As a simple example of a processing step, make sure the file ends |
| 19 |
// with exactly one newline character. |
| 20 |
return source.replace(/\s+$/m, "\n"); |
| 21 |
}); |