Skip to content

Commit

Permalink
Merge 651882e into 9b60a46
Browse files Browse the repository at this point in the history
  • Loading branch information
amitgilad3 authored Jan 4, 2018
2 parents 9b60a46 + 651882e commit a1f3b8e
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 29 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## [unreleased]

- 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

## [0.12.0-ext.11] - 2018-01-02

Expand Down
4 changes: 2 additions & 2 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ export const DEFAULT_BINDINGS_PREFIX = '@bit';

export const NODE_PATH_SEPARATOR = '.';

export const DEFAULT_DIR_STRUCTURE = `${BITS_DIRNAME}/{namespace}/{name}`;
export const DEFAULT_COMPONENTES_DIR = `${BITS_DIRNAME}/{namespace}/{name}`;

export const DEFAULT_DIR_DEPENDENCIES = '.dependencies';

export const DEFAULT_DIR_DEPENDENCIES_STRUCTURE = `${BITS_DIRNAME}/${DEFAULT_DIR_DEPENDENCIES}`;
export const DEFAULT_DEPENDENCIES_DIR = `${BITS_DIRNAME}/${DEFAULT_DIR_DEPENDENCIES}`;

export const DEFAULT_SEPARATOR = '/';

Expand Down
28 changes: 13 additions & 15 deletions src/consumer/bit-json/consumer-bit-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import R from 'ramda';
import path from 'path';
import AbstractBitJson from './abstract-bit-json';
import { BitJsonNotFound, BitJsonAlreadyExists, InvalidBitJson } from './exceptions';
import { BIT_JSON, DEFAULT_DIR_STRUCTURE, DEFAULT_DIR_DEPENDENCIES_STRUCTURE } from '../../constants';
import { BIT_JSON, DEFAULT_COMPONENTES_DIR, DEFAULT_DEPENDENCIES_DIR } from '../../constants';

function composePath(bitPath: string) {
return path.join(bitPath, BIT_JSON);
Expand All @@ -19,7 +19,8 @@ export default class ConsumerBitJson extends AbstractBitJson {
// path to remove while storing build artifacts. If, for example the code is in 'src' directory, and the component
// is-string is in src/components/is-string, the dists files will be in dists/component/is-string (without the 'src')
distEntry: ?string;
structure: Object; // directory structure templates where to store imported components and dependencies
componentsDefaultDirectory: string;
dependenciesDirectory: string;
saveDependenciesAsComponents: boolean; // save hub dependencies as bit components rather than npm packages

constructor({
Expand All @@ -32,24 +33,24 @@ export default class ConsumerBitJson extends AbstractBitJson {
lang,
distTarget,
distEntry,
structure,
componentsDefaultDirectory,
dependenciesDirectory,
bindingPrefix,
extensions
}) {
super({ impl, spec, compiler, tester, dependencies, lang, bindingPrefix, extensions });
this.distTarget = distTarget;
this.distEntry = distEntry;
this.structure = structure || {
components: DEFAULT_DIR_STRUCTURE,
dependencies: DEFAULT_DIR_DEPENDENCIES_STRUCTURE
};
this.componentsDefaultDirectory = componentsDefaultDirectory || DEFAULT_COMPONENTES_DIR;
this.dependenciesDirectory = dependenciesDirectory || DEFAULT_DEPENDENCIES_DIR;
this.saveDependenciesAsComponents = saveDependenciesAsComponents || false;
}

toPlainObject() {
const superObject = super.toPlainObject();
const consumerObject = R.merge(superObject, {
structure: this.structure,
componentsDefaultDirectory: this.componentsDefaultDirectory,
dependenciesDirectory: this.dependenciesDirectory,
saveDependenciesAsComponents: this.saveDependenciesAsComponents
});
if (this.distEntry || this.distTarget) {
Expand Down Expand Up @@ -94,18 +95,14 @@ export default class ConsumerBitJson extends AbstractBitJson {
env,
dependencies,
lang,
structure,
componentsDefaultDirectory,
dependenciesDirectory,
dist,
bindingPrefix,
extensions,
saveDependenciesAsComponents
} = object;

// todo: this is a backward compatibility, remove it on the next major version
const finalStructure = R.is(String, structure)
? { components: structure, dependencies: DEFAULT_DIR_DEPENDENCIES_STRUCTURE }
: structure;

return new ConsumerBitJson({
impl: R.propOr(undefined, 'impl', sources),
spec: R.propOr(undefined, 'spec', sources),
Expand All @@ -116,7 +113,8 @@ export default class ConsumerBitJson extends AbstractBitJson {
extensions,
dependencies,
saveDependenciesAsComponents,
structure: finalStructure || {},
componentsDefaultDirectory,
dependenciesDirectory,
distTarget: R.propOr(undefined, 'target', dist),
distEntry: R.propOr(undefined, 'entry', dist)
});
Expand Down
11 changes: 7 additions & 4 deletions src/consumer/consumer.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ export default class Consumer {

get dirStructure(): DirStructure {
if (!this._dirStructure) {
this._dirStructure = new DirStructure(this.bitJson.structure);
this._dirStructure = new DirStructure(
this.bitJson.componentsDefaultDirectory,
this.bitJson.dependenciesDirectory
);
}
return this._dirStructure;
}
Expand Down Expand Up @@ -613,9 +616,9 @@ export default class Consumer {
moveExistingComponent(bitMap: BitMap, component: Component, oldPath: string, newPath: string) {
if (fs.existsSync(newPath)) {
throw new Error(
`could not move the component ${component.id} from ${oldPath} to ${
newPath
} as the destination path already exists`
`could not move the component ${
component.id
} from ${oldPath} to ${newPath} as the destination path already exists`
);
}
const componentMap = bitMap.getComponent(component.id);
Expand Down
17 changes: 9 additions & 8 deletions src/consumer/dir-structure/dir-structure.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
// @flow
import R from 'ramda';
import { DEFAULT_DIR_STRUCTURE, DEFAULT_DIR_DEPENDENCIES_STRUCTURE } from '../../constants';
import { DEFAULT_COMPONENTES_DIR, DEFAULT_DEPENDENCIES_DIR } from '../../constants';

export default class BitStructure {
structureStr: string;
dependenciesDir: string;
constructor(structure: Object) {
this.structureStr = structure.components || DEFAULT_DIR_STRUCTURE;
this.dependenciesDir = structure.dependencies || DEFAULT_DIR_DEPENDENCIES_STRUCTURE;
componentsDefaultDirectory: string;
dependenciesDirectory: string;
constructor(componentsDefaultDirectory, dependenciesDirectory) {
this.componentsDefaultDirectory = componentsDefaultDirectory || DEFAULT_COMPONENTES_DIR;
this.dependenciesDirectory = dependenciesDirectory || DEFAULT_DEPENDENCIES_DIR;
console.log('dsffds');
}

_getComponentStructurePart(componentStructure: string, componentPart: string): string {
Expand All @@ -27,11 +28,11 @@ export default class BitStructure {
}

get dependenciesDirStructure(): string {
return this.dependenciesDir;
return this.dependenciesDirectory;
}

get componentsDirStructure(): Object {
const dirStructure = this.structureStr;
const dirStructure = this.componentsDefaultDirectory;
const staticParts = [];
const dynamicParts = [];
dirStructure.split('/').forEach((dir) => {
Expand Down

0 comments on commit a1f3b8e

Please sign in to comment.