Skip to content

Improve bootstrap flow of a Ghost application#1858

Merged
ErisDS merged 1 commit intoTryGhost:masterfrom
hswolff:improve-bootstrap-flow
Feb 8, 2014
Merged

Improve bootstrap flow of a Ghost application#1858
ErisDS merged 1 commit intoTryGhost:masterfrom
hswolff:improve-bootstrap-flow

Conversation

@hswolff
Copy link
Contributor

@hswolff hswolff commented Jan 5, 2014

addresses #1789, #1364

  • Moves ./core/server/loader -> ./core/bootstrap.
    The bootstrap file is only accessed once during startup,
    and it’s sole job is to ensure a config.js file exists
    (creating one if it doesn’t) and then validates
    the contents of the config file.

    Since this is directly related to the initializing
    the application is is appropriate to have
    it in the ./core folder, named bootstrap as that
    is what it does.

    This also improves the dependency graph, as now
    the bootstrap file require’s the ./core/server/config
    module and is responsible for passing in the validated
    config file.

    Whereas before we had ./core/server/config
    require’ing ./core/server/loader and running its
    init code and then passing that value back to itself,
    the flow is now more straight forward of
    ./core/bootstrap handling initialization and then
    instatiation of config module

  • Merges ./core/server/config/paths into ./core/server/config
    This flow was always confusing me to that some config
    options were on the config object, and some were on
    the paths object.

    This change now incorporates all of the variables
    previously defined in config/paths directly
    into the config module, and in extension,
    the config.js file.

    This means that you now have the option of deciding
    at startup where the content directory for ghost
    should reside.

  • broke out loader tests in config_spec to bootstrap_spec

  • updated all relevant files to now use config().paths

  • moved urlFor and urlForPost function into
    ./server/config/url.js

💃

@hswolff
Copy link
Contributor Author

hswolff commented Jan 8, 2014

Note for self: Use https://github.com/snowmantw/Fe to test that a non content content directory works perhaps.

@hswolff hswolff mentioned this pull request Jan 30, 2014
9 tasks
@hswolff
Copy link
Contributor Author

hswolff commented Feb 1, 2014

Aside from structural improvements this PR introduces the ability for a Ghost blog to define where the content directory resides. This is a step towards enabling Ghost to be used as a npm module.

I'm currently taking advantage of this PR for my own blog.

Let's say you want to use Ghost as a npm module, and want the content folder to exist outside of the npm module.

Create a repo with the following files (as I have in my blog repo:

- content/
- config.js
- index.js
- package.json

content/
The content/ folder is a direct copy of Ghost's content folder.

config.js
The config.js file is a copy of the config.example.js file, however it has additional configuration values that you can ovveride. (In actuality you can now override every config value if you so desire, allowing for greater flexibility without increasing the complexity of the code.)

Of particular interest is the new top-level property paths. Whatever you assign in here is used throughout the code base though the config module.

So this means that you can make this configuration:

production: {
  paths: {
      contentPath: path.join(__dirname, '/content/'),
  }
}

Assigning the location of the contentPath to exist where you desire, in this case relative to your config.js file.

index.js
The index.js is where you bootup your application and instantiate Ghost. This file can be a complete copy of Ghost's own index.js file.

package.json
This is where you define Ghost as a npm module.

My package.json looks like this:

"dependencies": {
    "ghost": "git://github.com/hswolff/Ghost.git#prod"
}

I'm using the GitHub dependency format for the moment as Ghost is not yet published on npm.

Another big caveot: because Ghost requires compiling the admin assets I actually do this within the module and upload those contents directly.

cd node_modules/ghost/
grunt production

This is one issue that is noted in #2078.

Hope this helps clarify!

@hswolff
Copy link
Contributor Author

hswolff commented Feb 1, 2014

Added tests.

@ErisDS
Copy link
Member

ErisDS commented Feb 7, 2014

Will merge just as soon as the build passes 👍

@ErisDS ErisDS modified the milestone: 0.5 Feb 7, 2014
@hswolff
Copy link
Contributor Author

hswolff commented Feb 7, 2014

Passing now on all except Postgres. Seems this commit does break postgres, and it's not just a fluke of travis. I don't have postgres installed locally to test it unfortunately (although I do need to get that set up).

@ErisDS
Copy link
Member

ErisDS commented Feb 7, 2014

I'm pretty sure postgress is already mostly broken. I don't have it locally either yet. I'm just looking through all your comments and how the code has changed. One thing I don't understand... but easier to commend directly.

addresses TryGhost#1789, TryGhost#1364

- Moves ./core/server/loader -> ./core/bootstrap.
The bootstrap file is only accessed once during startup,
and it’s sole job is to ensure a config.js file exists
(creating one if it doesn’t) and then validates
the contents of the config file.

Since this is directly related to the initializing 
the application is is appropriate to have 
it in the ./core folder, named bootstrap as that
is what it does.

This also improves the dependency graph, as now
the bootstrap file require’s the ./core/server/config
module and is responsible for passing in the validated
config file.

Whereas before we had ./core/server/config
require’ing ./core/server/loader and running its
init code and then passing that value back to itself,
the flow is now more straight forward of
./core/bootstrap handling initialization and then
instatiation of config module

- Merges ./core/server/config/paths into 
./core/server/config
This flow was always confusing me to that some config
options were on the config object, and some were on
the paths object.

This change now incorporates all of the variables
previously defined in config/paths directly
into the config module, and in extension,
the config.js file.

This means that you now have the option of deciding
at startup where the content directory for ghost
should reside.

- broke out loader tests in config_spec to bootstrap_spec

- updated all relevant files to now use config().paths

- moved urlFor and urlForPost function into 
 ./server/config/url.js
ErisDS added a commit that referenced this pull request Feb 8, 2014
Improve bootstrap flow of a Ghost application
@ErisDS ErisDS merged commit 37b7907 into TryGhost:master Feb 8, 2014
@hswolff hswolff deleted the improve-bootstrap-flow branch February 8, 2014 15:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants