Skip to content

Commit

Permalink
Updated to install masthead (placeholder) theme by default
Browse files Browse the repository at this point in the history
refs TryGhost/Product#3510

- Updated install command to use masthead theme by default if version >= 5.63.0
- Updated update command to install but not activate masthead theme if upgrading to >= 5.63.0
- Updated backup command to ignore the masthead theme in backups
  • Loading branch information
cmraible committed Sep 13, 2023
1 parent ee26bf9 commit 4a28f49
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 15 deletions.
29 changes: 21 additions & 8 deletions lib/commands/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ class InstallCommand extends Command {
title: 'Linking latest Ghost and recording versions',
task: this.link.bind(this)
}, {
title: 'Linking latest Casper',
task: this.casper
title: 'Linking latest default theme',
task: this.defaultTheme
}], false)
}], {
argv: {...argv, version},
Expand Down Expand Up @@ -129,12 +129,25 @@ class InstallCommand extends Command {
ctx.installPath = path.join(process.cwd(), 'versions', resolvedVersion); // eslint-disable-line require-atomic-updates
}

casper() {
// Create a symlink to the theme from the current version
return symlinkSync(
path.join(process.cwd(), 'current', 'content', 'themes', 'casper'),
path.join(process.cwd(), 'content', 'themes', 'casper')
);
defaultTheme(ctx) {
const semver = require('semver');
const version = ctx.version;

// Starting with version 5.63.0, we are shipping an updated version of Casper with breaking changes under a new name
// If installing a version < 5.63.0, we need to symlink Casper
// We don't want the theme to outpace Ghost (e.g. try to use features that don't exist in Ghost yet)
if (semver.gte(version, '5.63.0')) {
// Create a symlink to the theme from the current version
return symlinkSync(
path.join(process.cwd(), 'current', 'content', 'themes', 'masthead'),
path.join(process.cwd(), 'content', 'themes', 'masthead')
);
} else {
return symlinkSync(
path.join(process.cwd(), 'current', 'content', 'themes', 'casper'),
path.join(process.cwd(), 'content', 'themes', 'casper')
);
}
}

link(ctx) {
Expand Down
9 changes: 9 additions & 0 deletions lib/commands/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,19 @@ class UpdateCommand extends Command {

link({instance, installPath, version, rollback}) {
const symlinkSync = require('symlink-or-copy').sync;
const semver = require('semver');

fs.removeSync(path.join(process.cwd(), 'current'));
symlinkSync(installPath, path.join(process.cwd(), 'current'));

// If upgrading from a version < 5.63.0, we need to symlink masthead so it is installed and available to update
if (semver.lt(instance.version, '5.63.0') && semver.gte(version, '5.63.0')) {
symlinkSync(
path.join(process.cwd(), 'current', 'content', 'themes', 'masthead'),
path.join(process.cwd(), 'content', 'themes', 'masthead')
);
}

instance.previousVersion = rollback ? null : instance.version;
instance.version = version;
instance.nodeVersion = process.versions.node;
Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/backup.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ module.exports = async function (ui, instance) {
const zipPath = path.join(process.cwd(), `backup-${backupSuffix}.zip`);

try {
await zip.compress(path.join(instance.dir, 'content/'), zipPath, {glob: `{data/${contentExportFile},data/${membersExportFile},files/**,images/**,media/**,settings/**,themes/**}`, ignore: 'themes/casper'});
await zip.compress(path.join(instance.dir, 'content/'), zipPath, {glob: `{data/${contentExportFile},data/${membersExportFile},files/**,images/**,media/**,settings/**,themes/**}`, ignore: 'themes/casper,themes/masthead'});
} catch (err) {
throw new ProcessError(err);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ghost-cli",
"version": "1.24.2",
"version": "1.24.3",
"description": "CLI Tool for installing & updating Ghost",
"author": "Ghost Foundation",
"homepage": "https://ghost.org",
Expand Down
28 changes: 23 additions & 5 deletions test/unit/commands/install-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ describe('Unit: Commands > Install', function () {
const runCommandStub = sinon.stub(testInstance, 'runCommand').resolves();
const versionStub = sinon.stub(testInstance, 'version').resolves();
const linkStub = sinon.stub(testInstance, 'link').resolves();
const casperStub = sinon.stub(testInstance, 'casper').resolves();
const defaultThemeStub = sinon.stub(testInstance, 'defaultTheme').resolves();

return testInstance.run({version: '1.0.0', setup: false, 'check-empty': true}).then(() => {
expect(dirEmptyStub.calledOnce).to.be.true;
Expand All @@ -216,7 +216,7 @@ describe('Unit: Commands > Install', function () {
expect(ensureStructureStub.calledOnce).to.be.true;
expect(versionStub.calledOnce).to.be.true;
expect(linkStub.calledOnce).to.be.true;
expect(casperStub.calledOnce).to.be.true;
expect(defaultThemeStub.calledOnce).to.be.true;
expect(runCommandStub.calledOnce).to.be.true;
});
});
Expand Down Expand Up @@ -412,16 +412,34 @@ describe('Unit: Commands > Install', function () {
});
});

describe('tasks > casper', function () {
it('links casper version correctly', function () {
describe('tasks > defaultTheme', function () {
it('links masthead version correctly if version >= 5.63.0', function () {
const symlinkSyncStub = sinon.stub();
const InstallCommand = proxyquire(modulePath, {
'symlink-or-copy': {sync: symlinkSyncStub}
});

const testInstance = new InstallCommand({}, {});

testInstance.casper();
const context = {version: '5.63.0'};
testInstance.defaultTheme(context);
expect(symlinkSyncStub.calledOnce).to.be.true;
expect(symlinkSyncStub.calledWithExactly(
path.join(process.cwd(), 'current/content/themes/masthead'),
path.join(process.cwd(), 'content/themes/masthead')
));
});

it('links casper version correctly if version < 5.63.0', function () {
const symlinkSyncStub = sinon.stub();
const InstallCommand = proxyquire(modulePath, {
'symlink-or-copy': {sync: symlinkSyncStub}
});

const testInstance = new InstallCommand({}, {});

const context = {version: '5.62.0'};
testInstance.defaultTheme(context);
expect(symlinkSyncStub.calledOnce).to.be.true;
expect(symlinkSyncStub.calledWithExactly(
path.join(process.cwd(), 'current/content/themes/casper'),
Expand Down
25 changes: 25 additions & 0 deletions test/unit/commands/update-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1068,5 +1068,30 @@ describe('Unit: Commands > Update', function () {
expect(instance.previousVersion).to.be.null;
expect(instance.nodeVersion).to.equal(process.versions.node);
});

it('installs masthead theme when upgrading from < 5.63.0 to >= 5.63.0', function () {
const command = new UpdateCommand({}, {});
const envCfg = {
dirs: ['versions/5.62.0', 'versions/5.63.0', 'versions/5.63.0/content/themes/masthead', 'content/themes'],
links: [['versions/5.62.0', 'current']]
};
const env = setupTestFolder(envCfg);
sinon.stub(process, 'cwd').returns(env.dir);
const instance = {
version: '5.62.0'
};
const context = {
installPath: path.join(env.dir, 'versions/5.63.0'),
version: '5.63.0',
rollback: false,
instance
};

command.link(context);
expect(fs.readlinkSync(path.join(env.dir, 'current'))).to.equal(path.join(env.dir, 'versions/5.63.0'));
expect(instance.version).to.equal('5.63.0');
expect(instance.previousVersion).to.equal('5.62.0');
expect(instance.nodeVersion).to.equal(process.versions.node);
});
});
});

0 comments on commit 4a28f49

Please sign in to comment.