forked from microsoft/fluentui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateFlightConfig.js
95 lines (77 loc) · 3.36 KB
/
createFlightConfig.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
/*
Creates a configuration JS file that exposes the build ID and base URL that the site should load.
*/
const fs = require('fs');
const path = require('path');
const { argv, logger } = require('@fluentui/scripts');
/**
* Task function for the Fluent UI website that generates a manifest for the non-UHF "internal" site
*/
module.exports.createInternalFlightConfigTask = function() {
return function() {
let date = new Date();
// Produces date string of the form yyyyMMdd, e.g. 20180701
let today = date.getFullYear() + ('0' + (date.getMonth() + 1)).slice(-2) + ('0' + date.getDate()).slice(-2);
let configsToGenerate = ['fabric-website-internal-prod-config', 'fabric-website-internal-df-config'];
let configData = {
version: process.env.BUILD_BUILDNUMBER || '0',
baseCDNUrl: argv().baseCDNUrl,
buildName: process.env.BUILD_DEFINITIONNAME || 'localbuild',
createdDate: today,
};
logger.info('config data:');
logger.info(configData);
configsToGenerate.forEach(fileName => {
generateConfig(fileName, path.resolve(process.cwd(), 'flights'), configData);
});
};
};
/**
* Task function for the Fluent UI website that generates a manifest for the UHF public site
*/
module.exports.createPublicFlightConfigTask = function() {
return function() {
let date = new Date();
// Produces date string of the form yyyyMMdd, e.g. 20180701
let today = date.getFullYear() + ('0' + (date.getMonth() + 1)).slice(-2) + ('0' + date.getDate()).slice(-2);
let configsToGenerate = ['fabric-website-prod', 'fabric-website-df'];
let configData = {
version: process.env.BUILD_BUILDNUMBER || '0',
baseCDNUrl: argv().baseCDNUrl,
buildName: process.env.BUILD_DEFINITIONNAME || 'localbuild',
createdDate: today,
};
logger.info('config data:');
logger.info(configData);
configsToGenerate.forEach(fileName => {
generateConfig(fileName, path.resolve(process.cwd(), 'flights'), configData);
});
};
};
function generateConfig(fileName, outDir, configData) {
try {
if (!fs.existsSync(outDir)) {
fs.mkdirSync(outDir);
}
let configInitializationCode = `var Flight=${JSON.stringify(configData, null)};`;
fs.writeFile(path.join(outDir, `${fileName}.js`), configInitializationCode, err => {
if (err) {
logger.error(`Error writing ${outDir}/${fileName}.js: `, err);
return;
} else {
logger.info(`Wrote ${outDir}/${fileName}.js`);
}
});
} catch (e) {
logger.error('Error creating output folder', e);
}
}
// let sampleConfig = {
// "version": "fabric-website-internal_20180720.6",
// "baseCDNUrl": "https://odspuxe.blob.core.windows.net/uifabric/fabric-website-internal_20180730.1",
// "buildName": "fabric-website-internal-prod-release",
// "createdDate": "20180701"
// };
// Run this to test pointing to a particular build
// set BUILD_ID=fabric-website-internal_20180720.6&& set FILE_NAME=fabric-website-internal-df-release&& set BASE_CDN_URL=https://odspuxe.blob.core.windows.net/uifabric/fabric-website-internal_20180730.1&& set BUILD_NAME=fabric-website-internal-prod-release&& node createFlightConfig.js
// npm run create-flight-config -- buildNumber=fabric-website-internal_20180720.6 baseCDNUrl=https://odspuxe.blob.core.windows.net/uifabric/fabric-website-internal_20180730.1 buildName=fabric-website-internal-prod-release