Skip to content

Commit

Permalink
New: add update API (fixes #185) (#195)
Browse files Browse the repository at this point in the history
* Add update function

* Add version getter

* Remove duplicate map call
  • Loading branch information
taylortom committed Aug 10, 2023
1 parent ae090d5 commit 068d835
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 068d835

Please sign in to comment.