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

Add LightningCAD Generator #118

Open
wants to merge 49 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
3b5ad23
add lightning-cad install generator
Malachirwin Apr 29, 2023
16236f6
update big int reference
Malachirwin Apr 29, 2023
fcd8926
update devise again
Malachirwin Apr 29, 2023
31ffbed
fix organization migration
Malachirwin Apr 29, 2023
dc3d17f
Updates for running rails new with esbuild
Malachirwin Apr 29, 2023
d97554c
Remove unneeded css
Malachirwin Apr 29, 2023
60cd6ad
Update to use the package approach
Malachirwin Jun 19, 2023
d6389b5
Remove index files from import paths
Malachirwin Jun 19, 2023
62db757
add editor layout
Malachirwin Jun 19, 2023
db92d9b
fix usage of layout
Malachirwin Jun 19, 2023
14d321c
update the smart json initializer
Malachirwin Jun 28, 2023
fef579f
update webpack config
Malachirwin Aug 18, 2023
1c86527
Remove jest
Malachirwin Nov 2, 2023
76bf066
Update install generator to use npm pkg set script instead of appending
Malachirwin Nov 2, 2023
b7fb2ad
Cleanup testing setup
Malachirwin Nov 7, 2023
bc11360
fix typo
Malachirwin Nov 7, 2023
dccf1cc
update the file paths
Malachirwin Nov 7, 2023
1413f0d
match webpack config to what is currently used by default
Malachirwin Nov 7, 2023
293f3de
remove dependencies
Malachirwin Nov 7, 2023
0200b9f
remove unnecessary comments
Malachirwin Nov 7, 2023
81afcf6
Update the required dependencies
Malachirwin Nov 29, 2023
37ae4e7
split generators into install and jasmine
Malachirwin Nov 29, 2023
bdf1b3e
Move spec initializer into jasmine generator
Malachirwin Nov 29, 2023
4e3c88a
rename the jasmine generator to test
Malachirwin Nov 29, 2023
c606880
Remove the extra module around the generators
Malachirwin Nov 29, 2023
cc5e750
fix all generator
Malachirwin Nov 29, 2023
485c65c
Update react controller to match react 18
Malachirwin Nov 30, 2023
6117d62
remove optics from install list
Malachirwin Nov 30, 2023
cf176fa
abscract webpack into its own generator
Malachirwin Jan 11, 2024
640b9d1
fix string assignments
Malachirwin Jan 11, 2024
28da903
fix webpack indentation
Malachirwin Jan 11, 2024
9164c2f
attempt to fix indentation
Malachirwin Jan 11, 2024
267d5d2
Update indentation
Malachirwin Jan 11, 2024
bf96be3
fix var names
Malachirwin Jan 11, 2024
1a4c772
fix extra new line
Malachirwin Jan 11, 2024
18de83b
add more dependencies
Malachirwin Apr 19, 2024
78fb889
Update documentation
Malachirwin Apr 19, 2024
f05c203
Make sure the tools get initialized
Malachirwin Apr 19, 2024
40c2f3b
Add chromeCAD support
Malachirwin Apr 19, 2024
3fabe03
update the readme
Malachirwin Apr 22, 2024
44e6872
PR Cleanup
Malachirwin Apr 22, 2024
ffcb40e
Cleanup unused files
Malachirwin Apr 22, 2024
5aa74a4
Update the node version
Malachirwin Jun 25, 2024
17fad57
Update the esbuild target
Malachirwin Jun 25, 2024
158f078
trim webpack config specific to L.CAD
Malachirwin Jun 25, 2024
7ea71cc
add node script hooks
Malachirwin Jul 23, 2024
9dc8336
Add file filter loader
Malachirwin Oct 25, 2024
42f4cc4
Add browser testing
Malachirwin Oct 25, 2024
1900cf7
fix file name
Malachirwin Oct 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .node-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
18.15.0
20.15.0
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ bin/rails g
* [Editors](./lib/generators/rolemodel/editors)
* [Tailored Select](./lib/generators/rolemodel/tailored_select)

### LightningCAD

For LightningCAD apps there are [generators](./lib/generators/lightning_cad) to add the required setup

## Development

Install the versions of Node and Ruby specified in `.node-version` and `.ruby-version` on your machine. https://asdf-vm.com/ is a great tool for managing language versions. Then run `npm install -g yarn`.
Expand Down
31 changes: 31 additions & 0 deletions lib/generators/lightning_cad/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# LightningCAD Generator

Run all the generators:

```
rails g lightning_cad:all
```

Or run them individually
```
rails g lightning_cad:install
rails g lightning_cad:webpack
rails g lightning_cad:test
```

## Depends On

- `rolemodel:linters:eslint`
- `rolemodel:optics:base`
- `rolemodel:webpack`
- `rolemodel:react`

## What you get

Pulls in [LightningCAD](https://github.com/RoleModel/lightning-cad) and sets up a demo editor

This will add a route for `/editor` with a blank canvas.

The main entrypoint into the JavaScript code is `/app/javascript/components/App.jsx`. In this file a project is created. You can manually add components like lines or shapes to that project.

After running the generators additional setup is required see [how to setup a LightningCAD app](https://github.com/RoleModel/lightning-cad?tab=readme-ov-file#app-setup) for more details.
15 changes: 15 additions & 0 deletions lib/generators/lightning_cad/USAGE
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Description:
This generator requires JavaScript setup including webpack, react, and eslint

Install:
Installs required dependencies
Generates a demo editor

Webpack:
Modifies the webpack config to work better for LightningCAD apps

Test:
Installs jasmine and adds the test setup required for LightningCAD models

Example:
bin/rails generate lightning-cad:all
13 changes: 13 additions & 0 deletions lib/generators/lightning_cad/all_generator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require 'rails'

module LightningCad
class AllGenerator < Rails::Generators::Base
source_root File.expand_path('./templates', __dir__)

def run_all_the_generators
generate 'lightning_cad:install'
generate 'lightning_cad:webpack'
generate 'lightning_cad:test'
end
end
end
81 changes: 81 additions & 0 deletions lib/generators/lightning_cad/install_generator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
require 'rails'

module LightningCad
class InstallGenerator < Rails::Generators::Base
source_root File.expand_path('./templates', __dir__)

def install_yarn_dependencies
say 'Adding lightning-cad dependency'
copy_file '.npmrc', '.npmrc'

dependencies = %w[
@rolemodel/lightning-cad
@rolemodel/lightning-cad-ui
mobx-react@^6.1.5
mobx-utils@^5.5.2
mobx@^5.15.2
glob@^10.2.2
import-glob@1.5.0
react-router-dom@^5.0.1
react-popper@^1.3.7
classnames@^2.2.5
]


run "yarn add #{dependencies.join(" ")}"
end

def create_basic_app
say "Creating React App Component"
insert_into_file 'app/javascript/controllers/react_controller.js', "import App from '../components/App.jsx'\n", before: "import HelloReact from '../components/HelloReact.jsx'\n"
insert_into_file 'app/javascript/controllers/react_controller.js', " App,\n", after: "const registeredComponents = {\n"
copy_file 'app/javascript/components/MaterialIcon.jsx', 'app/javascript/components/MaterialIcon.jsx'
copy_file 'app/javascript/components/LocalIconFactory.jsx', 'app/javascript/components/LocalIconFactory.jsx'
copy_file 'app/javascript/components/App.jsx', 'app/javascript/components/App.jsx'
end

def add_stylesheets
stylesheets = <<~CSS
@import '@rolemodel/lightning-cad-ui/scss/lightning-cad.scss';
CSS

prepend_to_file 'app/assets/stylesheets/application.scss', stylesheets
end

def global_configuration
copy_file '.eslintrc.js', '.eslintrc.js'
end

def create_controller
say "Creating Rails controller and view"
template 'app/views/layouts/editor.html.slim'
copy_file 'app/controllers/editor_controller.rb', 'app/controllers/editor_controller.rb'
copy_file 'app/views/editor/editor.html.slim', 'app/views/editor/editor.html.slim'
route "get '/editor/*all', to: 'editor#editor'"
route "get :editor, to: 'editor#editor'"
end

def add_javascript_initializers
say "Adding JavaScript initializers"
initializer_setup = <<~JS
import './config/initializers/**/*.js'
JS
append_to_file 'app/javascript/application.js', initializer_setup
copy_file 'app/javascript/config/initializers/smartJSON.js', 'app/javascript/config/initializers/smartJSON.js'
copy_file 'app/javascript/helpers/hooks.js', 'app/javascript/helpers/hooks.js'
copy_file 'app/javascript/helpers/register_hooks.js', 'app/javascript/helpers/register_hooks.js'
# To prevent smartJSON from throwing an error
run 'mkdir app/javascript/shared'
run 'mkdir app/javascript/shared/domain-models'
run 'touch app/javascript/shared/domain-models/.keep'
end

def setup_chrome_cad
chrome_cad_setup = <<~JS
import { ChromeCADEventEmitter } from '@rolemodel/lightning-cad/drawing-editor'
window.__LCAD_CHROME_CAD_EVENT_EMITTER = new ChromeCADEventEmitter()
JS
append_to_file 'app/javascript/application.js', chrome_cad_setup
end
end
end
123 changes: 123 additions & 0 deletions lib/generators/lightning_cad/templates/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -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.

root: true,
env: {
browser: true,
node: true,
es6: true,
},
plugins: ["react"],
extends: ["eslint:recommended", "plugin:react/recommended"],
parser: "babel-eslint",
parserOptions: {
ecmaFeatures: {
jsx: true,
},
ecmaVersion: 2017,
},
rules: {
"accessor-pairs": "warn",
"arrow-body-style": "warn",
"arrow-parens": ["warn", "as-needed"],
"arrow-spacing": "warn",
"comma-dangle": ["warn", "only-multiline"],
"comma-style": ["warn", "last"],
"computed-property-spacing": ["warn", "never"],
"consistent-this": "warn",
curly: ["warn", "multi-line"],
"default-case": "warn",
"dot-location": ["warn", "property"],
eqeqeq: "warn",
"generator-star-spacing": "warn",
"id-blacklist": "warn",
"id-match": "warn",
"jsx-quotes": "warn",
"linebreak-style": ["warn", "unix"],
"max-nested-callbacks": "warn",
"no-array-constructor": "warn",
"no-caller": "warn",
"no-catch-shadow": "warn",
"no-console": "off",
"no-continue": "warn",
"no-div-regex": "warn",
"no-duplicate-imports": "warn",
"no-extra-label": "warn",
"no-extra-semi": "warn",
"no-floating-decimal": "warn",
"no-implicit-coercion": [
"warn",
{
boolean: false,
number: false,
string: false,
},
],
"no-implied-eval": "warn",
"no-inner-declarations": ["warn", "functions"],
"no-invalid-this": "warn",
"no-iterator": "warn",
"no-label-var": "warn",
"no-labels": "warn",
"no-lone-blocks": "warn",
"no-mixed-requires": "warn",
"no-mixed-spaces-and-tabs": "warn",
"no-multi-str": "warn",
"no-new": "warn",
"no-new-func": "warn",
"no-new-object": "warn",
"no-new-require": "warn",
"no-new-wrappers": "warn",
"no-octal-escape": "warn",
"no-process-exit": "warn",
"no-proto": "warn",
"no-redeclare": "warn",
"no-restricted-globals": "warn",
"no-restricted-imports": "warn",
"no-restricted-modules": "warn",
"no-restricted-syntax": "warn",
"no-script-url": "warn",
"no-self-compare": "warn",
"no-shadow-restricted-names": "warn",
"no-spaced-func": "warn",
"no-undef": "warn",
"no-undef-init": "warn",
"no-unexpected-multiline": "warn",
"no-unmodified-loop-condition": "warn",
"no-unneeded-ternary": [
"warn",
{
defaultAssignment: true,
},
],
"no-unreachable": "warn",
"no-unused-vars": [
"warn",
{
argsIgnorePattern: "^_", // Allow unused arguments starting with an underscore
varsIgnorePattern: "^_", // Allow unused variables starting with an underscore
},
],
"no-useless-call": "warn",
"no-useless-concat": "warn",
"no-useless-constructor": "warn",
"no-useless-escape": "warn",
"no-var": "warn",
"no-void": "warn",
"no-whitespace-before-property": "warn",
"no-with": "warn",
"prefer-arrow-callback": "warn",
"prefer-const": "warn",
"prefer-template": "warn",
"require-yield": "warn",
semi: ["warn", "never"],
"sort-imports": "warn",
"template-curly-spacing": "warn",
"wrap-regex": "warn",
"yield-star-spacing": "warn",
yoda: ["warn", "never"],
},
settings: {
react: {
version: "16.6.0",
},
},
};
2 changes: 2 additions & 0 deletions lib/generators/lightning_cad/templates/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@rolemodel:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=${GITHUB_PACKAGES_TOKEN}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class EditorController < ApplicationController
def editor
render layout: 'editor'
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import React from 'react'
import { createBrowserHistory } from 'history'
import PropTypes from 'prop-types'

import {
Icon,
IconFactoryContext,
MultiPerspectiveProjectEditorView,
} from '@rolemodel/lightning-cad-ui'
import { Router } from 'react-router-dom'
import LocalIconFactory from './LocalIconFactory.jsx'

import {
DrawingEditor,
VersionedProject,
Project
} from '@rolemodel/lightning-cad/drawing-editor'

export default class App extends React.Component {
static propTypes = {
basePath: PropTypes.string,
backPath: PropTypes.string
}

static defaultProps = {
basePath: '/',
backPath: '/'
}

constructor(props) {
super(props)
this._modalRoot = document.getElementById('modal_root') || document.createElement('div')

this._project = new VersionedProject(new Project())

const top = new DrawingEditor(this._project)
top.toolPalette()
this._drawingEditors = { top }
}

modalRoot() { return this._modalRoot }

history() {
if (!this._history) {
this._history = createBrowserHistory({ basename: this.props.basePath })
}
return this._history
}

iconFactory() {
return this._iconFactory ??= new LocalIconFactory()
}

render() {
return (
<IconFactoryContext.Provider value={this.iconFactory()}>
<Router history={this.history()}>
<MultiPerspectiveProjectEditorView
drawingEditors={this._drawingEditors}
versionedProject={this._project}
perspectiveOptions={{
top: {
actionBarOptions: {
includePerspectiveIcons: false,
renderBackLink: (_drawingEditor) => (
<a
href={this.props.backPath}
title='Back'
className='action-bar__back margin-right-md'
>
<Icon
name='KeyboardArrowLeft'
className='action-bar__icon'
/>
Back
</a>
),
},
},
}}
/>
</Router>
</IconFactoryContext.Provider>
)
}
}
Loading
Loading