-
Notifications
You must be signed in to change notification settings - Fork 24
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
feat: nested folder and index files #5
Comments
Hi @Gorniv, I did some modifications to my fork to handle creation of folders. You will find the change below : import { TemplateType } from './../enums/template-type';
export interface IResourceFile {
name: Function;
folder?: Function;
type: TemplateType;
condition?: Function;
} ressource.ts {
name: () => 'view.dart',
folder: () => '',
type: TemplateType.ViewTV,
}, ioutils.ts const mkdirp = require('mkdirp'); // Create the new folder
export const createSubFolder = async (loc: IPath, config: IConfig, files: IResourceFile[]) => {
files
.filter((file) => (file.condition ? file.condition(config, loc.params) : true))
// tslint:disable-next-line:ter-arrow-parens
.filter((file) => file.name(config) !== 'index.dart')
.map(async (file) => {
try {
const myPath = { ...loc };
const fileFolder: string = file.folder(config);
myPath.dirPath = path.join(myPath.dirPath, fileFolder);
await mkdirp(myPath.dirPath);
} catch (ex) {
await window.showErrorMessage(`Error: ${ex}`);
}
}); angular-cli.ts // tslint:disable-next-line:ter-arrow-parens
if (resource.hasOwnProperty('createFolder') && resource.createFolder(config)) {
await createFolder(loc);
await createSubFolder(loc, config, resource.files);
}
const filesASync: Promise<IFiles>[] = resource.files
// tslint:disable-next-line:ter-arrow-parens
.filter((file) => (file.condition ? file.condition(config, loc.params) : true))
// tslint:disable-next-line:ter-arrow-parens
.filter((file) => file.name(config) !== 'index.dart')
.map(async (file) => {
try {
const fileName: string = file.name(config);
const fileFolder: string = file.folder(config);
const fileFolderAndName: string = path.join(
fileFolder,
fileName.startsWith('_') ? `${loc.fileName}${fileName}` : `${loc.fileName}_${fileName}`,
);
const newName: string = path.join(loc.dirPath, fileFolderAndName);
const result: IFiles = {
name: newName,
content: await this.fc.getTemplateContent(
file.type,
config,
loc.fileName,
loc.params,
loc,
),
};
return result;
} catch (ex) {
console.log(ex);
await window.showErrorMessage(`Error: ${ex}`);
}
});
const files = await Promise.all(filesASync);
await createFiles(loc, files);
const filesIndex: Promise<IFiles>[] = resource.files
// tslint:disable-next-line:ter-arrow-parens
.filter((file) => (file.condition ? file.condition(config, loc.params) : true))
// tslint:disable-next-line:ter-arrow-parens
.filter((file) => file.name(config) === 'index.dart')
.map(async (file) => {
try {
let contentStr = '';
resource.files
// tslint:disable-next-line:ter-arrow-parens
.filter((dartFile) =>
dartFile.condition ? dartFile.condition(config, loc.params) : true,
)
// tslint:disable-next-line:ter-arrow-parens
.filter((dartFile) => dartFile.name(config) !== 'index.dart')
.forEach(function(val) {
const fileName: string = val.name(config);
const fileFolder: string = val.folder(config);
const fileFolderAndName: string = path.join(
fileFolder,
fileName.startsWith('_')
? `${loc.fileName}${fileName}`
: `${loc.fileName}_${fileName}`,
);
const newName: string = path.join(loc.dirPath, fileFolderAndName);
contentStr += `export '${fileFolderAndName}';\r\n`;
});
const fileName: string = file.name(config);
const result: IFiles = {
name: path.join(loc.dirPath, loc.fileName + '_' + fileName),
content: contentStr,
};
return result;
} catch (ex) {
console.log(ex);
await window.showErrorMessage(`Error: ${ex}`);
}
});
const indexFiles = await Promise.all(filesIndex);
await createFiles(loc, indexFiles);
} Typescript is not a language I'm familiar with, so they might be better solutions, and why I didn't risk a PR. PS: You could think of broaden the use of your extension. I use it personally to create the structure of a projet instead of Bloc. |
Hi bounty1342, Can I have an access to this fork, please? |
add export nested folder
The text was updated successfully, but these errors were encountered: