generator-addin

中文文档
4.1.2发布于 2025/06/04Apache-2.0ES Module

MyGeotab/Geotab Drive add-in generator

原始使用文档
文档目录12 节
  1. Features
  2. Package Management
  3. Local Debugging
  4. Release Build Process
  5. Getting Started
  6. Installation
  7. Using
  8. Documentation
  9. MyGeotab
  10. Addin Generator
  11. FAQ
  12. License

generator-addin NPM version Build Status

Yeoman generator for MyGeotab/Geotab Drive add-ins

[!IMPORTANT] The add-in generator currently works with Yeoman version 5.0.0.

Features

Package Management

Leverage NPM

Local Debugging

  • Run and debug the add-in locally without having to add to test database. MyGeotabApi mocks the API object passes to add-in to make requests to you test database.
  • Mock state - Drive add-in will try to use HTML5 features to mock Android/IOS device features (ex. Geolocation)
  • Automagically lint your scripts
  • Built-in preview server with Webpack's development server
  • Webpack makes use of ES2015 features by using Babel loaders

Release Build Process

  • Automagically lint your scripts
  • Minify, Obfuscate and Image optimization
  • Sandbox CSS as to not effect parent document CSS
  • Convert URLs to deployment location

Getting Started

Installation

  • Install dependencies: npm install -g [email protected]
  • Install the generator: npm install -g generator-addin
  • Create a directory for your project mkdir <projdir>
  • Change to your project cd <projdir>
  • Run yo addin to scaffold your addin

Using

  • Run npm install <package> to install frontend dependencies
  • Run npm run dev or npm run serve to preview and watch for changes
  • Run npm run build to build your addin for production (Creates a Zip File with the production files for testing in MyG)

Documentation

MyGeotab

For information on MyGeotab and Geotab Drive addins or the MyGeotab API head over to the MyGeotab SDK

Addin Generator

The addin generator runs using Webpack, and makes heavy use of Webpack's ability to build out Dependency Graphs. When a build is run, Webpack takes the Dependency Graph and generates a single optimized JS, CSS, and HTML file.

For more comprehensive information about Webpack, head over to the Webpack Documentation

Dependencies

Webpack treats separate JavaScript files as Modules, which requires code intended to be used in main.js to be exported first. Webpack's Module Support will handle browser compatibility for you.

Using Webpack allows us to leverage npm and it's associated libraries. For example, running npm install jquery and placing import $ from 'jquery'; in main.js will give you access to the jQuery library in your addin.

The entry point for the generator is .dev/index.js for development builds and app/index.js for production. Any files included in .dev/index.js will not be bundled into the end product. The recommended approach is including dependencies in app/scripts/main.js, as this will allow the files to be included in both production and development environments of Webpack.

Using with Older Addins

Many old addins run directly out of main.js, and have several references to external scripts in the main HTML page. To make old addins run with webpack, you will need to move any reference to static assets from the *.html file into main.js:

// in app/scripts/main.js
require('../styles/main.css');
require('../styles/other.css');

// Importing a library downloaded with npm
import Vue from 'vue/dist/vue';

// Importing functions from another file
import { helper1, helper2, helper3 } from './helper.js';

Any files that are being imported need to be converted to es2015 modules.

Using with Translations

To translate the addin on load, state.translate(...) must be called in initialize() and handed the addin's HTML root:

    initialize: function (freshApi, freshState, initializeCallback) {
      // Loading translations if available
      if (freshState.translate) {
        freshState.translate(elAddin || '');
      }
      // MUST call initializeCallback when done any setup
      initializeCallback();
    }

You can also translate sentences by directly passing them in using state.translate(...). This is useful for translating dynamically created content (IE. JavaScript):

    focus: function(api, state){
        document.querySelector('#app').textContent = state.translate('Translate this sentence');
    }

Any text that requires translation needs to be added into a {language}.json file, where {language} is a supported abbreviation.

FAQ

Do I have to make a reference to the build in my html file? No. Webpack handles this automatically

What version of node do I need? We support node 17.x and above. Node v22.12.0 recommended

I keep getting an error telling me regeneratorRuntime is not defined. What does this mean? Webpack compiles with compatibility in mind, and will attempt to transpile async functions for compatibility with older IE browsers. There is currently a bug with Webpack causing transpilations to fail unless the regeneratorRuntime is manually defined. Run npm i -D regenerator-runtime and place const regeneratorRuntime = require('regenerator-runtime'); in the effected files

I keep getting an error message in the console telling me that my file was not found, but I can see it in my directory. Why? This likely means that you have a reference to the file in your main HTML file. Remove this reference and instead import the file in main.js.

License

Apache-2.0 © Geotab Inc

版本与发布记录

generator-addin 共发布 34 个版本,首次发布于 2016/05/17;过去 12 个月发布了 0 个版本。

版本发布日期距今
4.1.2latest2025/06/041.4 年前
4.1.12025/02/281.7 年前
4.1.02025/02/251.7 年前
4.0.52024/12/101.9 年前
4.0.42024/11/271.9 年前
4.0.32024/08/182 年前

关于 generator-addin 的常见问题

generator-addin 是什么?

MyGeotab/Geotab Drive插件生成器

如何安装 generator-addin?

在项目目录运行 npm install generator-addin,或使用 pnpm add / yarn add / bun add。

generator-addin 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/generator-addin 是否存在。

generator-addin 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

generator-addin 可以商用吗?

generator-addin 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

generator-addin 还在维护吗?

最新版本 4.1.2 发布于 2025/06/04(1.4 年前);至今共发布 34 个版本,其中过去 12 个月发布了 0 个;首次发布于 2016/05/17。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。