-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathconfig.js
More file actions
170 lines (152 loc) · 4.82 KB
/
config.js
File metadata and controls
170 lines (152 loc) · 4.82 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
"use strict";
const argv = require("minimist")(process.argv.slice(2));
const path = require("path");
const os = require("os");
const src = argv.src || argv._.shift();
// Directories
const srcPath = src ? path.relative("", src) : ".";
const contentDir = path.join(srcPath, "content");
const themeDir = path.join(srcPath, "theme");
const publicDir = path.join(srcPath, "public");
const userConfigFile = path.join(srcPath, "config.js");
const dirs =
{
srcPath, contentDir, publicDir, themeDir,
pageDir: path.join(srcPath, "pages"),
layoutsDir: path.join(themeDir, "layouts"),
lessDir: path.join(themeDir, "less"),
lessTargetDir: path.join(publicDir, "css"),
browserifyDir: path.join(themeDir, "js"),
browserifyTargetDir: path.join(publicDir, "js"),
localesDir: path.join(srcPath, "locales"),
tempDir: path.join(os.tmpdir(), process.pid + "")
};
// Default port
let port = {
https: 4000,
http: 3000
};
let hostname = "127.0.0.1";
let root = "";
// Create gzip files
let gzip = false;
// i18n configuration
let i18nOptions = {
type: "Index", // "Index", "Double"
detectLang: false,
defaultLocale: "en",
prefix: "{",
postfix: "}",
// crowdinProject
crowdin: {
id: null,
updateOption: "update_as_unapproved"
}
};
let deployment =
{
where: "git",
branch: "gh-pages",
gitDir: srcPath
};
// Supported Page extensions
const pageExtensions = [".md", ".ejs", ".html"];
// Default data passed to the template
let templateData =
{
site: {
title: "CMintS",
description: "CMS created with the internationalization in mind"
},
page: {},
i18n: {}
};
// Markdown configuration
// See https://markdown-it.github.io/markdown-it/#MarkdownIt.new
let markdownOptions =
{
html: true,
xhtmlOut: false,
breaks: false,
langPrefix: "language-",
linkify: false,
typographer: false,
quotes: '“”‘’',
plugins: [require("markdown-it-html-entities")]
};
// Browserify configuration
// see https://github.com/browserify/browserify#browserifyfiles--opts
let jsModuleOptions = {};
// LESS configuration
// see http://lesscss.org/usage/#less-options
let lessOptions =
{
sourceMap: {
sourceMapFileInline: true
}
};
// Link to the example project ZIP file
let example = {
default: "https://github.com/cmints/multi-lang-starter/archive/master.zip",
single: "https://github.com/cmints/single-lang-starter/archive/master.zip",
multi: "https://github.com/cmints/multi-lang-starter/archive/master.zip"
};
// Files to watch for configuration reload
let configReloadWatchers = [userConfigFile];
const loadUserConfig = () =>
{
delete require.cache[path.resolve(userConfigFile)];
// Loading user configurations
try {
// Use workspace path in order to load config when installed globally
const userConfig = require(path.resolve(userConfigFile));
if (userConfig.templateData)
templateData = Object.assign(templateData, userConfig.templateData);
if (userConfig.markdownOptions)
{
const {plugins} = markdownOptions;
markdownOptions = Object.assign(markdownOptions, userConfig.markdownOptions);
if (userConfig.markdownOptions.plugins && plugins)
markdownOptions.plugins = [plugins, ...userConfig.markdownOptions.plugins];
}
if (userConfig.jsModuleOptions)
jsModuleOptions = Object.assign(jsModuleOptions, userConfig.jsModuleOptions);
if (userConfig.lessOptions)
lessOptions = Object.assign(lessOptions, userConfig.lessOptions);
if (userConfig.i18nOptions)
{
const {crowdin} = i18nOptions;
i18nOptions = Object.assign(i18nOptions, userConfig.i18nOptions);
if (crowdin)
i18nOptions.crowdin = Object.assign(crowdin, userConfig.i18nOptions.crowdin);
}
if (userConfig.deployment)
deployment = Object.assign(deployment, userConfig.deployment);
if (userConfig.dirs)
dirs = Object.assign(dirs, userConfig.dirs);
if (userConfig.port)
port = userConfig.port;
if (userConfig.hostname)
hostname = userConfig.hostname;
if (userConfig.root)
root = userConfig.root;
if (userConfig.gzip === true)
gzip = true;
if (userConfig.example)
example = userConfig.example;
if (userConfig.configReloadWatchers)
configReloadWatchers = configReloadWatchers.concat(userConfig.configReloadWatchers);
}
catch (e) {
if (e.code == "MODULE_NOT_FOUND")
console.log("Info: No custom config setup, see: https://cmints.io/documentation/getting-started/configuration");
else
console.error(e)
}
}
loadUserConfig();
// When localesDir doesn't exist make a single language website
const multiLang = require("fs").existsSync(dirs.localesDir);
module.exports = {dirs, templateData, markdownOptions, pageExtensions, port,
hostname, i18nOptions, multiLang, gzip, example, loadUserConfig,
configReloadWatchers, deployment, root, lessOptions, jsModuleOptions};