Skip to content

Commit d54df81

Browse files
committed
Add Cockpit Starter Kit infrastructure
* Based on commit b2379f78.
1 parent 1ace680 commit d54df81

21 files changed

+8050
-11915
lines changed

web/.babelrc.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"presets": [
3+
["@babel/env", {
4+
"targets": {
5+
"chrome": "57",
6+
"firefox": "52",
7+
"safari": "10.3",
8+
"edge": "16",
9+
"opera": "44"
10+
}
11+
}],
12+
"@babel/preset-react"
13+
]
14+
}

web/.eslintignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
src/lib/cockpit.js
1+
node_modules/*
2+
src/lib/*

web/.eslintrc.json

Lines changed: 48 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,52 @@
11
{
2-
"env": {
3-
"browser": true,
4-
"es2021": true,
5-
"jest": true
6-
},
7-
"extends": [
8-
"eslint:recommended",
9-
"plugin:react/recommended",
10-
"plugin:prettier/recommended"
11-
],
12-
"parserOptions": {
13-
"ecmaFeatures": {
14-
"jsx": true
2+
"root": true,
3+
"env": {
4+
"browser": true,
5+
"es6": true
156
},
16-
"ecmaVersion": "latest",
17-
"sourceType": "module"
18-
},
19-
"plugins": ["react"],
20-
"rules": {
21-
"react/prop-types": ["off"]
22-
},
23-
"settings": {
24-
"react": {
25-
"version": "detect"
7+
"extends": ["eslint:recommended", "standard", "standard-jsx", "standard-react"],
8+
"parser": "@babel/eslint-parser",
9+
"parserOptions": {
10+
"ecmaVersion": "7",
11+
"ecmaFeatures": {
12+
"jsx": true
13+
},
14+
"sourceType": "module"
15+
},
16+
"plugins": ["flowtype", "react", "react-hooks"],
17+
"rules": {
18+
"indent": ["error", 4,
19+
{
20+
"ObjectExpression": "first",
21+
"CallExpression": {"arguments": "first"},
22+
"MemberExpression": 2,
23+
"ignoredNodes": [ "JSXAttribute" ]
24+
}],
25+
"newline-per-chained-call": ["error", { "ignoreChainWithDepth": 2 }],
26+
"no-var": "error",
27+
"lines-between-class-members": ["error", "always", { "exceptAfterSingleLine": true }],
28+
"prefer-promise-reject-errors": ["error", { "allowEmptyReject": true }],
29+
"react/jsx-indent": ["error", 4],
30+
"semi": ["error", "always", { "omitLastInOneLineBlock": true }],
31+
32+
"react-hooks/rules-of-hooks": "error",
33+
"react-hooks/exhaustive-deps": "error",
34+
35+
"camelcase": "off",
36+
"comma-dangle": "off",
37+
"curly": "off",
38+
"jsx-quotes": "off",
39+
"key-spacing": "off",
40+
"no-console": "off",
41+
"quotes": "off",
42+
"react/jsx-curly-spacing": "off",
43+
"react/jsx-indent-props": "off",
44+
"react/prop-types": "off",
45+
"space-before-function-paren": "off",
46+
"standard/no-callback-literal": "off"
47+
},
48+
"globals": {
49+
"require": false,
50+
"module": false
2651
}
27-
}
2852
}

web/.gitignore

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,18 @@
1-
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2-
3-
# dependencies
4-
/node_modules
5-
/.pnp
6-
.pnp.js
7-
8-
# testing
9-
/coverage
10-
11-
# production
12-
/dist
13-
14-
# misc
15-
.DS_Store
16-
.env.local
17-
.env.development.local
18-
.env.test.local
19-
.env.production.local
20-
21-
npm-debug.log*
22-
yarn-debug.log*
23-
yarn-error.log*
24-
25-
# Web interface logs directory
26-
.log
1+
*~
2+
*.retry
3+
*.tar.xz
4+
*.rpm
5+
node_modules/
6+
dist/
7+
/*.spec
8+
/.vagrant
9+
package-lock.json
10+
Test*FAIL*
11+
/bots
12+
test/common/
13+
test/images/
14+
# src/lib/
15+
*.pot
16+
POTFILES*
17+
tmp/
18+
/po/LINGUAS

web/Makefile

Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
# extract name from package.json
2+
PACKAGE_NAME := $(shell awk '/"name":/ {gsub(/[",]/, "", $$2); print $$2}' package.json)
3+
RPM_NAME := cockpit-$(PACKAGE_NAME)
4+
VERSION := $(shell T=$$(git describe 2>/dev/null) || T=1; echo $$T | tr '-' '.')
5+
ifeq ($(TEST_OS),)
6+
TEST_OS = centos-8-stream
7+
endif
8+
export TEST_OS
9+
TARFILE=$(RPM_NAME)-$(VERSION).tar.xz
10+
NODE_CACHE=$(RPM_NAME)-node-$(VERSION).tar.xz
11+
SPEC=$(RPM_NAME).spec
12+
APPSTREAMFILE=org.cockpit-project.$(PACKAGE_NAME).metainfo.xml
13+
VM_IMAGE=$(CURDIR)/test/images/$(TEST_OS)
14+
# stamp file to check if/when npm install ran
15+
NODE_MODULES_TEST=package-lock.json
16+
# one example file in dist/ from webpack to check if that already ran
17+
WEBPACK_TEST=dist/manifest.json
18+
# one example file in src/lib to check if it was already checked out
19+
LIB_TEST=src/lib/cockpit-po-plugin.js
20+
# common arguments for tar, mostly to make the generated tarballs reproducible
21+
TAR_ARGS = --sort=name --mtime "@$(shell git show --no-patch --format='%at')" --mode=go=rX,u+rw,a-s --numeric-owner --owner=0 --group=0
22+
23+
all: $(WEBPACK_TEST)
24+
25+
#
26+
# i18n
27+
#
28+
29+
LINGUAS=$(basename $(notdir $(wildcard po/*.po)))
30+
31+
po/$(PACKAGE_NAME).js.pot:
32+
xgettext --default-domain=$(PACKAGE_NAME) --output=$@ --language=C --keyword= \
33+
--keyword=_:1,1t --keyword=_:1c,2,2t --keyword=C_:1c,2 \
34+
--keyword=N_ --keyword=NC_:1c,2 \
35+
--keyword=gettext:1,1t --keyword=gettext:1c,2,2t \
36+
--keyword=ngettext:1,2,3t --keyword=ngettext:1c,2,3,4t \
37+
--keyword=gettextCatalog.getString:1,3c --keyword=gettextCatalog.getPlural:2,3,4c \
38+
--from-code=UTF-8 $$(find src/ \( -name '*.js' -o -name '*.jsx' \) \! -path 'src/lib/*')
39+
40+
po/$(PACKAGE_NAME).html.pot: $(NODE_MODULES_TEST)
41+
po/html2po -o $@ $$(find src -name '*.html' \! -path 'src/lib/*')
42+
43+
po/$(PACKAGE_NAME).manifest.pot: $(NODE_MODULES_TEST)
44+
po/manifest2po src/manifest.json -o $@
45+
46+
po/$(PACKAGE_NAME).metainfo.pot: $(APPSTREAMFILE)
47+
xgettext --default-domain=$(PACKAGE_NAME) --output=$@ $<
48+
49+
po/$(PACKAGE_NAME).pot: po/$(PACKAGE_NAME).html.pot po/$(PACKAGE_NAME).js.pot po/$(PACKAGE_NAME).manifest.pot po/$(PACKAGE_NAME).metainfo.pot
50+
msgcat --sort-output --output-file=$@ $^
51+
52+
po/LINGUAS:
53+
echo $(LINGUAS) | tr ' ' '\n' > $@
54+
55+
# Update translations against current PO template
56+
update-po: po/$(PACKAGE_NAME).pot
57+
for lang in $(LINGUAS); do \
58+
msgmerge --output-file=po/$$lang.po po/$$lang.po $<; \
59+
done
60+
61+
#
62+
# Build/Install/dist
63+
#
64+
65+
%.spec: packaging/%.spec.in
66+
sed -e 's/%{VERSION}/$(VERSION)/g' $< > $@
67+
68+
$(WEBPACK_TEST): $(NODE_MODULES_TEST) $(LIB_TEST) $(shell find src/ -type f) package.json webpack.config.js
69+
NODE_ENV=$(NODE_ENV) node_modules/.bin/webpack
70+
71+
watch:
72+
NODE_ENV=$(NODE_ENV) node_modules/.bin/webpack --watch
73+
74+
clean:
75+
rm -rf dist/
76+
rm -f $(SPEC)
77+
rm -f po/LINGUAS
78+
79+
install: $(WEBPACK_TEST) po/LINGUAS
80+
mkdir -p $(DESTDIR)/usr/share/cockpit/$(PACKAGE_NAME)
81+
cp -r dist/* $(DESTDIR)/usr/share/cockpit/$(PACKAGE_NAME)
82+
mkdir -p $(DESTDIR)/usr/share/metainfo/
83+
msgfmt --xml -d po \
84+
--template $(APPSTREAMFILE) \
85+
-o $(DESTDIR)/usr/share/metainfo/$(APPSTREAMFILE)
86+
87+
# this requires a built source tree and avoids having to install anything system-wide
88+
devel-install: $(WEBPACK_TEST)
89+
mkdir -p ~/.local/share/cockpit
90+
ln -s `pwd`/dist ~/.local/share/cockpit/$(PACKAGE_NAME)
91+
92+
# assumes that there was symlink set up using the above devel-install target,
93+
# and removes it
94+
devel-uninstall:
95+
rm -f ~/.local/share/cockpit/$(PACKAGE_NAME)
96+
97+
print-version:
98+
@echo "$(VERSION)"
99+
100+
dist: $(TARFILE)
101+
@ls -1 $(TARFILE)
102+
103+
# when building a distribution tarball, call webpack with a 'production' environment
104+
# we don't ship node_modules for license and compactness reasons; we ship a
105+
# pre-built dist/ (so it's not necessary) and ship packge-lock.json (so that
106+
# node_modules/ can be reconstructed if necessary)
107+
$(TARFILE): export NODE_ENV=production
108+
$(TARFILE): $(WEBPACK_TEST) $(SPEC)
109+
if type appstream-util >/dev/null 2>&1; then appstream-util validate-relax --nonet *.metainfo.xml; fi
110+
touch -r package.json $(NODE_MODULES_TEST)
111+
touch dist/*
112+
tar --xz $(TAR_ARGS) -cf $(TARFILE) --transform 's,^,$(RPM_NAME)/,' \
113+
--exclude packaging/$(SPEC).in --exclude node_modules \
114+
$$(git ls-files) src/lib package-lock.json $(SPEC) dist/
115+
116+
$(NODE_CACHE): $(NODE_MODULES_TEST)
117+
tar --xz $(TAR_ARGS) -cf $@ node_modules
118+
119+
node-cache: $(NODE_CACHE)
120+
121+
# convenience target for developers
122+
srpm: $(TARFILE) $(NODE_CACHE) $(SPEC)
123+
rpmbuild -bs \
124+
--define "_sourcedir `pwd`" \
125+
--define "_srcrpmdir `pwd`" \
126+
$(SPEC)
127+
128+
# convenience target for developers
129+
rpm: $(TARFILE) $(NODE_CACHE) $(SPEC)
130+
mkdir -p "`pwd`/output"
131+
mkdir -p "`pwd`/rpmbuild"
132+
rpmbuild -bb \
133+
--define "_sourcedir `pwd`" \
134+
--define "_specdir `pwd`" \
135+
--define "_builddir `pwd`/rpmbuild" \
136+
--define "_srcrpmdir `pwd`" \
137+
--define "_rpmdir `pwd`/output" \
138+
--define "_buildrootdir `pwd`/build" \
139+
$(SPEC)
140+
find `pwd`/output -name '*.rpm' -printf '%f\n' -exec mv {} . \;
141+
rm -r "`pwd`/rpmbuild"
142+
rm -r "`pwd`/output" "`pwd`/build"
143+
144+
# build a VM with locally built distro pkgs installed
145+
# disable networking, VM images have mock/pbuilder with the common build dependencies pre-installed
146+
$(VM_IMAGE): $(TARFILE) $(NODE_CACHE) bots test/vm.install
147+
bots/image-customize --no-network --fresh \
148+
--upload $(NODE_CACHE):/var/tmp/ --build $(TARFILE) \
149+
--script $(CURDIR)/test/vm.install $(TEST_OS)
150+
151+
# convenience target for the above
152+
vm: $(VM_IMAGE)
153+
echo $(VM_IMAGE)
154+
155+
# convenience target to print the filename of the test image
156+
print-vm:
157+
echo $(VM_IMAGE)
158+
159+
# convenience target to setup all the bits needed for the integration tests
160+
# without actually running them
161+
prepare-check: $(NODE_MODULES_TEST) $(VM_IMAGE) test/common
162+
163+
# run the browser integration tests; skip check for SELinux denials
164+
# this will run all tests/check-* and format them as TAP
165+
check: prepare-check
166+
TEST_AUDIT_NO_SELINUX=1 test/common/run-tests
167+
168+
# checkout Cockpit's bots for standard test VM images and API to launch them
169+
# must be from main, as only that has current and existing images; but testvm.py API is stable
170+
# support CI testing against a bots change
171+
bots:
172+
git clone --quiet --reference-if-able $${XDG_CACHE_HOME:-$$HOME/.cache}/cockpit-project/bots https://github.com/cockpit-project/bots.git
173+
if [ -n "$$COCKPIT_BOTS_REF" ]; then git -C bots fetch --quiet --depth=1 origin "$$COCKPIT_BOTS_REF"; git -C bots checkout --quiet FETCH_HEAD; fi
174+
@echo "checked out bots/ ref $$(git -C bots rev-parse HEAD)"
175+
176+
# checkout Cockpit's test API; this has no API stability guarantee, so check out a stable tag
177+
# when you start a new project, use the latest release, and update it from time to time
178+
test/common:
179+
flock Makefile sh -ec '\
180+
git fetch --depth=1 https://github.com/cockpit-project/cockpit.git 265; \
181+
git checkout --force FETCH_HEAD -- test/common; \
182+
git reset test/common'
183+
184+
# checkout Cockpit's PF/React/build library; again this has no API stability guarantee, so check out a stable tag
185+
$(LIB_TEST):
186+
flock Makefile sh -ec '\
187+
git fetch --depth=1 https://github.com/cockpit-project/cockpit.git 265; \
188+
git checkout --force FETCH_HEAD -- ../pkg/lib; \
189+
git reset -- ../pkg/lib'
190+
mv ../pkg/lib/cockpit-po-plugin.js ../pkg/lib/cockpit-rsync-plugin.js src/lib && rm -r ../pkg
191+
192+
$(NODE_MODULES_TEST): package.json
193+
# if it exists already, npm install won't update it; force that so that we always get up-to-date packages
194+
rm -f package-lock.json
195+
# unset NODE_ENV, skips devDependencies otherwise
196+
env -u NODE_ENV npm install
197+
env -u NODE_ENV npm prune
198+
199+
.PHONY: all clean install devel-install print-version dist node-cache rpm check vm update-po print-vm devel-uninstall
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<component type="addon">
3+
<id>org.opensuse.d-installer</id>
4+
<metadata_license>CC0-1.0</metadata_license>
5+
<name>D-Installer</name>
6+
<summary>D-Installer cockpit module</summary>
7+
<description>
8+
<p>
9+
Cockpit module for D-Installer, a YaST-based installation tool.
10+
</p>
11+
</description>
12+
<extends>org.cockpit_project.cockpit</extends>
13+
<launchable type="cockpit-manifest">d-installer</launchable>
14+
<url type="homepage">https://github.com/yast/d-installer</url>
15+
<url type="bugtracker">https://github.com/yast/d-installer</url>
16+
<update_contact>yast-devel_AT_lists.opensuse.org</update_contact>
17+
</component>

0 commit comments

Comments
 (0)