UNPKG

apiconnect-project

Version:

Configuration module IBM API Connect Developer Toolkit

66 lines (60 loc) 2.27 kB
/********************************************************* {COPYRIGHT-TOP} *** * Licensed Materials - Property of IBM * 5725-Z22, 5725-Z63, 5725-U33, 5725-Z63 * * (C) Copyright IBM Corporation 2016, 2017 * * All Rights Reserved. * US Government Users Restricted Rights - Use, duplication or disclosure * restricted by GSA ADP Schedule Contract with IBM Corp. ********************************************************** {COPYRIGHT-END} **/ // Node module: apiconnect-project 'use strict'; var debug = require('debug')('apiconnect-project:lib:project-type'); var fs = require('fs'); var path = require('path'); module.exports = getProjectType; /** * Quick and dirty sync check to see if directory is a project we recognize. Currently only `loopback` is supported. * * @private * @param {string} path to directory to start searching. * @return {PathInfo} */ function getProjectType(searchDir) { // check if loopback var maybeLbDir = searchDir; // known non-loopback apps which will pass the first check do { try { debug('searching for %s/package.json', maybeLbDir); var p = require(path.join(maybeLbDir, 'package.json')); debug(p); if ( p.dependencies && p.dependencies.hasOwnProperty('loopback') && p.dependencies.hasOwnProperty('loopback-boot') && !p.hasOwnProperty('APIConnectGateway') ) { return { projectType: 'loopback', basePath: maybeLbDir, name: p.name, version: p.version }; }; return { projectType: 'node', basePath: maybeLbDir, name: p.name, version: p.version }; } catch (_) { // ignore } try { if (fs.statSync(path.join(maybeLbDir, '.swiftservergenerator-project')).isFile()) { var appNameFile = fs.existsSync(path.join(maybeLbDir, 'spec.json')) ? 'spec.json' : 'config.json'; var config = fs.readFileSync(path.join(maybeLbDir, appNameFile)); var name = JSON.parse(config).appName; return { projectType: 'swiftserver', basePath: maybeLbDir, name: name }; } } catch (_) { // ignore } var parentDir = path.dirname(maybeLbDir); if (parentDir === maybeLbDir) { break; } maybeLbDir = parentDir; } while (true); return { projectType: 'unknown', basePath: searchDir }; }