forked from handsontable/hyperformula
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck-file.js
45 lines (35 loc) · 1.61 KB
/
check-file.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
const { resolve } = require('path')
const assert = require('assert')
const fs = require('fs')
const htConfig = require('../ht.config')
const [ /* node bin */ , /* path to this script */ , fileToCheck] = process.argv;
if (!fileToCheck) {
throw Error('Missing file to check');
}
try {
const { HyperFormula } = require(resolve(fileToCheck));
// Check if the autogenerated static properties are correctly filled.
assert(HyperFormula.version === htConfig.HT_VERSION)
assert(HyperFormula.releaseDate === htConfig.HT_RELEASE_DATE)
// The modules are generated at a different time, so there can be some
// differences of up to several seconds. Here the only day we check.
assert(HyperFormula.buildDate.split(' ')[0] === htConfig.HT_BUILD_DATE.split(' ')[0])
const engine = HyperFormula.buildFromArray([
['42', '=A1 + 2']
], { licenseKey: 'gpl-v3' })
const valueA1 = engine.getCellValue({ sheet: 0, row: 0, col: 0 })
const valueB1 = engine.getCellValue({ sheet: 0, row: 0, col: 1 })
// Check if the engine works.
assert(valueA1 === 42)
assert(valueB1 === 44)
// Check if the file contains no redundant license comments
if (fileToCheck.includes('.js')) {
const fileContent = fs.readFileSync(resolve(fileToCheck), 'utf8')
const licenseComments = fileContent.match(/@license/g)
assert.equal(licenseComments.length, 2)
}
console.log(`Bundle check: \u001b[1;37m${fileToCheck}\u001b[0m \u001b[0;32mOK\u001b[0m`)
} catch (ex) {
console.log(`Bundle check: \u001b[1;37m${fileToCheck}\u001b[0m \u001b[0;31mERROR\u001b[0m`)
throw ex;
}