-
Notifications
You must be signed in to change notification settings - Fork 0
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
Malachirwin
wants to merge
48
commits into
master
Choose a base branch
from
lightning-cad-generator
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+777
−1
Open
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 0b96ea8
update big int reference
Malachirwin 8b976b6
update devise again
Malachirwin 0938e73
fix organization migration
Malachirwin a0355d0
Updates for running rails new with esbuild
Malachirwin a0ac225
Remove unneeded css
Malachirwin 1555091
Update to use the package approach
Malachirwin 0e3c036
Remove index files from import paths
Malachirwin 7e286fb
add editor layout
Malachirwin 153b88a
fix usage of layout
Malachirwin 329777a
update the smart json initializer
Malachirwin e5d1b7c
update webpack config
Malachirwin df7e742
Remove jest
Malachirwin 99b61f8
Update install generator to use npm pkg set script instead of appending
Malachirwin 8302f5d
Cleanup testing setup
Malachirwin cc9debc
fix typo
Malachirwin 71a72d8
update the file paths
Malachirwin 9cf16da
match webpack config to what is currently used by default
Malachirwin e841786
remove dependencies
Malachirwin a57d421
remove unnecessary comments
Malachirwin cee4137
Update the required dependencies
Malachirwin 5ed1264
split generators into install and jasmine
Malachirwin 65f9599
Move spec initializer into jasmine generator
Malachirwin c4b29bb
rename the jasmine generator to test
Malachirwin 0bfbc56
Remove the extra module around the generators
Malachirwin 89af371
fix all generator
Malachirwin e07314c
Update react controller to match react 18
Malachirwin bafc644
remove optics from install list
Malachirwin 4f237da
abscract webpack into its own generator
Malachirwin 98ce9bd
fix string assignments
Malachirwin 86307dc
fix webpack indentation
Malachirwin cc159ca
attempt to fix indentation
Malachirwin aa55a3f
Update indentation
Malachirwin 97f807a
fix var names
Malachirwin 9f9d209
fix extra new line
Malachirwin 13fa6bd
add more dependencies
Malachirwin e6b4921
Update documentation
Malachirwin 8d30d64
Make sure the tools get initialized
Malachirwin b1ed8f4
Add chromeCAD support
Malachirwin 74e9bf6
update the readme
Malachirwin d71fa17
PR Cleanup
Malachirwin 54be1e1
Cleanup unused files
Malachirwin fb65584
Update the esbuild target
Malachirwin 3e96998
trim webpack config specific to L.CAD
Malachirwin 9b55912
add node script hooks
Malachirwin c2972f2
Add file filter loader
Malachirwin a87668d
Add browser testing
Malachirwin 9d6cb01
fix file name
Malachirwin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| export default { | ||
| 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", | ||
| }, | ||
| }, | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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} |
5 changes: 5 additions & 0 deletions
5
lib/generators/lightning_cad/templates/app/controllers/editor_controller.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| class EditorController < ApplicationController | ||
| def editor | ||
| render layout: 'editor' | ||
| end | ||
| end |
86 changes: 86 additions & 0 deletions
86
lib/generators/lightning_cad/templates/app/javascript/components/App.jsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> | ||
| ) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.