Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ logs/*
demos/*
test/integration
test/integration-with-cgi-bin
test/fixtures/helix-pages
test/tmp/*
tmp/*
coverage/*
96 changes: 96 additions & 0 deletions src/helix-pages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
* Copyright 2019 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
const path = require('path');
const fse = require('fs-extra');
const shell = require('shelljs');
const { GitUrl } = require('@adobe/helix-shared');

function execAsync(cmd) {
return new Promise((resolve, reject) => {
shell.exec(cmd, (code, stdout, stderr) => {
if (code === 0) {
resolve(0);
} else {
reject(stderr);
}
});
});
}

/**
* Utilities for helix pages
*/
class HelixPages {
constructor(logger) {
this._logger = logger;
this._cwd = process.cwd();
this._repo = 'https://github.com/adobe/helix-pages.git';
this._ref = 'master';
}

withDirectory(value) {
this._cwd = value;
return this;
}

withRepo(value) {
this._repo = value;
}

get log() {
return this._logger;
}

get directory() {
return this._cwd;
}

get homeDirectory() {
return this._homeDirectory;
}

get srcDirectory() {
return this._srcDirectory;
}

get checkoutDirectory() {
return this._checkoutDir;
}

get staticURL() {
return this._staticURL;
}

async isPagesProject() {
return !await fse.pathExists(path.join(this.directory, 'src'));
}

async init() {
// check if helix-pages checkout exists
// todo: add support to check for updates and version control
this._homeDirectory = path.resolve(this.directory, '.hlx', 'pages');
this._checkoutDir = path.resolve(this.homeDirectory, this._ref);
this._srcDirectory = path.resolve(this.checkoutDirectory, 'src');
this._staticURL = new GitUrl('https://github.com/adobe/helix-pages.git/htdocs');

if (!await fse.pathExists(this.checkoutDirectory)) {
this.log.info(`Checking out sources from ${this._repo}#${this._ref}`);
try {
await execAsync(`git clone --branch ${this._ref} --quiet --depth 1 ${this._repo} ${this.checkoutDirectory}`);
} catch (e) {
throw Error(`Unable to checkout helix-pages repository: ${e}`);
}
}
}
}

module.exports = HelixPages;
60 changes: 53 additions & 7 deletions src/up.cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const { HelixProject } = require('@adobe/helix-simulator');
const GitUtils = require('./git-utils.js');
const BuildCommand = require('./build.cmd');
const pkgJson = require('../package.json');
const HelixPages = require('./helix-pages.js');

const HELIX_CONFIG = 'helix-config.yaml';

Expand All @@ -31,6 +32,7 @@ class UpCommand extends BuildCommand {
this._saveConfig = false;
this._overrideHost = null;
this._localRepos = [];
this._helixPagesRepo = '';
}

withHttpPort(p) {
Expand Down Expand Up @@ -62,6 +64,11 @@ class UpCommand extends BuildCommand {
return this;
}

withHelixPagesRepo(url) {
this._helixPagesRepo = url;
return this;
}

get project() {
return this._project;
}
Expand Down Expand Up @@ -162,19 +169,58 @@ class UpCommand extends BuildCommand {
};
}));

// start debugger (#178)
// https://nodejs.org/en/docs/guides/debugging-getting-started/#enable-inspector
if (process.platform !== 'win32') {
process.kill(process.pid, 'SIGUSR1');
}

this._project = new HelixProject()
.withCwd(this.directory)
.withBuildDir(this._target)
.withHelixConfig(this.config)
.withDisplayVersion(pkgJson.version)
.withRuntimeModulePaths(module.paths);

// special handling for helix pages project
const pages = new HelixPages(this._logger).withDirectory(this.directory);
if (await pages.isPagesProject()) {
this.log.info(' __ __ ___ ___ ');
this.log.info(' / // /__ / (_)_ __ / _ \\___ ____ ____ ___');
this.log.info(' / _ / -_) / /\\ \\ // ___/ _ `/ _ `/ -_|_-<');
this.log.info(' /_//_/\\__/_/_//_\\_\\/_/ \\_,_/\\_, /\\__/___/');
this.log.info(` /___/ v${pkgJson.version}`);
this.log.info('');

if (this._helixPagesRepo) {
pages.withRepo(this._helixPagesRepo);
}

await pages.init();

// use bundled helix-pages sources
this.withFiles([`${pages.srcDirectory}/**/*.htl`, `${pages.srcDirectory}/**/*.js`]);
this._project.withSourceDir(pages.srcDirectory);

// use bundled helix-pages htdocs
if (!await fse.pathExists(path.join(this.directory, 'htdocs'))) {
this.config.strains.get('default').static.url = pages.staticURL;
localRepos.push({
repoPath: pages.checkoutDirectory,
gitUrl: pages.staticURL,
});
this.config.strains.get('default').static.url = pages.staticURL;
}

// pretend to have config file to suppress message below
hasConfigFile = true;
} else {
this.log.info(' __ __ ___ ');
this.log.info(' / // /__ / (_)_ __ ');
this.log.info(' / _ / -_) / /\\ \\ / ');
this.log.info(` /_//_/\\__/_/_//_\\_\\ v${pkgJson.version}`);
this.log.info(' ');
}

// start debugger (#178)
// https://nodejs.org/en/docs/guides/debugging-getting-started/#enable-inspector
if (process.platform !== 'win32') {
process.kill(process.pid, 'SIGUSR1');
}

if (this._httpPort >= 0) {
this._project.withHttpPort(this._httpPort);
}
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/helix-pages/master/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
minimal checkout of helix pages for testing
Loading