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

Allow configs to be functions #1189

Merged
merged 21 commits into from Jun 13, 2020
Merged

Allow configs to be functions #1189

merged 21 commits into from Jun 13, 2020

Conversation

trusktr
Copy link
Member

@trusktr trusktr commented May 22, 2020

Summary

Allows user configs to be functions. A function config is passed an instance of the vm, which can be useful for referencing in other parts of the config, like in markdown.renderer hooks.

Also adds some unit tests in docsify.test.js to

  • test that the existing Docsify API is available globally when loaded via script tag.
  • test that Docsify accepts a config function (window.$docsify being a function that returns a config object)

What kind of change does this PR introduce? (check at least one)

  • Bugfix
  • Feature
  • Code style update
  • Refactor
  • Docs
  • Build-related changes
  • Other, please describe:

Does this PR introduce a breaking change? (check one)

  • Yes
  • No

The PR fulfills these requirements:

  • When resolving a specific issue, it's referenced in the PR's title (e.g. fix #xxx[,#xxx], where "xxx" is the issue number)

You have tested in the following browsers: (Providing a detailed version will be better.)

  • Chrome
  • Firefox
  • Safari
  • Edge
  • IE

If adding a new feature, the PR's description includes:

  • A convincing reason for adding this feature
  • Related documents have been updated
  • Related unit tests have been updated
  • e2e tests have been updated

@trusktr trusktr requested a review from anikethsaha May 22, 2020 08:43
@vercel
Copy link

vercel bot commented May 22, 2020

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/docsify-core/docsify-preview/pliopfhjf
✅ Preview: https://docsify-preview-git-allow-config-function.docsify-core.vercel.app

@trusktr
Copy link
Member Author

trusktr commented May 22, 2020

Gotta check what's going on with the failed e2e test.

@trusktr
Copy link
Member Author

trusktr commented May 22, 2020

Running npm run test:e2e passes for me locally.

@trusktr
Copy link
Member Author

trusktr commented May 22, 2020

Ooooh, is it because of older Node for one run of the test perhaps? I'll get back to this tomorrow.

@trusktr
Copy link
Member Author

trusktr commented May 23, 2020

Looks like I should re-do my commits to use the feat:, fix:, etc prefixes.

@trusktr
Copy link
Member Author

trusktr commented May 23, 2020

I tried switching to Node v10 locally, ran npm run test:e2e and all tests passed. Is there a different way to test it?

@anikethsaha
Copy link
Member

Looks like I should re-do my commits to use the feat:, fix:, etc prefixes.

yes, refer angular commit convention. I will add commitlint soon to guide with the commit message.

@anikethsaha anikethsaha added the semver-minor This needs a semver-minor release label May 23, 2020
src/core/index.js Outdated Show resolved Hide resolved
@trusktr
Copy link
Member Author

trusktr commented May 23, 2020

I will add commitlint soon to guide with the commit message.

Worth checking out semantic-release too. But that would be some work to set up. I feel like we need to clean things up, add tests, etc, first.

@anikethsaha
Copy link
Member

Worth checking out semantic-release too. But that would be some work to set up. I feel like we need to clean things up, add tests, etc, first.

yea, this will need changes in the publish script.

@trusktr
Copy link
Member Author

trusktr commented May 23, 2020

I just noticed something else! All tests pass (at least for me locally, not sure why it fails on CI yet), however, the npm run build command currently has a Rollup compile error, but the script exits 0 as if nothing happened.

I will fix this...

@trusktr
Copy link
Member Author

trusktr commented May 23, 2020

Ok, now that I could debug it (PR #1192), I found out that adding the export words in src/core/index.js causes Rollup to complain You must supply "output.name" for IIFE bundles.

Let me see here...

@anikethsaha anikethsaha reopened this May 23, 2020
@trusktr trusktr requested a review from a team May 23, 2020 21:04
…ld globals in favor of a single global DOCSIFY, and add tests for this
…e-new-single-global

update src/core/index.js to export all global APIs, deprecate old globals…
@trusktr
Copy link
Member Author

trusktr commented May 23, 2020

Nice. All checks have passed. What I could do though, is remove the config function stuff, and just make this a pull requests that adds the test updates, then make a new minimal PR just for the config function. Let me know if that's what I should do.

EDIT: The PR is not that big anyways. Turning on the Hide whitespace changes option makes a couple parts easier to read.

.editorconfig Show resolved Hide resolved
build/build.js Show resolved Hide resolved
@trusktr
Copy link
Member Author

trusktr commented Jun 10, 2020

@jhildenbiddle @sy-records @Koooooo-7 Can I get one more review from one of you on this?

test/unit/docsify.test.js Outdated Show resolved Hide resolved
anikethsaha
anikethsaha previously approved these changes Jun 10, 2020
Copy link
Member

@anikethsaha anikethsaha left a comment

Choose a reason for hiding this comment

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

LGTM

sy-records
sy-records previously approved these changes Jun 11, 2020
Copy link
Member

@sy-records sy-records left a comment

Choose a reason for hiding this comment

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

👍🏻

Koooooo-7
Koooooo-7 previously approved these changes Jun 11, 2020
Copy link
Member

@Koooooo-7 Koooooo-7 left a comment

Choose a reason for hiding this comment

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

I learned from it. 🚀

@anikethsaha
Copy link
Member

@trusktr feel free to fix the merge conflict and merge this.

jamesgeorge007
jamesgeorge007 previously approved these changes Jun 11, 2020
@trusktr
Copy link
Member Author

trusktr commented Jun 13, 2020

Yay. Ok tonight or tomorrow I'll fix the conflict and merge.

* develop:
  chore: update auto format config
@trusktr
Copy link
Member Author

trusktr commented Jun 13, 2020

I fixed the conflict with package-lock.json, and also I opened #1216 which should prevent conflicts from package-lock.

Also the e2e test failed. It is flaky. There's a race condition. I'll take a look soon. Let me re-run the tests...

build/css.js Outdated Show resolved Hide resolved
build/build.js Show resolved Hide resolved
Co-authored-by: James George <jamesgeorge998001@gmail.com>
@trusktr
Copy link
Member Author

trusktr commented Jun 13, 2020

tests passed. Merging!

@trusktr trusktr deleted the allow-config-function branch June 13, 2020 05:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver-minor This needs a semver-minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants