Skip to content

Commit

Permalink
check if tao is installed and touch mathjax
Browse files Browse the repository at this point in the history
  • Loading branch information
krampstudio committed Oct 26, 2017
1 parent 0696450 commit 8b827fd
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 7 deletions.
9 changes: 7 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,16 @@ config.load()
log.exit(`${result.dir} is not a TAO instance`);
}
data.taoRoot = result.dir;
return taoInstance.getExtensions();
})

.then( () => taoInstance.isInstalled() )
.then( result => {
if (!result) {
log.exit('It looks like the given TAO instance is not installed.');
}
})

// Select the extension to release
.then( () => taoInstance.getExtensions())
.then( extensions => inquirer.prompt({
type: 'list',
name: 'extension',
Expand Down
53 changes: 48 additions & 5 deletions src/taoInstance.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ const fs = require('fs');
const { normalize, basename } = require('path');
const { spawn, exec } = require('child_process');
const phpParser = require('php-parser');
const log = require('./log.js');

/**
* Get the taoInstance
Expand Down Expand Up @@ -74,6 +73,23 @@ module.exports = function taoInstanceFactory(rootDir = '', quiet = true, wwwUser
});
},

/**
* Check if the given TAO instance is installed
* @returns {Promise<Boolean>}
*/
isInstalled(){
const installFile = normalize(`${rootDir}/tao/views/locales/en-US/messages.json`);

return new Promise( resolve => {
fs.access(installFile, fs.constants.R_OK, err => {
if (err) {
return resolve(false);
}
return resolve(true);
});
});
},

/**
* Check if the given name is an extension of the TAO instance
* @param {String} extensionName - the name to verify
Expand Down Expand Up @@ -132,9 +148,9 @@ module.exports = function taoInstanceFactory(rootDir = '', quiet = true, wwwUser
},

/**
* Parse tao manifest and extract most of it's info
* Parse TAO manifest and extract most of it's info
* @param {String} manifestPath - the path to the extension manifest
* @return {Promise} resolves with an object that retprsents the manifest
* @return {Promise} resolves with an object that represents the manifest
*/
parseManifest(manifestPath = '') {
//reducer AST to JSON for arrays
Expand Down Expand Up @@ -181,7 +197,7 @@ module.exports = function taoInstanceFactory(rootDir = '', quiet = true, wwwUser
},

/**
* Extract the repository name from the exntesion composer
* Extract the repository name from the extension composer
* @param {String} extensionName - the name of the extension
* @returns {Promise} resolves with the repo name
*/
Expand Down Expand Up @@ -218,6 +234,31 @@ module.exports = function taoInstanceFactory(rootDir = '', quiet = true, wwwUser
options.stdio = 'inherit';
}

/**
* Touch the mathjax fallback if needed to prevent build to fail
* @returns {Promise}
*/
const mathJaxFallback = () => {
const touchFile = normalize(`${rootDir}/taoQtiItem/views/js/mathjax/MathJax.js`);
return new Promise( (resolve, reject) => {
fs.open(touchFile, 'wx', (openErr, fd) => {
if(openErr){
//the file exists we are fine with that
if( openErr.code !== 'EEXISTS'){
return resolve();
}
return reject(openErr);
}
fs.close(fd, closeErr => {
if(closeErr){
return reject(closeErr);
}
return resolve();
});
});
});
};

/**
* run the given grunt task for the current extension :
* `grunt extensionNametask`
Expand Down Expand Up @@ -275,7 +316,9 @@ module.exports = function taoInstanceFactory(rootDir = '', quiet = true, wwwUser
});
}).then( tasks => {
if(tasks.length){
return installNpm().then( () => runTasks(tasks));
return mathJaxFallback()
.then( () => installNpm() )
.then( () => runTasks(tasks));
}
});
},
Expand Down

0 comments on commit 8b827fd

Please sign in to comment.