Maxattax97 / openscad-format

A source code formatter for the OpenSCAD language.
GNU General Public License v3.0
27 stars 11 forks source link

Default installation doesn't seem to work on macOS #11

Open jareware opened 3 years ago

jareware commented 3 years ago
$ cat .openscad-format
---
BasedOnStyle: Mozilla
ColumnLimit: 80
# SortIncludes: true
IndentWidth: 4
AccessModifierOffset: -4
ContinuationIndentWidth: 4
TabWidth: 4
UseTab: Never
$ npm install openscad-format

+ openscad-format@1.0.0
added 191 packages from 177 contributors and audited 191 packages in 6.211s

4 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
$ ./node_modules/.bin/openscad-format --version
1.0.0
$ clang-format --version
clang-format version 11.1.0
$ echo 'cube(1);' > test.scad
$ ./node_modules/.bin/openscad-format < test.scad

The above outputs nothing. 🤔

pixelcmtd commented 3 years ago

just had the same thing happen to me

n8henrie commented 2 years ago

No luck here either. No output, no error, exit status 0, but doesn't seem to do anything.

n8henrie commented 2 years ago

@pixelcmtd @jareware it looks like it relies on clang-format for much of the heavy lifting. My code doesn't use any imports, and I already had llvm installed, so clang-format actually worked fine all on its own.

Here's a little bash script I whipped up:

#!/usr/bin/env bash

set -Eeuf -o pipefail
shopt -s inherit_errexit

main() {
  infile=$1
  tmpfile=$(mktemp)
  /opt/homebrew/opt/llvm/bin/clang-format "${infile}" > "${tmpfile}"
  cp "${tmpfile}" "${infile}"
}
main "$@"
FreeWilly2022 commented 2 years ago

I was able to sort of get it to work on my MacBook using the following steps -

Watched the first part of this video titled "What is NPM and why do we need it?" https://www.youtube.com/watch?v=P3aKRdUyr0s

That video does a good job of explaining what is going on. In summary, node is a JavaScript runtime built on Chrome's V8 JavaScript engine and npm is a program for downloading programs from npm which is a repository for sharing programs. It is annoying that they used the same name for a program and website, but hey its free. Per the video I went to nodejs.org and it showed me a download button for my operating system. This one button downloads both node and npm. Then I found the terminal program in the Applications folder/Utilities folder and checked that both ran by typing: node -v and: npm -v per the video.

After some failed attempts, I figured out that you have to type sudo in front of the npm install command to have admin privileges to actually get it to work somewhat. So, in terminal, type: sudo npm install -g openscad-format

It loaded something like 350 files, and had 3 errors and some files needed "funding". I have no idea how to resolve the errors, and was going to give up. But I tried openscad-format anyway and it seems to work.

I was able to run openscad-format by changing directory (cd) to where I had my file and typing the commands per the directions. It formatted my 800 line program to 1200 lines, but it looks better. In two of the lines that were long it broke up a variable and put commas in the center. I got undefined errors when I ran the preview and was able to easily fix it. I don't think the -j option works because I could not find any templates, so maybe this was related to the errors.

Note that I never created a NPM username or password, and I did not need to go to their website at all to do this.