Skip to content

Latest commit

 

History

History
125 lines (82 loc) · 2.75 KB

README.md

File metadata and controls

125 lines (82 loc) · 2.75 KB

gas-module

npm GitHub license GitHub issues

Run your google appscript code on your local machine for testing

Install

$ npm install gas-module

Usage

requireFile()

  • fileName - name or path of file to be imported
  • options (optional)
    • mocks - object containing mock variables and functions

requireDir()

  • dirName - name or path of directory containing files to be imported
  • recursion
    • true to import files from subdirectories too
    • false to ignore subdirectories
  • options (optional)
    • filterExtension
      • ['.js'] for files with .js extension (default if left undefined)
      • ['.ts'] for files with .ts extension
      • ['.js', '.ts'] for files with .js and .ts extensions
    • mocks - object containing mock variables and functions
    • order - array of filenames in desired order of execusion, if there is files that is not in the array, it will be executed after

Example

import a file

const { requireFile } = require('gas-module');

const file = requireFile('filename.js');

//run function defined in file

file.myFunction();

import with mocks

const { requireFile } = require('gas-module');

const mock = {
    editor: 'vscode',
    hotel: 'trivago'
}
const file = requireFile('filename.js', { mocks: mock});

// run function defined in file

file.myFunction();

// use mock varibale

console.log(file.editor);

import a directory

read only .js files and ignore subdirectories

const { requireDir } = require('gas-module');

const functions = requireDir('directoryname', false, { filterExtension: ['.js']})

// run function defined in any file

functions.myFunction();

read only .ts files including ones from subdirectories

const { requireDir } = require('gas-module');

const functions = requireDir('directoryname', true, { filterExtension: ['.ts']})

// run function defined in any file

functions.myFunction();

read from both .js and .ts files

const { requireDir } = require('gas-module');

const functions = requireDir('directoryname', true, { filterExtension: ['.js', '.ts']})

// run function defined in any file

functions.myFunction();

import with mocks

const { requireDir } = require('gas-module');

const mock = {
    editor: 'vscode',
    hotel: 'trivago'
}
const file = requireDir('directoryname', false, { mocks: mock});

// run function defined in file

file.myFunction();

// use mock varibale

console.log(file.editor);