Skip to content

Commit a22c5f6

Browse files
committed
Refactor makie tool to support plugins and add plugins
1 parent 446e0a3 commit a22c5f6

23 files changed

Lines changed: 1034 additions & 154 deletions

File tree

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 run examples.
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( 'EXAMPLES_FILTER=.*/'+subpath+'/.*' );
82+
}
83+
// Target:
84+
args.push( 'examples' );
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: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "",
3+
"version": "",
4+
"description": "makie plugin to run examples.",
5+
"author": {},
6+
"contributors": [],
7+
"scripts": {},
8+
"main": "./lib",
9+
"repository": {},
10+
"keywords": [
11+
"tools",
12+
"makie",
13+
"make",
14+
"makefile",
15+
"plugin",
16+
"examples"
17+
],
18+
"bugs": {},
19+
"dependencies": {},
20+
"devDependencies": {},
21+
"license": "MIT"
22+
}
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 lint Markdown files.
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( 'MARKDOWN_FILTER=.*/'+subpath+'/.*' );
82+
}
83+
// Target:
84+
args.push( 'lint-markdown' );
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: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "",
3+
"version": "",
4+
"description": "makie plugin to lint Markdown files.",
5+
"author": {},
6+
"contributors": [],
7+
"scripts": {},
8+
"main": "./lib",
9+
"repository": {},
10+
"keywords": [
11+
"tools",
12+
"makie",
13+
"make",
14+
"makefile",
15+
"plugin",
16+
"lint",
17+
"markdown",
18+
"mdown",
19+
"md"
20+
],
21+
"bugs": {},
22+
"dependencies": {},
23+
"devDependencies": {},
24+
"license": "MIT"
25+
}
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 list modules.
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( 'MODULES_FILTER=.*/'+subpath+'/.*' );
82+
}
83+
// Target:
84+
args.push( 'list-modules' );
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: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "",
3+
"version": "",
4+
"description": "makie plugin to list modules.",
5+
"author": {},
6+
"contributors": [],
7+
"scripts": {},
8+
"main": "./lib",
9+
"repository": {},
10+
"keywords": [
11+
"tools",
12+
"makie",
13+
"make",
14+
"makefile",
15+
"plugin",
16+
"list",
17+
"ls",
18+
"modules",
19+
"packages",
20+
"pkg",
21+
"pkgs"
22+
],
23+
"bugs": {},
24+
"dependencies": {},
25+
"devDependencies": {},
26+
"license": "MIT"
27+
}

0 commit comments

Comments
 (0)