Skip to content

Commit

Permalink
Optimize/cleanup makefile (#467)
Browse files Browse the repository at this point in the history
* Create desktop config in makefile

* set default target

* build for host OS by default

* Use OS sensitive path separator

* Stringify config object

* Merge build-desktop and desktop-dev

* Clean up/merge secrets and secret-clientid

* Revert "Try bashrc file for shared setup (#466)"

This reverts commit 6af9475.

* Fix $(/)

* Avoid using .nvmrc as a source to get nodejs version

* Fix env check

Removing BASE and ENV as a target dependency as it doesn't make a difference since it's a PHONY target.

* Match 10.5.0 and v10.5.0 node versions (#473)

The .nvmrc file in Calypso may be any version-ish nvm string.

Allow version matching test to match 10.5.0 and v10.5.0.

`node --version` prints `v10.5.0`.

Ensure the `node --version` output matches `10.5.0` from .nvmrc.

* Update secrets.md docs to recommend a Type: native OAuth token (#474)

* Update secrets.md docs to recommend a Type: native OAuth token

Native is appropriate for a Electron desktop app, as the "secret" is public -- can be extracted by anyone who downloads the app.

* Updated readme on how to build the app from this repo

* Update documentation for new build process

* Upgrade Babel to 7.0.0 beta 53 (#477)

This patch upgrades Babel to 7.0.0 beta 53 and adds a `babel.config.js` file.

The config file uses Babel Env Preset to specify a compilation target (Electron) and
is used to compile the `wp-desktop` files and also the `calypso/server` ones that are
included by `desktop/server/server.js`.

With `babel.config.js`, Babel will no longer load `calypso/.babelrc.js`, so the desired
config needs to be specified by the parent project.

This patch is a prerequisite to upgrading Babel in Calypso, too.

* Create desktop config in makefile

* set default target

* build for host OS by default

* Use OS sensitive path separator

* Stringify config object

* Merge build-desktop and desktop-dev

* Clean up/merge secrets and secret-clientid

* Fix $(/)

* Avoid using .nvmrc as a source to get nodejs version

* Fix env check

Removing BASE and ENV as a target dependency as it doesn't make a difference since it's a PHONY target.

* Fix messed up rebase
  • Loading branch information
adlk committed Jul 30, 2018
1 parent bc19ccd commit 123471d
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 80 deletions.
95 changes: 46 additions & 49 deletions Makefile
@@ -1,9 +1,13 @@
ifeq ($(OS),Windows_NT)
ENV_PATH_SEP := ;
FILE_PATH_SEP := \
ENV_PATH_SEP := ;
else
ENV_PATH_SEP := :
FILE_PATH_SEP := /
ENV_PATH_SEP := :
endif

/ = $(FILE_PATH_SEP)

THIS_MAKEFILE_PATH := $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
THIS_DIR := $(shell cd $(dir $(THIS_MAKEFILE_PATH));pwd)
NPM_BIN_DIR = $(shell npm bin)
Expand All @@ -21,13 +25,16 @@ CHECKMARK = ✓
CONFIG_ENV =
CALYPSO_ENV = desktop
NODE_ENV = production
BUILD_PLATFORM = mwl
BUILD_PLATFORM =
DEBUG =
TEST_PRODUCTION_BINARY = false

# Set default target
.DEFAULT_GOAL := build

# Build sources
# TODO: run tasks parallel when in dev mode
build-source: checks build-config build-calypso build-desktop
build-source: checks desktop$/config.json build-calypso build-desktop
@echo "$(CYAN)$(CHECKMARK) All parts built$(RESET)"

# Start app
Expand All @@ -40,33 +47,39 @@ start:
dev-server: CONFIG_ENV = development
dev-server: CALYPSO_ENV = desktop-development
dev-server: NODE_ENV = development
dev-server: checks
dev-server: checks desktop$/config.json
@echo "\n\n$(GREEN)+------------------------------------------------+"
@echo "| |"
@echo "| Wait for calypso to start the dev server |"
@echo "| and start the app with \`make dev\` |"
@echo "| |"
@echo "+------------------------------------------------+$(RESET)\n\n"

@$(MAKE) build-config CONFIG_ENV=$(CONFIG_ENV)


@npx concurrently -k \
-n "Calypso,Desktop" \
"$(MAKE) calypso-dev NODE_ENV=$(NODE_ENV) CALYPSO_ENV=$(CALYPSO_ENV)" \
"wait-on http://localhost:3000 && $(MAKE) desktop-dev NODE_ENV=$(NODE_ENV)" \
"wait-on http://localhost:3000 && $(MAKE) build-desktop NODE_ENV=$(NODE_ENV)" \

# Start app in dev mode
dev: NODE_ENV = development
dev: DEBUG = desktop:*
dev:
$(MAKE) start NODE_ENV=$(NODE_ENV) DEBUG=$(DEBUG)

# Build config
build-config:
@node $(THIS_DIR)/resource/build-scripts/build-config-file.js $(CONFIG_ENV)

@echo "$(CYAN)$(CHECKMARK) Config created$(RESET)"
BASE_CONFIG := $(THIS_DIR)/desktop-config/config-base.json
ENV_CONFIG := $(THIS_DIR)/desktop-config/config-$(CONFIG_ENV).json

.PHONY: desktop$/config.json
desktop$/config.json:
ifeq (,$(wildcard $(ENV_CONFIG)))
$(warning Config file for environment "$(CONFIG_ENV)" does not exist. Ignoring environment.)
else
$(eval EXTENDED = true)
endif
@node -e "const base = require('$(BASE_CONFIG)'); let env; try { env = require('$(ENV_CONFIG)'); } catch(err) {} console.log( JSON.stringify( Object.assign( base, env ), null, 2 ) )" > $@

@echo "$(GREEN)$(CHECKMARK) Config built $(if $(EXTENDED),(extended: config-$(CONFIG_ENV).json),)$(RESET)"

# Build calypso bundle
build-calypso:
Expand All @@ -82,15 +95,13 @@ calypso-dev:

# Build desktop bundle
build-desktop:
@NODE_ENV=$(NODE_ENV) NODE_PATH=calypso/server$(ENV_PATH_SEP)calypso/client CALYPSO_SERVER=true npx webpack --config $(THIS_DIR)/webpack.config.js

@echo "$(CYAN)$(CHECKMARK) Desktop built$(RESET)"
ifeq ($(NODE_ENV),development)
@echo "$(CYAN)$(CHECKMARK) Starting Desktop Server...$(RESET)"
endif

# Build and watch desktop scripts
desktop-dev:
@echo "$(CYAN)Starting Desktop Server...$(RESET)"
@NODE_ENV=$(NODE_ENV) NODE_PATH=calypso$/server$(ENV_PATH_SEP)calypso$/client CALYPSO_SERVER=true npx webpack --config $(THIS_DIR)$/webpack.config.js

@NODE_ENV=$(NODE_ENV) NODE_PATH=calypso/server$(ENV_PATH_SEP)calypso/client CALYPSO_SERVER=true npx webpack --watch --config $(THIS_DIR)/webpack.config.js
@echo "$(CYAN)$(CHECKMARK) Desktop built$(RESET)"

# Package App
package:
Expand All @@ -102,32 +113,18 @@ package:
build: build-source package

# Perform checks
checks: check-node-version-parity secret secret-clientid
checks: check-node-version-parity secret

# Check for secrets.json

# Check for secret and confirm proper clientid for production release
secret:
@if [ "$(CONFIG_ENV)" = "release" ] && [ ! -f $(CALYPSO_DIR)/config/secrets.json ]; \
then { \
if [ -z "${CIRCLECI}" ]; \
then { \
echo "$(RED)x calypso/config/secrets.json not found. Required file, see docs/secrets.md$(RESET)"; \
exit 1; \
} \
fi; \
} \
fi;


CLIENT_ID := $(shell node -p "require('$(CALYPSO_DIR)/config/secrets.json').desktop_oauth_client_id")

# Confirm proper clientid for production release
secret-clientid:
@if [ "$(CONFIG_ENV)" = "release" ] && [ ! $(CLIENT_ID) = "43452" ]; \
then { \
echo "$(RED)x calypso/config/secrets.json, \"desktop_oauth_client_id\" must be \"43452\" $(RESET)"; \
exit 1; \
} \
fi;
ifneq (,$(wildcard $(CALYPSO_DIR)$/config$/secrets.json))
ifneq (43452,$(shell node -p "require('$(CALYPSO_DIR)$/config$/secrets.json').desktop_oauth_client_id"))
$(error "desktop_oauth_client_id" must be "43452" in $(CALYPSO_DIR)$/config$/secrets.json)
endif
else
$(error $(CALYPSO_DIR)$/config$/secrets.json does not exist)
endif


# Sed to strip leading v to ensure 'v1.2.3' and '1.2.3' can match.
Expand All @@ -144,18 +141,18 @@ else
endif

test: CONFIG_ENV = test
test: build-config
test:
@echo "$(CYAN)$(CHECKMARK) Starting test...$(RESET)"

@TEST_PRODUCTION_BINARY=$(TEST_PRODUCTION_BINARY) npx xvfb-maybe mocha --compilers js:babel-core/register ./test
@TEST_PRODUCTION_BINARY=$(TEST_PRODUCTION_BINARY) npx xvfb-maybe mocha --compilers js:babel-core$/register .$/test

distclean: clean
@cd calypso; npm run distclean
@rm -rf ./node_modules
@rm -rf .$/node_modules

clean:
@cd calypso; npm run clean
@rm -rf ./release
@rm -rf ./build
@rm -rf .$/release
@rm -rf .$/build

.PHONY: test build-sources
31 changes: 0 additions & 31 deletions resource/build-scripts/build-config-file.js

This file was deleted.

0 comments on commit 123471d

Please sign in to comment.