Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create brjsify command #1611

Open
dchambers opened this issue Dec 1, 2015 · 4 comments
Open

Create brjsify command #1611

dchambers opened this issue Dec 1, 2015 · 4 comments

Comments

@dchambers
Copy link
Contributor

We should create a brjsify command that allows developers to create a simple project containing all of the NPM dependencies they wish to use within BRJS, for example:

  "dependencies": {
    "react": "^0.14.3",
    "redux": "^3.0.4",
  },
  "devDependencies": {
    "brjsify": "^1.0.0"
  }

which then allows them to BRJSify these libraries, and any transitive dependencies, to a given BRJS target directory, for example:

brjsify ~/dev/brjs

This would work as follows:

  1. Scans the dependencies in package.json to determine the list of libraries that will be exported.
  2. Copies over any source files needed by main to the src directory of the exported library.
  3. Creates a src/index.js file that re-exports whatever main points to.
  4. Copies required CSS files next to the modules that require them.
  5. Converts required HTML templates to modules returning a multi-line sting containing the template contents.
  6. Adds absolute requires to the list of exported libraries, so that these are exported too.
  7. Has a special rule that scoped libraries (e.g. @brjs/presenter) are named brjs-presenter, but have a requirePrefix of @brjs/presenter.
  8. Re-exports applicable libraries using BRJS compatible require paths, which involves applying the following production rules
    1. @brjs -> @br
    2. @<scope>/<lib> -> <scope>/<lib> (e.g. @caplin/trading -> caplin/trading)
    3. <require-prefix>/modules/<require-suffix> -> <require-prefix>/<require-suffix> (e.g. br/presenter/modules/PresentationNode -> br/presenter/PresentationNode)

Within BRJS, this will require us to add support for index.js files that allow us to define the root require-path.


Conundrum 1:

Copies over any source files needed by main to the src directory of the exported library.

What about BRJS libraries that are migrated to NPM, that don't naturally have a main entry, but where everything needs to be exported?

Conundrum 2:

What about the fact that we don't currently support require-paths with characters that can't be supported by NamespacedJs code?

@dchambers
Copy link
Contributor Author

@trueadm, do you think this command would meet your needs?

@trueadm
Copy link

trueadm commented Dec 1, 2015

@dchambers Looks good, my only concern is how modules in dependencies can work if, for whatever reason, they try to require a module that is from devDependencies?

@dchambers
Copy link
Contributor Author

Items 1, 2, 3 & 6 have been completed so far. 4 & 5 are less important, and can be done later, and 8 requires some discussion with the team since it's affected by #1621. For the time being, I'm going to work on item 7.

@dchambers
Copy link
Contributor Author

My plan for creating automated tests for brjsify is as follows (I'm not sure when I'll next be able to look at this):

Create an inner brjs-test folder with a package.json file containing:

  1. A number of NPM dependencies that fully exercise brjsify.
  2. A postpublish script that:
    1. Downloads and unzips BRJS into brjs-test/sdk.
    2. Uses brjsify (from the parent project) to export the NPM dependencies into brjs-test/test-app/libs, where brjs-test/test-app contains a BRJS app and tests that depend on the imported NPM libraries.
  3. A test script that runs brjs test on brjs-test/test-app to verify that the BRJS tests all pass.

Regarding the original items for this issue, Items 7 & 8 were completed yesterday, and 4 & 5 can be done later, so this is the main bit of work remaining on this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants