-
Notifications
You must be signed in to change notification settings - Fork 701
Added file writers to complete JSX/TSX deck generation. #1145
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7cbc59c
Added file writers to complete JSX/TSX deck generation.
carloskelly13 d881fed
Added style loader
carloskelly13 c988746
Ensure production flag is set on build.
carloskelly13 caffe56
Added default values for optional flags.
carloskelly13 ca76b97
Use the workspace package version for Spectacle in the CLI
carloskelly13 bbf0393
Lock file changes
carloskelly13 579d9c4
Added carrot to spectacle version specifier
carloskelly13 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
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,25 @@ | ||
| type BabelTemplateOptions = { | ||
| enableTypeScriptSupport: boolean; | ||
| }; | ||
|
|
||
| export const babelTemplate = (options: BabelTemplateOptions) => | ||
| `{ | ||
| "presets": [ | ||
| ${options.enableTypeScriptSupport ? '"@babel/preset-typescript",' : ''} | ||
| ["@babel/preset-env", { "modules": false }], | ||
| ["@babel/preset-react", { "runtime": "automatic" }] | ||
| ], | ||
| "plugins": [ | ||
| "@babel/plugin-proposal-object-rest-spread", | ||
| "@babel/plugin-proposal-class-properties" | ||
| ], | ||
| "env": { | ||
| "cjs": { | ||
| "presets": ["@babel/preset-env", "@babel/preset-react"] | ||
| }, | ||
| "test": { | ||
| "presets": ["@babel/preset-env", "@babel/preset-react"] | ||
| } | ||
| } | ||
| } | ||
| `; |
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,72 @@ | ||
| import path from 'path'; | ||
| import { existsSync } from 'fs'; | ||
| import { mkdir, writeFile, rm } from 'fs/promises'; | ||
| import { htmlTemplate } from './html'; | ||
| import { onePageTemplate } from './one-page'; | ||
| import { webpackTemplate } from './webpack'; | ||
| import { babelTemplate } from './babel'; | ||
| import { packageTemplate } from './package'; | ||
| import { indexTemplate } from './index'; | ||
| import { tsconfigTemplate } from './tsconfig'; | ||
|
|
||
| export type FileOptions = { | ||
| snakeCaseName: string; | ||
| name: string; | ||
| lang: string; | ||
| port: number; | ||
| enableTypeScriptSupport: boolean; | ||
| spectacleVersion: string; | ||
| }; | ||
|
|
||
| export const writeWebpackProjectFiles = async ({ | ||
| snakeCaseName, | ||
| name, | ||
| lang, | ||
| port, | ||
| enableTypeScriptSupport, | ||
| spectacleVersion | ||
| }: FileOptions) => { | ||
| const outPath = path.resolve(process.cwd(), snakeCaseName); | ||
|
|
||
| await rm(outPath, { recursive: true, force: true }); | ||
|
|
||
| if (existsSync(outPath)) { | ||
| throw new Error(`Directory named ${snakeCaseName} already exists.`); | ||
| } | ||
| await mkdir(outPath, { recursive: true }); | ||
| await writeFile(`${snakeCaseName}/index.html`, htmlTemplate({ name, lang })); | ||
| await writeFile( | ||
| `${snakeCaseName}/webpack.config.js`, | ||
| webpackTemplate({ port, usesTypeScript: enableTypeScriptSupport }) | ||
| ); | ||
| await writeFile( | ||
| `${snakeCaseName}/.babelrc`, | ||
| babelTemplate({ enableTypeScriptSupport }) | ||
| ); | ||
| await writeFile( | ||
| `${snakeCaseName}/package.json`, | ||
| packageTemplate({ | ||
| usesTypeScript: enableTypeScriptSupport, | ||
| name: snakeCaseName, | ||
| spectacleVersion | ||
| }) | ||
| ); | ||
| await writeFile( | ||
| `${snakeCaseName}/index.${enableTypeScriptSupport ? 'tsx' : 'jsx'}`, | ||
| indexTemplate({ | ||
| usesTypeScript: enableTypeScriptSupport, | ||
| name | ||
| }) | ||
| ); | ||
|
|
||
| enableTypeScriptSupport && | ||
| (await writeFile(`${snakeCaseName}/tsconfig.json`, tsconfigTemplate())); | ||
| }; | ||
|
|
||
| export const writeOnePageHTMLFile = async ({ | ||
| snakeCaseName, | ||
| name, | ||
| lang | ||
| }: FileOptions) => { | ||
| await writeFile(`${snakeCaseName}.html`, onePageTemplate({ name, lang })); | ||
| }; |
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 |
|---|---|---|
| @@ -1,29 +1,46 @@ | ||
| import path from 'path'; | ||
| import { existsSync } from 'fs'; | ||
| import { mkdir, writeFile } from 'fs/promises'; | ||
| import { htmlTemplate } from './html'; | ||
| import { onePageTemplate } from './one-page'; | ||
|
|
||
| type FileOptions = { | ||
| snakeCaseName: string; | ||
| type IndexTemplateOptions = { | ||
| name: string; | ||
| usesTypeScript: boolean; | ||
| }; | ||
|
|
||
| export const writeBaseWebpackProjectFiles = async ({ | ||
| snakeCaseName, | ||
| name | ||
| }: FileOptions) => { | ||
| const outPath = path.resolve(process.cwd(), snakeCaseName); | ||
| if (existsSync(outPath)) { | ||
| throw new Error(`Directory named ${snakeCaseName} already exists.`); | ||
| } | ||
| await mkdir(outPath, { recursive: true }); | ||
| await writeFile(`${snakeCaseName}/index.html`, htmlTemplate({ name })); | ||
| }; | ||
| export const indexTemplate = (options: IndexTemplateOptions) => | ||
| `import React from 'react'; | ||
| import { createRoot } from 'react-dom/client'; | ||
| import { Slide, Deck, FlexBox, Heading, SpectacleLogo, Box, FullScreen, AnimatedProgress } from 'spectacle'; | ||
| export const writeOnePageHTMLFile = async ({ | ||
| snakeCaseName, | ||
| name | ||
| }: FileOptions) => { | ||
| await writeFile(`${snakeCaseName}.html`, onePageTemplate({ name })); | ||
| }; | ||
| const template = () => ( | ||
| <FlexBox | ||
| justifyContent="space-between" | ||
| position="absolute" | ||
| bottom={0} | ||
| width={1} | ||
| > | ||
| <Box padding="0 1em"> | ||
| <FullScreen /> | ||
| </Box> | ||
| <Box padding="1em"> | ||
| <AnimatedProgress /> | ||
| </Box> | ||
| </FlexBox> | ||
| ); | ||
| const Presentation = () => ( | ||
| <Deck template={template}> | ||
| <Slide> | ||
| <FlexBox height="100%"> | ||
| <Heading>${options.name}</Heading> | ||
| </FlexBox> | ||
| </Slide> | ||
| <Slide> | ||
| <FlexBox height="100%"> | ||
| <Heading fontSize="h2">Made with</Heading> | ||
| <SpectacleLogo size={300} /> | ||
| </FlexBox> | ||
| </Slide> | ||
| </Deck> | ||
| ); | ||
| createRoot(document.getElementById('app')${ | ||
| options.usesTypeScript ? '!' : '' | ||
carloskelly13 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }).render(<Presentation />); | ||
| `; | ||
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,45 @@ | ||
| type PackageTemplateOptions = { | ||
| name: string; | ||
| spectacleVersion: string; | ||
| usesTypeScript: boolean; | ||
| }; | ||
|
|
||
| export const packageTemplate = (options: PackageTemplateOptions) => | ||
| `{ | ||
| "name": "${options.name}", | ||
| "private": true, | ||
| "scripts": { | ||
| "start": "webpack-dev-server --hot --config ./webpack.config.js", | ||
| "clean": "rimraf dist", | ||
| "build": "webpack --config ./webpack.config.js --mode production" | ||
| }, | ||
| "dependencies": { | ||
| "spectacle": "^${options.spectacleVersion}", | ||
| "react": "^18.1.0", | ||
| "react-dom": "^18.1.0" | ||
| }, | ||
| "devDependencies": { | ||
| "@babel/core": "^7.17.2", | ||
| "@babel/plugin-proposal-class-properties": "^7.12.1", | ||
| "@babel/plugin-proposal-object-rest-spread": "^7.12.1", | ||
| "@babel/preset-env": "^7.12.7", | ||
| "@babel/preset-react": "^7.16.7", | ||
| "babel-loader": "^8.0.6", | ||
| "html-webpack-plugin": "^5.3.1", | ||
| "style-loader": "^3.3.1", | ||
| "css-loader": "^5.1.3", | ||
| "file-loader": "^6.2.0", | ||
| "rimraf": "^3.0.0", | ||
| "webpack": "^5.68.0", | ||
| "webpack-cli": "^4.5.0", | ||
| "webpack-dev-server": "^4.7.4"${ | ||
| options.usesTypeScript | ||
| ? ',\n "typescript": "^4.5.2",' + | ||
| '\n "@babel/preset-typescript": "^7.16.0",' + | ||
| '\n "@types/react": "^18.0.12",' + | ||
| '\n "@types/react-dom": "^18.0.5"' | ||
| : '' | ||
| } | ||
| } | ||
| } | ||
| `; |
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,20 @@ | ||
| export const tsconfigTemplate = () => | ||
| `{ | ||
| "compilerOptions": { | ||
| "target": "ES6", | ||
| "lib": [ | ||
| "DOM", | ||
| "ES2019" | ||
| ], | ||
| "jsx": "react-jsx", | ||
| "module": "commonjs", | ||
| "moduleResolution": "node", | ||
| "allowUmdGlobalAccess": true, | ||
| "allowSyntheticDefaultImports": true, | ||
| "esModuleInterop": true, | ||
| "forceConsistentCasingInFileNames": true, | ||
| "strict": true, | ||
| "skipLibCheck": true | ||
| } | ||
| } | ||
| `; |
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,32 @@ | ||
| type WebpackTemplateOptions = { | ||
| port: number; | ||
| usesTypeScript: boolean; | ||
| }; | ||
|
|
||
| export const webpackTemplate = (options: WebpackTemplateOptions) => | ||
| `const path = require('path'); | ||
| const HtmlWebpackPlugin = require('html-webpack-plugin'); | ||
|
|
||
| module.exports = { | ||
| mode: 'development', | ||
| context: __dirname, | ||
| entry: './index.${options.usesTypeScript ? 'tsx' : 'jsx'}', | ||
| output: { | ||
| path: path.join(__dirname, '/dist'), | ||
| filename: 'app.bundle.js' | ||
| }, | ||
| devServer: { | ||
| port: ${options.port} | ||
| }, | ||
| module: { | ||
| rules: [ | ||
| { test: /\\.[tj]sx?$/, use: ['babel-loader'] }, | ||
| { test: /\\.(png|svg|jpg|gif)$/, use: ['file-loader'] }, | ||
| { test: /\\.css$/, use: ['style-loader', 'css-loader'] } | ||
| ] | ||
| }, | ||
| plugins: [ | ||
| new HtmlWebpackPlugin({ template: './index.html' }), | ||
| ] | ||
| }; | ||
| `; |
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
@carlos-kelly This is listed as a devDep, but it looks to me like it's being used as a runtime dependency ... does it somehow get "baked in"?
We could bring in
spectacleas a prod dep just to know the latest version. Hopefully it'd get cached since post-CLI you'd install it again.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.
If it's a runtime it will be included in the entire bin when we build this cli as runnable. We likely need to do a script to extract out the version number from the other package.json rather than some kind of cross-package dependency. @gksander and I were pondering this, but I'm really mixed if typing the version is easier. We do that on one-page today.
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.
Yeah I'm mixed too ... hard-coding it seems easy, but not as easy to maintain.
Uh oh!
There was an error while loading. Please reload this page.
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.
PNPM should work just with a "normal" spectacle dependency. My understanding is the
workspace:is only needed when theres a very customize setup that disables PNPM workspace inference (?)https://pnpm.io/workspaces#workspace-protocol-workspace
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.
I think we likely drop this, feels a bit over-engineered to avoid typing in a version number.
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.
I think we do need to change this before publishing, because currently trying to run the CLI (outside this repo) I think will fail.
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.
Yup! the CLI is not ready to be published yet. We still need to build the interactive prompts. Just flags are working.
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.
If we just want an "up-to-date" version number, tools like changesets, etc. can just take care of keeping this current on version/publish and then we could even have the CLI read it's own
package.json:devDependencies.spectacleto infer the correct version...