Skip to content

Commit 2814e4d

Browse files
committed
Add scripts for managing bundle packages
1 parent 95cf7c2 commit 2814e4d

File tree

7 files changed

+465
-0
lines changed

7 files changed

+465
-0
lines changed

dist/scripts/bundle_dirs.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* @license Apache-2.0
5+
*
6+
* Copyright (c) 2020 The Stdlib Authors.
7+
*
8+
* Licensed under the Apache License, Version 2.0 (the "License");
9+
* you may not use this file except in compliance with the License.
10+
* You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*/
20+
21+
/**
22+
* Script to list distributable bundle packages.
23+
*
24+
* ## Usage
25+
*
26+
* ```bash
27+
* $ NODE_PATH=./path/to/stdlib/lib/node_modules node /path/to/stdlib/dist/scripts/bundle_dirs.js
28+
* ```
29+
*/
30+
31+
'use strict';
32+
33+
// MODULES //
34+
35+
var bundleDirs = require( './utils/bundle_dirs.js' );
36+
37+
38+
// MAIN //
39+
40+
/**
41+
* Main execution sequence.
42+
*
43+
* @private
44+
*/
45+
function main() {
46+
var dirs = bundleDirs();
47+
if ( dirs instanceof Error ) {
48+
console.error( dirs.message ); // eslint-disable-line no-console
49+
process.exitCode = 1;
50+
return;
51+
}
52+
console.log( dirs.join( '\n' ) ); // eslint-disable-line no-console
53+
}
54+
55+
main();

dist/scripts/bundle_scripts.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* @license Apache-2.0
5+
*
6+
* Copyright (c) 2020 The Stdlib Authors.
7+
*
8+
* Licensed under the Apache License, Version 2.0 (the "License");
9+
* you may not use this file except in compliance with the License.
10+
* You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*/
20+
21+
/**
22+
* Script to list scripts for generating bundles in distributable bundle packages.
23+
*
24+
* ## Usage
25+
*
26+
* ```bash
27+
* $ NODE_PATH=./path/to/stdlib/lib/node_modules node /path/to/stdlib/dist/scripts/bundle_scripts.js
28+
* ```
29+
*/
30+
31+
'use strict';
32+
33+
// MODULES //
34+
35+
var join = require( 'path' ).join;
36+
var bundleDirs = require( './utils/bundle_dirs.js' );
37+
38+
39+
// MAIN //
40+
41+
/**
42+
* Main execution sequence.
43+
*
44+
* @private
45+
*/
46+
function main() {
47+
var list;
48+
var i;
49+
50+
list = bundleDirs();
51+
if ( list instanceof Error ) {
52+
console.error( list.message ); // eslint-disable-line no-console
53+
process.exitCode = 1;
54+
return;
55+
}
56+
for ( i = 0; i < list.length; i++ ) {
57+
// WARNING: we assume that each package adheres to the same layout and naming conventions...
58+
list[ i ] = join( list[ i ], 'scripts', 'build.js' );
59+
}
60+
console.log( list.join( '\n' ) ); // eslint-disable-line no-console
61+
}
62+
63+
main();

dist/scripts/update_versions.js

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* @license Apache-2.0
5+
*
6+
* Copyright (c) 2020 The Stdlib Authors.
7+
*
8+
* Licensed under the Apache License, Version 2.0 (the "License");
9+
* you may not use this file except in compliance with the License.
10+
* You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*/
20+
21+
/**
22+
* Script to update the versions of packages containing distributable files.
23+
*
24+
* ## Usage
25+
*
26+
* ```bash
27+
* $ NODE_PATH=./path/to/stdlib/lib/node_modules node /path/to/stdlib/dist/scripts/update_versions
28+
* ```
29+
*/
30+
31+
/* eslint-disable no-console */
32+
33+
'use strict';
34+
35+
// MODULES //
36+
37+
var join = require( 'path' ).join;
38+
var readJSON = require( '@stdlib/fs/read-json' ).sync;
39+
var writeFile = require( '@stdlib/fs/write-file' ).sync;
40+
var objectKeys = require( '@stdlib/utils/keys' );
41+
var bundleDirs = require( './utils/bundle_dirs.js' );
42+
var version = require( './utils/root_pkg_version.js' );
43+
44+
45+
// MAIN //
46+
47+
/**
48+
* Main execution sequence.
49+
*
50+
* @private
51+
*/
52+
function main() {
53+
var fopts;
54+
var fpath;
55+
var hash;
56+
var list;
57+
var keys;
58+
var pkg;
59+
var err;
60+
var txt;
61+
var v;
62+
var i;
63+
var k;
64+
65+
// Get the root version:
66+
v = version();
67+
if ( v instanceof Error ) {
68+
console.error( v.message );
69+
return;
70+
}
71+
// Get the list of distributable bundle package directories:
72+
list = bundleDirs();
73+
if ( list instanceof Error ) {
74+
console.error( list.message );
75+
return;
76+
}
77+
// For each package, update the version to match the root version:
78+
fopts = {
79+
'encoding': 'utf8'
80+
};
81+
hash = {};
82+
for ( i = 0; i < list.length; i++ ) {
83+
fpath = join( list[ i ], 'package.json' );
84+
pkg = readJSON( fpath, fopts );
85+
if ( pkg instanceof Error ) {
86+
console.error( pkg.message );
87+
return;
88+
}
89+
pkg.version = v;
90+
hash[ fpath ] = pkg;
91+
}
92+
// Save the changes:
93+
keys = objectKeys( hash );
94+
for ( i = 0; i < keys.length; i++ ) {
95+
k = keys[ i ];
96+
txt = JSON.stringify( hash[ k ], null, 2 );
97+
err = writeFile( k, txt+'\n', fopts );
98+
if ( err instanceof Error ) {
99+
console.error( err.message );
100+
}
101+
}
102+
}
103+
104+
main();

dist/scripts/utils/bundle_dirs.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2020 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var path = require( 'path' );
24+
var stat = require( 'fs' ).statSync; // eslint-disable-line no-sync
25+
var readDir = require( '@stdlib/fs/read-dir' ).sync;
26+
var DIST_DIR = require( './dist_dir.js' );
27+
28+
29+
// MAIN //
30+
31+
/**
32+
* Returns a list of bundle package directories.
33+
*
34+
* @private
35+
* @returns {(StringArray|Error)} list of bundle package directories
36+
*/
37+
function bundleDirs() {
38+
var stats;
39+
var tmp;
40+
var out;
41+
var f;
42+
var i;
43+
44+
tmp = readDir( DIST_DIR );
45+
if ( tmp instanceof Error ) {
46+
return tmp;
47+
}
48+
out = [];
49+
for ( i = 0; i < tmp.length; i++ ) {
50+
f = path.join( DIST_DIR, tmp[ i ] );
51+
stats = stat( f );
52+
if ( stats.isDirectory() && tmp[ i ] !== 'scripts' ) {
53+
out.push( f );
54+
}
55+
}
56+
return out;
57+
}
58+
59+
60+
// EXPORTS //
61+
62+
module.exports = bundleDirs;

dist/scripts/utils/dist_dir.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2020 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var resolve = require( 'path' ).resolve;
24+
25+
26+
// MAIN //
27+
28+
var DIST_DIR = resolve( __dirname, '..', '..' );
29+
30+
31+
// EXPORTS //
32+
33+
module.exports = DIST_DIR;
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2020 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var resolveParentPath = require( '@stdlib/fs/resolve-parent-path' ).sync;
24+
var readJSON = require( '@stdlib/fs/read-json' ).sync;
25+
var DIST_DIR = require( './dist_dir.js' );
26+
27+
28+
// MAIN //
29+
30+
/**
31+
* Returns the version of the root (project) `package.json`.
32+
*
33+
* @private
34+
* @returns {(string|Error)} version
35+
*/
36+
function version() {
37+
var root;
38+
var pkg;
39+
40+
// Find the root `package.json`:
41+
root = resolveParentPath( 'package.json', {
42+
'dir': DIST_DIR
43+
});
44+
45+
// Get the root version:
46+
pkg = readJSON( root );
47+
if ( pkg instanceof Error ) {
48+
return pkg;
49+
}
50+
return pkg.version;
51+
}
52+
53+
54+
// EXPORTS //
55+
56+
module.exports = version;

0 commit comments

Comments
 (0)