Skip to content
This repository has been archived by the owner on Sep 9, 2019. It is now read-only.

Commit

Permalink
Merge pull request #26 from easyops-cn/fix-scope-prefix
Browse files Browse the repository at this point in the history
fix(generator): scope is prefixed with `@`
  • Loading branch information
weareoutman committed Dec 3, 2018
2 parents 02bf682 + 3566418 commit f548fa7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
6 changes: 3 additions & 3 deletions __tests__/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -414,11 +414,11 @@ describe('generator-console-package:app:@console-plugin', () => {

describe('flattenModuleId', () => {
const testcases = [
['foo', 'bar', 'foo-bar'],
['@foo', 'bar', 'foo-bar'],
[undefined, 'bar/qux', 'bar-qux'],
['foo', 'bar/qux', 'foo-bar-qux']
['@foo', 'bar/qux', 'foo-bar-qux']
];
it.each(testcases)("flattenModuleId(%s, %s) should return %s", (scope, packageName, expected) => {
expect(Generator.flattenModuleId(scope, packageName)).toBe(expected);
})
});
});
8 changes: 7 additions & 1 deletion generators/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,16 @@ module.exports = class extends Generator {
}
};

/**
* compute flatten module id from scope and package name
* @param scope {string} a scope is prefixed by `@`
* @param packageName {string}
* @returns {string}
*/
Generator.flattenModuleId = function (scope, packageName) {
const separator = "-";
if (scope !== undefined) {
return [scope].concat(packageName.split("/")).join(separator);
return [scope.substring(1)].concat(packageName.split("/")).join(separator);
}
return packageName.split("/").join(separator);
}

0 comments on commit f548fa7

Please sign in to comment.