Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #558 from frappe/custom-templates
feat: Template Builder
- Loading branch information
Showing
74 changed files
with
3,264 additions
and
1,121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import fs from 'fs/promises'; | ||
import path from 'path'; | ||
import { TemplateFile } from 'utils/types'; | ||
|
||
export async function getTemplates() { | ||
const paths = await getPrintTemplatePaths(); | ||
if (!paths) { | ||
return []; | ||
} | ||
|
||
const templates: TemplateFile[] = []; | ||
for (const file of paths.files) { | ||
const filePath = path.join(paths.root, file); | ||
const template = await fs.readFile(filePath, 'utf-8'); | ||
const { mtime } = await fs.stat(filePath); | ||
templates.push({ template, file, modified: mtime.toISOString() }); | ||
} | ||
|
||
return templates; | ||
} | ||
|
||
async function getPrintTemplatePaths(): Promise<{ | ||
files: string[]; | ||
root: string; | ||
} | null> { | ||
let root = path.join(process.resourcesPath, `../templates`); | ||
|
||
try { | ||
const files = await fs.readdir(root); | ||
return { files, root }; | ||
} catch { | ||
root = path.join(__dirname, `../templates`); | ||
} | ||
|
||
try { | ||
const files = await fs.readdir(root); | ||
return { files, root }; | ||
} catch { | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.