facebookarchive/remodel

Having issues with requiring dependencies for custom plugin

KieranLafferty opened this issue · 1 comments

Warning : Javascript noob (apologies in advance)

Trying to create a custom plugin but getting hung up on requiring various js files.

What I have done:

  1. Installed via 'npm install -g remodel-gen'
  2. Made custom plugin 'dictionary_plugin.ts'
  3. Referenced the plugin in .valueObjectConfig as follows:
{
    "customPluginPaths": [
        "plugins/dictionary_plugin.ts"
    ]
}
  1. Require via absolute path in dictionary_plugin.ts
var ValueObject = require('/usr/local/lib/node_modules/remodel-gen/bin/dist/value-object');

No errors occur when I gen (it finds the plugin properly and I refer to it in my .value object). However any time I access an attribute of ValueObject it crashes. Looking at the contents of value-object.js in particular was confusing as it only contains a single line

"use strict";

So theres a couple things odd to me that may stem from my lack knowledge on nodejs.

  1. When installed via npm all dependencies i.e. value-object are .js files, however on this repo they are all .ts files (understand the difference in language, just unsure why the discrepency).
  2. When trying to install directly from github using 'npm install -g https://github.com/facebook/remodel.git' none of the ts files get included

Ultimately, my question is what is the simplest way I can import/require all of the files required for creating the plugin from the npm installation inside of dictionary_plugin.ts. In general I am looking for objc.js, value-object.js, maybe.js, etc. Unable to figure out a straight forward way to do this. Thanks a ton for any help you can provide!

dictionary_plugin.ts path

 ProjectRoot/ValueModels/plugins/dictionary_plugin.ts

.valueObjectConfig path

 ProjectRoot/ValueModels/.valueObjectConfig

So, I think there are a couple of things here.

First of all, we should probably have a simple example of a working plugin.

We don't have one yet, but it's something that's been on our radar.

You are correct that none of the .ts files are exposed -- at some point we'll want to build a better system for exposing that part of remodel (for more context, see https://blogs.msdn.microsoft.com/typescript/2016/06/15/the-future-of-declaration-files/)

In terms of what to do now: the simplest will be to write your plugin in raw js. As long as the plugin is simple, this should work out fine for you.

If you really want a ts step, that is doable, but not beautiful. You'll need to clone to repo, and then link directly to the .ts files in a ugly, hard coded fashion like:

import ValueObject = require('../../remodel/src/value-object');

If you do this, you'll then need to add a build step into your plug-in project that will compile your .ts -> .js (the remodel project itself has a decent template for this). Finally, you can link to the output of that build process (which is a js file) like:

{ "customPluginPaths": [ "plugins/dictionary_plugin.js" ] }