Skip to content

Commit 40c69c1

Browse files
committed
code-maintainence-backup-1
1 parent 9704c69 commit 40c69c1

File tree

11 files changed

+1905
-1075
lines changed

11 files changed

+1905
-1075
lines changed

lib/config/default.js

Lines changed: 80 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,84 @@
11
module.exports = exports = {
2-
port: 4000,
3-
cache: true,
4-
logs: {
5-
console: true,
6-
json: true,
7-
path: "./_logs"
8-
},
9-
view: {
10-
module: "nunjucks",
11-
extension: "html",
12-
scaffold: true,
13-
minify: true
14-
},
15-
languages: [
16-
{
17-
code: "en-us",
18-
relative_url_prefix: "/"
19-
}
20-
],
21-
storage: {
22-
provider: "FileSystem",
23-
options: {
24-
basedir: "./_content"
25-
}
26-
},
27-
assets: {
28-
pattern: "/assets/:uid/:filename",
29-
basedir: "./_content",
30-
options: {
31-
dotfiles: 'ignore',
32-
etag: true,
33-
extensions: [ 'html', 'htm'],
34-
fallthrough: true,
35-
index: 'index.html',
36-
lastModified: true,
37-
maxAge: 0,
38-
redirect: true,
39-
setHeaders: function (res, path, stat) {
40-
res.set('x-timestamp', Date.now());
41-
}
42-
}
2+
port: 4000,
3+
cache: true,
4+
logs: {
5+
console: true,
6+
json: true,
7+
path: './_logs'
8+
},
9+
view: {
10+
module: 'nunjucks',
11+
extension: 'html',
12+
scaffold: true,
13+
minify: true
14+
},
15+
languages: [{
16+
code: 'en-us',
17+
relative_url_prefix: '/'
18+
}],
19+
storage: {
20+
provider: 'FileSystem',
21+
options: {
22+
basedir: './_content'
23+
}
24+
},
25+
assets: {
26+
pattern: '/assets/:uid/:filename',
27+
basedir: './_content',
28+
options: {
29+
dotfiles: 'ignore',
30+
etag: true,
31+
extensions: ['html', 'htm'],
32+
fallthrough: true,
33+
index: 'index.html',
34+
lastModified: true,
35+
maxAge: 0,
36+
redirect: true,
37+
setHeaders: function(res, path, stat) {
38+
res.set('x-timestamp', Date.now());
39+
}
40+
}
41+
},
42+
'static': {
43+
url: '/static',
44+
path: 'public',
45+
options: {
46+
dotfiles: 'ignore',
47+
etag: true,
48+
extensions: ['html', 'htm'],
49+
fallthrough: true,
50+
index: 'index.html',
51+
lastModified: true,
52+
maxAge: 0,
53+
redirect: true,
54+
setHeaders: function(res, path, stat) {
55+
res.set('x-timestamp', Date.now());
56+
}
57+
}
58+
},
59+
contentstack: {
60+
host: 'https://api.contentstack.io',
61+
version: 'v3',
62+
socket: 'https://realtime.contentstack.io/',
63+
urls: {
64+
stacks: '/stacks/',
65+
content_types: '/content_types/',
66+
entries: '/entries/',
67+
assets: '/assets/',
68+
environments: '/environments/',
69+
publish_queue: '/publish-queue/',
70+
session: '/user-session/',
71+
user: '/user/'
4372
},
44-
"static": {
45-
url: "/static",
46-
path: "public",
47-
options: {
48-
dotfiles: 'ignore',
49-
etag: true,
50-
extensions: [ 'html', 'htm'],
51-
fallthrough: true,
52-
index: 'index.html',
53-
lastModified: true,
54-
maxAge: 0,
55-
redirect: true,
56-
setHeaders: function (res, path, stat) {
57-
res.set('x-timestamp', Date.now());
58-
}
59-
}
73+
events: {
74+
delete: 'delete',
75+
publish: 'publish',
76+
unpublish: 'unpublish'
6077
},
61-
contentstack: {
62-
host: "https://api.contentstack.io",
63-
version: "v3",
64-
socket: "https://contentstack-realtime.built.io/",
65-
urls: {
66-
stacks: "/stacks/",
67-
content_types: "/content_types/",
68-
entries: "/entries/",
69-
assets: "/assets/",
70-
environments: "/environments/",
71-
publish_queue: "/publish-queue/",
72-
session: "/user-session/",
73-
user: "/user/"
74-
},
75-
events: {
76-
delete: "delete",
77-
publish: "publish",
78-
unpublish: "unpublish"
79-
},
80-
types: {
81-
asset: "asset",
82-
entry: "entry",
83-
form: "form"
84-
}
78+
types: {
79+
asset: 'asset',
80+
entry: 'entry',
81+
form: 'form'
8582
}
86-
}
83+
}
84+
}

lib/config/index.js

Lines changed: 63 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -9,56 +9,78 @@
99
/**
1010
* Module Dependencies.
1111
*/
12-
var fs = require('fs'),
13-
path = require('path'),
14-
resolve = require('resolve'),
15-
folderPath;
12+
var fs = require('fs');
13+
var path = require('path');
14+
var resolve = require('resolve');
15+
var folderPath;
1616

17+
/**
18+
* Load config from contentstack-express
19+
* @return {Object} contentstack-express config
20+
*/
1721
exports.config = function() {
18-
try {
19-
var frameworkPath, contentstack, config, rootPath = process.cwd();
20-
frameworkPath = resolve.sync('contentstack-express', {paths: [], basedir: rootPath});
21-
folderPath = frameworkPath.replace('contentstack.js', '');
22-
contentstack = require(frameworkPath);
23-
return contentstack.config;
24-
} catch (error) {
25-
console.error("contentstack-express is not installed.", error.message);
26-
console.error("Please run the command from the Contentstack Application folder.");
27-
process.exit(0);
28-
}
22+
try {
23+
var frameworkPath, contentstack, config, rootPath = process.cwd();
24+
frameworkPath = resolve.sync('contentstack-express', {
25+
paths: [],
26+
basedir: rootPath
27+
});
28+
folderPath = frameworkPath.replace('contentstack.js', '');
29+
contentstack = require(frameworkPath);
30+
return contentstack.config;
31+
} catch (error) {
32+
console.error(
33+
`contentstack-express module could not be resolved!\n${error.message || error}`
34+
);
35+
console.error(
36+
`Please run the command from the contentstack-express application directory`
37+
);
38+
process.exit(0);
39+
}
2940
};
3041

42+
/**
43+
* Load contentstack-express's sync module
44+
* @return {Module} contentstack-express's sync module
45+
*/
3146
exports.sync = function() {
32-
if(folderPath && fs.existsSync(folderPath)) {
33-
folderPath = path.join(folderPath, 'lib', 'sync', 'sync.js');
34-
if(folderPath && fs.existsSync(folderPath)) {
35-
return require(folderPath);
36-
}
47+
if (folderPath && fs.existsSync(folderPath)) {
48+
folderPath = path.join(folderPath, 'lib', 'sync', 'sync.js');
49+
if (folderPath && fs.existsSync(folderPath)) {
50+
return require(folderPath);
3751
}
38-
return ;
39-
}
52+
}
53+
return;
54+
};
4055

56+
/**
57+
* Get default config
58+
* @return {Object} default config
59+
*/
4160
exports.getDefault = function() {
42-
var config = require('./default');
43-
var _config = {
44-
get: function(key) {
45-
var _value = key.split('.').reduce(function(prev, crnt) {
46-
if(prev && prev[crnt]) return prev[crnt];
47-
return;
48-
}, config);
49-
return _value;
50-
}
51-
};
52-
53-
return _config;
61+
var config = require('./default');
62+
var _config = {
63+
get: function(key) {
64+
var _value = key.split('.').reduce(function(prev, crnt) {
65+
if (prev && prev[crnt]) return prev[crnt];
66+
return;
67+
}, config);
68+
return _value;
69+
}
70+
};
71+
return _config;
5472
};
5573

74+
/**
75+
* Get contentstack-express's package.json file
76+
* @return {Object} package.json file
77+
*/
5678
exports.package = function() {
57-
if(folderPath && fs.existsSync(folderPath)) {
58-
folderPath = path.join(folderPath, 'package.json');
59-
if(folderPath && fs.existsSync(folderPath)) {
60-
return require(folderPath);
61-
}
79+
if (folderPath && fs.existsSync(folderPath)) {
80+
folderPath = path.join(folderPath, 'package.json');
81+
if (folderPath && fs.existsSync(folderPath)) {
82+
return require(folderPath);
6283
}
63-
return ;
64-
};
84+
}
85+
return;
86+
};

0 commit comments

Comments
 (0)