Skip to content

Commit

Permalink
feat: extract package name and se for ComponentSource
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed Mar 16, 2020
1 parent 5452a1b commit 71d6f13
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
10 changes: 9 additions & 1 deletion core/instrument/src/misc/packageInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,12 @@ export const packageInfo = async (
.replace('{committish}', templates.committish || 'master');
};
const result: Repository = {};
const { storeBrowseLink, storeDocsLink, storeIssuesLink } = opts || {};
const {
storeBrowseLink,
storeDocsLink,
storeIssuesLink,
storePackageName,
} = opts || {};
if (storeBrowseLink) {
result.browse = fillTemplate(templates.browsefiletemplate);
}
Expand All @@ -110,6 +115,9 @@ export const packageInfo = async (
if (storeIssuesLink) {
result.issues = fillTemplate(templates.bugstemplate);
}
if (storePackageName) {
result.name = packageJSON.name;
}
return result;
}
}
Expand Down
6 changes: 6 additions & 0 deletions core/instrument/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export const defaultPackageOptions: PackageInfoOptions = {
storeBrowseLink: true,
storeDocsLink: true,
storeIssuesLink: true,
storePackageName: true,
};

export const defaultComponentOptions: ComponentOptions = {
Expand All @@ -106,6 +107,11 @@ export interface PackageInfoOptions {
*/
packageJsonName?: string;

/**
* Whether to save the package name in the repository field
*/
storePackageName?: boolean;

/**
* Whether to save the link for browsing the file in the repository field
*/
Expand Down
4 changes: 4 additions & 0 deletions core/specification/src/utility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export interface CodeLocation {
*
*/
export interface Repository {
/**
* package name
*/
name?: string;
/**
* link for browsing the file
*/
Expand Down
10 changes: 6 additions & 4 deletions ui/blocks/src/ComponentSource/ComponentSource.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ export const ComponentSource: FC<ComponentSourceProps> = ({
of,
});
let source;
const { from, importedName, name: componentName } = component || {};
if (from) {
const { from, importedName, name: componentName, repository } =
component || {};
const importFrom = repository && repository.name ? repository.name : from;
if (importFrom) {
source =
importedName !== 'default' && importedName !== 'namespace'
? `import { ${componentName} } from '${from}';`
: `import ${componentName} from '${from}';`;
? `import { ${componentName} } from '${importFrom}';`
: `import ${componentName} from '${importFrom}';`;
}

if (!source) {
Expand Down

0 comments on commit 71d6f13

Please sign in to comment.