forked from xdan/jodit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
314 lines (262 loc) · 9.08 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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
cwd := $(dir $(mkfile_path))
pwd := $(shell pwd)
build ?= es2015
devMode ?= development
generateTypes ?= false
es ?= es2015
uglify ?= true
browsers ?= FirefoxHeadless
includeLanguages ?= ''
excludeLanguages ?= ''
includePlugins ?= ''
excludePlugins ?= ''
singleRun ?= true
isTest ?= false
debug ?= false
updateTests ?= false
fat ?= false
push ?= true
outputFolder ?= ''
version = $(shell cat package.json | ./node_modules/node-jq/bin/jq -r '.version')
WEBPACK_DEV_PORT := 2000
ACTIONS_URL := https://github.com/xdan/jodit/actions/
BUILD_DTS := true
BUILD_ESM := true
UGLIFY_ESM := false
CHANGELOG_URL := https://github.com/xdan/jodit/blob/main/CHANGELOG.md
NODE_MODULES_BIN := ./node_modules/.bin
TS_NODE_BASE := $(NODE_MODULES_BIN)/ts-node --project $(cwd)tools/tsconfig.json
TSX_BASE := $(NODE_MODULES_BIN)/tsx
WEBPACK := $(TS_NODE_BASE) $(NODE_MODULES_BIN)/webpack
KARMA := @TS_NODE_TRANSPILE_ONLY=true $(TS_NODE_BASE) $(NODE_MODULES_BIN)/karma start
.PHONY: update
update:
@npm update
.PHONY: version
version:
@echo $(version)
@echo super_cwd: $(cwd)
@echo cwd: $(shell pwd)
.PHONY: start dev love
start dev love:
@WEBPACK_DEV_PORT=$(WEBPACK_DEV_PORT) $(WEBPACK) serve --progress --mode $(devMode) \
--env stat=true \
--env es=$(es) \
--env uglify=$(uglify) \
--env includeLanguages=$(includeLanguages) \
--env excludeLanguages=$(excludeLanguages) \
--env includePlugins=$(includePlugins) \
--env excludePlugins=$(excludePlugins) \
--env isTest=$(isTest) \
--env fat=$(fat)
.PHONY: build
build:
@TS_NODE_TRANSPILE_ONLY=true $(WEBPACK) --progress --mode production \
--env stat=true \
--env es=$(es) \
--env uglify=$(uglify) \
--env isTest=$(isTest) \
--env includeLanguages=$(includeLanguages) \
--env excludeLanguages=$(excludeLanguages) \
--env includePlugins=$(includePlugins) \
--env excludePlugins=$(excludePlugins) \
--env outputFolder=$(outputFolder) \
--env fat=$(fat) \
--env generateTypes=$(generateTypes)
.PHONY: clean
clean:
@echo Clean cache and build folder ...
@rm -rf $(pwd)/node_modules/.cache && rm -rf $(pwd)/build/*
.PHONY: dts
ifeq ($(BUILD_DTS), true)
dts:
@echo Prepare types ...
@mkdir -p ./build/types/types
@cp -R ./tsconfig.json ./build/types/
@echo 'Copy declarations ...';
@$(TS_NODE_BASE) $(cwd)/tools/utils/copy-declaration-files-to-esm-build.ts $(pwd)/src/ $(pwd)/build/types ;
@if [ -d ./build/types/node_modules/jodit ]; then \
echo "Remove super types ..."; \
rm -rf ./build/types/node_modules/; \
fi;
@if [ -d ./build/types/src ]; then \
echo "Normalize self types ..."; \
cp -R ./build/types/src/* ./build/types/; \
rm -rf ./build/types/src/; \
fi;
@$(TS_NODE_BASE) $(cwd)tools/utils/resolve-alias-imports.ts --cwd=./build/types --mode=dts --ver=$(version)
@$(NODE_MODULES_BIN)/replace "import .+.(less|svg)('|\");" '' ./build/types -r --include='*.d.ts' --silent
@if [ -d ./build/esm ]; then \
echo "Copy types to esm folder ..."; \
cp -R ./build/types/* ./build/esm; \
fi
else
dts:
@echo "Types not yet available"
endif
.PHONY: esm
ifeq ($(BUILD_ESM), true)
esm:
@echo 'Build esm modules ...' $(BUILD_ESM)
rm -rf $(pwd)/build/esm
tsc -p $(pwd)/tsconfig.esm.json --rootDir $(pwd)/src --importHelpers false --allowJs true --checkJs false --excludeDirectories $(pwd)/node_modules --module es2020 --target es2020 --removeComments false --sourceMap false --outDir $(pwd)/build/esm
@echo 'Remove style imports ...'
@$(NODE_MODULES_BIN)/replace "import .+\.(less|css)('|\");" '' $(pwd)/build/esm -r --silent
echo 'Resolve alias imports ...'
$(TS_NODE_BASE) $(cwd)tools/utils/resolve-alias-imports.ts --cwd=$(pwd)/build/esm --mode=esm --ver=$(version)
@if [ -d "$(pwd)/src/langs" ]; then\
echo 'Copy langs ...'; \
rsync -r --exclude '*.test.js' $(pwd)/src/langs/*.js $(pwd)/build/esm/langs ;\
$(NODE_MODULES_BIN)/replace "module.exports = " "export default " $(pwd)/build/esm/ -r --silent; \
fi
@echo 'Copy icons ...'
@$(TS_NODE_BASE) $(cwd)/tools/utils/copy-icons-in-esm.ts $(pwd)/src/ $(pwd)/build/esm
@if [ "$(UGLIFY_ESM)" = "true" ]; then \
echo 'Uglify esm modules ...'; \
find "$(pwd)/build/esm" -name "*.js" | while read fname; do \
$(NODE_MODULES_BIN)/terser "$$fname" -o "$$fname" --compress passes=5,ecma=2020 --mangle --keep-classnames --keep-fnames --module; \
done \
fi;
else
esm:
@echo "ESM build not yet available"
endif
.PHONY: check-esm-build
check-esm-build:
@echo 'Check esm modules ...'
@$(TSX_BASE) $(cwd)/tools/check-esm-build.ts
.PHONY: build-all
build-all:
make clean
@mkdir -p $(pwd)/build/
@$(TS_NODE_BASE) $(cwd)tools/utils/prepare-publish.ts $(pwd)
@$(NODE_MODULES_BIN)/replace "4\.0\.1\.\d+" "$(version)" $(pwd)/build/README.md --silent
@echo 'Build esm ...'
make esm
@echo 'Build types ...'
make build es=es2018 uglify=false generateTypes=$(BUILD_DTS)
make dts
@echo 'Builds ...'
make build es=es2018
make build es=es2018 uglify=true fat=true
make build es=es2015
make build es=es2015 uglify=false
make build es=es2015 uglify=true fat=true
make build es=es2021
make build es=es2021 uglify=false
make build es=es2021 uglify=true fat=true
make build es=es5
make build es=es5 uglify=false
make build es=es5 uglify=true fat=true
make build es=es2021 includeLanguages=en
make build es=es2021 includeLanguages=en uglify=false
make build es=es2021 includeLanguages=en uglify=true fat=true
.PHONY: test-all
test-all:
make test-only-run build=es2021 uglify=$(uglify) fat=$(fat)
make test-only-run build=es2018 uglify=$(uglify) fat=$(fat)
make test-only-run build=es2015 uglify=$(uglify) fat=$(fat)
make test-only-run build=es5 uglify=$(uglify) fat=$(fat)
.PHONY: lint
lint:
$(NODE_MODULES_BIN)/tsc --noemit --noErrorTruncation
$(NODE_MODULES_BIN)/eslint ./src/ ./test/
$(NODE_MODULES_BIN)/stylelint ./src/**/**.less
.PHONY: fix
fix:
$(NODE_MODULES_BIN)/eslint ./src/ ./test/ --fix
make prettify
prettify:
$(NODE_MODULES_BIN)/prettier --write ./src/*.{ts,less} ./src/**/*.{ts,less} ./src/**/**/*.{ts,less} ./src/**/**/**/*.{ts,less} ./src/**/**/**/**/*.{ts,less}
.PHONY: test
test:
make test-find
make clean
make build es=$(es) uglify=$(uglify) isTest=true fat=$(fat)
make test-only-run build=$(es) uglify=$(uglify) fat=$(fat) browsers=$(browsers)
.PHONY: test-find find-test
test-find find-test:
$(TS_NODE_BASE) $(cwd)tools/utils/find-tests.ts
.PHONY: test-only-run test-run-only
test-only-run test-run-only:
$(KARMA) --browsers $(browsers) $(cwd)tools/karma.conf.ts --single-run $(singleRun) --build=$(build) --min=$(uglify) --fat=$(fat) --cwd=$(pwd)
.PHONY: coverage
coverage:
npx --yes type-coverage ./src --detail --ignore-files 'build/**' --ignore-files 'test/**' --ignore-files 'examples/**'
.PHONY: screenshots-update
screenshots-update:
make build es=es2021 fat=true uglify=true
make screenshots-build-image
make screenshots-test es=es2021 fat=true min=true updateTests=true
.PHONY: screenshots-all
screenshots-all:
make screenshots-build-image
make screenshots-test build=es5 fat=true min=true
make screenshots-test build=es2015 fat=true min=true
make screenshots-test build=es2018 fat=true min=true
make screenshots-test build=es2021 fat=true min=true
.PHONY: screenshots-test
screenshots-test:
docker run --ipc=host \
-p 9323:9323 \
-v $(shell pwd)/build:/app/build/ \
-v $(shell pwd)/test:/app/test/ \
-v $(shell pwd)/src:/app/src/ \
-v $(shell pwd)/tools:/app/tools/ \
-v $(shell pwd)/tools:/app/tools/ \
-v $(shell pwd)/playwright-report:/app/playwright-report/ \
-v $(shell pwd)/playwright.config.ts:/app/playwright.config.ts \
-e BUILD=$(es) \
-e MIN=$(uglify) \
-e FAT=$(fat) \
jodit-screenshots \
npx playwright test --update-snapshots
.PHONY: screenshots-build-image
screenshots-build-image:
docker build -t jodit-screenshots -f test/screenshots/Dockerfile .
.PHONY: newversion
newversion:
npm version patch --no-git-tag-version
#npm version prerelease --preid=beta --no-git-tag-version
make newversion-git
.PHONY: newversion-git
newversion-git:
git config user.name "xdan"
git config user.email "[email protected]"
git add --all && git commit -m "New version $(version) Read more $(CHANGELOG_URL)"
git tag $(version)
@if [ "$(push)" = "true" ]; then \
git push --tags origin HEAD:main;\
fi
@echo "New version $(version) Actions: $(ACTIONS_URL)"
.PHONY: jodit
jodit:
cd ../jodit-react/
npm update
npm run newversion
cd ../jodit-pro
npm run newversion
cd ../jodit-joomla
npm run newversion
.PHONY: sync
sync:
$(TS_NODE_BASE) $(cwd)tools/utils/sync.ts --source $(cwd) --target ../jodit-pro/node_modules/jodit
.PHONY: examples
examples:
@echo "Copy build to examples"
@if [ -d ./examples/build ]; then rm -rf ./examples/build; fi;
@mkdir -p ./examples/build
@cp -R ./build/* ./examples/build
@$(NODE_MODULES_BIN)/replace '../build' './build' ./examples -r --include='*.html'
.PHONY: esm-t
esm-t:
make clean
@echo 'Build esm ...'
make esm
@echo 'Build types ...'
make build es=es2018 uglify=false generateTypes=true
make dts
rm -rf ../jodit-examples/node_modules/jodit/esm
mkdir ../jodit-examples/node_modules/jodit/esm
cp -R ./build/esm/* ../jodit-examples/node_modules/jodit/esm