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

Fix some CodeClimate issues #352

Open
wants to merge 3 commits into
base: staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
46 changes: 23 additions & 23 deletions src/Config.hx
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,37 @@ import haxe.macro.Compiler;

class Config {

public static inline var repoOrganisation : String = 'HaxeFoundation';
public static inline var activeClass : String = 'active';
public static inline var repoOrganisation : String = "HaxeFoundation";
public static inline var activeClass : String = "active";
public static inline var baseEditLink : String = 'https://github.com/$repoOrganisation/haxe.org/tree/staging/';
public static inline var blogTitle : String = 'The Haxe Blog';
public static inline var blogDescription : String = 'Announcements, Case Studies, and Tech Insights from the Haxe Foundation.';
public static inline var blogOutput : String = 'blog';
public static inline var videoOutput : String = 'videos';
public static inline var downloadOutput : String = 'download';
public static inline var blogTitle : String = "The Haxe Blog";
public static inline var blogDescription : String = "Announcements, Case Studies, and Tech Insights from the Haxe Foundation.";
public static inline var blogOutput : String = "blog";
public static inline var videoOutput : String = "videos";
public static inline var downloadOutput : String = "download";
public static inline var compareBaseUrl : String = 'https://github.com/$repoOrganisation/haxe/compare';
public static inline var description : String = 'Haxe is an open source toolkit based on a modern, high level, strictly typed programming language.';
public static inline var disqusShortName : String = 'haxe';
public static inline var description : String = "Haxe is an open source toolkit based on a modern, high level, strictly typed programming language.";
public static inline var disqusShortName : String = "haxe";
public static inline var downloadBaseUrl : String = 'https://github.com/$repoOrganisation/haxe/releases/download';
public static inline var index : String = 'index.html';
public static inline var manualRepo : String = 'HaxeManual';
public static inline var manualRepoBranch : String = 'master';
public static inline var index : String = "index.html";
public static inline var manualRepo : String = "HaxeManual";
public static inline var manualRepoBranch : String = "master";
public static inline var manualBaseEditLink : String = 'https://github.com/$repoOrganisation/$manualRepo/tree/$manualRepoBranch/HaxeManual/';
public static inline var manualImageDir : String = 'manual/HaxeManual/assets/graphics/generated';
public static inline var pagesPath : String = 'pages';
public static inline var postsPath : String = 'posts';
public static inline var videosPath : String = 'videos';
public static inline var downloadsPath : String = 'downloads';
public static inline var sitemapDividerUrl : String = '#divider';
public static inline var manualImageDir : String = "manual/HaxeManual/assets/graphics/generated";
public static inline var pagesPath : String = "pages";
public static inline var postsPath : String = "posts";
public static inline var videosPath : String = "videos";
public static inline var downloadsPath : String = "downloads";
public static inline var sitemapDividerUrl : String = "#divider";
public static inline var tagBaseUrl : String = 'https://github.com/$repoOrganisation/haxe/releases/tag';
public static inline var title : String = 'Haxe - The Cross-Platform Toolkit';
public static inline var viewsPath : String = 'views';
public static inline var title : String = "Haxe - The Cross-Platform Toolkit";
public static inline var viewsPath : String = "views";

public static var outputFolder : String = {
if (Compiler.getDefine('out') != null) {
Compiler.getDefine('out');
if (Compiler.getDefine("out") != null) {
Compiler.getDefine("out");
} else {
'out';
"out";
}
};
}
118 changes: 60 additions & 58 deletions src/Deploy.hx
Original file line number Diff line number Diff line change
Expand Up @@ -11,67 +11,69 @@ using StringTools;
* - AWS_DEFAULT_REGION
*/
class Deploy {
static function cmd(cmd:String, ?params:Array<String>):Void {
Sys.println('run: $cmd $params');
var exitCode = Sys.command(cmd, params);
if (exitCode != 0)
throw 'Error running $cmd $params';
}
static function aws(params:Array<String>):Void {
cmd("aws", params);
}
static function main() {
var S3_BUCKET = Sys.getEnv("S3_BUCKET");
var BRANCH = Sys.getEnv("TRAVIS_BRANCH");
var downloadsData = DownloadsData.getData();

switch([Sys.getEnv("AWS_ACCESS_KEY_ID"), Sys.getEnv("AWS_SECRET_ACCESS_KEY")]) {
case [null, _] | [_, null]:
Sys.println("missing aws credentials, skip deploy");
return;
case _:
//pass
}
static function cmd(cmd:String, ?params:Array<String>) {
Sys.println('run: $cmd $params');
var exitCode = Sys.command(cmd, params);
if (exitCode != 0) {
throw 'Error running $cmd $params';
}
}
static function aws(params:Array<String>) {
cmd("aws", params);
}
static function main() {
var S3_BUCKET = Sys.getEnv("S3_BUCKET");
var BRANCH = Sys.getEnv("TRAVIS_BRANCH");
var downloadsData = DownloadsData.getData();

// Sync all the files to S3 and delete the removed files.
aws(["s3", "sync", "out", 's3://${S3_BUCKET}/${BRANCH}', "--delete"]);
switch ([Sys.getEnv("AWS_ACCESS_KEY_ID"), Sys.getEnv("AWS_SECRET_ACCESS_KEY")]) {
case [null, _] | [_, null]:
Sys.println("missing aws credentials, skip deploy");
return;
case _:
//pass
}

// Set up redirections of the download files to GitHub releases.
for (version in downloadsData.versions) {
for (download in (version.api != null ? [version.api] : []).concat(version.downloads.all)) {
aws([
"s3api", "put-object",
"--acl", "public-read",
"--website-redirect-location", download.url,
"--bucket", S3_BUCKET,
"--key", '${BRANCH}/website-content/downloads/${version.version}/downloads/${download.filename}'
]);
}
if (version.version == downloadsData.current) {
for (download in version.downloads.all) {
aws([
"s3api", "put-object",
"--acl", "public-read",
"--website-redirect-location", download.url,
"--bucket", S3_BUCKET,
"--key", '${BRANCH}/website-content/downloads/latest/downloads/${download.filename.replace(version.version, "latest")}'
]);
}
}
}
// Sync all the files to S3 and delete the removed files.
aws(["s3", "sync", "out", 's3://${S3_BUCKET}/${BRANCH}', "--delete"]);

// invalidate CloudFront cache
switch(Sys.getEnv('CLOUDFRONT_DISTRIBUTION_ID_${BRANCH}')) {
case null:
Sys.println('missing CLOUDFRONT_DISTRIBUTION_ID_${BRANCH}, skip CloudFront cache invalidation');
case distID:
aws(["configure", "set", "preview.cloudfront", "true"]);
aws([
"cloudfront", "create-invalidation",
"--distribution-id", distID,
"--paths", "/*"
]);
}
// Set up redirections of the download files to GitHub releases.
for (version in downloadsData.versions) {
for (download in (version.api != null ? [version.api] : []).concat(version.downloads.all)) {
aws([
"s3api", "put-object",
"--acl", "public-read",
"--website-redirect-location", download.url,
"--bucket", S3_BUCKET,
"--key", '${BRANCH}/website-content/downloads/${version.version}/downloads/${download.filename}'
]);
}
if (version.version == downloadsData.current) {
for (download in version.downloads.all) {
aws([
"s3api", "put-object",
"--acl", "public-read",
"--website-redirect-location", download.url,
"--bucket", S3_BUCKET,
"--key", '${BRANCH}/website-content/downloads/latest/downloads/${download.filename.replace(version.version, "latest")}'
]);
}
}
}

}
// invalidate CloudFront cache
switch (Sys.getEnv('CLOUDFRONT_DISTRIBUTION_ID_${BRANCH}')) {
case null:
Sys.println('missing CLOUDFRONT_DISTRIBUTION_ID_${BRANCH}, skip CloudFront cache invalidation');
case distID:
aws(["configure", "set", "preview.cloudfront", "true"]);
aws([
"cloudfront", "create-invalidation",
"--distribution-id", distID,
"--paths", "/*"
]);
}

}
}
3 changes: 2 additions & 1 deletion src/DownloadsData.hx
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,9 @@ class DownloadsData {
return { title: title, url:url, filename: Path.withoutDirectory(url) };
}
var githubRelease = githubReleases.find(function(r) return r.tag_name == version.tag);
if (githubRelease == null)
if (githubRelease == null) {
throw 'missing github release for version ${version.tag}';
}
var downloadUrls = githubRelease.assets.map(function(a) return a.browser_download_url);

//TODO: make something a little less horrible here
Expand Down
18 changes: 6 additions & 12 deletions src/HxcppDoc.hx
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ class HxcppDoc {
"../../../../hxcpp/docs/build_xml/XmlInjection" => "Xml Injection",
];

for (path in newDoc.keys())
{
for (path in newDoc.keys()) {
var label = newDoc[path];

cppSection.sub.push({
Expand All @@ -44,18 +43,13 @@ class HxcppDoc {
return sections;
}

static function findCppSection (inSections:Array<Section>) {
for (section in inSections)
{
if (section.label == "target-cpp")
{
static function findCppSection (inSections:Array<Section>) : Section {
for (section in inSections) {
if (section.label == "target-cpp") {
return section;
}
else
{
} else {
var sub = findCppSection(section.sub);
if (sub != null)
{
if (sub != null) {
return sub;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Utils.hx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Utils {
}

public static function readContentFile (path:String) : String {
if(!FileSystem.exists(path)){
if (!FileSystem.exists(path)){
return null;
}
var content = File.getContent(path);
Expand Down
5 changes: 2 additions & 3 deletions src/generators/Blog.hx
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ class Blog {
}
}

static function list (title:String, posts:Array<Post>, description:String, path:String, ?avatar:String) {
static function list (title:String, posts:Array<Post>, description:String, path:String, avatar:String = null) {
var content = Views.BlogList(title, description, posts, avatar);

Utils.save(path, content, null, null);
Expand Down Expand Up @@ -247,7 +247,6 @@ class Blog {
}
}


try {
var xml = Xml.parse(Markdown.markdownToHtml(blogContent));
changeHtml('${data.date}-${data.name}', xml);
Expand Down Expand Up @@ -280,7 +279,7 @@ class Blog {
}

if (xml.nodeType == Xml.Element && xml.nodeName == "table") {
xml.set("class", 'table');
xml.set("class", "table");
}

if (xml.nodeType == Xml.Document || xml.nodeType == Xml.Element) {
Expand Down
4 changes: 2 additions & 2 deletions src/generators/Manual.hx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ typedef Page = {

class Manual {

static var inPath = Path.join(["manual", "output", "HaxeManual", "website"]);
static var inPath:String = Path.join(["manual", "output", "HaxeManual", "website"]);

public static function getDefaultSections () : Array<Section> {
return Json.parse(File.getContent(Path.join([inPath, "sections.txt"])));
Expand Down Expand Up @@ -109,7 +109,7 @@ class Manual {

// Create dictionary page
var dictionaryPage = {
url: '/manual/dictionary.html',
url: "/manual/dictionary.html",
title: "Dictionary",
sub: [],
editLink: null,
Expand Down
2 changes: 1 addition & 1 deletion src/generators/Pages.hx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Pages {
var folder = path.length > 1 ? path.shift() : "/";
var file = path.join("/");
if (Path.extension(file) == "scripts" || Path.extension(file) == "styles") {
Sys.println("\tSkipping script page '"+ file + "'");
Sys.println("\tSkipping script page '" + file + "'");
continue;
}
var inPath = Path.join([Config.pagesPath, folder, file]);
Expand Down
4 changes: 2 additions & 2 deletions src/generators/Redirections.hx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ class Redirections {
"/foundation/shop.html" => "/foundation/shop/",
"/api/index.html" => "https://api.haxe.org/",
];

// fix some old links to toplevel api classes.
for(oldName in "reflect,array,date,sys,type,map,int,math,dynamic,enum,float,class,xml".split(",")) {
for (oldName in "reflect,array,date,sys,type,map,int,math,dynamic,enum,float,class,xml".split(",")) {
var newName = oldName.charAt(0).toUpperCase() + oldName.substr(1);
list.set('/api/$oldName/index.html', 'https://api.haxe.org/$newName.html');
}
Expand Down
29 changes: 20 additions & 9 deletions src/generators/Videos.hx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ typedef VideoSection = {
https://try.haxe.org/#2dA2f
**/
class Videos {

public static function generate () {
Sys.println("Generating videos ...");

Expand Down Expand Up @@ -95,7 +96,9 @@ class Videos {

// assign extra/missing data to video
for (video in videos) {
if (!Reflect.hasField(video, "featured")) video.featured = false;
if (!Reflect.hasField(video, "featured")) {
video.featured = false;
}
if (video.featured && category.featuredVideos.length <= 5) {
category.userFeaturedVideos.push(video);
category.featuredVideos.push(video);
Expand All @@ -119,7 +122,9 @@ class Videos {
var i = 0;
while (category.featuredVideos.length < 5 && category.videos.length >= 5) {
var v = category.videos[i++];
if (category.featuredVideos.indexOf(v) < 0) category.featuredVideos.push(v);
if (category.featuredVideos.indexOf(v) < 0) {
category.featuredVideos.push(v);
}
}
category.userFeaturedVideos.sort(function(a, b) return a.date < b.date ? 1 : -1);
category.featuredVideos.sort(function(a, b) return a.date < b.date ? 1 : -1);
Expand All @@ -131,7 +136,7 @@ class Videos {
// assign next/prev videos
for (section in sections) {
for (category in section.categories) {
for (i in 0 ... category.videos.length) {
for (i in 0...category.videos.length) {
var video = category.videos[i];
video.prev = category.videos[i - 1];
video.next = category.videos[i + 1];
Expand Down Expand Up @@ -160,7 +165,7 @@ class Videos {

// generate video pages
for (video in category.videos) {
totalVideos ++;
totalVideos++;
Utils.save(Path.join([Config.outputFolder, video.path]), Views.VideoPage(
video,
section.categories,
Expand All @@ -175,16 +180,22 @@ class Videos {

static function getName(value:String):String {
var name = stripAccents(value.toLowerCase()).replace(" ", "-").replace("&", "-").replace(".", "-").replace("/", "-").replace(",", "").replace('"', "").replace("'", "").replace(":", "").replace("?", "").replace("(", "").replace(")", "").replace("#", "");
while (name.indexOf("--") != -1) name = name.replace("--", "-");
if (name.startsWith("-")) name = name.substr(1);
if (name.endsWith("-")) name = name.substr(0, name.length-1);
while (name.indexOf("--") != -1) {
name = name.replace("--", "-");
}
if (name.startsWith("-")) {
name = name.substr(1);
}
if (name.endsWith("-")) {
name = name.substr(0, name.length - 1);
}
return name;
}

static function stripAccents(value:String) {
static function stripAccents(value:String):String {
var inChars = ["à", "á", "â", "ã", "ä", "ç", "è", "é", "ê", "ë", "ì", "í", "î", "ï", "ñ", "ò", "ó", "ô", "õ", "ö", "ù", "ú", "û", "ü", "ý", "ÿ"];
var outChars = ["a", "a", "a", "a", "a", "c", "e", "e", "e", "e", "i", "i", "i", "i", "n", "o", "o", "o", "o", "o", "u", "u", "u", "u", "y", "y"];
for (i in 0 ... inChars.length) {
for (i in 0...inChars.length) {
value = value.replace(inChars[i], outChars[i]);
}
return value;
Expand Down
Loading