Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into ochampari/stylesheet_refactoring_changes
# Conflicts: # generators/workspace/templates/package.tmpl.json
- Loading branch information
Showing
25 changed files
with
1,256 additions
and
262 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
/.tscache | ||
/.idea | ||
/build/ | ||
/dist/tsBuildInfoFile | ||
/lib/ | ||
*.egg-info/ | ||
*.py[cod] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
/.tscache | ||
/.idea | ||
/build/ | ||
/dist/tsBuildInfoFile | ||
/lib/ | ||
node_modules/ | ||
/src/**/*.js | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
const fse = require('fs-extra'); | ||
const path = require('path'); | ||
const NpmUtils = require('../../utils/NpmUtils'); | ||
const glob = require('glob').sync; | ||
const semver = require('semver'); | ||
|
||
class AutoUpdateUtils { | ||
static async autoUpdate(repo, pluginType, currentVersion, targetVersion, cwd, parent) { | ||
const updatesDir = path.join(__dirname, 'updates'); | ||
const excecuteUpdates = AutoUpdateUtils.getAvailableUpdates(updatesDir).filter((version) => semver.gtr(version, currentVersion)); | ||
return parent.newListr( | ||
[...excecuteUpdates.map((version) => { | ||
return { | ||
title: 'update ' + version, | ||
options: { | ||
bottomBar: Infinity, | ||
persistentOutput: true | ||
}, | ||
task: async (ctx, task) => AutoUpdateUtils.updateLogic(version, targetVersion, pluginType, cwd, task, ctx) | ||
}; | ||
})], { exitOnError: true, concurrent: false, rendererOptions: { showErrorMessage: true, collapseErrors: false, collapse: false } } | ||
); | ||
} | ||
|
||
/** | ||
* Runs a single update and writes version to yo-rc.json if successful. | ||
* @param {*} nextVersion | ||
* @param {*} targetVersion | ||
* @param {*} pluginType | ||
* @param {*} cwd | ||
* @param {*} task | ||
* @param {*} ctx | ||
*/ | ||
static async updateLogic(nextVersion, targetVersion, pluginType, cwd, task, ctx) { | ||
const filePath = `./updates/update-${nextVersion}.js`; | ||
const repo = path.basename(cwd); | ||
const { update, description } = require(filePath); | ||
|
||
const log = (text) => task.output = text; | ||
const currentVersion = AutoUpdateUtils.readConfig('localVersion', cwd) || NpmUtils.decrementVersion(targetVersion); | ||
|
||
if (currentVersion === nextVersion) { | ||
throw new Error(`${repo}: Duplicate version tag "${currentVersion}"`); | ||
} | ||
return update(repo, pluginType, cwd, log) | ||
.then(async () => { | ||
AutoUpdateUtils.setConfig('localVersion', nextVersion, cwd); | ||
return ctx[repo].descriptions.push(`#### ${currentVersion} to ${nextVersion}\n ${description}`); | ||
}) | ||
|
||
.catch((e) => { | ||
const msg = `${repo}: Update ${currentVersion} to ${nextVersion} failed with ${e.message}`; | ||
e.message = msg; | ||
throw e; | ||
}); | ||
} | ||
|
||
/** | ||
* Reads and sorts all available updates by their versions. | ||
* @param {string} updatesDir Absolute path to the updates dir. | ||
* @returns {string[]} The versions in ascending order. | ||
*/ | ||
static getAvailableUpdates(updatesDir) { | ||
const files = glob('update-*.js', { | ||
cwd: updatesDir | ||
}) || []; | ||
const versions = files.map((file) => file.match(/(?<=update-).*?(?=.js)/)[0]); | ||
return semver.sort(versions); | ||
} | ||
|
||
/** | ||
* Sets a key in `.yo-rc.json`. | ||
* @param {string} key Key name | ||
* @param {string} value Value | ||
* @param {string} cwd Path to the current repo | ||
*/ | ||
static setConfig(key, value, cwd) { | ||
const target = path.join(cwd + '/.yo-rc.json'); | ||
const file = fse.readJSONSync(target); | ||
file['generator-phovea'][key] = value; | ||
fse.writeJSONSync(target, file, { spaces: 2 }); | ||
} | ||
|
||
static readConfig(key, cwd) { | ||
const file = fse.readJSONSync(path.join(cwd + '/.yo-rc.json')); | ||
return file['generator-phovea'][key]; | ||
} | ||
|
||
static getCredentials(org) { | ||
org = org.toUpperCase(); | ||
return { | ||
username: process.env[`${org}_USER`], | ||
token: process.env[`${org}_TOKEN`] | ||
}; | ||
} | ||
} | ||
|
||
module.exports = AutoUpdateUtils; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
const rp = require('request-promise'); | ||
const _ = require('lodash'); | ||
|
||
class GithubRestUtils { | ||
static commonPostOptions() { | ||
return { | ||
method: 'POST', | ||
headers: { | ||
'User-Agent': 'request' | ||
}, | ||
body: { | ||
accept: 'application/vnd.github.v3+json', | ||
}, | ||
json: true | ||
}; | ||
} | ||
static createPullRequest(baseName, data = {}, {username, token}) { | ||
const config = _.merge({}, | ||
GithubRestUtils.commonPostOptions(), | ||
{ | ||
uri: `https://${username}:${token}@api.github.com/repos/${baseName}/pulls`, | ||
body: { | ||
...data | ||
}, | ||
}); | ||
return rp(config); | ||
} | ||
|
||
static setAssignees(baseName, prNumber, assignees, {username, token}) { | ||
const config = _.merge({}, | ||
GithubRestUtils.commonPostOptions(), | ||
{ | ||
uri: `https://${username}:${token}@api.github.com/repos/${baseName}/issues/${prNumber}/assignees`, | ||
body: { | ||
assignees | ||
}, | ||
}); | ||
return rp(config); | ||
} | ||
} | ||
|
||
module.exports = GithubRestUtils; |
Oops, something went wrong.