forked from ohmygod481999/izzi-shopify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
62 lines (54 loc) · 1.99 KB
/
build.js
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
60
61
62
const ElasticClient = require("./utils/es");
const config = require("./utils/config");
const { Liquid } = require("liquidjs");
const { registCustomFilter, registCustomTag } = require("./liquid/index");
const utils = require("./utils/utils");
const fs = require("fs-extra");
const path = require("path");
const build = async (inputFolderPath) => {
console.log("built with " + inputFolderPath);
// init engine
const engine = new Liquid({
extname: ".liquid",
root: [
`./${inputFolderPath}/layout`,
`./${inputFolderPath}/sections`,
`./${inputFolderPath}/snippets`,
`./${inputFolderPath}/templates`,
],
});
registCustomTag(engine, inputFolderPath);
registCustomFilter(engine, inputFolderPath);
// get all pages
const allPages = [];
fs.readdirSync(inputFolderPath + "/templates").forEach((fname) => {
const splitNameArr = fname.split(".");
if (splitNameArr[splitNameArr.length - 1] === "liquid") {
splitNameArr.splice(splitNameArr.length - 1, 1);
allPages.push(splitNameArr.join("."));
}
});
// console.log(utils.getSchemaFromLiquidSection(raw))
// utils.getContentForIndex(inputFolderPath, engine, {})
// console.log(utils.getPage(engine, inputFolderPath, "index"));
const folderName = inputFolderPath.split("/")[
inputFolderPath.split("/").length - 1
];
const buildPath = "build/" + folderName;
if (!fs.existsSync(buildPath)) {
fs.mkdirSync(buildPath);
}
const assetsInputPath = inputFolderPath + "/" + "assets";
if (!fs.existsSync(assetsInputPath)) {
return console.log("Shopify folder does not have assets folder");
}
fs.copySync(inputFolderPath, buildPath);
utils.exportSassFromCss(inputFolderPath);
};
if (process.argv.length < 3) {
return console.log(
"Pls tell me the path to shopify folder you want to build"
);
}
const inputFolderPath = process.argv[2];
build(inputFolderPath);