aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorn-peugnet <n.peugnet@free.fr>2019-11-11 18:50:56 +0100
committern-peugnet <n.peugnet@free.fr>2019-11-12 00:35:29 +0100
commite4bc65433283e0725a2e7bf07ae0c84f7905af17 (patch)
treeabf9e2c4ff0c601eda5400ef6fea9639fbd3cb18
parentc0cf03fcb5aeaa4011c9b8eef4b9bc505b24485d (diff)
downloadwcms-e4bc65433283e0725a2e7bf07ae0c84f7905af17.tar.gz
wcms-e4bc65433283e0725a2e7bf07ae0c84f7905af17.zip
feat: make Sentry optional
- move sentry to PHP dev requirements. - try...catch Sentry integration in PHP. - update Makefile: - add comments as documentation. - remove recursive call from PREV_ENV_FILE target. - make dist and sentryrelease ENV variable. - add touch target for more efficient rebuilds. - add `dist` build ENV functionnality not to include dev-requirements in the zip release.
-rw-r--r--.default.env2
-rw-r--r--.gitignore1
-rw-r--r--Makefile116
-rw-r--r--composer.json4
-rw-r--r--composer.lock319
-rw-r--r--index.php30
-rw-r--r--webpack.config.js6
7 files changed, 270 insertions, 208 deletions
diff --git a/.default.env b/.default.env
index 16df89f..4f0192c 100644
--- a/.default.env
+++ b/.default.env
@@ -1,6 +1,6 @@
# .env
-# Build environment. (prod|dev)
+# Build environment. (dev|prod|dist)
ENV=dev
# GitHub token used by release-it to publish releases
diff --git a/.gitignore b/.gitignore
index 241abeb..2fc5d5d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,6 +8,7 @@ database/*
fonts/*
media/*
render/
+build/
dist/
vendor/*
node_modules/
diff --git a/Makefile b/Makefile
index 8503720..803b57e 100644
--- a/Makefile
+++ b/Makefile
@@ -2,45 +2,69 @@ include .default.env
include .env
export
+build_dir := build
+
+# Misc variables.
PATH := vendor/bin:node_modules/.bin:$(PATH)
override GIT_VERSION := $(shell git --no-pager describe --always --tags)
override CUR_VERSION := $(strip $(shell cat VERSION 2>/dev/null))
-PREV_ENV_FILE := /tmp/wcms_prev_env
-PREV_ENV=$(strip $(shell cat $(PREV_ENV_FILE) 2>/dev/null))
-
-js_sources := $(wildcard src/*.js)
-js_bundles := $(js_sources:src/%.js=assets/js/%.bundle.js)
-js_srcmaps := $(js_sources:src/%.js=assets/js/%.bundle.js.map)
+override WEBPACK_FLAGS += $(if $(filter $(ENV),dist),-p)
+override COMPOSER_FLAGS += $(if $(filter $(ENV),dist),--no-dev --prefer-dist)
+PREV_ENV_FILE := $(build_dir)/prev_env
+PREV_ENV := $(strip $(shell cat $(PREV_ENV_FILE) 2>/dev/null))
+
+# Files variables.
+js_src_dir := src
+js_sources := $(wildcard $(js_src_dir)/*.js)
+js_bundles := $(js_sources:$(js_src_dir)/%.js=assets/js/%.bundle.js)
+js_srcmaps := $(js_sources:$(js_src_dir)/%.js=assets/js/%.bundle.js.map)
zip_release := dist/w_cms_$(GIT_VERSION).zip
-all: vendor build
+# Default target. This executes everything targets needed to get a fully
+# working development environment.
+.PHONY: all
+all: $(PREV_ENV_FILE) vendor build
+# Build generated files.
+.PHONY: build
build: VERSION $(PREV_ENV_FILE) $(js_bundles)
+# Run webpack in watch mode.
+.PHONY: watch
watch: node_modules
webpack --env dev --watch
+# Create a new release and upload it on GitHub.
+.PHONY: release
release: node_modules
release-it
+# Inform Sentry of a new release.
+.PHONY: sentryrelease
+sentryrelease: ENV := dist
sentryrelease:
- $(MAKE) .sentryrelease ENV=prod
+ $(MAKE) .sentryrelease ENV=$(ENV)
-.sentryrelease: build
+.PHONY: .sentryrelease
+.sentryrelease: $(PREV_ENV_FILE) build $(js_srcmaps)
sentry-cli releases new $(GIT_VERSION)
sentry-cli releases set-commits $(GIT_VERSION) --auto
sentry-cli releases files $(GIT_VERSION) upload-sourcemaps assets/js --url-prefix '~/assets/js' --rewrite
sentry-cli releases finalize $(GIT_VERSION)
+# Generate the distribution files.
+.PHONY: dist
+dist: ENV := dist
dist:
- $(MAKE) .dist ENV=prod
+ $(MAKE) .dist ENV=$(ENV)
+.PHONY: .dist
.dist: distclean $(zip_release) $(js_srcmaps)
dist/w_cms_%.zip: all
- @echo "Building Zip release..."
+ @echo Building Zip release...
mkdir -p $(dir $@)
-# Include git tracked files (everything except ignored) + needed files
+# Include git tracked files (everything except ignored) + needed files.
zip -r $@ \
$(shell git ls-tree -r HEAD --name-only) \
VERSION \
@@ -48,11 +72,11 @@ dist/w_cms_%.zip: all
vendor \
-x "*test*" \
-x "*docs*"
-# Include non-empty git tracked directories (to keep dir permissions)
+# Include non-empty git tracked directories (to keep dir permissions).
zip $@ $(shell git ls-tree -r HEAD --name-only -d)
-# Remove non-useful files
+# Remove non-useful files.
zip -d $@ \
- $(js_sources) \
+ "$(js_src_dir)/*" \
$(js_srcmaps) \
.default.env \
.gitignore \
@@ -62,52 +86,74 @@ dist/w_cms_%.zip: all
"package*" \
webpack.config.js
-assets/js/%.bundle.js assets/js/%.bundle.js.map: src/%.js node_modules
- @echo "Building JS Bundles..."
+# Generate the js bundles (and sourcemaps).
+assets/js/%.bundle.js assets/js/%.bundle.js.map: $(js_src_dir)/%.js node_modules
+ @echo Building JS Bundles...
mkdir -p $(dir $@)
- webpack $< -o $@ $(if $(filter $(ENV),prod),--env prod -p,--env dev)
+ webpack $< -o $@ --env $(ENV) $(WEBPACK_FLAGS)
+# Generate a .env file if none is present.
.env:
- cp .default.env .env
+ cp .default.env $@
-# use a force (fake) target to always rebuild this file but have Make
-# consider this updated if it was actually rewritten (a .PHONY target
-# is always considered new)
+# Generate the VERSION file.
VERSION: .FORCE
ifneq ($(CUR_VERSION),$(GIT_VERSION))
- @echo $(GIT_VERSION) > $@
+ echo $(GIT_VERSION) > $@
endif
-$(PREV_ENV_FILE): .FORCE
+# Trick to force rebuild if the build environment has changed.
ifneq ($(PREV_ENV),$(ENV))
+$(PREV_ENV_FILE): touch
+ifdef PREV_ENV
@echo Build env has changed !
- $(MAKE) buildclean
- @echo $(ENV) > $@
+else
+ @echo New build env.
+endif
+ mkdir -p $(dir $@)
+ echo $(ENV) > $@
endif
+# Install PHP dependencies.
vendor: composer.json composer.lock
- @echo "Installing PHP dependencies..."
- composer install $(if $(filter $(ENV),prod),--no-dev --prefer-dist,)
+ @echo Installing PHP dependencies...
+ composer install $(COMPOSER_FLAGS)
+# Install JS dependencies.
node_modules: package.json package-lock.json
- @echo "Installing JS dependencies..."
+ @echo Installing JS dependencies...
npm install --loglevel=error
+# Clean files generated by `make all`.
+.PHONY: clean
clean: buildclean
- @echo "Cleaning make artifacts..."
+ @echo Cleaning make artifacts...
rm -rf vendor
rm -rf node_modules
rm -rf VERSION
+# Clean files generated by `make dist`.
+.PHONY: distclean
distclean:
- @echo "Cleaning dist artifacts..."
+ @echo Cleaning dist artifacts...
rm -rf dist
+# Clean files generated by `make build`.
+.PHONY: buildclean
buildclean:
- @echo "Cleaning build artifacts..."
+ @echo Cleaning build artifacts...
rm -rf $(js_bundles)
rm -rf $(js_srcmaps)
-
+ rm -rf $(build_dir)
+
+# Touch files affected by the build environment to force the execution
+# of the corresponding targets.
+.PHONY: touch
+touch:
+ touch $(js_sources)
+ touch composer.json
+
+# Special (fake) target to always run a target but have Make consider
+# this updated if it was actually rewritten (a .PHONY target is always
+# considered new).
.FORCE: ;
-
-.PHONY: all build watch release sentryrelease .sentryrelease dist .dist clean distclean buildclean
diff --git a/composer.json b/composer.json
index 230c14e..7b7a74a 100644
--- a/composer.json
+++ b/composer.json
@@ -6,7 +6,9 @@
"altorouter/altorouter": "^1.2",
"jamesmoss/flywheel": "^0.5.2",
"league/plates": "^3.3",
- "michelf/php-markdown": "^1.8",
+ "michelf/php-markdown": "^1.8"
+ },
+ "require-dev": {
"sentry/sdk": "^2.0"
},
"autoload": {
diff --git a/composer.lock b/composer.lock
index 7523bfb..032b962 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
- "content-hash": "96e0ee3f2bc01b230b311421f62799f9",
+ "content-hash": "e05bfe26b073b9471312ec3c4fdd83fe",
"packages": [
{
"name": "altorouter/altorouter",
@@ -62,6 +62,165 @@
"time": "2015-11-30T00:47:43+00:00"
},
{
+ "name": "jamesmoss/flywheel",
+ "version": "0.5.2",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/jamesmoss/flywheel.git",
+ "reference": "869eced5f6b7b11599aa96b753e3540054ca85de"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/jamesmoss/flywheel/zipball/869eced5f6b7b11599aa96b753e3540054ca85de",
+ "reference": "869eced5f6b7b11599aa96b753e3540054ca85de",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3.2"
+ },
+ "require-dev": {
+ "mikey179/vfsstream": "1.2.0",
+ "mockery/mockery": "dev-master@dev",
+ "mustangostang/spyc": "0.5.*@dev",
+ "phpunit/phpunit": "3.7.*"
+ },
+ "suggest": {
+ "mustangostang/spyc": "You must install this if you're using the YAML or Markdown formatters."
+ },
+ "type": "library",
+ "autoload": {
+ "psr-0": {
+ "JamesMoss\\Flywheel\\": [
+ "src/",
+ "test/"
+ ]
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "James Moss",
+ "email": "james@moss.io",
+ "homepage": "http://moss.io"
+ }
+ ],
+ "description": "A lightweight, flat-file, document database",
+ "homepage": "http://github.com/jamesmoss/flywheel",
+ "keywords": [
+ "db",
+ "document",
+ "file",
+ "flat"
+ ],
+ "time": "2017-01-31T09:48:58+00:00"
+ },
+ {
+ "name": "league/plates",
+ "version": "3.3.0",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/thephpleague/plates.git",
+ "reference": "b1684b6f127714497a0ef927ce42c0b44b45a8af"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/thephpleague/plates/zipball/b1684b6f127714497a0ef927ce42c0b44b45a8af",
+ "reference": "b1684b6f127714497a0ef927ce42c0b44b45a8af",
+ "shasum": ""
+ },
+ "require": {
+ "php": "^5.3 | ^7.0"
+ },
+ "require-dev": {
+ "mikey179/vfsstream": "^1.4",
+ "phpunit/phpunit": "~4.0",
+ "squizlabs/php_codesniffer": "~1.5"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "3.0-dev"
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "League\\Plates\\": "src"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Jonathan Reinink",
+ "email": "jonathan@reinink.ca",
+ "role": "Developer"
+ }
+ ],
+ "description": "Plates, the native PHP template system that's fast, easy to use and easy to extend.",
+ "homepage": "http://platesphp.com",
+ "keywords": [
+ "league",
+ "package",
+ "templates",
+ "templating",
+ "views"
+ ],
+ "time": "2016-12-28T00:14:17+00:00"
+ },
+ {
+ "name": "michelf/php-markdown",
+ "version": "1.8.0",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/michelf/php-markdown.git",
+ "reference": "01ab082b355bf188d907b9929cd99b2923053495"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/michelf/php-markdown/zipball/01ab082b355bf188d907b9929cd99b2923053495",
+ "reference": "01ab082b355bf188d907b9929cd99b2923053495",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3.0"
+ },
+ "type": "library",
+ "autoload": {
+ "psr-4": {
+ "Michelf\\": "Michelf/"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "BSD-3-Clause"
+ ],
+ "authors": [
+ {
+ "name": "Michel Fortin",
+ "email": "michel.fortin@michelf.ca",
+ "homepage": "https://michelf.ca/",
+ "role": "Developer"
+ },
+ {
+ "name": "John Gruber",
+ "homepage": "https://daringfireball.net/"
+ }
+ ],
+ "description": "PHP Markdown",
+ "homepage": "https://michelf.ca/projects/php-markdown/",
+ "keywords": [
+ "markdown"
+ ],
+ "time": "2018-01-15T00:49:33+00:00"
+ }
+ ],
+ "packages-dev": [
+ {
"name": "clue/stream-filter",
"version": "v1.4.1",
"source": {
@@ -286,62 +445,6 @@
"time": "2018-07-31T19:32:56+00:00"
},
{
- "name": "jamesmoss/flywheel",
- "version": "0.5.2",
- "source": {
- "type": "git",
- "url": "https://github.com/jamesmoss/flywheel.git",
- "reference": "869eced5f6b7b11599aa96b753e3540054ca85de"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/jamesmoss/flywheel/zipball/869eced5f6b7b11599aa96b753e3540054ca85de",
- "reference": "869eced5f6b7b11599aa96b753e3540054ca85de",
- "shasum": ""
- },
- "require": {
- "php": ">=5.3.2"
- },
- "require-dev": {
- "mikey179/vfsstream": "1.2.0",
- "mockery/mockery": "dev-master@dev",
- "mustangostang/spyc": "0.5.*@dev",
- "phpunit/phpunit": "3.7.*"
- },
- "suggest": {
- "mustangostang/spyc": "You must install this if you're using the YAML or Markdown formatters."
- },
- "type": "library",
- "autoload": {
- "psr-0": {
- "JamesMoss\\Flywheel\\": [
- "src/",
- "test/"
- ]
- }
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "MIT"
- ],
- "authors": [
- {
- "name": "James Moss",
- "email": "james@moss.io",
- "homepage": "http://moss.io"
- }
- ],
- "description": "A lightweight, flat-file, document database",
- "homepage": "http://github.com/jamesmoss/flywheel",
- "keywords": [
- "db",
- "document",
- "file",
- "flat"
- ],
- "time": "2017-01-31T09:48:58+00:00"
- },
- {
"name": "jean85/pretty-package-versions",
"version": "1.2",
"source": {
@@ -393,107 +496,6 @@
"time": "2018-06-13T13:22:40+00:00"
},
{
- "name": "league/plates",
- "version": "3.3.0",
- "source": {
- "type": "git",
- "url": "https://github.com/thephpleague/plates.git",
- "reference": "b1684b6f127714497a0ef927ce42c0b44b45a8af"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/thephpleague/plates/zipball/b1684b6f127714497a0ef927ce42c0b44b45a8af",
- "reference": "b1684b6f127714497a0ef927ce42c0b44b45a8af",
- "shasum": ""
- },
- "require": {
- "php": "^5.3 | ^7.0"
- },
- "require-dev": {
- "mikey179/vfsstream": "^1.4",
- "phpunit/phpunit": "~4.0",
- "squizlabs/php_codesniffer": "~1.5"
- },
- "type": "library",
- "extra": {
- "branch-alias": {
- "dev-master": "3.0-dev"
- }
- },
- "autoload": {
- "psr-4": {
- "League\\Plates\\": "src"
- }
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "MIT"
- ],
- "authors": [
- {
- "name": "Jonathan Reinink",
- "email": "jonathan@reinink.ca",
- "role": "Developer"
- }
- ],
- "description": "Plates, the native PHP template system that's fast, easy to use and easy to extend.",
- "homepage": "http://platesphp.com",
- "keywords": [
- "league",
- "package",
- "templates",
- "templating",
- "views"
- ],
- "time": "2016-12-28T00:14:17+00:00"
- },
- {
- "name": "michelf/php-markdown",
- "version": "1.8.0",
- "source": {
- "type": "git",
- "url": "https://github.com/michelf/php-markdown.git",
- "reference": "01ab082b355bf188d907b9929cd99b2923053495"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/michelf/php-markdown/zipball/01ab082b355bf188d907b9929cd99b2923053495",
- "reference": "01ab082b355bf188d907b9929cd99b2923053495",
- "shasum": ""
- },
- "require": {
- "php": ">=5.3.0"
- },
- "type": "library",
- "autoload": {
- "psr-4": {
- "Michelf\\": "Michelf/"
- }
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "BSD-3-Clause"
- ],
- "authors": [
- {
- "name": "Michel Fortin",
- "email": "michel.fortin@michelf.ca",
- "homepage": "https://michelf.ca/",
- "role": "Developer"
- },
- {
- "name": "John Gruber",
- "homepage": "https://daringfireball.net/"
- }
- ],
- "description": "PHP Markdown",
- "homepage": "https://michelf.ca/projects/php-markdown/",
- "keywords": [
- "markdown"
- ],
- "time": "2018-01-15T00:49:33+00:00"
- },
- {
"name": "ocramius/package-versions",
"version": "1.4.0",
"source": {
@@ -1583,7 +1585,6 @@
"time": "2019-10-10T17:38:20+00:00"
}
],
- "packages-dev": [],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": [],
diff --git a/index.php b/index.php
index 1c197f6..13f7bfa 100644
--- a/index.php
+++ b/index.php
@@ -13,24 +13,32 @@ require('./vendor/autoload.php');
$app = new Wcms\Application();
$app->wakeup();
-Sentry\init([
- 'dsn' => Wcms\Config::sentrydsn(),
- 'release' => getversion(),
- 'project_root' => 'app',
-]);
-Sentry\configureScope(function (Sentry\State\Scope $scope): void {
- $scope->setUser([
- 'id' => Wcms\Config::url(),
- 'username' => Wcms\Config::basepath(),
+try {
+ Sentry\init([
+ 'dsn' => Wcms\Config::sentrydsn(),
+ 'release' => getversion(),
+ 'project_root' => 'app',
]);
-});
+ Sentry\configureScope(function ($scope) {
+ $scope->setUser([
+ 'id' => Wcms\Config::url(),
+ 'username' => Wcms\Config::basepath(),
+ ]);
+ });
+} catch (Throwable $th) {
+ // No problem: Sentry is optionnal
+}
try {
$matchoper = new Wcms\Routes();
$matchoper->match();
} catch (Exception $e) {
- Sentry\captureException($e);
+ try {
+ Sentry\captureException($e);
+ } catch (Throwable $th) {
+ // No problem: Sentry is optionnal
+ }
echo '<h1>⚠ Woops ! There is a little problem : </h1>', $e->getMessage(), "\n";
}
diff --git a/webpack.config.js b/webpack.config.js
index 02d9318..8cd7764 100644
--- a/webpack.config.js
+++ b/webpack.config.js
@@ -5,7 +5,11 @@ module.exports = (env) => {
return {
// Environment dependent
mode: env == 'dev' ? 'development' : 'production',
- devtool: env == 'dev' ? 'cheap-eval-source-map' : 'source-map',
+ devtool: env == 'dev' ?
+ 'cheap-eval-source-map' :
+ env == 'dist' ?
+ 'hidden-source-map' :
+ 'source-map',
stats: env == 'dev' ? {} : { warnings: false },
// Constant