From 068d835991130fdf72667b426f6677f29ee3e6cc Mon Sep 17 00:00:00 2001 From: Tom Taylor Date: Thu, 10 Aug 2023 09:27:58 +0100 Subject: [PATCH] New: add update API (fixes #185) (#195) * Add update function * Add version getter * Remove duplicate map call --- lib/api.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/lib/api.js b/lib/api.js index 2842ee8..345fcf0 100644 --- a/lib/api.js +++ b/lib/api.js @@ -64,6 +64,40 @@ class API { }) } + /** + * Updates an existing installation of the framework + * @param {Object} options + * @param {string} [options.version=null] Specific version of the framework to install + * @param {string} [options.repository] URL to github repo + * @param {string} [options.cwd=process.cwd()] Directory to install into + * @return {Promise} + */ + async updateFramework ({ + version = null, + repository = ADAPT_FRAMEWORK, + cwd = process.cwd(), + logger + } = {}) { + // cache state of plugins, as these will be wiped + const plugins = (await new Project({ cwd }).getInstallTargets()) + .map(p => p.isLocalSource ? p.sourcePath : `${p.name}@${p.requestedVersion}`) + + await this.installFramework({ version, repository, cwd, logger }) + // restore plugins + await this.installPlugins({ plugins, cwd, logger }) + } + + /** + * @param {Object} options + * @param {string} [options.cwd=process.cwd()] Directory to install into + * @returns {string} + */ + getCurrentFrameworkVersion ({ + cwd = process.cwd(), + } = {}) { + return new Project({ cwd }).version + } + /** * @param {Object} options * @param {Object} [options.repository=ADAPT_FRAMEWORK] The github repository url