Skip to content

Commit

Permalink
Merge pull request #6 from liquid-labs/work-liquid-labs/liq-controls/5
Browse files Browse the repository at this point in the history
Move controls schema here
  • Loading branch information
zanerock authored Jun 6, 2023
2 parents 9a968d3 + b0d7db4 commit 8781be4
Show file tree
Hide file tree
Showing 21 changed files with 226 additions and 71 deletions.
74 changes: 36 additions & 38 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
BUILD_KEY:=liq-controls
SRC:=src
CATALYST_JS_LIB_SRC_PATH:=$(SRC)/lib

.DELETE_ON_ERROR:
.PHONY: all build lint lint-fix qa test

Expand All @@ -7,11 +10,9 @@ SHELL:=bash
default: build

DIST:=dist
DOCS:=docs
QA:=qa
TEST_STAGING:=test-staging
ifndef (SRC)
SRC:=src
endif

.PRECIOUS: $(QA)/unit-test.txt $(QA)/lint.txt

Expand All @@ -20,46 +21,40 @@ CATALYST_JS_JEST:=npx jest
CATALYST_JS_ROLLUP:=npx rollup
CATALYST_JS_ESLINT:=npx eslint

ifndef CATALYST_JS_LIB_SRC_PATH
ifeq ($(SRC)/lib, $(shell ls -d $(SRC)/lib 2> /dev/null))
CATALYST_JS_LIB_SRC_PATH:=$(SRC)/lib
else ifeq ($(SRC), $(shell ls -d $(SRC)))
CATALYST_JS_LIB_SRC_PATH:=$(SRC)
else
ERROR:=$(error 'CATALYST_JS_LIB_SRC_PATH' is not set and cannot be resolved automatically.)
endif
endif

ifeq ($(SRC)/cli, $(shell ls -d $(SRC)/cli 2> /dev/null))
CATALYST_JS_CLI_SRC_PATH:=$(SRC)/cli
endif

# all source files (cli and lib)
CATALYST_JS_ALL_FILES_SRC:=$(shell find $(SRC) \( -name "*.js" -o -name "*.mjs" -o -name "*.cjs" \))
CATALYST_JS_TEST_FILES_SRC:=$(shell find $(SRC) -name "*.js")
CATALYST_JS_ALL_FILES_SRC:=$(shell find $(SRC) \( -name "*.js" -o -name "*.mjs" -o -name "*.cjs" \) -not -path "*/test/data/*" -not -path "*/test/data-*/*")
CATALYST_JS_TEST_FILES_SRC:=$(shell find $(SRC) -name "*.js" -not -path "*/test/data/*" -not -path "*/test/data-*/*" -type f)
CATALYST_JS_TEST_FILES_BUILT:=$(patsubst $(SRC)/%, test-staging/%, $(CATALYST_JS_TEST_FILES_SRC))
# all test data (cli and lib)
CATALYST_JS_TEST_DATA_SRC:=$(shell find $(SRC) -path "*/test/data/*" -type f)
CATALYST_JS_TEST_DATA_SRC:=$(shell find $(SRC) -type f \( -path "*/test/data/*" -o -path "*/test/data-*/*" \))
CATALYST_JS_TEST_DATA_BUILT:=$(patsubst $(SRC)/%, $(TEST_STAGING)/%, $(CATALYST_JS_TEST_DATA_SRC))
# lib specific files
CATALYST_JS_LIB_FILES_SRC:=$(shell find $(CATALYST_JS_LIB_SRC_PATH) \( -name "*.js" -o -name "*.mjs" -o -name "*.cjs" \) -not -path "*/test/*" -not -name "*.test.js")
CATALYST_JS_LIB:=dist/$(BUILD_KEY).js
# cli speciifc files
ifdef CATALYST_JS_CLI_SRC_PATH
CATALYST_JS_CLI_FILES_SRC:=$(shell find $(CATALYST_JS_CLI_SRC_PATH) \( -name "*.js" -o -name "*.mjs" -o -name "*.cjs" \) -not -path "*/test/*" -not -name "*.test.js")
CATALYST_JS_CLI:=dist/$(BUILD_KEY)-cli.js
endif

LINT_IGNORE_PATTERNS:=--ignore-pattern '$(DIST)/**/*' \
--ignore-pattern '$(TEST_STAGING)/**/*' \
--ignore-pattern '$(DOCS)/**/*'

# build rules
BUILD_TARGETS+=$(CATALYST_JS_LIB)

INSTALL_BASE:=$(shell npm explore @liquid-labs/catalyst-scripts-node-project -- pwd)

ifneq ($(wildcard make/*.mk),)
include make/*.mk
endif

ifdef CATALYST_JS_LIB_SRC_PATH
BUILD_TARGETS+=$(CATALYST_JS_LIB)

$(CATALYST_JS_LIB): package.json $(CATALYST_JS_LIB_FILES_SRC)
JS_BUILD_TARGET=$(CATALYST_JS_LIB_SRC_PATH)/index.js \
JS_OUT=$@ \
$(CATALYST_JS_ROLLUP) --config $(INSTALL_BASE)/dist/rollup/rollup.config.mjs
endif

ifdef CATALYST_JS_CLI_SRC_PATH
BUILD_TARGETS+=$(CATALYST_JS_CLI)
Expand All @@ -68,7 +63,7 @@ BUILD_TARGETS+=$(CATALYST_JS_CLI)
$(CATALYST_JS_CLI): package.json $(CATALYST_JS_ALL_FILES_SRC)
JS_BUILD_TARGET=$(CATALYST_JS_CLI_SRC_PATH)/index.js \
JS_OUT=$@ \
JS_OUT_PREAMBLE='#!/usr/bin/env node' \
JS_OUT_PREAMBLE='#!/usr/bin/env -S node --enable-source-maps' \
$(CATALYST_JS_ROLLUP) --config $(INSTALL_BASE)/dist/rollup/rollup.config.mjs
chmod a+x $@
endif
Expand All @@ -78,7 +73,7 @@ endif
UNIT_TEST_REPORT:=$(QA)/unit-test.txt
UNIT_TEST_PASS_MARKER:=$(QA)/.unit-test.passed

$(CATALYST_JS_TEST_DATA_BUILT): test-staging/%: $(CATALYST_JS_LIB_SRC_PATH)/%
$(CATALYST_JS_TEST_DATA_BUILT): test-staging/%: $(SRC)/%
@echo "Copying test data..."
@mkdir -p $(dir $@)
@cp $< $@
Expand All @@ -94,46 +89,49 @@ $(CATALYST_JS_TEST_FILES_BUILT) &: $(CATALYST_JS_ALL_FILES_SRC)
$(SRC)

# Tried to use '--testPathPattern=$(TEST_STAGING)' awithout the 'cd $(TEST_STAGING)', but it seemed to have no effect'
$(UNIT_TEST_PASS_MARKER): $(CATALYST_JS_TEST_FILES_BUILT) $(CATALYST_JS_TEST_DATA_BUILT)
# '--runInBand' because some suites require serial execution (yes, it's "best practice" to have unit tests totally
# independent, but in practice there are sometimes good reasons why it's useful or necessary to run sequentially);
# also, it may be faster this way; see:
# https://stackoverflow.com/questions/43864793/why-does-jest-runinband-speed-up-tests
$(UNIT_TEST_PASS_MARKER) $(UNIT_TEST_REPORT): package.json $(CATALYST_JS_TEST_FILES_BUILT) $(CATALYST_JS_TEST_DATA_BUILT)
@rm -f $@
@mkdir -p $(dir $@)
@echo -n 'Test git rev: ' > $(UNIT_TEST_REPORT)
@git rev-parse HEAD >> $(UNIT_TEST_REPORT)
@( set -e; set -o pipefail; \
( cd $(TEST_STAGING) && $(CATALYST_JS_JEST) \
--config=$(INSTALL_BASE)/dist/jest/jest.config.js \
--runInBand 2>&1 ) \
| tee -a $(UNIT_TEST_REPORT))
@touch $@
--runInBand \
$(TEST) 2>&1 ) \
| tee -a $(UNIT_TEST_REPORT); \
touch $@ )

TEST_TARGETS+=$(UNIT_TEST_PASS_MARKER)
TEST_TARGETS+=$(UNIT_TEST_PASS_MARKER) $(UNIT_TEST_REPORT)

# lint rules
LINT_REPORT:=$(QA)/lint.txt
LINT_PASS_MARKER:=$(QA)/.lint.passed
$(LINT_PASS_MARKER): $(CATALYST_JS_LIB_ALL_FILES)
$(LINT_PASS_MARKER) $(LINT_REPORT): $(CATALYST_JS_LIB_ALL_FILES)
@mkdir -p $(dir $@)
@echo -n 'Test git rev: ' > $(LINT_REPORT)
@git rev-parse HEAD >> $(LINT_REPORT)
@( set -e; set -o pipefail; \
$(CATALYST_JS_ESLINT) \
--config $(INSTALL_BASE)/dist/eslint/eslint.config.js \
--ext .cjs,.js,.mjs,.cjs,.xjs \
--ignore-pattern '$(DIST)/**/*' \
--ignore-pattern '$(TEST_STAGING)/**/*' \
$(LINT_IGNORE_PATTERNS) \
. \
| tee -a $(LINT_REPORT))
touch $@
| tee -a $(LINT_REPORT); \
touch $@ )

LINT_TARGETS+=$(LINT_PASS_MARKER)
LINT_TARGETS+=$(LINT_PASS_MARKER) $(LINT_REPORT)

lint-fix:
@( set -e; set -o pipefail; \
$(CATALYST_JS_ESLINT) \
--config $(INSTALL_BASE)/dist/eslint/eslint.config.js \
--ext .js,.mjs,.cjs,.xjs \
--ignore-pattern $(DIST)/**/* \
--ignore-pattern '$(TEST_STAGING)/**/*' \
$(LINT_IGNORE_PATTERNS) \
--fix . )


Expand Down
8 changes: 8 additions & 0 deletions make/01-schema.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
SCHEMA_SRC:=$(SRC)/schema
SCHEMA_FILES:=$(SCHEMA_SRC)/controls.schema.json
SCHEMA_DIST:=$(patsubst $(SCHEMA_SRC)%, $(DIST)%, $(SCHEMA_FILES))

$(SCHEMA_DIST): $(DIST)% : $(SCHEMA_SRC)%
cp $< $@

BUILD_TARGETS+=$(SCHEMA_DIST)
93 changes: 65 additions & 28 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"preversion": "npm test && make lint",
"qa": "make qa"
},
"files": [ "dist/*" ],
"keywords": [],
"author": "Zane Rockenbaugh <[email protected]>",
"license": "UNLICENSED",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ reporter.log = jest.fn((msg) => { logs.push(msg) })
reporter.error = jest.fn((msg) => { errors.push(msg) })

const LIQ_PLAYGROUND_PATH = fsPath.resolve(__dirname, 'data', 'playgroundA')
console.log('LIQ_PLAYGROUND_PATH:', LIQ_PLAYGROUND_PATH) // DEBUG
const projectA01Path = fsPath.resolve(LIQ_PLAYGROUND_PATH, 'orgA', 'projectA01')
// const controlsMapPath = fsPath.resolve(LIQ_PLAYGROUND_PATH, 'orgA', 'projectA01', 'data', 'orgs', 'controlsMap.json')
const expectedControlsMap = [{ controlSet : 'project-create-controls', name : 'project-uses-database-queries' }]
const pkgRoot = fsPath.resolve(__dirname, '..', '..', '..', '..', '..')
const pkgRoot = fsPath.resolve(__dirname, '..', '..', '..', '..', '..', '..')
// const pkgPath = fsPath.join(pkgRoot, 'package.json')
// const packageJSON = JSON.parse(readFileSync(pkgPath, { encoding : 'utf8' }))

Expand All @@ -24,16 +25,25 @@ describe('GET:/orgs/:orgKey/controls/list and GET:/orgs/controls/list', () => {
let cache

beforeAll(async() => {
model.initialize({ LIQ_PLAYGROUND_PATH, reporter });
({ app, cache } = await appInit({ model, skipCorePlugins : true, pluginDirs : [pkgRoot], reporter }))
process.env.LIQ_REGISTRIES = 'raw.githubusercontent.com/liquid-labs/liq-registry/main/registry.yaml'
model.initialize({ LIQ_PLAYGROUND_PATH, reporter })
try {
({ app, cache } = await appInit({
model,
pluginDirs : [pkgRoot],
reporter,
skipCorePlugins : true
}))
}
catch (e) { console.log('hey', e) }
})

afterEach(() => {
logs.splice(0, logs.length)
errors.splice(0, errors.length)
})

afterAll(() => { cache.release() }) /* cache has timers that must be stopped */
afterAll(() => { cache?.release() }) /* cache has timers that must be stopped */

test('will list named org controls', async() => {
const { body, headers, status } = await request(app)
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/index.js → src/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ export * from './handlers'
const name = 'controls'
const summary = 'Manages and enables policy controls.'

export { name, summary }
export { name, summary }
Loading

0 comments on commit 8781be4

Please sign in to comment.