Skip to content

Commit

Permalink
feat: set engine version from current svrx
Browse files Browse the repository at this point in the history
  • Loading branch information
int64ago committed Sep 27, 2019
1 parent ddd5fb4 commit c99db41
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 16 deletions.
8 changes: 7 additions & 1 deletion lib/Generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ const ora = require('ora');
const chalk = require('chalk');

const Editor = require('./Editor');
const { spawn, getPluginName, getPackageName } = require('./utils');
const {
spawn,
getPluginName,
getPackageName,
getEngineVersion,
} = require('./utils');

class Generator extends Editor {
constructor({ root, questions }) {
Expand All @@ -32,6 +37,7 @@ class Generator extends Editor {
async write() {
const answers = {
...this.answers,
engineVersion: await getEngineVersion(),
pluginName: getPluginName(this.answers.projectName, this.answers.scopeName),
packageName: getPackageName(this.answers.projectName, this.answers.scopeName),
};
Expand Down
13 changes: 13 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const cp = require('child_process');
const { paramCase } = require('change-case');
const requireg = require('requireg');

const isSvrxPlugin = (name) => /^svrx-plugin-/.test(name);
exports.isSvrxPlugin = isSvrxPlugin;
Expand Down Expand Up @@ -60,3 +61,15 @@ exports.getAuthor = () => {
return 'svrx';
}
};

exports.getEngineVersion = async () => {
try {
const Manager = requireg('@svrx/cli/lib');
new Manager(); // eslint-disable-line
const svrx = await Manager.loadSvrx();
const version = svrx.Svrx.getCurrentVersion();
return `^${version.split('.')[0]}.0.0`;
} catch (err) {
return '>=0.0.1';
}
};
59 changes: 55 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"fs-extra": "^8.1.0",
"inquirer": "^7.0.0",
"ora": "^3.4.0",
"requireg": "^0.2.2",
"yargs": "^14.0.0"
}
}
6 changes: 3 additions & 3 deletions template/_package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"<%- pluginName %>"
],
"engines": {
"svrx": "~0.0"
"svrx": "<%- engineVersion %>"
},
"author": "<%- author %>",
"scripts": {
Expand All @@ -25,10 +25,10 @@
"chai": "^4.2.0",
"chai-json-schema": "^1.5.1",
"eslint": "^6.2.0",
"global-modules": "^2.0.0",
"husky": "^3.0.4",
"lint-staged": "^9.2.3",
"mocha": "^6.2.0"
"mocha": "^6.2.0",
"requireg": "^0.2.2"
},
"husky": {
"hooks": {
Expand Down
14 changes: 6 additions & 8 deletions template/example/start.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
const path = require('path');
const { existsSync } = require('fs');
const reguireg = require('requireg');

const svrxCLI = path.resolve(require('global-modules'), '@svrx', 'cli', 'lib');

if (!existsSync(svrxCLI)) {
let Manager;
try {
Manager = reguireg('@svrx/cli/lib');
} catch (err) {
console.log('Please install svrx-cli by `npm i @svrx/cli -g`');
process.exit();
}

const Manager = require(svrxCLI);

process.chdir(__dirname);

const manager = new Manager();
manager.loadConfigFile();
new Manager(); // eslint-disable-line
Manager.loadSvrx({}, {
root: __dirname,
plugins: [{ path: path.resolve('..') }],
Expand Down

0 comments on commit c99db41

Please sign in to comment.