custom-functions-metadata
Advanced tools
Comparing version 1.0.43 to 1.0.44
@@ -11,3 +11,3 @@ #!/usr/bin/env node | ||
commander | ||
.command("generate <source-file> <metadata-file>") | ||
.command("generate <source-file> [output-file]") | ||
.description("Generate the metadata for the custom functions from the source code.") | ||
@@ -14,0 +14,0 @@ .action(commands.generate); |
@@ -1,1 +0,1 @@ | ||
export declare function generate(inputFile: string, outputFile: string): Promise<void>; | ||
export declare function generate(inputPath: string, outputPath: string): Promise<void>; |
@@ -13,14 +13,12 @@ // Copyright (c) Microsoft Corporation. All rights reserved. | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const fs_1 = require("fs"); | ||
const office_addin_cli_1 = require("office-addin-cli"); | ||
const generateMetadata = require("./generate"); | ||
function generate(inputFile, outputFile) { | ||
const generate_1 = require("./generate"); | ||
function generate(inputPath, outputPath) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
if (!inputFile) { | ||
if (!inputPath) { | ||
throw new Error("You need to provide the path to the source file for custom functions."); | ||
} | ||
if (!outputFile) { | ||
throw new Error("You need to provide the path to the output file for the custom functions metadata."); | ||
} | ||
const results = yield generateMetadata.generate(inputFile, outputFile); | ||
const results = yield generate_1.generateCustomFunctionsMetadata(inputPath); | ||
if (results.errors.length > 0) { | ||
@@ -30,2 +28,15 @@ console.error("Errors found:"); | ||
} | ||
else { | ||
if (outputPath) { | ||
try { | ||
fs_1.writeFileSync(outputPath, results.metadataJson); | ||
} | ||
catch (err) { | ||
throw new Error(`Cannot write to file: ${outputPath}.`); | ||
} | ||
} | ||
else { | ||
console.log(results.metadataJson); | ||
} | ||
} | ||
} | ||
@@ -32,0 +43,0 @@ catch (err) { |
@@ -8,14 +8,14 @@ import * as ts from "typescript"; | ||
name: string; | ||
description: string; | ||
helpUrl: string; | ||
description?: string; | ||
helpUrl?: string; | ||
parameters: IFunctionParameter[]; | ||
result: IFunctionResult; | ||
options: IFunctionOptions; | ||
result?: IFunctionResult; | ||
options?: IFunctionOptions; | ||
} | ||
export interface IFunctionOptions { | ||
cancelable: boolean; | ||
requiresAddress: boolean; | ||
stream: boolean; | ||
volatile: boolean; | ||
requiresParameterAddresses: boolean; | ||
cancelable?: boolean; | ||
requiresAddress?: boolean; | ||
stream?: boolean; | ||
volatile?: boolean; | ||
requiresParameterAddresses?: boolean; | ||
} | ||
@@ -26,11 +26,12 @@ export interface IFunctionParameter { | ||
type: string; | ||
dimensionality: string; | ||
optional: boolean; | ||
repeating: boolean; | ||
dimensionality?: string; | ||
optional?: boolean; | ||
repeating?: boolean; | ||
} | ||
export interface IFunctionResult { | ||
type: string; | ||
dimensionality: string; | ||
type?: string; | ||
dimensionality?: string; | ||
} | ||
export interface IGenerateResult { | ||
metadataJson: string; | ||
associate: IAssociate[]; | ||
@@ -64,3 +65,3 @@ errors: string[]; | ||
*/ | ||
export declare function generate(inputFile: string, outputFileName: string, wantConsoleOutput?: boolean): Promise<IGenerateResult>; | ||
export declare function generateCustomFunctionsMetadata(inputFile: string, wantConsoleOutput?: boolean): Promise<IGenerateResult>; | ||
/** | ||
@@ -67,0 +68,0 @@ * Takes the sourceCode and attempts to parse the functions information |
@@ -76,9 +76,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. | ||
*/ | ||
function generate(inputFile, outputFileName, wantConsoleOutput = false) { | ||
function generateCustomFunctionsMetadata(inputFile, wantConsoleOutput = false) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const errors = []; | ||
const associate = []; | ||
const generateResults = { | ||
associate, | ||
errors | ||
metadataJson: "", | ||
associate: [], | ||
errors: [] | ||
}; | ||
@@ -88,22 +87,12 @@ if (fs.existsSync(inputFile)) { | ||
const parseTreeResult = parseTree(sourceCode, inputFile); | ||
parseTreeResult.extras.forEach(extra => extra.errors.forEach(err => errors.push(err))); | ||
generateResults.associate = [...parseTreeResult.associate]; | ||
if (errors.length === 0) { | ||
const json = JSON.stringify({ functions: parseTreeResult.functions }, null, 4); | ||
try { | ||
fs.writeFileSync(outputFileName, json); | ||
if (wantConsoleOutput) { | ||
console.log(`${outputFileName} created for file: ${inputFile}`); | ||
} | ||
parseTreeResult.extras.forEach(extra => extra.errors.forEach(err => generateResults.errors.push(err))); | ||
if (generateResults.errors.length > 0) { | ||
if (wantConsoleOutput) { | ||
console.error("Errors in file: " + inputFile); | ||
generateResults.errors.forEach(err => console.error(err)); | ||
} | ||
catch (err) { | ||
if (wantConsoleOutput) { | ||
console.error(err); | ||
} | ||
throw new Error(`Error writing: ${outputFileName} : ${err}`); | ||
} | ||
} | ||
else if (wantConsoleOutput) { | ||
console.error("Errors in file: " + inputFile); | ||
errors.forEach(err => console.error(err)); | ||
else { | ||
generateResults.metadataJson = JSON.stringify({ functions: parseTreeResult.functions }, null, 4); | ||
generateResults.associate = [...parseTreeResult.associate]; | ||
} | ||
@@ -114,6 +103,6 @@ } | ||
} | ||
return Promise.resolve(generateResults); | ||
return generateResults; | ||
}); | ||
} | ||
exports.generate = generate; | ||
exports.generateCustomFunctionsMetadata = generateCustomFunctionsMetadata; | ||
/** | ||
@@ -120,0 +109,0 @@ * Takes the sourceCode and attempts to parse the functions information |
{ | ||
"name": "custom-functions-metadata", | ||
"version": "1.0.43", | ||
"version": "1.0.44", | ||
"description": "Generate metadata for Excel Custom Functions.", | ||
@@ -32,3 +32,3 @@ "main": "./lib/main.js", | ||
"nconf": "^0.10.0", | ||
"office-addin-cli": "^1.0.18", | ||
"office-addin-cli": "^1.0.19", | ||
"xregexp": "^4.3.0" | ||
@@ -45,4 +45,4 @@ }, | ||
"mocha": "^7.1.1", | ||
"office-addin-lint": "^1.1.1", | ||
"office-addin-prettier-config": "^1.0.14", | ||
"office-addin-lint": "^1.1.2", | ||
"office-addin-prettier-config": "^1.0.15", | ||
"rimraf": "^3.0.2", | ||
@@ -60,3 +60,3 @@ "ts-node": "^8.8.1", | ||
"prettier": "office-addin-prettier-config", | ||
"gitHead": "61b59fc16533b5b9da81d914c0c21919d27a06bf" | ||
"gitHead": "7b2a6eb4debb64cf9d2054903d20fb7feb136667" | ||
} |
@@ -15,11 +15,6 @@ # Custom-Functions-Metadata | ||
`custom-functions-metadata generate <sourceFile> <metadataFile>` | ||
`custom-functions-metadata generate <sourceFile> [outputFile]` | ||
`sourceFile`: path to the source file (.ts or .js). | ||
`metadataFile`: path to the metadata file (i.e functions.json). | ||
`outputFile`: If specified, the metadata is written to the file. Otherwise, it is written to the console. | ||
Notes: | ||
* The metadata file is written if there are no errors. | ||
* Otherwise, errors are displayed in the console. | ||
@@ -17,2 +17,3 @@ # Custom Functions Metadata Specification | ||
* [@requiresAddress](#requiresAddress) | ||
* [@requiresParameterAddresses](#requiresParameterAddresses) | ||
* [@returns](#returns) _{type}_ | ||
@@ -110,3 +111,3 @@ * [@streaming](#streaming) | ||
The last function parameter must be of type `CustomFunctions.Invocation` or a derived type. When the function is called, the `parameterAddresses` property will contain address of each parameter. | ||
The last function parameter must be of type `CustomFunctions.Invocation` or a derived type. When the function is called, the `parameterAddresses` property will contain an array containing the address of each parameter. | ||
@@ -113,0 +114,0 @@ --- |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1156
83051
20
3
Updatedoffice-addin-cli@^1.0.19