-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
101 lines (80 loc) · 2.44 KB
/
gulpfile.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
"use strict";
const gulp = require("gulp");
const path = require("path");
const child_process = require("child_process");
const del = require("del");
const IN_DIR = "lambda/custom/";
const OUT_DIR = "dist/custom/";
gulp.task("tsc", function (done) {
const tscPath = path.normalize("./node_modules/.bin/tsc");
const command = `${tscPath} -p tsconfig.json`;
child_process.execSync(command, {
stdio: "inherit"
});
done();
});
// gulp.task("test", gulp_base.test);
gulp.task("json", function () {
return gulp.src(IN_DIR + '/**/package.json').pipe(gulp.dest(OUT_DIR));
});
gulp.task("models", function (done) {
const fs = require("fs");
/**
* Reads the model for the given locale and returns the parsed JSON.
*
* @param {string} locale
*/
function readModel(locale) {
const model = fs.readFileSync(`${__dirname}/models/${locale}.json`, "utf-8");
return JSON.parse(model);
}
/**
* Writes the given model to the file.
*
* @param {object} model
* @param {string} locale
*/
function writeModel(model, locale) {
const json = JSON.stringify(model, null, 2);
fs.writeFileSync(`${__dirname}/models/${locale}.json`, json);
}
const Locales = {
enUS: "en-US"
};
const Environments = {
Dev: "dev",
Prod: "prod",
};
const invocations = {
[Environments.Dev]: {
[Locales.enUS]: "greeter",
},
[Environments.Prod]: {
[Locales.enUS]: "greeter",
},
};
// make sure we have the environment set
if (!process.env.ENV) {
throw new Error("ENV environment variable not set");
}
// get the current environment
const env = process.env.ENV;
// make sure the env is valid
if (env !== Environments.Local
&& env !== Environments.Dev
&& env !== Environments.Prod) {
throw new Error("Invalid ENV environment variable: " + env);
}
// read the models
const enUSModel = readModel(Locales.enUS);
// set the invocation names
enUSModel.interactionModel.languageModel.invocationName = invocations[env][Locales.enUS];
// write the model to the file
writeModel(enUSModel, Locales.enUS);
done();
});
gulp.task("clean", () => {
return del([".coverage", "dist"]);
});
gulp.task("default", gulp.series("clean", gulp.parallel("tsc", "json")));
gulp.task("release", gulp.series("default"));