Skip to content

Commit

Permalink
Merge pull request #466 from phovea/release-7.0.0
Browse files Browse the repository at this point in the history
Release 7.0.0
  • Loading branch information
Anita Steiner authored Feb 15, 2021
2 parents df6a3c4 + 5cfac08 commit a24e777
Show file tree
Hide file tree
Showing 114 changed files with 5,952 additions and 3,259 deletions.
54 changes: 42 additions & 12 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
version: 2
jobs:
build:
version: 2.1

executors:
node-executor:
working_directory: ~/phovea
docker:
- image: circleci/node:12-browsers
- image: circleci/node:12.13-buster-browsers

jobs:
build:
executor: node-executor
steps:
- checkout
- run:
Expand All @@ -12,22 +17,37 @@ jobs:
node -v
npm -v
- restore_cache:
key: deps-{{ .Branch }}-{{ checksum "package.json" }}
key: deps1-{{ .Branch }}-{{ checksum "package.json" }}
- run:
name: Install npm dependencies
command: npm install
- save_cache:
key: deps-{{ .Branch }}-{{ checksum "package.json" }}
paths:
- ./node_modules
key: deps1-{{ .Branch }}-{{ checksum "package.json" }}
paths: ./node_modules

- run:
name: Show installed npm dependencies
command: npm list --depth=1 || true
- run:
name: Run test
command: npm run test
- persist_to_workspace:
root: ~/phovea
paths: .
publish:
executor: node-executor
steps:
- attach_workspace:
at: ~/phovea
- run:
name: Authentication
command: |
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
- run:
name: Publish package
command: npm publish
workflows:
version: 2
version: 2.1
# build-nightly:
# triggers:
# - schedule:
Expand All @@ -38,17 +58,27 @@ workflows:
# - develop
# jobs:
# - build
build-branch:
build-branches-only:
jobs:
- build:
filters:
tags:
ignore: /^v.*/
build-tag:
ignore: /.*/
build-publish-tag:
jobs:
- build:
filters:
branches:
ignore: /.*/
tags:
only: /^v.*/
- publish:
context:
- org-public
requires:
- build
filters:
branches:
ignore: /.*/
tags:
only: /^v.*/
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @thinkh
* @anita-steiner
25 changes: 25 additions & 0 deletions base/BaseInitHybridGenerator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use strict';
const BaseInitPluginGenerator = require('./BaseInitPluginGenerator');
const {basetype} = require('./config');

class BaseInitHybridGenerator extends BaseInitPluginGenerator {

constructor(args, options) {
super(args, options, basetype.HYBRID);
}

initializing() {
// since just last in the hierarchy used, need to do super calls
super.initializing();
}

default() {
return super.default();
}

writing() {
return super.writing();
}
}

module.exports = BaseInitHybridGenerator;
95 changes: 95 additions & 0 deletions base/BaseInitPluginGenerator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
'use strict';
const path = require('path');
const fs = require('fs-extra');
const chalk = require('chalk');
const GeneratorUtils = require('../utils/GeneratorUtils');
const BasePhoveaGenerator = require('../base/BasePhoveaGenerator');
const config = require('./config');

class BaseInitPluginGenerator extends BasePhoveaGenerator {

constructor(args, options, basetype) {
super(args, options);
this.type = path.basename(path.dirname(this.resolved)).substring(5); // init-web ... web
this.basetype = basetype || config.basetype.WEB;
// Make options available
this.option('skipInstall');
this.option('noSamples');
this.option('useDefaults');
this.cwd = '';
}

initializing() {
if (this._isInvalidWorkspace()) {
throw new Error(chalk.red('Execution failed, because a ".yo-rc.json" and ".yo-rc-workspace.json" file was found. If this directory is a workspace, please remove the ".yo-rc.json" file and try again.\n'));
}

this.composeWith(['phovea:_check-own-version', 'phovea:check-node-version']);

this.config.defaults({
type: this.type
});
}

_isWorkspace() {
return fs.existsSync(this.destinationPath('.yo-rc-workspace.json'));
}

_hasConfigFile() {
return fs.existsSync(this.destinationPath('.yo-rc.json'));
}

/**
* If there is both a `.yo-rc-workspace.json` and `.yo-rc.json` file in the current directory
* the workspace is invalid and the generator cannot function properly.
*/
_isInvalidWorkspace() {
return this._isWorkspace() && this._hasConfigFile();
}

/**
* Create a subdirectory in the current directory.
* Initialize the property cwd.
* @param {string} dir Directory name.
*/
async _createSubDir(dir) {
if (this._isWorkspace() && this.cwd !== dir + '/') {
this.cwd = dir + '/';
return GeneratorUtils.mkdir(dir);
}
return Promise.resolve();
}

readmeAddon() {
const f = this.templatePath('README.partial.md');
if (fs.existsSync(f)) {
return this.fs.read(f);
}
return '';
}

default() {
this.composeWith('phovea:_init-' + this.basetype, {
options: Object.assign({
readme: this.readmeAddon() + (this.options.readme ? `\n\n${this.options.readme}` : '')
}, this.options),
isWorkspace: this._isWorkspace() // inform the sub generator that the cwd is the workspace to avoid reading prompt default values from the workspace package.json
});
}

async writing() {
const config = this.config.getAll();
await this._createSubDir(config.app || config.serviceName || config.name);
if (fs.existsSync(this.templatePath('package.tmpl.json'))) {
this._patchPackageJSON(config, null, null, null, this.cwd);
}
if (fs.existsSync(this.templatePath('_gitignore'))) {
this.fs.copy(this.templatePath('_gitignore'), this.destinationPath(this.cwd + '.gitignore'));
}

this._writeTemplates(config, !this.options.noSamples, this.cwd);

}
}

module.exports = BaseInitPluginGenerator;
26 changes: 26 additions & 0 deletions base/BaseInitServerGenerator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict';

const BaseInitPluginGenerator = require('./BaseInitPluginGenerator');
const {basetype} = require('./config');

class BaseInitServerGenerator extends BaseInitPluginGenerator {

constructor(args, options) {
super(args, options, basetype.PYTHON);
}

initializing() {
// since just last in the hierarchy used, need to do super calls
super.initializing();
}

default() {
return super.default();
}

writing() {
return super.writing();
}
}

module.exports = BaseInitServerGenerator;
98 changes: 98 additions & 0 deletions base/BasePhoveaGenerator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
'use strict';
const Generator = require('yeoman-generator');
const {merge, template} = require('lodash');
const path = require('path');
const glob = require('glob').sync;
const fs = require('fs-extra');
const GeneratorUtils = require('../utils/GeneratorUtils');

class BasePhoveaGenerator extends Generator {

/**
* Modify package.json by passing the configuration.
*
* @param {object} config Current configuration
* @param {*} unset
* @param {*} extra
* @param {*} replaceExtra
* @param {string} cwd The directory from which the generator is being called, i.e., `tdp_core/`.
* If cwd is provided than the `package.json` is going to be written to that subdirectory, otherwise to the current directory.
*/
_patchPackageJSON(config, unset, extra, replaceExtra, cwd = '') {
const pkg = this.fs.readJSON(this.destinationPath(cwd + 'package.json'), {});
let pkgPatch;
if (fs.existsSync(this.templatePath('package.tmpl.json'))) {
pkgPatch = JSON.parse(template(this.fs.read(this.templatePath('package.tmpl.json')))(config));
} else {
pkgPatch = {};
}
merge(pkg, pkgPatch);
if (replaceExtra && extra) {
Object.assign(pkg, extra);
} else {
merge(pkg, extra || {});
}

(unset || []).forEach((d) => delete pkg[d]);

this.fs.writeJSON(this.destinationPath(cwd + 'package.json'), pkg);
}

/**
* Copies the template files to the current directory or to a subdirectory if `cwd` is provided.
* @param {object} config Current configuration
* @param {*} withSamples
* @param {string} cwd The directory from which the generator is being called, i.e., `tdp_core/`.
* If `cwd` is provided than the `package.json` is going to be written to that subdirectory, otherwise to the current directory.
*/
_writeTemplates(config, withSamples, cwd = '') {
const includeDot = {
globOptions: {
dot: true
}
};

const pattern = GeneratorUtils.stringifyAble(config);

const copyTpl = (base, dbase, initialize_once) => {
// see https://github.com/SBoudrias/mem-fs-editor/issues/25
// copyTpl doesn't support glob options
const f = glob(base + '/**/*', {
dot: true,
nodir: true
});
f.forEach((fi) => {
const rel = path.relative(base, fi);
if (!initialize_once || !fs.existsSync(this.destinationPath(cwd + dbase + rel))) {
this.fs.copyTpl(fi, this.destinationPath(cwd + dbase + rel), pattern);
}
});
};

const copy = (prefix) => {
if (fs.existsSync(this.templatePath(prefix + 'plain'))) {
this.fs.copy(this.templatePath(prefix + 'plain/**/*'), this.destinationPath(cwd), includeDot);
}

const plainTemplatePath = this.templatePath(prefix + 'plain_initialize_once');
if (fs.existsSync(plainTemplatePath)) {
copyTpl(plainTemplatePath, '', true);
}

copyTpl(this.templatePath(prefix + 'processed'), '', false);

if (config.name) {
if (fs.existsSync(this.templatePath(prefix + 'pluginname_plain'))) {
this.fs.copy(this.templatePath(prefix + 'pluginname_plain/**/*'), this.destinationPath(cwd + config.name.toLowerCase() + '/'), includeDot);
}
copyTpl(this.templatePath(prefix + 'pluginname_processed'), config.name.toLowerCase() + '/', false);
}
};
copy('');
if (withSamples) {
copy('sample_');
}
}
}

module.exports = BasePhoveaGenerator;
13 changes: 13 additions & 0 deletions base/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

/**
* Base classes types each plugin type can belong to.
*/
const basetype = {
PYTHON: 'python',
WEB: 'web',
HYBRID: 'hybrid'
};

module.exports = {
basetype
};
10 changes: 5 additions & 5 deletions generators/_init-hybrid/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use strict';
const Base = require('../../utils').Base;
const known = () => require('../../utils/known');
const {toLibraryAliasMap, toLibraryExternals} = require('../_init-web');
const BaseInitPluginGenerator = require('../../base/BaseInitPluginGenerator');
const RepoUtils = require('../../utils/RepoUtils');

class Generator extends Base {
class Generator extends BaseInitPluginGenerator {

initializing() {
this.config.defaults({
Expand Down Expand Up @@ -31,8 +31,8 @@ class Generator extends Base {
this.config.set('modules', props.modules);
this.config.set('libraries', props.libraries);
}
this.config.set('libraryAliases', toLibraryAliasMap.call(this, this.config.get('modules'), this.config.get('libraries')));
this.config.set('libraryExternals', toLibraryExternals.call(this, this.config.get('modules'), this.config.get('libraries')));
this.config.set('libraryAliases', RepoUtils.toLibraryAliasMap(this.config.get('modules'), this.config.get('libraries')));
this.config.set('libraryExternals', RepoUtils.toLibraryExternals(this.config.get('modules'), this.config.get('libraries')));
});
}

Expand Down
1 change: 1 addition & 0 deletions generators/_init-hybrid/templates/_gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/.tscache
/.idea
/build/
/dist/tsBuildInfoFile
/lib/
*.egg-info/
*.py[cod]
Expand Down
Loading

0 comments on commit a24e777

Please sign in to comment.