Skip to content

Commit

Permalink
Ported the build system to JS
Browse files Browse the repository at this point in the history
  • Loading branch information
cedx committed Jan 13, 2020
1 parent 0cb91d9 commit b4b9754
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 29 deletions.
5 changes: 5 additions & 0 deletions .gulp.json
@@ -0,0 +1,5 @@
{
"flags": {
"gulpfile": "gulpfile.cjs"
}
}
1 change: 0 additions & 1 deletion etc/tsconfig.json
@@ -1,7 +1,6 @@
{
"extends": "../tsconfig.json",
"include": [
"../*.ts",
"../src/**/*.ts",
"../test/**/*.ts"
]
Expand Down
45 changes: 22 additions & 23 deletions gulpfile.ts → gulpfile.cjs
@@ -1,20 +1,19 @@
import {spawn, SpawnOptions} from 'child_process';
import * as del from 'del';
import {promises} from 'fs';
import * as gulp from 'gulp';
import * as replace from 'gulp-replace';
import {EOL} from 'os';
import {delimiter, normalize, resolve} from 'path';
const {spawn} = require('child_process');
const del = require('del');
const {promises} = require('fs');
const {dest, series, src, task, watch} = require('gulp');
const replace = require('gulp-replace');
const {EOL} = require('os');
const {delimiter, normalize, resolve} = require('path');

/** The file patterns providing the list of source files. */
const sources: string[] = ['*.ts', 'src/**/*.ts', 'test/**/*.ts'];

// Shortcuts.
const {dest, series, src, task, watch} = gulp;
const {copyFile, readFile, writeFile} = promises;
/**
* The file patterns providing the list of source files.
* @type {string[]}
*/
const sources = ['src/**/*.ts', 'test/**/*.ts'];

// Initialize the build system.
const _path = process.env.PATH ?? '';
const _path = 'PATH' in process.env ? process.env.PATH : '';
const _vendor = resolve('node_modules/.bin');
if (!_path.includes(_vendor)) process.env.PATH = `${_vendor}${delimiter}${_path}`;

Expand All @@ -36,8 +35,8 @@ task('coverage', () => _exec('coveralls', ['var/lcov.info']));

/** Builds the documentation. */
task('doc', async () => {
for (const path of ['CHANGELOG.md', 'LICENSE.md']) await copyFile(path, `doc/about/${path.toLowerCase()}`);
await _exec('typedoc', ['--gaID', process.env.GOOGLE_ANALYTICS_ID!, '--options', 'etc/typedoc.json', '--tsconfig', 'src/tsconfig.json']);
for (const path of ['CHANGELOG.md', 'LICENSE.md']) await promises.copyFile(path, `doc/about/${path.toLowerCase()}`);
await _exec('typedoc', ['--gaID', process.env.GOOGLE_ANALYTICS_ID, '--options', 'etc/typedoc.json', '--tsconfig', 'src/tsconfig.json']);
await _exec('mkdocs', ['build', '--config-file=doc/mkdocs.yaml']);
return del(['doc/about/changelog.md', 'doc/about/license.md', 'web/mkdocs.yaml']);
});
Expand Down Expand Up @@ -70,8 +69,8 @@ task('upgrade', async () => {

/** Builds the version file. */
task('version', async () => {
const {version} = JSON.parse(await readFile('package.json', 'utf8'));
return writeFile('src/version.g.ts', [
const {version} = JSON.parse(await promises.readFile('package.json', 'utf8'));
return promises.writeFile('src/version.g.ts', [
'/** The version number of the package. */',
`export const packageVersion: string = '${version}';`, ''
].join(EOL));
Expand All @@ -88,12 +87,12 @@ task('default', series('version', 'build'));

/**
* Spawns a new process using the specified command.
* @param command The command to run.
* @param args The command arguments.
* @param options The settings to customize how the process is spawned.
* @return Completes when the command is finally terminated.
* @param {string} command The command to run.
* @param {string[]} args The command arguments.
* @param {object} options The settings to customize how the process is spawned.
* @return {Promise<void>} Completes when the command is finally terminated.
*/
function _exec(command: string, args: string[] = [], options: SpawnOptions = {}): Promise<void> {
function _exec(command, args = [], options = {}) {
return new Promise((fulfill, reject) => spawn(normalize(command), args, {shell: true, stdio: 'inherit', ...options})
.on('close', code => code ? reject(new Error(`${command}: ${code}`)) : fulfill())
);
Expand Down
8 changes: 3 additions & 5 deletions package.json
Expand Up @@ -21,13 +21,11 @@
"devDependencies": {
"@cedx/coveralls": "^9.3.0",
"@types/chai": "^4.2.7",
"@types/gulp": "^4.0.6",
"@types/gulp-replace": "^0.0.31",
"@types/mocha": "^5.2.7",
"@types/node": "^13.1.6",
"@types/node-fetch": "^2.5.4",
"@typescript-eslint/eslint-plugin": "^2.15.0",
"@typescript-eslint/parser": "^2.15.0",
"@typescript-eslint/eslint-plugin": "^2.16.0",
"@typescript-eslint/parser": "^2.16.0",
"chai": "^4.2.0",
"del": "^5.1.0",
"eslint": "^6.8.0",
Expand All @@ -38,7 +36,7 @@
"rollup": "^1.29.0",
"source-map-support": "^0.5.16",
"terser": "^4.6.2",
"ts-node": "^8.6.1",
"ts-node": "^8.6.2",
"typedoc": "^0.16.2",
"typescript": "^3.7.4"
},
Expand Down

0 comments on commit b4b9754

Please sign in to comment.