-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathentrypoint.js
More file actions
59 lines (52 loc) · 2.07 KB
/
entrypoint.js
File metadata and controls
59 lines (52 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const fs = require("fs");
const path = require("path");
/**
* @description Recursively copies a directory or file from source to destination,
* handling directories by creating them and their contents, and files by copying
* them with optional cloning.
*
* @param {string} src - The source directory or file path.
*
* @param {string} dest - The destination path to copy or create files/directories.
*/
var copyRecursiveSync = function(src, dest) {
var exists = fs.existsSync(src);
var stats = exists && fs.statSync(src);
var isDirectory = exists && stats.isDirectory();
if (isDirectory) {
fs.mkdirSync(dest, { recursive: true });
fs.readdirSync(src).forEach(function(childItemName) {
// Copies files recursively.
copyRecursiveSync(path.join(src, childItemName),
path.join(dest, childItemName));
});
} else {
fs.copyFileSync(src, dest, fs.constants.COPYFILE_FICLONE);
}
};
// Create required directories under GHOST_CONTENT if they don't exist
const requiredDirectories = ['files', 'logs', 'apps', 'themes', 'data', 'public', 'settings', 'images', 'media'];
const ghostContent = process.env.GHOST_CONTENT;
console.log("Creating required directories under: ", ghostContent);
requiredDirectories.forEach(function(dir) {
const dirPath = path.join(ghostContent, dir);
if (!fs.existsSync(dirPath)) {
fs.mkdirSync(dirPath, { recursive: true });
}
});
// Define sources and destinations for both themes named "casper" and "source".
// Get an environment variable that specifies the path for sourcePath + "/content/themes"
let sourcePath = process.env.GHOST_CONTENT_ORIGINAL + "/themes";
console.log("Source path: ", sourcePath);
let destinationPath = process.env.GHOST_CONTENT + "/themes/";
console.log("Destination path: ", destinationPath);
// Wrap the function in a try/catch block to handle any errors.
try {
copyRecursiveSync(sourcePath, destinationPath);
console.log("Copy successful!");
}
catch (error) {
console.error("Error copying files: ", error);
}
// Run Ghost from the current version.
require("./index.js");