Switch to make

This commit is contained in:
Liam Newman 2018-07-10 12:16:10 -07:00
parent 54f8e464b4
commit 84c66d62a7
11 changed files with 130 additions and 102 deletions

1
.gitignore vendored
View File

@ -13,5 +13,6 @@ python/jsbeautifier.egg-info
target
dist/
build/
js/lib/
.idea/

View File

@ -16,4 +16,4 @@ install:
- rm -rf ~/.nvm && git clone https://github.com/creationix/nvm.git ~/.nvm && (cd ~/.nvm && git checkout `git describe --abbrev=0 --tags`) && source ~/.nvm/nvm.sh && nvm install $TRAVIS_NODE_VERSION
- npm install
script: "./build ci"
script: "make ci"

View File

@ -14,13 +14,12 @@ While developing, you may locally build and test the JavaScript or Python (or bo
* Familiarize yourself with the folder structure and code style before you dive in.
* Make changes to the implementation of your choice.
* If working in the JavaScript implementation:
* Run `./build js`
* Run `./build static` to see changes served locally at `http://localhost:8080`
* Run `make static` to see changes served locally at `http://localhost:8080`
* To load a debug (human readable) version of the beautifier, open `http://localhost:8080/?debug`
* If working in the Python implementation:
* Run `./build py`
* Run `make py`
* Add tests to `/test/data/*/test.js`.
* Run `./build jstest` or `./build pytest` to run style checks, and to generate and run tests.
* Run `make jstest` or `make pytest` to run style checks, and to generate and run tests.
* Include all changed files in your commit - The generated test files are checked in along with changes to the test data files.
### 2. Ensure Feature Parity
@ -28,7 +27,7 @@ Any changes made to one implementation must be also made to the other implementa
The implementations are already very similar and neither Python nor JavaScript are that hard to understand. Take the plunge, it is easier than you think. If you get stuck, go ahead and file a Pull Request and we can discuss how to move forward.
* Run `./build` (with no parameters) to run style checks, and to generate and run tests on both implementations.
* Run `make` (with no parameters) to run style checks, and to generate and run tests on both implementations.
* Include all changed files in your commit - The generated test files are checked in along with changes to the test data files.
### 3. Update Documentation and Tools
@ -37,7 +36,7 @@ Also, check if your change needs any tooling updates. For example, the CDN URLs
### 4. Submit a Pull Request
* Run `./build full` locally after commit but before creation of Pull Request. You may start a Pull Request even if this reports errors, but the PR will not be merged until all errors are fixed.
* Run `make ci` locally after commit but before creation of Pull Request. You may start a Pull Request even if this reports errors, but the PR will not be merged until all errors are fixed.
* Include description of changes. Include examples of input and expected output if possible.
* Pull requests must pass build checks on all platforms before being merged. We use Travis CI and AppVeyor to run tests on Linux and Windows across multiple versions of Node.js and Python.
@ -73,7 +72,7 @@ This project has been around for a while. While some parts have improved signif
into disrepair and were mothballed. All branches named `attic-*` are significantly out of date and kept for reference purposes only.
### PHP
`attic-php` contains a PHP implmenetation of the beautifier.
`attic-php` contains a PHP implmenetation of the beautifier.
If you're interested in using it feel free.
If you plan to enhance it, please consider joining this project, and updating this version to match current functionality.
@ -83,7 +82,7 @@ Take a look and feel free to resurrect them, but know it's pretty dusty back the
### Generic Eval Unpacker
The `attic-genericeval` branch includes an unpacker that calls `eval` on whatever source is passed to it.
This file may be useful when working with source that unpacks itself when `eval` is called on it, but is also very unsafe.
This file may be useful when working with source that unpacks itself when `eval` is called on it, but is also very unsafe.
We have isolated it on this separate branch to keep it from hurting the other children.
# How to publish a new version
@ -107,9 +106,9 @@ To publish a release:
* Close the Milestone for this release on github
* Run `./tools/release-all.sh <version>`.
This is script will:
This is script will:
* Update README.md with correct cdn links
* Update README.md with correct cdn links
* Update CHANGLOG.md with the milestone description and a list of closed issues
* Publish the python version to PyPI
* Publish the javascript version to npm
@ -120,7 +119,7 @@ so if you publish a Python release, you publish a Node release as well.
## Publish to Beta Channel
To publish a Beta or RC (Release Candidate), add `-beta1` or `-rc1` to the end of the version, incrementing the number on the end as needed.
To publish a Beta or RC (Release Candidate), add `-beta1` or `-rc1` to the end of the version, incrementing the number on the end as needed.

102
Makefile Normal file
View File

@ -0,0 +1,102 @@
PROJECT_ROOT=$(dir $(realpath $(firstword $(MAKEFILE_LIST))))
BUILD_DIR=$(PROJECT_ROOT)/build
SCRIPT_DIR=$(PROJECT_ROOT)/tools
SHELL=/bin/bash
PYTHON=$(SCRIPT_DIR)/python
NODE=$(SCRIPT_DIR)/node
NPM=$(SCRIPT_DIR)/npm
all: depends js jstest py pytest beautify
help:
@echo "make <action>"
@echo " all - build both implementations"
@echo " static - serve static version of site locally"
@echo " js - build javascript"
@echo " py - build python"
@echo " alltest - test both implementations, js and python"
@echo " pytest - test python implementation"
@echo " jstest - test javascript implementation"
ci: all git-status-clear
static: $(BUILD_DIR)/node
./node_modules/.bin/static
js: js/lib/*.js
py: python/dist/*
generate-tests: $(BUILD_DIR)/tests
jstest: depends generate-tests js
@echo Testing javascript implementation...
@$(NODE) --version && \
./node_modules/.bin/mocha --recursive js/test && \
./js/test/shell-smoke-test.sh
pytest: depends generate-tests py
@echo Testing python implementation...
@cd python && \
$(PYTHON) --version && \
./jsbeautifier/tests/shell-smoke-test.sh
beautify:
$(SCRIPT_DIR)/build.sh beautify
# Build
#######################################################
# javascript bundle generation
js/lib/*.js: $(BUILD_DIR)/node $(wildcard js/src/**/*) tools/template/* webpack.config.js
$(SCRIPT_DIR)/build.sh js
# python package generation
python/dist/*: $(BUILD_DIR)/python $(wildcard python/**/*.py) python/jsbeautifier/*
@echo Building python module...
@cd python && \
$(PYTHON) setup.py sdist
# Test generation
$(BUILD_DIR)/tests: $(BUILD_DIR)/node test/generate-tests.js $(wildcard test/data/**/*)
$(NODE) test/generate-tests.js
@touch $(BUILD_DIR)/tests
# Handling dependencies
#######################################################
depends: $(BUILD_DIR)/node $(BUILD_DIR)/python
# update dependencies information
update: depends
npm update
# when we pull dependencies also pull docker image
# without this images can get stale and out of sync from CI system
$(BUILD_DIR)/node: package.json package-lock.json | $(BUILD_DIR)
$(NPM) install
@touch $(BUILD_DIR)/node
$(BUILD_DIR)/python: python/setup.py
$(PYTHON) -m pip install -e ./python
@touch $(BUILD_DIR)/python
# Miscellaneous tasks
#######################################################
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
git-status-clear:
$(SCRIPT_DIR)/git-status-clear.sh
clean:
git clean -xfd
#######################################################
.PHONY: all beautify clean depends generate-tests git-status-clear help static update

View File

@ -19,8 +19,10 @@ environment:
install:
# Get the latest stable version of Node.js or io.js
- ps: Install-Product node $env:nodejs_version
- "SET PATH=%PYTHON%;%PYTHON%\\Scripts;%PATH%"
- "SET PATH=%PYTHON%;%PYTHON%\\Scripts;c:\\MinGW\\bin;%PATH%"
- pip --version
- copy c:\MinGW\bin\mingw32-make.exe c:\MinGW\bin\make.exe
- make --version
# Post-install test scripts.
test_script:
@ -29,7 +31,7 @@ test_script:
- npm --version
- python --version
# run tests
- bash -c "./build ci"
- bash -c "make ci"
# Don't actually build.
build: off

5
build
View File

@ -1,5 +0,0 @@
#!/usr/bin/env bash
REL_SCRIPT_DIR="`dirname \"$0\"`"
SCRIPT_DIR="`( cd \"$REL_SCRIPT_DIR\" && pwd )`"
$SCRIPT_DIR/tools/build.sh $*

View File

@ -4,58 +4,11 @@ REL_SCRIPT_DIR="`dirname \"$0\"`"
SCRIPT_DIR="`( cd \"$REL_SCRIPT_DIR\" && pwd )`"
PROJECT_DIR="`( cd \"$SCRIPT_DIR/..\" && pwd )`"
build_help()
{
echo "build.sh <action>"
echo " full - build and test all implementations"
echo " all - build both implementations"
echo " static - serve static version of site locally"
echo " js - build javascript"
echo " py - build python"
echo " alltest - test both implementations, js and python"
echo " pytest - test python implementation"
echo " jstest - test javascript implementation"
}
build_ci()
{
build_full
build_git_status
}
build_full()
{
build_all
build_alltest
beautify
}
build_all()
{
build_py
build_js
}
build_static()
{
npm install || exit 1
./node_modules/.bin/static
}
build_py()
{
echo Building python module...
/usr/bin/env python -m pip install -e ./python || exit 1
}
build_js()
{
echo Building javascript...
cd $PROJECT_DIR
npm install || exit 1
generate_tests
# generate lib files
$PROJECT_DIR/node_modules/.bin/webpack
@ -84,7 +37,7 @@ build_js()
$PROJECT_DIR/node_modules/.bin/jshint 'js/src' 'test' || exit 1
}
beautify()
build_beautify()
{
cd $PROJECT_DIR
# beautify test and data
@ -120,41 +73,6 @@ beautify()
build_js
}
generate_tests()
{
node test/generate-tests.js || exit 1
}
build_alltest()
{
build_jstest
build_pytest
}
build_pytest()
{
echo Testing python implementation...
generate_tests
pushd python
python --version
./jsbeautifier/tests/shell-smoke-test.sh || exit 1
popd
}
build_jstest()
{
echo Testing javascript implementation...
generate_tests
node --version
./node_modules/.bin/mocha --recursive js/test || exit 1
./js/test/shell-smoke-test.sh || exit 1
}
build_git_status()
{
$SCRIPT_DIR/git-status-clear.sh || exit 1
}
build_update-codemirror()
{
rm -rf node_modules/codemirror

View File

@ -1,3 +1,5 @@
#!/usr/bin/env bash
echo "Post-build git status check..."
echo "Ensuring no changes visible to git have been made to '$*' ..."

3
tools/node Executable file
View File

@ -0,0 +1,3 @@
#!/usr/bin/env bash
/usr/bin/env node $@

3
tools/npm Executable file
View File

@ -0,0 +1,3 @@
#!/usr/bin/env bash
/usr/bin/env npm $@

3
tools/python Executable file
View File

@ -0,0 +1,3 @@
#!/usr/bin/env bash
/usr/bin/env python $@