This repository was archived by the owner on Dec 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathsky-pages.config.js
153 lines (135 loc) · 4.36 KB
/
sky-pages.config.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
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
/*jshint node: true*/
'use strict';
const fs = require('fs-extra');
const path = require('path');
const merge = require('merge');
const logger = require('../../utils/logger');
/**
* Resolves a path given a root path and an array-like arguments object.
* @name resolve
* @param {String} root The root path.
* @param {Array} args An array or array-like object of additional path parts to add to the root.
* @returns {String} The resolved path.
*/
function resolve(root, args) {
args = root.concat(Array.prototype.slice.call(args));
return path.resolve.apply(path, args);
}
function readConfig(file) {
return fs.readJsonSync(file, 'utf8');
}
module.exports = {
/**
* Merge's configs in the following order:
* 1. Builder's skyuxconfig.json
* 2. Builder's skyuxconfig.{command}.json
* 3. App's skyuxconfig.json
* 4. App's skyuxconfig.{command}.json
* @name getSkyPagesConfig
* @param {argv} Optional arguments from command line
* @returns [SkyPagesConfig] skyPagesConfig
*/
getSkyPagesConfig: function (command) {
let skyuxConfig = {};
const hierarchy = [
{
fileName: `App Builder skyuxconfig.json`,
filePath: this.outPath(`skyuxconfig.json`)
},
{
fileName: `App Builder skyuxconfig.${command}.json`,
filePath: this.outPath(`skyuxconfig.${command}.json`)
},
{
fileName: `SPA skyuxconfig.json`,
filePath: this.spaPath(`skyuxconfig.json`)
},
{
fileName: 'SPA skyuxconfig.${command}.json',
filePath: this.spaPath(`skyuxconfig.${command}.json`)
}
];
hierarchy.forEach(file => {
if (fs.existsSync(file.filePath)) {
logger.info(`Merging ${file.fileName}`);
merge.recursive(skyuxConfig, readConfig(file.filePath));
}
});
let config = {
runtime: {
app: {
inject: false,
template: this.outPath('src', 'main.ejs')
},
command: command,
componentsPattern: '**/*.component.ts',
componentsIgnorePattern: './public/**/*',
includeRouteModule: true,
routesPattern: '**/index.html',
runtimeAlias: 'sky-pages-internal/runtime',
srcPath: 'src/app/',
spaPathAlias: 'sky-pages-spa',
skyPagesOutAlias: 'sky-pages-internal',
skyuxPathAlias: '@blackbaud/skyux/dist',
useTemplateUrl: false
},
skyux: skyuxConfig
};
// Manually set after as it depends on properties set above
config.runtime.app.base = this.getAppBase(config);
return config;
},
/**
* Reads the name field of package.json.
* Removes "blackbaud-skyux-spa-" and wraps in "/".
* @name getAppName
* @returns {String} appName
*/
getAppBase: function (skyPagesConfig) {
let name = '';
if (skyPagesConfig.skyux.name) {
name = skyPagesConfig.skyux.name;
} else {
const packagePath = this.spaPath('package.json');
const packageJson = fs.existsSync(packagePath) ? readConfig(packagePath) : {};
if (packageJson.name) {
name = packageJson.name;
} else {
logger.error('The `name` property should exist in package.json or skyuxconfig.json');
}
}
return '/' + name.replace(/blackbaud-skyux-spa-/gi, '') + '/';
},
/**
* Takes one or more path parts and returns the fully-qualified path to the file
* contained in this project (@blackbaud/skyux-builder).
* @returns {String} The fully-qualified path.
*/
outPath: function () {
return resolve([__dirname, '..', '..'], arguments);
},
/**
* Takes one or more path parts and returns the fully-qualified path to the file
* contained in the SPA project.
* @returns {String} The fully-qualified path.
*/
spaPath: function () {
return resolve([process.cwd()], arguments);
},
/**
* Takes one or more path parts and returns the fully-qualified path to the file
* contained in the temp source folder in the SPA project.
* @returns {String} The fully-qualified path.
*/
spaPathTemp: function () {
return resolve([this.spaPath(), '.skypagestmp'], arguments);
},
/**
* Takes one or more path parts and returns the fully-qualified path to the file
* contained in the temp folder in the SPA project.
* @returns {String} The fully-qualified path.
*/
spaPathTempSrc: function () {
return resolve([this.spaPathTemp(), 'src'], arguments);
}
};