Skip to content

Commit

Permalink
Merge pull request #48 from IgniteUI/source-file-extraction
Browse files Browse the repository at this point in the history
fix(file-operations): source file extraction
  • Loading branch information
Aleksandyr authored Feb 24, 2020
2 parents fcdb5b1 + 02a8ba8 commit 486398f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 31 deletions.
17 changes: 8 additions & 9 deletions components/convert-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,14 @@ export class ConvertComponent extends ConverterComponent {


private onResolveBegin(context) {
const files = context.project.files;
/**
* Creates the directory structure of the json's generetion.
*/
this.fileOperations.prepareOutputDirectory(this.mainDirToExport, files);
/**
* Create main file which would contains all global functions.
*/
this.fileOperations.createFile(this.mainDirToExport, null, Constants.GLOBAL_FUNCS_FILE_NAME, 'json');
this.fileOperations.appendFileData(this.mainDirToExport, null, Constants.GLOBAL_FUNCS_FILE_NAME, 'json', {});
}

private onResolveEnd(...rest) {
private onResolveEnd() {
/**
* Write the last built json file.
*
Expand All @@ -104,7 +99,9 @@ export class ConvertComponent extends ConverterComponent {
*/
if (this.factoryInstance && !this.factoryInstance.isEmpty()) {
const filePath = this.reflection.sources[0].fileName;
this.fileOperations.appendFileData(this.mainDirToExport, filePath, this.jsonObjectName, 'json', this.factoryInstance.getJsonContent());
const processedDir = this.fileOperations.getFileDir(filePath);
this.fileOperations.createFile(this.mainDirToExport, processedDir, this.jsonObjectName, 'json');
this.fileOperations.appendFileData(this.mainDirToExport, processedDir, this.jsonObjectName, 'json', this.factoryInstance.getJsonContent());
}

/**
Expand Down Expand Up @@ -132,8 +129,10 @@ export class ConvertComponent extends ConverterComponent {
*/
if (this.jsonObjectName !== reflection.name && this.jsonObjectName !== undefined) {
if (!this.factoryInstance.isEmpty()) {
const filePath = this.reflection.sources[0].fileName
this.fileOperations.appendFileData(this.mainDirToExport, filePath, this.jsonObjectName, 'json', this.factoryInstance.getJsonContent());
const filePath = this.reflection.sources[0].fileName;
const processedDir = this.fileOperations.getFileDir(filePath);
this.fileOperations.createFile(this.mainDirToExport, processedDir, this.jsonObjectName, 'json');
this.fileOperations.appendFileData(this.mainDirToExport, processedDir, this.jsonObjectName, 'json', this.factoryInstance.getJsonContent());
}
}

Expand Down
6 changes: 5 additions & 1 deletion components/render-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ export class RenderComponenet extends RendererComponent {
*/
parser: Parser;

public constructor(owner) {
super(owner)
}

public initialize() {
this.listenTo(this.owner, {
[RendererEvent.BEGIN]: this.onRenderBegin,
Expand Down Expand Up @@ -65,7 +69,7 @@ export class RenderComponenet extends RendererComponent {
case ReflectionKind.Interface:
const filePath = reflection.sources[0].fileName;
let processedDir = this.mainDirOfJsons;
const parsedPath = this.fileOperations.getProcessedDir(filePath);
const parsedPath = this.fileOperations.getFileDir(filePath);
if (parsedPath) {
processedDir = path.join(processedDir, parsedPath);
}
Expand Down
9 changes: 6 additions & 3 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,19 @@ import { ThemeComponent } from './components/theme-component';
import { pluginOptions } from './utils/options';

module.exports = (PluginHost: Application) => {
const app = PluginHost.owner;

const app = PluginHost.owner;
/**
* Add Options register Component.
*/
pluginOptions(app.options)
pluginOptions(app.options);

let startConverter = false;
let startRenderer = false;

app.inputFiles.forEach(f => {
f = f.toLocaleLowerCase().includes(app.project) ? f.substring(app.project.length + 1, f.length) : f;
});

const processArgs = process.argv;
/**
* Determines it it is necessary to run Conversion or Render process based on the
Expand Down
22 changes: 4 additions & 18 deletions utils/file-operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import * as path from 'path';
import { Logger } from 'typedoc/dist/lib/utils/loggers';

export class FileOperations {

public logger;

constructor(logger: Logger) {
Expand Down Expand Up @@ -87,22 +86,9 @@ export class FileOperations {
});
}

public getProcessedDir(filePath) {
if (!filePath) {
return;
}

public getFileDir(filePath: string) {
const parsedPath = path.parse(filePath);
const splitPath = parsedPath.dir.split('/');
const fileStructureDir = splitPath[0];
const componentDir = splitPath[1];
if (fileStructureDir === "" && componentDir === undefined || parsedPath.root) {
return null;
} else if (fileStructureDir && componentDir === undefined) {
return fileStructureDir;
}

return path.join(fileStructureDir, componentDir);
return parsedPath.dir;
}

public appendFileData(mainDir, filePath, fileName, extension, data) {
Expand Down Expand Up @@ -131,8 +117,8 @@ export class FileOperations {
return fs.readJsonSync(jsonFilePath);
}

private constructFilePath(mainDir, filePath) {
const processedPath = this.getProcessedDir(filePath);
private constructFilePath(mainDir, filePath: string) {
const processedPath = filePath ? path.normalize(filePath).toString() : filePath;
let filePathBuilder = mainDir;
if (processedPath) {
filePathBuilder = path.join(filePathBuilder, processedPath);
Expand Down

0 comments on commit 486398f

Please sign in to comment.