Skip to content

Commit

Permalink
build(docgen): fixes docgen module usage failing on Windows platform (#…
Browse files Browse the repository at this point in the history
…11208)

Reworks the calling of titanium-docgen generation and validation due to child process spawning being broken on Windows

Fixes TIMOB-27388
  • Loading branch information
ypbnv authored and sgtcoolguy committed Sep 12, 2019
1 parent 16f04c5 commit 29f02e2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
7 changes: 4 additions & 3 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,12 @@ module.exports = function (grunt) {

grunt.registerTask('validate:docs', 'Validates the docs.', function () {
const done = this.async();
const fork = require('child_process').fork, // eslint-disable-line security/detect-child-process
const spawn = require('child_process').spawn, // eslint-disable-line security/detect-child-process
path = require('path'),
apidoc = path.join(__dirname, 'apidoc');
apidoc = path.join(__dirname, 'apidoc'),
cmd = process.platform === 'win32' ? 'tdoc-validate.cmd' : 'tdoc-validate';

const validate = fork(path.join(__dirname, 'node_modules', '.bin', 'tdoc-validate'), [ apidoc ], { silent: true });
const validate = spawn(path.join(__dirname, 'node_modules', '.bin', cmd), [ apidoc ], { silent: true });
let output = '';

validate.stderr.on('data', function (data) {
Expand Down
6 changes: 4 additions & 2 deletions build/lib/docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ class Documentation {
}

async generateReport(format, filename) {
const args = [ path.join(ROOT_DIR, 'node_modules', '.bin', 'docgen'), '-f', format, '-o', this.outputDir + path.sep, DOC_DIR ];
const cmd = process.platform === 'win32' ? 'docgen.cmd' : 'docgen';
const cmdPath = path.join(ROOT_DIR, 'node_modules', '.bin', cmd);
const args = [ '-f', format, '-o', this.outputDir + path.sep, DOC_DIR ];
if (this.hasWindows && format !== 'typescript') {
args.push([
'-a', path.join(ROOT_DIR, 'windows/doc/Titanium'),
Expand All @@ -30,7 +32,7 @@ class Documentation {
const outputFile = path.join(this.outputDir, filename);

return new Promise((resolve, reject) => {
const prc = spawn('node', args, { cwd: DOC_DIR });
const prc = spawn(cmdPath, args, { cwd: DOC_DIR });
prc.stdout.on('data', data => console.log(data.toString().trim()));
prc.stderr.on('data', data => console.error(data.toString().trim()));
prc.on('close', code => {
Expand Down

0 comments on commit 29f02e2

Please sign in to comment.