Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
7d92d68
add lightning-cad install generator
Malachirwin Apr 29, 2023
0b96ea8
update big int reference
Malachirwin Apr 29, 2023
8b976b6
update devise again
Malachirwin Apr 29, 2023
0938e73
fix organization migration
Malachirwin Apr 29, 2023
a0355d0
Updates for running rails new with esbuild
Malachirwin Apr 29, 2023
a0ac225
Remove unneeded css
Malachirwin Apr 29, 2023
1555091
Update to use the package approach
Malachirwin Jun 19, 2023
0e3c036
Remove index files from import paths
Malachirwin Jun 19, 2023
7e286fb
add editor layout
Malachirwin Jun 19, 2023
153b88a
fix usage of layout
Malachirwin Jun 19, 2023
329777a
update the smart json initializer
Malachirwin Jun 28, 2023
e5d1b7c
update webpack config
Malachirwin Aug 18, 2023
df7e742
Remove jest
Malachirwin Nov 2, 2023
99b61f8
Update install generator to use npm pkg set script instead of appending
Malachirwin Nov 2, 2023
8302f5d
Cleanup testing setup
Malachirwin Nov 7, 2023
cc9debc
fix typo
Malachirwin Nov 7, 2023
71a72d8
update the file paths
Malachirwin Nov 7, 2023
9cf16da
match webpack config to what is currently used by default
Malachirwin Nov 7, 2023
e841786
remove dependencies
Malachirwin Nov 7, 2023
a57d421
remove unnecessary comments
Malachirwin Nov 7, 2023
cee4137
Update the required dependencies
Malachirwin Nov 29, 2023
5ed1264
split generators into install and jasmine
Malachirwin Nov 29, 2023
65f9599
Move spec initializer into jasmine generator
Malachirwin Nov 29, 2023
c4b29bb
rename the jasmine generator to test
Malachirwin Nov 29, 2023
0bfbc56
Remove the extra module around the generators
Malachirwin Nov 29, 2023
89af371
fix all generator
Malachirwin Nov 29, 2023
e07314c
Update react controller to match react 18
Malachirwin Nov 30, 2023
bafc644
remove optics from install list
Malachirwin Nov 30, 2023
4f237da
abscract webpack into its own generator
Malachirwin Jan 11, 2024
98ce9bd
fix string assignments
Malachirwin Jan 11, 2024
86307dc
fix webpack indentation
Malachirwin Jan 11, 2024
cc159ca
attempt to fix indentation
Malachirwin Jan 11, 2024
aa55a3f
Update indentation
Malachirwin Jan 11, 2024
97f807a
fix var names
Malachirwin Jan 11, 2024
9f9d209
fix extra new line
Malachirwin Jan 11, 2024
13fa6bd
add more dependencies
Malachirwin Apr 19, 2024
e6b4921
Update documentation
Malachirwin Apr 19, 2024
8d30d64
Make sure the tools get initialized
Malachirwin Apr 19, 2024
b1ed8f4
Add chromeCAD support
Malachirwin Apr 19, 2024
74e9bf6
update the readme
Malachirwin Apr 22, 2024
d71fa17
PR Cleanup
Malachirwin Apr 22, 2024
54be1e1
Cleanup unused files
Malachirwin Apr 22, 2024
fb65584
Update the esbuild target
Malachirwin Jun 25, 2024
3e96998
trim webpack config specific to L.CAD
Malachirwin Jun 25, 2024
9b55912
add node script hooks
Malachirwin Jul 23, 2024
c2972f2
Add file filter loader
Malachirwin Oct 25, 2024
a87668d
Add browser testing
Malachirwin Oct 25, 2024
9d6cb01
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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ bin/rails g
* [Tailored Select](./lib/generators/rolemodel/tailored_select)
* [Lograge](./lib/generators/rolemodel/lograge)

### 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