-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f458183
commit ff61dc4
Showing
7 changed files
with
715 additions
and
564 deletions.
There are no files selected for viewing
Binary file not shown.
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 |
---|---|---|
@@ -1,50 +1,54 @@ | ||
const path = require('path') | ||
const fs = require('fs') | ||
const electron = require('electron') | ||
const decache = require('decache') | ||
const path = require("path"); | ||
const fs = require("fs"); | ||
const electron = require("electron"); | ||
const decache = require("decache"); | ||
|
||
const userDataPath = (electron.app || electron.remote.app) | ||
.getPath('userData') | ||
const thumbsPath = `${userDataPath}/templates/thumbs` | ||
const mockupsPath = `${userDataPath}/templates/mockups` | ||
const userDataPath = (electron.app || electron.remote.app).getPath("userData"); | ||
const thumbsPath = `${userDataPath}/templates/thumbs`; | ||
const mockupsPath = `${userDataPath}/templates/mockups`; | ||
|
||
if (!fs.existsSync(`${userDataPath}/templates`)) fs.mkdir(`${userDataPath}/templates`) | ||
if (!fs.existsSync(`${mockupsPath}`)) fs.mkdir(mockupsPath) | ||
if (!fs.existsSync(`${thumbsPath}`)) fs.mkdir(thumbsPath) | ||
if (!fs.existsSync(`${userDataPath}`)) fs.mkdir(`${userDataPath}`); | ||
if (!fs.existsSync(`${userDataPath}/templates`)) | ||
fs.mkdir(`${userDataPath}/templates`); | ||
if (!fs.existsSync(`${mockupsPath}`)) fs.mkdir(mockupsPath); | ||
if (!fs.existsSync(`${thumbsPath}`)) fs.mkdir(thumbsPath); | ||
|
||
function getAllTemplatesFiles() { | ||
return fs | ||
.readdirSync(`${userDataPath}/templates`) | ||
.filter(fileName => /\.(json)/.test(fileName)) | ||
.filter(fileName => /\.(json)/.test(fileName)); | ||
} | ||
|
||
function createTemplateDirectory() { | ||
fs.mkdirSync(`${userDataPath}/templates`) | ||
fs.mkdirSync(thumbsPath) | ||
fs.mkdirSync(mockupsPath) | ||
fs.mkdirSync(`${userDataPath}/templates`); | ||
fs.mkdirSync(thumbsPath); | ||
fs.mkdirSync(mockupsPath); | ||
} | ||
|
||
function getLoadTemplateObj() { | ||
return new Promise((resolve, reject) => { | ||
const templates = getAllTemplatesFiles() | ||
const obj = templates.map((filePath) => { | ||
decache(`${userDataPath}/templates/${filePath}`) | ||
let content = require(`${userDataPath}/templates/${filePath}`) | ||
content.fileName = filePath | ||
const templates = getAllTemplatesFiles(); | ||
const obj = templates.map(filePath => { | ||
decache(`${userDataPath}/templates/${filePath}`); | ||
let content = require(`${userDataPath}/templates/${filePath}`); | ||
content.fileName = filePath; | ||
if (!path.isAbsolute(content.mockup.path)) { | ||
content.mockup.path = path.join(`${userDataPath}/templates/`, content.mockup.path) | ||
content.mockup.path = path.join( | ||
`${userDataPath}/templates/`, | ||
content.mockup.path | ||
); | ||
} | ||
return content | ||
}) | ||
return content; | ||
}); | ||
|
||
resolve({ 'yourMockups': obj }) | ||
}) | ||
resolve({ yourMockups: obj }); | ||
}); | ||
} | ||
|
||
module.exports = { | ||
getAllTemplatesFiles, | ||
userDataPath, | ||
thumbsPath, | ||
mockupsPath, | ||
getLoadTemplateObj, | ||
} | ||
getLoadTemplateObj | ||
}; |
Oops, something went wrong.