forked from finos/morphir-elm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
317 lines (269 loc) · 8.28 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
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
const { series, parallel, src, dest } = require('gulp');
const os = require('os')
const path = require('path')
const util = require('util')
const fs = require('fs')
const tmp = require('tmp')
const git = require('isomorphic-git')
const http = require('isomorphic-git/http/node')
const del = require('del')
const elmMake = require('node-elm-compiler').compile
const execa = require('execa');
const mocha = require('gulp-mocha');
const ts = require('gulp-typescript');
const tsProject = ts.createProject('./cli2/tsconfig.json')
const config = {
morphirJvmVersion: '0.9.1',
morphirJvmCloneDir: tmp.dirSync()
}
const stdio = 'inherit';
async function clean() {
return del(['dist'])
}
async function cloneMorphirJVM() {
return await git.clone({
fs,
http,
dir: config.morphirJvmCloneDir.name,
url: 'https://github.com/finos/morphir-jvm',
ref: `tags/v${config.morphirJvmVersion}`,
singleBranch: true
})
}
function copyMorphirJVMAssets() {
const sdkFiles = path.join(config.morphirJvmCloneDir.name, 'morphir/sdk/core/src*/**')
return src([sdkFiles]).pipe(dest('redistributable/Scala/sdk'))
}
async function cleanupMorphirJVM() {
return del(config.morphirJvmCloneDir.name + '/**', { force: true });
}
function checkElmDocs() {
return elmMake([], { docs: "docs.json" })
}
function make(rootDir, source, target) {
return elmMake([source], { cwd: path.join(process.cwd(), rootDir), output: target })
}
function makeCLI() {
return make('cli', 'src/Morphir/Elm/CLI.elm', 'Morphir.Elm.CLI.js')
}
function makeCLI2() {
return make('cli2', 'src/Morphir/Elm/CLI.elm', 'Morphir.Elm.CLI.js')
}
function makeDevCLI() {
return make('cli', 'src/Morphir/Elm/DevCLI.elm', 'Morphir.Elm.DevCLI.js')
}
function makeDevServer() {
return make('cli', 'src/Morphir/Web/DevelopApp.elm', 'web/index.js')
}
function makeDevServerAPI() {
return make('cli', 'src/Morphir/Web/DevelopApp.elm', 'web/insightapp.js')
}
function makeInsightAPI() {
return make('cli', 'src/Morphir/Web/Insight.elm', 'web/insight.js')
}
function makeTryMorphir() {
return make('cli', 'src/Morphir/Web/TryMorphir.elm', 'web/try-morphir.html')
}
const buildCLI2 =
parallel(
compileCli2Ts,
makeCLI2
)
const build =
series(
checkElmDocs,
makeCLI,
makeDevCLI,
buildCLI2,
makeDevServer,
makeDevServerAPI,
makeInsightAPI,
makeTryMorphir
)
function morphirElmMake(projectDir, outputPath, options = {}) {
args = ['./cli/morphir-elm.js', 'make', '-p', projectDir, '-o', outputPath]
if (options.typesOnly) {
args.push('--types-only')
}
console.log("Running: " + args.join(' '));
return execa('node', args, { stdio })
}
function morphirElmMake2(projectDir, outputPath, options = {}) {
args = ['./cli2/lib/morphir.js', 'make', '-p', projectDir, '-o', outputPath]
if (options.typesOnly) {
args.push('--types-only')
}
console.log("Running: " + args.join(' '));
return execa('node', args, { stdio })
}
function morphirElmGen(inputPath, outputDir, target) {
args = ['./cli/morphir-elm.js', 'gen', '-i', inputPath, '-o', outputDir, '-t', target]
console.log("Running: " + args.join(' '));
return execa('node', args, { stdio })
}
async function testUnit(cb) {
await execa('elm-test');
}
async function compileCli2Ts() {
src('./cli2/*.ts').pipe(tsProject()).pipe(dest('./cli2/lib/'))
}
function testIntegrationClean() {
return del([
'tests-integration/generated',
'tests-integration/reference-model/morphir-ir.json'
])
}
async function testIntegrationMake(cb) {
await morphirElmMake(
'./tests-integration/reference-model',
'./tests-integration/generated/refModel/morphir-ir.json')
}
async function testIntegrationMorphirTest(cb) {
src('./tests-integration/generated/refModel/morphir-ir.json')
.pipe(dest('./tests-integration/reference-model/'))
await execa(
'node',
['./cli/morphir-elm.js', 'test', '-p', './tests-integration/reference-model'],
{ stdio },
)
}
async function testIntegrationGenScala(cb) {
await morphirElmGen(
'./tests-integration/generated/refModel/morphir-ir.json',
'./tests-integration/generated/refModel/src/scala/',
'Scala')
}
async function testIntegrationBuildScala(cb) {
// try {
// await execa(
// 'mill', ['__.compile'],
// { stdio, cwd: 'tests-integration' },
// )
// } catch (err) {
// if (err.code == 'ENOENT') {
console.log("Skipping testIntegrationBuildScala as `mill` build tool isn't available.");
// } else {
// throw err;
// }
// }
}
async function testIntegrationMakeSpark(cb) {
await morphirElmMake(
'./tests-integration/spark/model',
'./tests-integration/generated/sparkModel/morphir-ir.json')
}
async function testIntegrationGenSpark(cb) {
await morphirElmGen(
'./tests-integration/generated/sparkModel/morphir-ir.json',
'./tests-integration/generated/sparkModel/src/spark/',
'Spark')
}
async function testIntegrationBuildSpark(cb) {
try {
await execa(
'mill', ['__.compile'],
{ stdio, cwd: 'tests-integration' },
)
} catch (err) {
if (err.code == 'ENOENT') {
console.log("Skipping testIntegrationBuildSpark as `mill` build tool isn't available.");
} else {
throw err;
}
}
}
async function testIntegrationTestSpark(cb) {
try {
await execa(
'mill', ['spark.test'],
{ stdio, cwd: 'tests-integration' },
)
} catch (err) {
if (err.code == 'ENOENT') {
console.log("Skipping testIntegrationTestSpark as `mill` build tool isn't available.");
} else {
throw err;
}
}
}
// Generate TypeScript API for reference model.
async function testIntegrationGenTypeScript(cb) {
await morphirElmGen(
'./tests-integration/generated/refModel/morphir-ir.json',
'./tests-integration/generated/refModel/src/typescript/',
'TypeScript')
}
// Compile generated Typescript API and run integration tests.
function testIntegrationTestTypeScript(cb) {
return src('tests-integration/typescript/TypesTest-refModel.ts')
.pipe(mocha({ require: 'ts-node/register' }));
}
testIntegrationSpark = series(
testIntegrationMakeSpark,
testIntegrationGenSpark,
testIntegrationBuildSpark,
testIntegrationTestSpark,
)
const testIntegration = series(
testIntegrationClean,
testIntegrationMake,
parallel(
testIntegrationMorphirTest,
testIntegrationSpark,
series(
testIntegrationGenScala,
testIntegrationBuildScala,
),
series(
testIntegrationGenTypeScript,
testIntegrationTestTypeScript,
),
)
)
async function testMorphirIRMake(cb) {
await morphirElmMake('.', 'tests-integration/generated/morphirIR/morphir-ir.json',
{ typesOnly: true })
}
// Generate TypeScript API for Morphir.IR itself.
async function testMorphirIRGenTypeScript(cb) {
await morphirElmGen(
'./tests-integration/generated/morphirIR/morphir-ir.json',
'./tests-integration/generated/morphirIR/src/typescript/',
'TypeScript')
}
// Compile generated Typescript API and run integration tests.
function testMorphirIRTestTypeScript(cb) {
return src('tests-integration/typescript/CodecsTest-Morphir-IR.ts')
.pipe(mocha({ require: 'ts-node/register' }));
}
testMorphirIR = series(
testMorphirIRMake,
testMorphirIRGenTypeScript,
testMorphirIRTestTypeScript,
)
const test =
parallel(
testUnit,
testIntegration,
// testMorphirIR,
)
exports.clean = clean;
exports.makeCLI = makeCLI;
exports.makeDevCLI = makeDevCLI;
exports.buildCLI2 = buildCLI2;
exports.build = build;
exports.test = test;
exports.testIntegration = testIntegration;
exports.testIntegrationSpark = testIntegrationSpark;
exports.testMorphirIR = testMorphirIR;
exports.testMorphirIRTypeScript = testMorphirIR;
exports.default =
series(
clean,
series(
cloneMorphirJVM,
copyMorphirJVMAssets,
cleanupMorphirJVM
),
build
);