Skip to content
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

Add a script to zip the built examples #30130

Merged
merged 4 commits into from
Apr 29, 2020
Merged

Conversation

XhmikosR
Copy link
Member

@XhmikosR XhmikosR commented Feb 3, 2020

Fixes #30076

Preview: https://deploy-preview-30130--twbs-bootstrap.netlify.com/docs/4.3/examples/

TODO:

  • remove integrity and crossorigin attributes
  • tighten the regex so that it only changes links and script tags, not a tags
  • maybe copy favicons or remove them from the HTML

@XhmikosR
Copy link
Member Author

XhmikosR commented Feb 3, 2020 via email

@XhmikosR
Copy link
Member Author

XhmikosR commented Feb 4, 2020

How about we mention the examples zip package in getting started?

@XhmikosR XhmikosR force-pushed the master-xmr-zip-examples branch from 12c7ac7 to ed67acf Compare February 4, 2020 13:14
@XhmikosR
Copy link
Member Author

XhmikosR commented Feb 4, 2020

Now that I think about it, I'm not happy with this patch. The asset paths still are /docs/.../css etc, so I don't think this is a good solution to the problem.

I'm not sure how to solve this in an easy way.

@XhmikosR
Copy link
Member Author

XhmikosR commented Feb 4, 2020

And even if we set up https://gohugo.io/content-management/urls/#relative-urls, it'll still need further processing to keep the directory structure simple.

Otherwise try this patch:

 config.yml   | 1 +
 package.json | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/config.yml b/config.yml
index 63648ec1a..3ccc68b54 100644
--- a/config.yml
+++ b/config.yml
@@ -10,6 +10,7 @@ markup:
   highlight:
     noClasses:          false
 
+relativeURLs: true
 buildDrafts:            true
 buildFuture:            true
 
diff --git a/package.json b/package.json
index bc78e8882..4e7b1aeb6 100644
--- a/package.json
+++ b/package.json
@@ -61,7 +61,7 @@
     "release-sri": "node build/generate-sri.js",
     "release-version": "node build/change-version.js",
     "release-zip": "cross-env-shell \"rm -rf bootstrap-$npm_package_version-dist && cp -r dist/ bootstrap-$npm_package_version-dist && zip -r9 bootstrap-$npm_package_version-dist.zip bootstrap-$npm_package_version-dist && rm -rf bootstrap-$npm_package_version-dist\"",
-    "release-zip-examples": "cross-env-shell \"rm -rf bootstrap-$npm_package_version-examples && cp -r _gh_pages/docs/$npm_package_version_short/examples/ bootstrap-$npm_package_version-examples && rm bootstrap-$npm_package_version-examples/index.html && zip -r9 bootstrap-$npm_package_version-examples.zip bootstrap-$npm_package_version-examples && rm -rf bootstrap-$npm_package_version-examples\"",
+    "release-zip-examples": "cross-env-shell \"rm -rf bootstrap-$npm_package_version-examples && zip -r9 bootstrap-$npm_package_version-examples.zip _gh_pages/docs/$npm_package_version_short/examples/ _gh_pages/docs/$npm_package_version_short/dist/",
     "dist": "npm-run-all --parallel css js",
     "test": "npm-run-all lint dist js-test docs-build docs-lint",
     "netlify": "npm-run-all dist release-sri docs-production",

@XhmikosR XhmikosR force-pushed the master-xmr-zip-examples branch from 0a47957 to 7e22269 Compare February 4, 2020 16:09
@XhmikosR
Copy link
Member Author

XhmikosR commented Feb 4, 2020

So basically this works fine:

rm -rf bootstrap-4.3.1-examples && cp -r _gh_pages/docs/4.3/examples/ bootstrap-4.3.1-examples && cp -r _gh_pages/docs/4.3/dist/ bootstrap-4.3.1-examples && rm bootstrap-4.3.1-examples/index.html && find bootstrap-4.3.1-examples -name \"*.html\" -print | xargs sed -i 's#\"/docs/4.3/#\"../#g' && zip -r9 bootstrap-4.3.1-examples.zip bootstrap-4.3.1-examples && rm -rf bootstrap-4.3.1-examples

If I don't find a solution with cross-env-shell, I will just try to move all these to a shell script.

@XhmikosR XhmikosR force-pushed the master-xmr-zip-examples branch from 8e6bf81 to d648c02 Compare February 4, 2020 16:56
@MartijnCuppens
Copy link
Member

The bootstrap CSS, JS and favicons are not included in the zip files here

@XhmikosR
Copy link
Member Author

XhmikosR commented Feb 4, 2020

The CSS and JS is included for sure. The favicons are not included on purpose.

@MartijnCuppens
Copy link
Member

Indeed, never mind

@MartijnCuppens
Copy link
Member

It seems we also need to remove the integrity and crossorigin attributes, otherwise I get cross origin errors when I open the html file through my filesystem:

index.html:1 Access to script at 'file:///Users/martijn.cuppens/workspace/twbs-bootstrap/bootstrap-4.3.1-examples/js/bootstrap.bundle.min.js' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, brave, https.

@XhmikosR
Copy link
Member Author

XhmikosR commented Feb 4, 2020

For that I'd need some help, so feel free to tweak the script.

@XhmikosR XhmikosR force-pushed the master-xmr-zip-examples branch 3 times, most recently from 0519791 to a5864bd Compare February 5, 2020 13:59
@XhmikosR XhmikosR force-pushed the master-xmr-zip-examples branch from a5864bd to 8e2f74c Compare April 1, 2020 11:44
@XhmikosR
Copy link
Member Author

XhmikosR commented Apr 1, 2020

@mdo @MartijnCuppens @ffoodd can you guys try this now? Not sure if the regex is perfect, but it seems to work. I also confirmed the dashboard example works since it has 3rd-party scripts.

cp -r "_gh_pages/docs/$version_short/examples/" "$folder_name"
cp -r "_gh_pages/docs/$version_short/dist/" "$folder_name"
rm "$folder_name/index.html"
find "$folder_name" -name "*.html" -exec sed -i "s#\"/docs/$version_short/#\"../#g" '{}' \;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tighten this so that it only changes links and script tags, not a tags

@MartijnCuppens
Copy link
Member

It works!

Some sidenotes:

  • The favicons aren't yet copied
  • Maybe we should remove the "Download sourcecode" button, imo it's an odd place to have it

@XhmikosR
Copy link
Member Author

XhmikosR commented Apr 1, 2020

The favicons aren't yet copied

Already in the PR TODO, but I might not be able to remove them and TBH I don't think it's an issue.

Maybe we should remove the "Download sourcecode" button, imo it's an odd place to have it

Unrelated to this PR, though. 😛


// remove any previously create folder with the same name
sh.rm('-rf', folderName)
sh.mkdir('-p', folderName)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's a bit weird to use sh here, you can use native Node.js methods to do that, it'll work everywhere

const path = require('path')
const sh = require('shelljs')

const { version, version_short } = require('../package.json')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const { version, version_short: versionShort } = require('../package.json')

to avoid using: /* eslint-disable camelcase */

@XhmikosR
Copy link
Member Author

XhmikosR commented Apr 2, 2020 via email


/*!
* Script to create the built examples zip archive;
* requires the `zip` command to be present!
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we can add a devDeps to avoid this requirement ?

@XhmikosR
Copy link
Member Author

XhmikosR commented Apr 2, 2020 via email

@Johann-S
Copy link
Member

Johann-S commented Apr 2, 2020

@XhmikosR yep and I think we can avoid to have this system requirement by using a dev deps

@XhmikosR
Copy link
Member Author

XhmikosR commented Apr 2, 2020

Feel free to suggest another patch. The less dependencies the better for me.

@XhmikosR XhmikosR force-pushed the master-xmr-zip-examples branch 2 times, most recently from 1db5c2f to 5ccfa2e Compare April 15, 2020 18:29
@XhmikosR XhmikosR force-pushed the master-xmr-zip-examples branch from 5ccfa2e to 97019b8 Compare April 20, 2020 06:33
@XhmikosR XhmikosR force-pushed the master-xmr-zip-examples branch from 97019b8 to 5b558c3 Compare April 20, 2020 06:41
@XhmikosR
Copy link
Member Author

I'm gonna merge this as a first patch. Everyone can improve later as needed 🙂

@XhmikosR XhmikosR merged commit df88748 into master Apr 29, 2020
@XhmikosR XhmikosR deleted the master-xmr-zip-examples branch April 29, 2020 18:03
XhmikosR added a commit that referenced this pull request Apr 29, 2020
Add a script to zip the built examples
XhmikosR added a commit that referenced this pull request Apr 30, 2020
Add a script to zip the built examples
XhmikosR added a commit that referenced this pull request May 2, 2020
Add a script to zip the built examples
olsza pushed a commit to olsza/bootstrap that referenced this pull request Oct 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Downloadable Bootstrap Examples
4 participants