Skip to content

Commit

Permalink
Merge branch 'develop' into ochampari/stylesheet_refactoring_changes
Browse files Browse the repository at this point in the history
# Conflicts:
#	generators/workspace/templates/package.tmpl.json
  • Loading branch information
thinkh committed Dec 29, 2020
2 parents 17102c9 + 1b16ea6 commit 54a6b28
Show file tree
Hide file tree
Showing 25 changed files with 1,256 additions and 262 deletions.
1 change: 1 addition & 0 deletions generators/_init-hybrid/templates/_gitignore
Expand Up @@ -2,6 +2,7 @@
/.tscache
/.idea
/build/
/dist/tsBuildInfoFile
/lib/
*.egg-info/
*.py[cod]
Expand Down
1 change: 1 addition & 0 deletions generators/_init-web/templates/_gitignore
@@ -1,6 +1,7 @@
/.tscache
/.idea
/build/
/dist/tsBuildInfoFile
/lib/
node_modules/
/src/**/*.js
Expand Down
2 changes: 2 additions & 0 deletions generators/_init-web/templates/plain/tsconfig.json
Expand Up @@ -11,6 +11,8 @@
"declarationDir": "dist",
"outDir": "dist",
"experimentalDecorators": true,
"incremental": true,
"tsBuildInfoFile": "dist/tsBuildInfoFile",
"noImplicitAny": false,
"skipLibCheck": true,
"esModuleInterop": false,
Expand Down
98 changes: 98 additions & 0 deletions generators/auto-update/AutoUpdateUtils.js
@@ -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;
42 changes: 42 additions & 0 deletions generators/auto-update/GithubRestUtils.js
@@ -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;

0 comments on commit 54a6b28

Please sign in to comment.