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

Make module for npm-based package #1

Open
sadr0b0t opened this issue Apr 7, 2018 · 12 comments
Open

Make module for npm-based package #1

sadr0b0t opened this issue Apr 7, 2018 · 12 comments
Labels
enhancement New feature or request

Comments

@sadr0b0t
Copy link
Owner

sadr0b0t commented Apr 7, 2018

Convert project to modulle compatible with OpenSCAD-Modules OpenSCAD module manager experimental project (based on NPM) and publish to openscad-modules registry.

https://github.com/RobertFach/Openscad-Modules
http://forum.openscad.org/A-Package-Manager-for-OpenSCAD-td23465.html

example project
https://github.com/RobertFach/openscad-fractals/blob/master/package.json

For reference - another experimental module manager project for OpenSCAD based on Ruby gems
https://github.com/lostapathy/scad_bundler#draft-conventions

@sadr0b0t sadr0b0t added the enhancement New feature or request label Apr 7, 2018
@sadr0b0t
Copy link
Owner Author

sadr0b0t commented Apr 7, 2018

  1. We would download and install deps to scad_modules dir in current project dir (instead of node_modules)
  2. To make OpenSCAD see modules from this dir with use and include directives, we can add scad_modules dir (it would be relative to currently opened scad file) to OPENSCADPATH env variable
export OPENSCADPATH=scad_modules

then run openscad from same terminal or add this line to ~/.profile file

  1. Modules located inside scad_modules dir can also use and include each other with path relative to curr_project/scad_modules

For details on use, include and library dirs see here:
https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/The_OpenSCAD_Language#Use_and_Include
https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Libraries

for example, we have 2 modules installed in project/scad_modules dir
project/scad_modules/pd-gears/pd-gears.scad
project/scad_modules/gearbox/gearbox.scad

example scad design:
project/gearbox-demo.scad

Example design uses gearbox module and gearbox module depends on pd-gears module.

Use gearbox module inside gearbox-demo.scad like this:

use <gearbox/gearbox.scad>

Also inside gearbox module use pd-gears dependance module in the same way:

project/scad_modules/gearbox/gearbox.scad

use <pd-gears/pd-gears.scad>

This would also work

@sadr0b0t
Copy link
Owner Author

sadr0b0t commented Apr 9, 2018

Looks like we can't replace node_modules with scad_modules with default npm without patching it

https://docs.npmjs.com/files/folders
https://stackoverflow.com/questions/21818701/use-a-custom-directory-name-instead-of-node-modules-when-installing-with-npm#21818724

So, will have to install openscad modules to node_modules as well

export OPENSCADPATH=node_modules

@sadr0b0t
Copy link
Owner Author

sadr0b0t commented Apr 14, 2018

add to either ~~~/.profile~~ (will not work with ~/.profile) ~/.bashrc or ~/.bash_aliases:

alias spm='npm --registry=https://registry.openscad-modules.tk'

check on new login

spm search fractal

@sadr0b0t
Copy link
Owner Author

spm adduser
Username: sadr0b0t
Password: 
Email: (this IS public) [email protected]
Logged in as sadr0b0t on https://registry.openscad-modules.tk/.

@sadr0b0t
Copy link
Owner Author

to generate test package before publishing to registry

spm pack

Then check out pd-gears-2.0.0.tgz

Publish to registry:

spm publish

check in new project dir:

spm install pd-gears

@sadr0b0t
Copy link
Owner Author

sadr0b0t commented Apr 14, 2018

export OPENSCADPATH=node_modules

only works when start OpenSCAD from console, unfortunately

when start from console, then check help > info (import works):

OPENSCADPATH: node_modules
OpenSCAD library path:
/home/user/projects/gearbox/node_modules

when open .scad file from file manager (import does NOT work):

OPENSCADPATH: node_modules
OpenSCAD library path:
/home/user/node_modules

so, it does not use OPENSCADPATH variablle dynamically, it just takes OPENSCADPATH at start and puts it together with current dir (in case, if the path is relative, most likely). When open .scad file from file manager current dir by some reason is set to $HOME

@sadr0b0t
Copy link
Owner Author

sadr0b0t commented Apr 15, 2018

submitted feature request here
openscad/openscad#2377

@sadr0b0t
Copy link
Owner Author

And another issue here

https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Libraries

In the case of a library file itself having use <...> or include <...> the directory of the library .scad file is the 'calling' file, i.e. when looking for libraries within a library, it does not check the directory of the top level .scad file.

So, even if we include gearbox.scad like "gearbox/gearbox.scad" from "node_modules" relatively to current project, and then gearbox.scad would also include pd-gears.scad with relative path like "pd-gears/pd-gears.scad" or even like "node_modues/pd-gears/pd-gears.scad", it won't see it, because it will not go down to the root module and would look pd-gears some where near node_modules/gearbox/ or in global libraries.

@sadr0b0t
Copy link
Owner Author

sadr0b0t commented Apr 20, 2018

pull request to handle all above:
openscad/openscad#2384

@RobertFach
Copy link

RobertFach commented Apr 24, 2018

Hi,
I was running in the same issues, especially because of NPMs flat dependency feature. However,
as far as I have looked up the issue, setting OPENSCADPATH=node_modules on startup helps to fix this. I haven't yet updated the documentation, because was running out of time.

For example (extended by MCAD):

We have the following dependencies (in this example MCAD is used with the same version for all modules, if not, NPM would installs it nested and hence the problem itself would not be present) and at least the following files/libraries are present:

node_modules/gearbox/gearbox.scad -> depends node_modules/gears/pd_gears.scad, node_modules/MCAD/nuts_and_bolts.scad
node_modules/gears/pd_gears.scad -> depends node_modules/MCAD/gears.scad
node_modules/MCAD/gears.scad node_modules/MCAD/nuts_and_bolts.scad

NPM will recognize that MCAD is used by multiple modules of the whole project and installs it flat (on top level of node_modules) folder.
So, setting OPENSCAD_PATH=node_modules (root node_modules folder of project) and everything should be fine (so far :) ).

@sadr0b0t
Copy link
Owner Author

So, setting OPENSCAD_PATH=node_modules (root node_modules folder of project) and everything should be fine (so far :) ).

Unfortunately, this only works when start OpenSCAD from console from project dir. Will not work when double-click on .scad file in file manager.

That's because currently OpenSCAD always simply creates absolute paths from relative paths in OPENSCADPATH

add_librarydir(fs::absolute(fs::path(boost::copy_range<std::string>(*it))).string());

See this comment:
#1 (comment)

I have opened issue
openscad/openscad#2377
and created patch with pull requst
openscad/openscad#2384

with more details on this, please, take a look

@sadr0b0t
Copy link
Owner Author

offtopic side-note for openscad build instructions - to change install dir before build do:

qmake openscad.pro PREFIX='/home/user/apps/openscad'
make install

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

No branches or pull requests

2 participants