Skip to content

Commit d2774a9

Browse files
committed
Add makie plugin for enumerating source code annotations
1 parent cfd35a6 commit d2774a9

File tree

4 files changed

+126
-3
lines changed

4 files changed

+126
-3
lines changed

etc/.makie.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ config.plugins = plugins;
2121
// PLUGINS //
2222

2323
plugins[ 'repl' ] = path.join( prefix, 'makie-repl' );
24+
plugins[ 'notes' ] = path.join( prefix, 'makie-notes' );
2425
plugins[ 'examples' ] = path.join( prefix, 'makie-examples' );
2526
plugins[ 'test' ] = path.join( prefix, 'makie-test' );
2627
plugins[ 'test-summary' ] = path.join( prefix, 'makie-test-summary' );

tools/make/lib/notes/Makefile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11

22
# VARIABLES #
33

4+
# Define keywords identifying annotations:
5+
NOTES ?= 'TODO|FIXME|WARNING|HACK|NOTE|OPTIMIZE'
6+
47
# Define the command for `grep`:
58
GREP ?= grep
69

710
# Define the command-line options to use when invoking `grep`:
811
GREP_FLAGS ?= -Ern
912

10-
# Define keywords identifying annotations:
11-
NOTES ?= 'TODO|FIXME|WARNING|HACK|NOTE|OPTIMIZE'
13+
# Define the search directory:
14+
GREP_DIR ?= $(ROOT_DIR)
1215

1316

1417
# TARGETS #
@@ -18,7 +21,7 @@ NOTES ?= 'TODO|FIXME|WARNING|HACK|NOTE|OPTIMIZE'
1821
# This target searches for annotated comments which indicate work that remains to be completed. Annotated comments will be output, along with the filename and line number where they appear.
1922

2023
notes:
21-
$(GREP) $(GREP_FLAGS) $(NOTES) $(ROOT_DIR) \
24+
$(GREP) $(GREP_FLAGS) $(NOTES) $(GREP_DIR) \
2225
--exclude-dir "$(NODE_MODULES)/*" \
2326
--exclude-dir "$(BUILD_DIR)/*" \
2427
--exclude "$(this_file)" \
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
'use strict';
2+
3+
// MODULES //
4+
5+
var spawn = require( 'child_process' ).spawn;
6+
7+
8+
// FUNCTIONS //
9+
10+
/**
11+
* Callback invoked upon encountering an error.
12+
*
13+
* @private
14+
* @param {Error} error - error object
15+
*/
16+
function onError( error ) {
17+
process.stderr.write( error.message+'\n', 'utf8' );
18+
return process.exit( 1 );
19+
} // end FUNCTION onError()
20+
21+
/**
22+
* Callback invoked upon child process close.
23+
*
24+
* @private
25+
* @param {number} code - exit code
26+
*/
27+
function onFinish( code ) {
28+
if ( code !== 0 ) {
29+
process.stderr.write( '`make` process exited with code `'+code + '.\n' );
30+
return process.exit( code );
31+
}
32+
// Cannot write to `stdout` and then immediately `exit` as `buffer` may not yet have drained https://github.com/nodejs/node/issues/6456.
33+
// process.exit( 0 );
34+
35+
// HACK: workaround is to use `console.log` and no exit:
36+
console.log( '' );
37+
} // end FUNCTION onFinish()
38+
39+
/**
40+
* Callback invoked upon receiving data from `stdout`.
41+
*
42+
* @private
43+
* @param {Buffer} data - standard output
44+
*/
45+
function stdout( data ) {
46+
process.stdout.write( data );
47+
} // end FUNCTION stdout()
48+
49+
/**
50+
* Callback invoked upon receiving data from `stderr`.
51+
*
52+
* @private
53+
* @param {Buffer} data - standard error
54+
*/
55+
function stderr( data ) {
56+
process.stderr.write( data );
57+
} // end FUNCTION stderr()
58+
59+
60+
// PLUGIN //
61+
62+
/**
63+
* `makie` plugin to enumerate source code annotations.
64+
*
65+
* @param {string} dir - Makefile directory
66+
* @param {string} cwd - current working directory
67+
* @param {string} subpath - subdirectory path
68+
*/
69+
function plugin( dir, cwd, subpath ) {
70+
var opts;
71+
var args;
72+
var proc;
73+
74+
opts = {};
75+
opts.cwd = dir;
76+
77+
args = [];
78+
79+
// Environment variables:
80+
if ( subpath ) {
81+
args.push( 'GREP_DIR='+cwd );
82+
}
83+
// Target:
84+
args.push( 'notes' );
85+
86+
proc = spawn( 'make', args, opts );
87+
proc.on( 'error', onError );
88+
proc.stdout.on( 'data', stdout );
89+
proc.stderr.on( 'data', stderr );
90+
proc.on( 'close', onFinish );
91+
} // end FUNCTION plugin()
92+
93+
94+
// EXPORTS //
95+
96+
module.exports = plugin;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "",
3+
"version": "",
4+
"description": "makie plugin to enumerate source code annotations.",
5+
"author": {},
6+
"contributors": [],
7+
"scripts": {},
8+
"main": "./lib",
9+
"repository": {},
10+
"keywords": [
11+
"tools",
12+
"makie",
13+
"make",
14+
"makefile",
15+
"plugin",
16+
"grep",
17+
"notes"
18+
],
19+
"bugs": {},
20+
"dependencies": {},
21+
"devDependencies": {},
22+
"license": "MIT"
23+
}

0 commit comments

Comments
 (0)