Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug/#508 dynamic structure #578

Merged
merged 4 commits into from
Jan 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- rename default extension to core extension
- when a nested dependency is imported directly, re-link all its dependents
- [#527](https://github.com/teambit/bit/issues/527) rename structure property in bit.json
- [#508](https://github.com/teambit/bit/issues/508) structure do not support anything other than one dynamic param per folder
- support yarn as package manager
- add package manager config to bit.json

Expand Down
28 changes: 27 additions & 1 deletion e2e/commands/import.e2e.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
// covers also init, create, commit, modify commands
import { expect } from 'chai';
import chai, { expect } from 'chai';
import path from 'path';
import fs from 'fs-extra';
import glob from 'glob';
import normalize from 'normalize-path';
import Helper, { VERSION_DELIMITER } from '../e2e-helper';
import { AUTO_GENERATED_MSG } from '../../src/constants';

chai.use(require('chai-fs'));

describe('bit import', function () {
this.timeout(0);
const helper = new Helper();
Expand Down Expand Up @@ -135,6 +137,30 @@ describe('bit import', function () {
expect(output).to.have.string('successfully imported one component');
});
});
describe('import component with custom dsl as destenation dir for import', () => {
let output;
before(() => {
helper.reInitLocalScope();
helper.setComponentsDirInBitJson('{scope}/{namespace}-{name}');
helper.addRemoteScope();
helper.importComponent('global/simple');
output = helper.importComponent('global/simple');
});
it('should import the component successfully', () => {
expect(output).to.have.string('successfully imported one component');
});
it('should import the component into new dir structure according to dsl', () => {
expect(path.join(helper.localScopePath, helper.remoteScope, 'global-simple')).to.be.a.directory(
'should not be empty'
).and.not.empty;
});
it('bitmap should contain component with correct rootDir according to dsl', () => {
const bitMap = helper.readBitMap();
const cmponentId = `${helper.remoteScope}/global/simple@0.0.1`;
expect(bitMap).to.have.property(cmponentId);
expect(bitMap[cmponentId].rootDir).to.equal(`${helper.remoteScope}/global-simple`);
});
});
});

describe('with compiler and tests', () => {
Expand Down
5 changes: 5 additions & 0 deletions e2e/e2e-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ export default class Helper {
const bitMapPath = path.join(this.localScopePath, '.bit.map.json');
return fs.writeJSONSync(bitMapPath, bitMap);
}
setComponentsDirInBitJson(content: string, bitJsonPath: string = path.join(this.localScopePath, 'bit.json')) {
const bitJson = this.readBitJson(bitJsonPath);
bitJson.componentsDefaultDirectory = content;
this.writeBitJson(bitJson);
}
writeGitIgnore(list: string[]) {
const gitIgnorePath = path.join(this.localScopePath, '.gitignore');
return fs.writeFileSync(gitIgnorePath, list.join('\n'));
Expand Down
6 changes: 2 additions & 4 deletions src/consumer/consumer.js
Original file line number Diff line number Diff line change
Expand Up @@ -817,10 +817,8 @@ export default class Consumer {
}

composeRelativeBitPath(bitId: BitId): string {
const { staticParts, dynamicParts } = this.dirStructure.componentsDirStructure;
const dynamicDirs = dynamicParts.map(part => bitId[part]);
const addToPath = [...staticParts, ...dynamicDirs];
return path.join(...addToPath);
const { componentsDefaultDirectory } = this.dirStructure;
return format(componentsDefaultDirectory, { name: bitId.name, scope: bitId.scope, namespace: bitId.box });
}

composeComponentPath(bitId: BitId): string {
Expand Down