forked from stdlib-js/stdlib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_bugs
More file actions
executable file
·102 lines (83 loc) · 2.17 KB
/
Copy pathupdate_bugs
File metadata and controls
executable file
·102 lines (83 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/env node
'use strict';
/*
* Update package `package.json` files by setting the `bugs` field.
*
* This script is called with the following arguments:
*
* * *$1*: root search directory
*
* If not provided a root search directory, the root search directory is the current working directory.
*
* To enable verbose logging, set the `DEBUG` environment variable.
*
* ``` bash
* $ DEBUG=* update_bugs .
* ```
*/
// MODULES //
var debug = require( 'debug' )( 'update-package-bugs' );
var join = require( 'path' ).join;
var resolve = require( 'path' ).resolve;
var writeFile = require( 'fs' ).writeFileSync;
var parseArgs = require( 'minimist' );
var cwd = require( '@stdlib/utils/cwd' );
var findPkgs = require( './../../pkgs/find' ).sync;
var standardize = require( './../standardize' );
// VARIABLES //
var BUGS = {
'url': 'https://github.com/stdlib-js/stdlib/issues'
};
var opts;
var args;
var dir;
// FUNCTIONS //
/**
* Updates package `package.json` files by setting the `bugs` field.
*
* @private
* @param {string} dir - root search directory
*/
function main( dir ) {
var fpath;
var opts;
var pkgs;
var pkg;
var i;
debug( 'Searching for packages in %s.', dir );
opts = {
'dir': dir,
'pattern': '**/package.json'
};
pkgs = findPkgs( opts );
debug( 'Found %d packages.', pkgs.length );
for ( i = 0; i < pkgs.length; i++ ) {
fpath = join( pkgs[ i ], 'package.json' );
debug( 'Loading package file: %s (%d of %d).', fpath, i+1, pkgs.length );
pkg = require( fpath );
if ( pkg.bugs ) {
debug( 'Current bug reporting endpoint: %s.', JSON.stringify( pkg.bugs ) );
}
debug( 'Updating bugs field.' );
pkg.bugs = BUGS;
debug( 'Standardizing package data.' );
pkg = standardize( pkg );
debug( 'Serializing package data.' );
pkg = JSON.stringify( pkg, null, 2 ); // 2-space indentation
debug( 'Writing package data to file.' );
writeFile( fpath, pkg+'\n', {
'encoding': 'utf8'
});
}
debug( 'Finished updating all packages.' );
} // end FUNCTION main()
// MAIN //
// Parse command-line arguments:
opts = {};
args = parseArgs( process.argv.slice( 2 ), opts );
if ( args._[ 0 ] ) {
dir = resolve( cwd(), args._[ 0 ] );
} else {
dir = cwd();
}
main( dir );