All Projects → fossamagna → gas-entry-generator

fossamagna / gas-entry-generator

Licence: other
No description or website provided.

Programming Languages

javascript
184084 projects - #8 most used programming language

gas-entry-generator NPM version Build Status Dependency Status  Coverage percentage

Top level function generator for Google Apps Script.

About

In Google Apps Script, it must be top level function declaration that entry point called from google.script.run. gas-entry-generator generate a top level function declaration statement, when it detect a function assignment expression to global object.

Installation

$ npm install gas-entry-generator --save-dev

example

foo.js:

/**
 * comment for foo function.
 */
global.foo = function () {
};

generate.js:

const fs = require('fs');
const { generate } = require('gas-entry-generator');

const fooSource = fs.readFileSync('foo.js', {encoding: 'utf8'});
const options = {
  comment: true
};
const output = generate(fooSource, options);
console.log(output.entryPointFunctions);

Console output:

/**
 * comment for foo function.
 */
function foo() {
}

Execute to generate function as entry point.

$ node generate.js

geranate global assignment expressions from exports.*

foo.ts:

/**
 * comment for foo function.
 */
exports.foo = () => 'bar';

generate.js:

const fs = require('fs');
const { generate } = require('gas-entry-generator');

const fooSource = fs.readFileSync('foo.js', {encoding: 'utf8'});
const options = {
  comment: true,
  autoGlobalExports: true // Enable to detect exports.* to generate entry point functions.
};
const output = generate(fooSource, options);
console.log(output.entryPointFunctions);
console.log('-----');
console.log(output.globalAssignments);

Console output:

/**
 * comment for foo function.
 */
function foo() {
}
-----
global.foo = exports.foo;
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].