Skip to content

Commit d160968

Browse files
committed
Initial commit
0 parents  commit d160968

File tree

5 files changed

+167
-0
lines changed

5 files changed

+167
-0
lines changed

.gitignore

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
6+
# Runtime data
7+
pids
8+
*.pid
9+
*.seed
10+
*.pid.lock
11+
12+
# Directory for instrumented libs generated by jscoverage/JSCover
13+
lib-cov
14+
15+
# Coverage directory used by tools like istanbul
16+
coverage
17+
18+
# nyc test coverage
19+
.nyc_output
20+
21+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
22+
.grunt
23+
24+
# node-waf configuration
25+
.lock-wscript
26+
27+
# Compiled binary addons (http://nodejs.org/api/addons.html)
28+
build/Release
29+
30+
# Dependency directories
31+
node_modules
32+
jspm_packages
33+
34+
# Optional npm cache directory
35+
.npm
36+
37+
# Optional eslint cache
38+
.eslintcache
39+
40+
# Optional REPL history
41+
.node_repl_history
42+
43+
# Output of 'npm pack'
44+
*.tgz

LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
(The MIT License)
2+
3+
Copyright (c) 2016, Ryan Zimmerman <[email protected]>
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
this software and associated documentation files (the 'Software'), to deal in
7+
the Software without restriction, including without limitation the rights to
8+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
the Software, and to permit persons to whom the Software is furnished to do so,
10+
subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# edit-script
2+
3+
Edit npm scripts from the command line without worrying about json escaping.
4+
5+
## Installation
6+
7+
```bash
8+
npm install edit-script
9+
```
10+
11+
## Usage
12+
13+
```
14+
edit-script <script-name>
15+
```
16+
17+
## License
18+
19+
MIT

cli.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/bin/env node
2+
'use strict';
3+
var fs = require('fs-promise');
4+
var inquirer = require('inquirer');
5+
var findPkg = require('pkg-up');
6+
7+
var script = process.argv[2];
8+
9+
var pkgPath;
10+
var pkg = {}
11+
var scripts = {};
12+
13+
if (!script) {
14+
console.error('Error: Must pass a script name');
15+
process.exit(1);
16+
}
17+
18+
findPkg()
19+
.then(function (p) {
20+
pkgPath = p;
21+
return fs.readJson(pkgPath);
22+
})
23+
.then(function (data) {
24+
pkg = data;
25+
scripts = pkg.scripts;
26+
27+
return inquirer.prompt([
28+
{
29+
type: 'confirm',
30+
name: 'create',
31+
message: `The script "${script}" does not exist. Create it?`,
32+
when: !scripts[script],
33+
},
34+
]);
35+
})
36+
.then(function (answers) {
37+
if (!scripts[script] && !answers.create) {
38+
console.log('Aborting');
39+
process.exit();
40+
}
41+
})
42+
.then(function () {
43+
return inquirer.prompt([
44+
{
45+
type: 'editor',
46+
name: 'script',
47+
message: 'Edit your script; an empty script deletes the script',
48+
default: scripts[script],
49+
},
50+
])
51+
})
52+
.then(function (answers) {
53+
var val = answers.script.trim();
54+
if (!val) {
55+
console.log('Deleting script.');
56+
delete scripts[script];
57+
} else {
58+
scripts[script] = val;
59+
}
60+
return fs.writeJson(pkgPath, pkg)
61+
});

package.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "edit-script",
3+
"version": "0.0.1",
4+
"description": "",
5+
"keywords": [],
6+
"bin": "cli.js",
7+
"author": "Ryan Zimmerman <[email protected]>",
8+
"bugs": "https://github.com/RyanZim/edit-script/issues",
9+
"homepage": "https://github.com/RyanZim/edit-script#readme",
10+
"license": "MIT",
11+
"repository": {
12+
"type": "git",
13+
"url": "git+https://github.com/RyanZim/edit-script.git"
14+
},
15+
"scripts": {
16+
"test": "echo \"Error: no test specified\" && exit 1"
17+
},
18+
"dependencies": {
19+
"fs-promise": "^0.5.0",
20+
"inquirer": "^1.2.2",
21+
"pkg-up": "^1.0.0"
22+
}
23+
}

0 commit comments

Comments
 (0)