Skip to content

Commit d93c4d1

Browse files
committed
make.js
1 parent 03ebcb9 commit d93c4d1

3 files changed

Lines changed: 58 additions & 2 deletions

File tree

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Shell.js is a portable (Windows included) implementation of Unix shell commands
44

55
The project is both [unit-tested](http://travis-ci.org/arturadib/shell.js) and battle-tested at Mozilla's [pdf.js](http://github.com/mozilla/pdf.js).
66

7+
78
### Example
89

910
```javascript
@@ -80,6 +81,15 @@ target.docs = function() {
8081

8182
To run the target `all`, call the above script without arguments: `$ node make`. To run the target `docs`: `$ node make docs`, and so on.
8283

84+
### Installing
85+
86+
Via npm:
87+
88+
```bash
89+
$ npm install shelljs
90+
```
91+
92+
Or simply copy `shell.js` into your project's directory, and `require()` accordingly.
8393

8494

8595
<!--
@@ -89,7 +99,7 @@ To run the target `all`, call the above script without arguments: `$ node make`.
8999
-->
90100

91101

92-
# Command reference
102+
# Commands reference
93103

94104

95105
All commands run synchronously, unless otherwise stated.

make.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
require('./global');
2+
3+
global.target = {};
4+
5+
// This ensures we only execute the script targets after the entire script has
6+
// been evaluated
7+
var args = process.argv.slice(2);
8+
setTimeout(function() {
9+
10+
if (args.length === 1 && args[0] === '--help') {
11+
console.log('Available targets:');
12+
for (t in target)
13+
console.log(' ' + t);
14+
return;
15+
}
16+
17+
// Wrap targets to prevent duplicate execution
18+
for (t in target) {
19+
(function(t, oldTarget){
20+
21+
// Wrap it
22+
target[t] = function(force) {
23+
if (oldTarget.done && !force)
24+
return;
25+
oldTarget.done = true;
26+
return oldTarget(arguments);
27+
}
28+
29+
})(t, target[t]);
30+
}
31+
32+
// Execute desired targets
33+
if (args.length > 0) {
34+
args.forEach(function(arg) {
35+
if (arg in target)
36+
target[arg]();
37+
else {
38+
log('no such target: ' + arg);
39+
exit(1);
40+
}
41+
});
42+
} else if ('all' in target) {
43+
target.all();
44+
}
45+
46+
}, 0);

scripts/docs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ var docs = grep('//@', 'shell.js');
1010
// Remove '//@'
1111
docs = docs.replace(/\/\/\@ */g, '');
1212
// Append docs to README
13-
sed('-i', /# Command reference(.|\n)*/, '# Command reference\n\n' + docs, 'README.md');
13+
sed('-i', /# Commands reference(.|\n)*/, '# Commands reference\n\n' + docs, 'README.md');
1414

1515
echo('All done.');

0 commit comments

Comments
 (0)