forked from Automattic/simplenote-electron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
170 lines (122 loc) · 3.61 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
ifeq ($(OS),Windows_NT)
FILE_PATH_SEP := \\
IS_WINDOWS := true
else
FILE_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 ?= $(NODE) $(shell which npm)
NPM_BIN = $(shell npm bin)
RED=`tput setaf 1`
RESET=`tput sgr0`
SIMPLENOTE_JS := $(THIS_DIR)/dist/app.js
SIMPLENOTE_CHANGES_STD := `find "$(THIS_DIR)" -newer "$(SIMPLENOTE_JS)" \( -name "*.js" -o -name "*.jsx" -o -name "*.json" -o -name "*.scss" \) -type f -print -quit | grep -v .min. | wc -l`
SIMPLENOTE_BRANCH = $(shell git --git-dir .git branch | sed -n -e 's/^\* \(.*\)/\1/p')
##############
# SIMPLENOTE #
##############
# Node environment
NODE_ENV ?= production
# Defines if we should compile web app via `build` target
SKIP_BUILD ?= false
# Host for dev server
HOST ?= 0.0.0.0
# Port for dev server
PORT ?= 4000
### TODO: changes for HOST and PORT aren't yet reflected in `desktop/app.js`
# Access dev server or locally built web app files
DEV_SERVER ?= false
# electron-builder publish option
# options: always|onTag|onTagOrDraft|never
PUBLISH ?= onTag
# Main targets
.PHONY: start
start: rebuild-deps
@NODE_ENV=$(NODE_ENV) DEV_SERVER=$(DEV_SERVER) npx electron .
.PHONY: dev
dev:
@npx misty
.PHONY: dev-server
dev-server:
@$(MAKE) build NODE_ENV=$(NODE_ENV)
@NODE_ENV=$(NODE_ENV) npx webpack-dev-server --config ./webpack.config.js --content-base dist --host $(HOST) --port $(PORT) --hot
.PHONY: test
test:
@npx jest
# Build web app
.PHONY: build
build:
ifeq ($(SKIP_BUILD),false)
@echo "Building Simplenote Desktop on branch $(RED)$(SIMPLENOTE_BRANCH)$(RESET)"
# IS_PRODUCTION is a helper var for the inline conditional in `build-app`
ifeq ($(NODE_ENV),production)
$(eval IS_PRODUCTION = true)
endif
@$(MAKE) build-app NODE_ENV=$(NODE_ENV) IS_PRODUCTION=$(IS_PRODUCTION)
endif
# Build utils
.PHONY: build-app
build-app:
@NODE_ENV=$(NODE_ENV) npx webpack $(if $(IS_PRODUCTION),-p) --config ./webpack.config.js
.PHONY: build-if-not-exists
build-if-not-exists: config.json
@if [ -f $(SIMPLENOTE_JS) ]; then true; else make build; fi
.PHONY: build-if-changed
build-if-changed: build-if-not-exists
@if [ $(SIMPLENOTE_CHANGES_STD) -eq 0 ]; then true; else make build; fi;
# Build binaries only
.PHONY: osx
osx: config-release build-if-changed
@npx electron-builder -m --dir
.PHONY: linux
linux: config-release build-if-changed
@npx electron-builder -l --dir
.PHONY: win32
win32: config-release build-if-changed
@npx electron-builder -w --dir
# Build installers
.PHONY: package
package: build-if-changed
.PHONY: package-win32
package-win32:
ifeq ($(IS_WINDOWS),true)
@echo Building .appx as well
@npx electron-builder --win -p $(PUBLISH) --config=./electron-builder-appx.json
else
@echo Skipping .appx as we are not on a Windows host
@npx electron-builder --win -p $(PUBLISH)
endif
.PHONY: package-osx
package-osx: build-if-changed
@npx electron-builder --mac -p $(PUBLISH)
.PHONY: package-linux
package-linux: build-if-changed
@npx electron-builder --linux -p $(PUBLISH)
# NPM
.PHONY:
install: node_modules
node_modules/%:
@npm install $(notdir $@)
node_modules: package.json
@npm prune
@npm install
@touch node_modules
# Checks
config.json:
ifeq (,$(wildcard $(THIS_DIR)$/config.json))
$(error config.json not found. Required file, see docs)
endif
# Utils
.PHONY: config-release
config-release: config.json install
.PHONY: rebuild-deps
rebuild-deps:
@npx electron-rebuild
.PHONY: format
format:
@npx prettier --write {desktop,lib,sass}/{**/,*}.{js,json,jsx,sass}
.PHONY: lint
lint:
@npx eslint --ext .js --ext .jsx lib