From 065f3652b96ff0fcd182b06e46d5485d94e64db6 Mon Sep 17 00:00:00 2001 From: davbree Date: Tue, 24 Aug 2021 11:05:45 +0300 Subject: [PATCH 1/3] Run sourcemap generation --- scripts/build-dist.js | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/scripts/build-dist.js b/scripts/build-dist.js index 8917ebc3..859618db 100755 --- a/scripts/build-dist.js +++ b/scripts/build-dist.js @@ -9,19 +9,39 @@ const generateDistComponentMap = require('./generate-components-map'); console.log('Building components library'); +function runBabel(inputDir='src', outputDir='dist') { + console.log('running babel...'); + const babelResult = childProcess.spawnSync('./node_modules/.bin/babel', ['--config-file', './babel.dist.config.json', '--out-dir', outputDir, inputDir]); + if (babelResult.status === 0) { + console.log(String(babelResult.stdout)); + } else { + console.log(String(babelResult.stderr)); + process.exit(1); + } +} + if (args.includes('--clean')) { console.log('removing dist folder...'); fse.rmdirSync('dist', { recursive: true }); } -console.log('runing babel...'); -const babelResult = childProcess.spawnSync('babel', '--config-file ./babel.dist.config.json --out-dir dist src'.split(' ')); +runBabel(); -if (babelResult.status === 0) { - console.log(String(babelResult.stdout)); -} else { - console.log(String(babelResult.stderr)); - process.exit(1); +if (process.env.SOURCEMAP_COMMAND) { + const cmdParts = process.env.SOURCEMAP_COMMAND.split(' '); + const tempSrcDir = path.resolve('src'); + const annotationResult = childProcess.spawnSync(cmdParts[0], [cmdParts.slice(1).join(' ') + ` ${tempSrcDir} ${tempSrcDir} node_modules/@stackbit/components`], { + shell: true + }); + console.log(String(annotationResult.stdout)); + console.log(String(annotationResult.stderr)); + runBabel('src', 'temp-dist'); + // apply using: patch -p1 -i sourcemap.patch + childProcess.spawnSync('diff', ['-rc', 'dist temp-dist > dist/sourcemap.patch'], { + shell: true + }); + childProcess.spawnSync('git', ['checkout', '--', 'src']); + fse.rmdirSync('temp-dist', { recursive: true }); } console.log('copy package.json and remove peerDependencies marked as devDependencies...'); From e8083451676594da72aea369549f9536525e6bf4 Mon Sep 17 00:00:00 2001 From: davbree Date: Tue, 24 Aug 2021 11:21:23 +0300 Subject: [PATCH 2/3] cleanup --- scripts/build-dist.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/scripts/build-dist.js b/scripts/build-dist.js index b4a84fa9..275b3953 100755 --- a/scripts/build-dist.js +++ b/scripts/build-dist.js @@ -1,5 +1,5 @@ #!/usr/bin/env node - +const path = require('path'); const childProcess = require('child_process'); const fse = require('fs-extra'); const args = process.argv.slice(2); @@ -27,13 +27,14 @@ if (args.includes('--clean')) { runBabel(); if (process.env.SOURCEMAP_COMMAND) { + console.log('running sourcemap generation...'); const cmdParts = process.env.SOURCEMAP_COMMAND.split(' '); const tempSrcDir = path.resolve('src'); - const annotationResult = childProcess.spawnSync(cmdParts[0], [cmdParts.slice(1).join(' ') + ` ${tempSrcDir} ${tempSrcDir} node_modules/@stackbit/components`], { + const sourcemapResult = childProcess.spawnSync(cmdParts[0], [cmdParts.slice(1).join(' ') + ` ${tempSrcDir} ${tempSrcDir} node_modules/@stackbit/components`], { shell: true }); - console.log(String(annotationResult.stdout)); - console.log(String(annotationResult.stderr)); + console.log(String(sourcemapResult.stdout)); + console.log(String(sourcemapResult.stderr)); runBabel('src', 'temp-dist'); // apply using: patch -p1 -i sourcemap.patch childProcess.spawnSync('diff', ['-rc', 'dist temp-dist > dist/sourcemap.patch'], { From 6636783e34882b32d0ad536650dbeec289ebbf9d Mon Sep 17 00:00:00 2001 From: davbree Date: Wed, 25 Aug 2021 10:16:26 +0300 Subject: [PATCH 3/3] import react --- src/components/Action/index.js | 1 + src/components/Badge/index.js | 2 ++ src/components/ContentSection/index.js | 2 +- src/components/CtaSection/index.js | 2 +- src/components/FeaturedPostsSection/index.js | 1 + src/components/Footer/index.js | 1 + src/components/HeroSection/index.js | 3 ++- src/components/ImageBlock/index.js | 2 ++ src/components/NavBar/index.js | 1 + src/components/VideoBlock/index.js | 2 ++ 10 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/components/Action/index.js b/src/components/Action/index.js index f15490d0..54b825a9 100644 --- a/src/components/Action/index.js +++ b/src/components/Action/index.js @@ -1,3 +1,4 @@ +import React from 'react'; import classNames from 'classnames'; import Link from '../../utils/link'; import ArrowRight from '../../svgs/arrow-right'; diff --git a/src/components/Badge/index.js b/src/components/Badge/index.js index b8a805f0..24abd64b 100644 --- a/src/components/Badge/index.js +++ b/src/components/Badge/index.js @@ -1,3 +1,5 @@ +import React from 'react'; + export default function Badge({ label, ...other }) { if (!label) { return null; diff --git a/src/components/ContentSection/index.js b/src/components/ContentSection/index.js index 459fefa8..66e4a4f5 100644 --- a/src/components/ContentSection/index.js +++ b/src/components/ContentSection/index.js @@ -1,7 +1,7 @@ +import React from 'react'; import Markdown from 'markdown-to-jsx'; import classNames from 'classnames'; import Badge from '../Badge'; -import React from 'react'; import InlineMarkdown from '../InlineMarkdown'; export default function ContentSection(props) { diff --git a/src/components/CtaSection/index.js b/src/components/CtaSection/index.js index 649bcd2c..11513fa4 100644 --- a/src/components/CtaSection/index.js +++ b/src/components/CtaSection/index.js @@ -1,8 +1,8 @@ +import React from 'react'; import Markdown from 'markdown-to-jsx'; import classNames from 'classnames'; import Badge from '../Badge'; import Action from '../Action'; -import React from 'react'; import InlineMarkdown from '../InlineMarkdown'; export default function CtaSection(props) { diff --git a/src/components/FeaturedPostsSection/index.js b/src/components/FeaturedPostsSection/index.js index 79d3514f..b85517f4 100644 --- a/src/components/FeaturedPostsSection/index.js +++ b/src/components/FeaturedPostsSection/index.js @@ -1,3 +1,4 @@ +import React from 'react'; import classNames from 'classnames'; import Link from 'next/link'; import Badge from '../Badge'; diff --git a/src/components/Footer/index.js b/src/components/Footer/index.js index e2510da1..a45d8413 100644 --- a/src/components/Footer/index.js +++ b/src/components/Footer/index.js @@ -1,3 +1,4 @@ +import React from 'react'; import Markdown from 'markdown-to-jsx'; import classNames from 'classnames'; import Action from '../Action'; diff --git a/src/components/HeroSection/index.js b/src/components/HeroSection/index.js index afa2d0e9..2b9a96c6 100644 --- a/src/components/HeroSection/index.js +++ b/src/components/HeroSection/index.js @@ -1,6 +1,7 @@ -import { getDynamicComponent } from '../../components-registry'; +import React from 'react'; import Markdown from 'markdown-to-jsx'; import classNames from 'classnames'; +import { getDynamicComponent } from '../../components-registry'; import Badge from '../Badge'; import Action from '../Action'; import InlineMarkdown from '../InlineMarkdown'; diff --git a/src/components/ImageBlock/index.js b/src/components/ImageBlock/index.js index 96c4039a..5082a084 100644 --- a/src/components/ImageBlock/index.js +++ b/src/components/ImageBlock/index.js @@ -1,3 +1,5 @@ +import React from 'react'; + export default function ImageBlock(props) { const imageUrl = props.imageUrl; if (!imageUrl) { diff --git a/src/components/NavBar/index.js b/src/components/NavBar/index.js index 9b94b0b3..3a769cd4 100644 --- a/src/components/NavBar/index.js +++ b/src/components/NavBar/index.js @@ -1,3 +1,4 @@ +import React from 'react'; import { useState } from 'react'; import classNames from 'classnames'; import Action from '../Action'; diff --git a/src/components/VideoBlock/index.js b/src/components/VideoBlock/index.js index f8532a18..ef57d6c9 100644 --- a/src/components/VideoBlock/index.js +++ b/src/components/VideoBlock/index.js @@ -1,3 +1,5 @@ +import React from 'react'; + export default function VideoBlock(props) { const videoUrl = props.videoUrl; if (!videoUrl) {