diff --git a/scripts/build-dist.js b/scripts/build-dist.js index d88712e3..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); @@ -8,19 +8,40 @@ 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) { + console.log('running sourcemap generation...'); + const cmdParts = process.env.SOURCEMAP_COMMAND.split(' '); + const tempSrcDir = path.resolve('src'); + const sourcemapResult = childProcess.spawnSync(cmdParts[0], [cmdParts.slice(1).join(' ') + ` ${tempSrcDir} ${tempSrcDir} node_modules/@stackbit/components`], { + shell: true + }); + 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'], { + shell: true + }); + childProcess.spawnSync('git', ['checkout', '--', 'src']); + fse.rmdirSync('temp-dist', { recursive: true }); } console.log('copy package.json and remove peerDependencies marked as devDependencies...'); 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) {