Skip to content

Commit

Permalink
handle 'prepare-addon' not finished task
Browse files Browse the repository at this point in the history
  • Loading branch information
gilax committed Aug 19, 2018
1 parent 224a792 commit 79d3e2e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 32 deletions.
2 changes: 1 addition & 1 deletion gulp/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ var SERVERS = {
* var PROXY_SERVER = 'http://abc-primo.hosted.exlibrisgroup.com'
* var PROXY_SERVER = 'https://abc-primo.hosted.exlibrisgroup.com:443'
*/
var PROXY_SERVER = 'http://your-server:your-port';
var PROXY_SERVER = 'https://sqa-na04.alma.exlibrisgroup.com';


let buildParams = {
Expand Down
44 changes: 17 additions & 27 deletions gulp/tasks/prepareAddon.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';
const gulp = require('gulp');
const config = require('../config.js');
const exec = require('child_process').exec;
const spawn = require('child_process').spawn;
const fs = require('fs');
const Promise = require('bluebird');
const prompt = require('prompt');
Expand All @@ -21,30 +21,16 @@ gulp.task('prepare-addon', ['select-view', 'custom-js','custom-scss','custom-css

let runNpmInitIfNeeded = new Promise((resolve, reject) => {
if (!fs.existsSync(packageJsonPath)) {
// console.error("You need to run 'npm init' before running this gulp task");
let childProcess = exec('npm init', {cwd: buildParams.viewRootDir()}, err => {
if (err) {
reject(err);
}
resolve();
});
let childProcess = spawn('npm', ['init'], {cwd: buildParams.viewRootDir(), shell: true, stdio: 'inherit'});

childProcess.stdout.on('data', function(data) {
process.stdout.write(data);
childProcess.on('error', err => {
reject(err);
});

process.stdin.on('readable', function() {
let chunk = process.stdin.read();

if(chunk !== null && childProcess.stdin.writable) {
childProcess.stdin.write(chunk);
childProcess.on('exit', (code, signal) => {
if (!code) {
resolve();
}

setTimeout(() => {
if (fs.existsSync(packageJsonPath)) {
childProcess.stdin.end();
}
}, 150);
});
} else {
resolve();
Expand All @@ -63,13 +49,17 @@ gulp.task('prepare-addon', ['select-view', 'custom-js','custom-scss','custom-css

function findNpmIdInPackageJson() {
return new Promise((resolve, reject) => {
fs.readFile(packageJsonPath, (err, data) => {
if (err) {
reject(err);
fs.exists(packageJsonPath, exists => {
if (exists) {
fs.readFile(packageJsonPath, (err, data) => {
if (err) {
reject(err);
}
let packageJson = JSON.parse(data.toString());
npmId = camelCase(packageJson.name);
resolve();
});
}
let packageJson = JSON.parse(data.toString());
npmId = camelCase(packageJson.name);
resolve();
});
});
}
Expand Down
4 changes: 0 additions & 4 deletions node_modules/.gitignore

This file was deleted.

0 comments on commit 79d3e2e

Please sign in to comment.