Skip to content

Add LightningCAD Generator #118

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

Open
wants to merge 49 commits into
base: master
Choose a base branch
from
Open

Conversation

Malachirwin
Copy link
Contributor

Why?

The former system for spinning up a L.CAD app doesn't work in the slightest and was not worth repairing. This pulls some pieces from that but is implemented on rolemodel_rails

What Changed

  • Pull required setup from the old generator
  • Split the generators into install, test, and webpack
  • Add ChromeCAD support out of the box

What the generator adds

  • Global setup
    • .npmrc
    • .eslintrc.js
  • L.CAD Setup
    • Initializers
      • javascript/config/initializers/smartJSON.js
    • React components
      • javascript/components/LocalIconFactory.jsx
      • javascript/components/MaterialIcon.jsx
  • Demo editor
    • controllers/editor_controller.rb
    • views/editor/editor.html.slim
    • javascript/components/App.jsx
  • Jasmine test setup
    • jasmine.json
    • spec/javascript/shared/TestSetup.js
    • spec/javascript/shared/testSpec.js

Later

This doesn't fully support the setup for persisted project setup which is most of the use case we need to setup. This only replaces the old generators that don't work. After we have the replacement we can look at some of those other bells and whistles.

Copy link
Contributor

@kylesmile kylesmile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing we'll want to keep in mind is that this repo is public at the moment, whereas LightningCAD is private. We'll want to be mindful of how much L.CAD-specific code ends up in this repo.

@@ -0,0 +1,123 @@
export default {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably better to just use the ESLint config provided by the generic (non-L.CAD) generator. There might be changes from projects that could be good to bring in to our base config.

say 'Adding jasmine'
run "yarn add --dev jasmine@^5.1.0"

run 'npm pkg set scripts.test_shared="NODE_ENV=test NODE_PATH="./node_modules:./app/javascript:$NODE_PATH" jasmine --config=jasmine.json"'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think NODE_PATH works with ESM, but we can add a custom import hook to replicate the behavior.

say 'Updating esbuild loader in the config'

insert_into_file 'webpack.config.js', " include: /app\\/javascript|@rolemodel\\/lightning-cad/,\n", before: " loader: 'esbuild-loader',"
gsub_file 'webpack.config.js', 'es2021', 'esnext'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably don't want to change the output target.

def update_esbuild_loader
say 'Updating esbuild loader in the config'

insert_into_file 'webpack.config.js', " include: /app\\/javascript|@rolemodel\\/lightning-cad/,\n", before: " loader: 'esbuild-loader',"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is needed, since the base config doesn't seem to exclude node_modules from being processed with esbuild-loader.

@Malachirwin Malachirwin force-pushed the lightning-cad-generator branch from a32aac9 to 62a7dd6 Compare October 25, 2024 21:12
@Malachirwin Malachirwin force-pushed the lightning-cad-generator branch from a3e66e0 to 1900cf7 Compare January 28, 2025 12:45
@OutlawAndy
Copy link
Member

OutlawAndy commented May 12, 2025

@Malachirwin Looks like there is a lot here. Since LightningCAD apps are a thing unto themselves, would it make sense to convert this into a stand alone application template instead? That may be easier to maintain over time & across major Rails versions.

That wouldn't prevent you from making use of generators in the rolemodel_rails gem either. For example:

gem_group :development do
  gem 'rolemodel_rails', github: 'RoleModel/rolemodel_rails'
end

# ...

after_bundle do
  rails_command('generate rolemodel:slim')
  rails_command('generate rolemodel:webpack') if yes?('Use Webpack?')
  rails_command('generate rolemodel:testing:all')
end

cc @kylesmile , @Jeremy-Walton

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

Successfully merging this pull request may close these issues.

3 participants