2019-04-08 20:38:26 -04:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one
|
|
|
|
* or more contributor license agreements. See the NOTICE file
|
|
|
|
* distributed with this work for additional information
|
|
|
|
* regarding copyright ownership. The ASF licenses this file
|
|
|
|
* to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance
|
|
|
|
* with the License. You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
const fs = require('fs-extra');
|
2019-06-14 10:53:19 -04:00
|
|
|
|
2019-04-08 20:38:26 -04:00
|
|
|
const readfile = '../docs/content/querying/sql.md';
|
|
|
|
const writefile = 'lib/sql-function-doc.ts';
|
|
|
|
|
2019-06-14 10:53:19 -04:00
|
|
|
const heading = `/*
|
2019-04-08 20:38:26 -04:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one
|
|
|
|
* or more contributor license agreements. See the NOTICE file
|
|
|
|
* distributed with this work for additional information
|
|
|
|
* regarding copyright ownership. The ASF licenses this file
|
|
|
|
* to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance
|
|
|
|
* with the License. You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
2019-06-14 10:53:19 -04:00
|
|
|
*/
|
2019-04-08 20:38:26 -04:00
|
|
|
|
2019-06-14 10:53:19 -04:00
|
|
|
// This file is auto generated and should not be modified
|
2019-04-08 20:38:26 -04:00
|
|
|
|
2019-06-14 10:53:19 -04:00
|
|
|
export interface FunctionDescription {
|
2019-06-01 13:14:13 -04:00
|
|
|
syntax: string;
|
|
|
|
description: string;
|
2019-06-14 10:53:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* tslint:disable:quotemark */
|
2019-04-08 20:38:26 -04:00
|
|
|
|
2019-06-14 10:53:19 -04:00
|
|
|
export const SQLFunctionDoc: FunctionDescription[] = `;
|
2019-04-08 20:38:26 -04:00
|
|
|
|
|
|
|
const readDoc = async () => {
|
|
|
|
try {
|
|
|
|
const data = await fs.readFile(readfile, 'utf-8');
|
2019-06-14 10:53:19 -04:00
|
|
|
const sections = data.split("##");
|
2019-04-08 20:38:26 -04:00
|
|
|
|
2019-06-14 10:53:19 -04:00
|
|
|
let entries = [];
|
2019-04-08 20:38:26 -04:00
|
|
|
sections.forEach((section) => {
|
2019-06-14 10:53:19 -04:00
|
|
|
if (!/^#.*function/.test(section)) return;
|
2019-04-08 20:38:26 -04:00
|
|
|
|
2019-06-14 10:53:19 -04:00
|
|
|
entries = entries.concat(
|
|
|
|
section.split('\n').map(line => {
|
2019-04-08 20:38:26 -04:00
|
|
|
if (line.startsWith('|`')) {
|
2019-06-14 10:53:19 -04:00
|
|
|
const rawSyntax = line.match(/\|`(.*)`\|/);
|
|
|
|
if (rawSyntax == null) return null;
|
|
|
|
const syntax = rawSyntax[1]
|
|
|
|
.replace(/\\/g,'')
|
|
|
|
.replace(/|/g,'|');
|
|
|
|
|
|
|
|
// Must have an uppercase letter
|
|
|
|
if (!/[A-Z]/.test(syntax)) return null;
|
2019-04-08 20:38:26 -04:00
|
|
|
|
2019-06-14 10:53:19 -04:00
|
|
|
const rawDescription = line.match(/`\|(.*)\|/);
|
|
|
|
if (rawDescription == null) return null;
|
|
|
|
const description = rawDescription[1];
|
2019-04-08 20:38:26 -04:00
|
|
|
|
2019-06-14 10:53:19 -04:00
|
|
|
return {
|
2019-04-08 20:38:26 -04:00
|
|
|
syntax: syntax,
|
|
|
|
description: description
|
2019-06-14 10:53:19 -04:00
|
|
|
};
|
2019-04-08 20:38:26 -04:00
|
|
|
}
|
2019-06-14 10:53:19 -04:00
|
|
|
}).filter(Boolean)
|
|
|
|
);
|
2019-04-08 20:38:26 -04:00
|
|
|
});
|
|
|
|
|
2019-06-14 10:53:19 -04:00
|
|
|
// Make sure there are at least 10 functions for sanity
|
|
|
|
if (entries.length < 10) {
|
|
|
|
throw new Error(`Did not find any entries did the structure of '${readfile}' change?`);
|
|
|
|
}
|
|
|
|
|
|
|
|
const content = heading + JSON.stringify(entries, null, 2) + ';\n';
|
2019-04-08 20:38:26 -04:00
|
|
|
|
|
|
|
try {
|
2019-06-14 10:53:19 -04:00
|
|
|
await fs.writeFile(writefile, content, 'utf-8');
|
2019-04-08 20:38:26 -04:00
|
|
|
} catch (e) {
|
|
|
|
console.log(`Error when writing to ${writefile}: `, e);
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
console.log(`Error when reading ${readfile}: `, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
readDoc();
|