mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
Build assets with ember, and serve with ghost
This commit is contained in:
parent
d61b2e1a00
commit
388a8dd3f0
15 changed files with 37 additions and 140 deletions
|
@ -3,7 +3,6 @@ import Resolver from 'ember/resolver';
|
|||
import loadInitializers from 'ember/load-initializers';
|
||||
import 'ghost/utils/link-view';
|
||||
import 'ghost/utils/text-field';
|
||||
import configureApp from 'ghost/config';
|
||||
import config from './config/environment';
|
||||
|
||||
Ember.MODEL_FACTORY_INJECTIONS = true;
|
||||
|
@ -13,7 +12,6 @@ var App = Ember.Application.extend({
|
|||
podModulePrefix: config.podModulePrefix,
|
||||
Resolver: Resolver
|
||||
});
|
||||
configureApp(App);
|
||||
|
||||
loadInitializers(App, config.modulePrefix);
|
||||
|
||||
|
|
|
@ -38,17 +38,16 @@
|
|||
{{#unless skip_google_fonts}}
|
||||
<link rel="stylesheet" type="text/css" href="//fonts.googleapis.com/css?family=Open+Sans:400,300,700" />
|
||||
{{/unless}}
|
||||
|
||||
<link rel="stylesheet" href="{{asset "css/vendor.css" ghost="true"}}" />
|
||||
<link rel="stylesheet" href="{{asset "css/ghost.css" ghost="true"}}" />
|
||||
|
||||
<link rel="stylesheet" href="{{asset "vendor.css" ghost="true"}}" />
|
||||
<link rel="stylesheet" href="{{asset "ghost.css" ghost="true"}}" />
|
||||
{{content-for 'head-footer'}}
|
||||
</head>
|
||||
<body>
|
||||
{{content-for 'body'}}
|
||||
|
||||
{{{ghost_script_tags}}}
|
||||
<script src="assets/vendor.js"></script>
|
||||
<script src="assets/ghost.js"></script>
|
||||
<script src="{{asset "vendor.js" ghost="true"}}"></script>
|
||||
<script src="{{asset "ghost.js" ghost="true"}}"></script>
|
||||
|
||||
{{content-for 'body-footer'}}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
|
||||
@font-face {
|
||||
font-family: 'GhostIcons';
|
||||
src:url('../fonts/icons.woff') format('woff');
|
||||
src:url('fonts/icons.woff') format('woff');
|
||||
font-weight: normal;
|
||||
font-style: normal;
|
||||
}
|
||||
|
|
|
@ -21,10 +21,10 @@ module.exports = function(environment) {
|
|||
|
||||
if (environment === 'development') {
|
||||
// ENV.APP.LOG_RESOLVER = true;
|
||||
// ENV.APP.LOG_ACTIVE_GENERATION = true;
|
||||
// ENV.APP.LOG_TRANSITIONS = true;
|
||||
// ENV.APP.LOG_TRANSITIONS_INTERNAL = true;
|
||||
// ENV.APP.LOG_VIEW_LOOKUPS = true;
|
||||
ENV.APP.LOG_ACTIVE_GENERATION = true;
|
||||
ENV.APP.LOG_TRANSITIONS = true;
|
||||
ENV.APP.LOG_TRANSITIONS_INTERNAL = true;
|
||||
ENV.APP.LOG_VIEW_LOOKUPS = true;
|
||||
}
|
||||
|
||||
if (environment === 'test') {
|
||||
|
|
4
core/client/lib/.jshintrc
Normal file
4
core/client/lib/.jshintrc
Normal file
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"node": true,
|
||||
"browser": false
|
||||
}
|
8
core/client/lib/asset-delivery/index.js
Normal file
8
core/client/lib/asset-delivery/index.js
Normal file
|
@ -0,0 +1,8 @@
|
|||
module.exports = {
|
||||
name: 'asset-delivery',
|
||||
postBuild: function (results) {
|
||||
var fs = this.project.require('fs-extra');
|
||||
|
||||
fs.copySync(results.directory + '/index.html', '../server/views/default.hbs');
|
||||
}
|
||||
};
|
6
core/client/lib/asset-delivery/package.json
Normal file
6
core/client/lib/asset-delivery/package.json
Normal file
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"name": "asset-delivery",
|
||||
"keywords": [
|
||||
"ember-addon"
|
||||
]
|
||||
}
|
|
@ -24,15 +24,19 @@
|
|||
"ember-cli": "0.1.15",
|
||||
"ember-cli-6to5": "^3.0.0",
|
||||
"ember-cli-app-version": "0.3.1",
|
||||
"ember-cli-autoprefixer": "0.3.0",
|
||||
"ember-cli-content-security-policy": "0.3.0",
|
||||
"ember-cli-dependency-checker": "0.0.7",
|
||||
"ember-cli-htmlbars": "^0.7.4",
|
||||
"ember-cli-ic-ajax": "0.1.1",
|
||||
"ember-cli-inject-live-reload": "^1.3.0",
|
||||
"ember-cli-qunit": "0.3.7",
|
||||
"ember-cli-sass": "3.1.0-beta",
|
||||
"ember-cli-uglify": "1.0.1",
|
||||
"ember-data": "1.0.0-beta.14.1",
|
||||
"ember-export-application-global": "^1.0.2",
|
||||
"express": "^4.8.5",
|
||||
"fs-extra": "0.16.3",
|
||||
"glob": "^4.0.5"
|
||||
},
|
||||
"ember-addon": {
|
||||
|
@ -40,4 +44,4 @@
|
|||
"lib/asset-delivery"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -176,7 +176,7 @@ ConfigManager.prototype.set = function (config) {
|
|||
|
||||
availableThemes: this._config.paths.availableThemes || {},
|
||||
availableApps: this._config.paths.availableApps || {},
|
||||
builtScriptPath: path.join(corePath, 'built/scripts/')
|
||||
builtScriptPath: path.join(corePath, '/client/dist/assets/')
|
||||
},
|
||||
theme: {
|
||||
// normalise the URL by removing any trailing slash
|
||||
|
|
|
@ -1,25 +0,0 @@
|
|||
// # Ghost Script Tags Helpers
|
||||
// Used in the ghost admin only
|
||||
//
|
||||
// We use the name ghost_script_tags to match the helper for consistency:
|
||||
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers
|
||||
|
||||
var _ = require('lodash'),
|
||||
utils = require('./utils'),
|
||||
config = require('../config'),
|
||||
ghost_script_tags;
|
||||
|
||||
ghost_script_tags = function () {
|
||||
var scriptList = utils.isProduction ? utils.scriptFiles.production : utils.scriptFiles.development;
|
||||
|
||||
scriptList = _.map(scriptList, function (fileName) {
|
||||
return utils.scriptTemplate({
|
||||
source: config.paths.subdir + '/ghost/scripts/' + fileName,
|
||||
version: config.assetHash
|
||||
});
|
||||
});
|
||||
|
||||
return scriptList.join('');
|
||||
};
|
||||
|
||||
module.exports = ghost_script_tags;
|
|
@ -38,8 +38,6 @@ coreHelpers.title = require('./title');
|
|||
coreHelpers.url = require('./url');
|
||||
coreHelpers.image = require('./image');
|
||||
|
||||
coreHelpers.ghost_script_tags = require('./ghost_script_tags');
|
||||
|
||||
coreHelpers.helperMissing = function (arg) {
|
||||
if (arguments.length === 2) {
|
||||
return undefined;
|
||||
|
@ -108,7 +106,6 @@ registerHelpers = function (adminHbs) {
|
|||
registerAsyncThemeHelper('post_class', coreHelpers.post_class);
|
||||
|
||||
// Register admin helpers
|
||||
registerAdminHelper('ghost_script_tags', coreHelpers.ghost_script_tags);
|
||||
registerAdminHelper('asset', coreHelpers.asset);
|
||||
};
|
||||
|
||||
|
@ -116,4 +113,3 @@ module.exports = coreHelpers;
|
|||
module.exports.loadCoreHelpers = registerHelpers;
|
||||
module.exports.registerThemeHelper = registerThemeHelper;
|
||||
module.exports.registerAsyncThemeHelper = registerAsyncThemeHelper;
|
||||
module.exports.scriptFiles = utils.scriptFiles;
|
||||
|
|
|
@ -5,18 +5,7 @@ utils = {
|
|||
assetTemplate: _.template('<%= source %>?v=<%= version %>'),
|
||||
linkTemplate: _.template('<a href="<%= url %>"><%= text %></a>'),
|
||||
scriptTemplate: _.template('<script src="<%= source %>?v=<%= version %>"></script>'),
|
||||
isProduction: process.env.NODE_ENV === 'production',
|
||||
scriptFiles: {
|
||||
production: [
|
||||
'vendor.min.js',
|
||||
'ghost.min.js'
|
||||
],
|
||||
development: [
|
||||
'vendor-dev.js',
|
||||
'templates-dev.js',
|
||||
'ghost-dev.js'
|
||||
]
|
||||
}
|
||||
isProduction: process.env.NODE_ENV === 'production'
|
||||
};
|
||||
|
||||
module.exports = utils;
|
||||
|
|
|
@ -67,9 +67,7 @@ function initDbHashAndFirstRun() {
|
|||
function builtFilesExist() {
|
||||
var deferreds = [],
|
||||
location = config.paths.builtScriptPath,
|
||||
|
||||
fileNames = process.env.NODE_ENV === 'production' ?
|
||||
helpers.scriptFiles.production : helpers.scriptFiles.development;
|
||||
fileNames = ['ghost.js', 'vendor.js', 'ghost.css', 'vendor.css'];
|
||||
|
||||
function checkExist(fileName) {
|
||||
var errorMessage = 'Javascript files have not been built.',
|
||||
|
|
|
@ -235,7 +235,6 @@ setupMiddleware = function (blogAppInstance, adminApp) {
|
|||
// Static assets
|
||||
blogApp.use('/shared', express['static'](path.join(corePath, '/shared'), {maxAge: utils.ONE_HOUR_MS}));
|
||||
blogApp.use('/content/images', storage.getStorage().serve());
|
||||
blogApp.use('/ghost/scripts', express['static'](path.join(corePath, '/built/scripts'), {maxAge: utils.ONE_YEAR_MS}));
|
||||
blogApp.use('/public', express['static'](path.join(corePath, '/built/public'), {maxAge: utils.ONE_YEAR_MS}));
|
||||
|
||||
// First determine whether we're serving admin or theme content
|
||||
|
@ -244,7 +243,7 @@ setupMiddleware = function (blogAppInstance, adminApp) {
|
|||
blogApp.use(configHbsForContext);
|
||||
|
||||
// Admin only config
|
||||
blogApp.use('/ghost', express['static'](path.join(corePath, '/client/assets'), {maxAge: utils.ONE_YEAR_MS}));
|
||||
blogApp.use('/ghost', express['static'](path.join(corePath, '/client/dist/assets'), {maxAge: utils.ONE_YEAR_MS}));
|
||||
|
||||
// Force SSL
|
||||
// NOTE: Importantly this is _after_ the check above for admin-theme static resources,
|
||||
|
|
|
@ -1,79 +0,0 @@
|
|||
/*globals describe, before, after, afterEach, it*/
|
||||
/*jshint expr:true*/
|
||||
var should = require('should'),
|
||||
rewire = require('rewire'),
|
||||
utils = require('./utils'),
|
||||
|
||||
// Stuff we are testing
|
||||
helpers = rewire('../../../server/helpers');
|
||||
|
||||
// ## Admin only helpers
|
||||
describe('ghost_script_tags helper', function () {
|
||||
var rendered;
|
||||
|
||||
before(function () {
|
||||
utils.loadHelpers();
|
||||
utils.overrideConfig({assetHash: 'abc'});
|
||||
});
|
||||
|
||||
after(function () {
|
||||
utils.restoreConfig();
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
helpers.__set__('utils.isProduction', false);
|
||||
});
|
||||
|
||||
it('has loaded ghostScriptTags helper', function () {
|
||||
should.exist(helpers.ghost_script_tags);
|
||||
});
|
||||
|
||||
it('outputs correct scripts for development mode', function () {
|
||||
rendered = helpers.ghost_script_tags();
|
||||
should.exist(rendered);
|
||||
String(rendered).should.equal(
|
||||
'<script src="/ghost/scripts/vendor-dev.js?v=abc"></script>' +
|
||||
'<script src="/ghost/scripts/templates-dev.js?v=abc"></script>' +
|
||||
'<script src="/ghost/scripts/ghost-dev.js?v=abc"></script>'
|
||||
);
|
||||
});
|
||||
|
||||
it('outputs correct scripts for production mode', function () {
|
||||
helpers.__set__('utils.isProduction', true);
|
||||
|
||||
rendered = helpers.ghost_script_tags();
|
||||
should.exist(rendered);
|
||||
String(rendered).should.equal(
|
||||
'<script src="/ghost/scripts/vendor.min.js?v=abc"></script>' +
|
||||
'<script src="/ghost/scripts/ghost.min.js?v=abc"></script>'
|
||||
);
|
||||
});
|
||||
|
||||
describe('with /blog subdirectory', function () {
|
||||
before(function () {
|
||||
utils.overrideConfig({url: 'http://testurl.com/blog'});
|
||||
});
|
||||
|
||||
it('outputs correct scripts for development mode', function () {
|
||||
helpers.__set__('utils.isProduction', false);
|
||||
rendered = helpers.ghost_script_tags();
|
||||
should.exist(rendered);
|
||||
String(rendered).should.equal(
|
||||
'<script src="/blog/ghost/scripts/vendor-dev.js?v=abc"></script>' +
|
||||
'<script src="/blog/ghost/scripts/templates-dev.js?v=abc"></script>' +
|
||||
'<script src="/blog/ghost/scripts/ghost-dev.js?v=abc"></script>'
|
||||
);
|
||||
});
|
||||
|
||||
it('outputs correct scripts for production mode', function () {
|
||||
helpers.__set__('utils.isProduction', true);
|
||||
|
||||
rendered = helpers.ghost_script_tags();
|
||||
should.exist(rendered);
|
||||
String(rendered).should.equal(
|
||||
'<script src="/blog/ghost/scripts/vendor.min.js?v=abc"></script>' +
|
||||
'<script src="/blog/ghost/scripts/ghost.min.js?v=abc"></script>'
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Add table
Reference in a new issue