diff --git a/.eslintrc.json b/.eslintrc.json index 144db4a..70febb7 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,11 +1,9 @@ { "parserOptions": { - "ecmaVersion": 5 + "ecmaVersion": 6, + "sourceType": "module" }, "extends": "eslint:recommended", - "env": { - "commonjs": true - }, "globals": { "console": true }, diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..4435abb --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,12 @@ +**Description of the change** + +Clearly and concisely describe the purpose of the pull request. If this PR relates to an existing issue or change proposal, please link to it. Include any other background context that would help reviewers understand the motivation for this PR. + +--- + +**Checklist:** + +- [ ] Added the change to the changelog's "Unreleased" section with a reference to this PR (e.g. "- Made a change (#0000)") +- [ ] Linked any existing issues or proposals that this pull request should close +- [ ] Updated or added relevant documentation +- [ ] Added a test for the contribution (if applicable) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e2972ba..c69237a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,6 +1,10 @@ name: CI -on: push +on: + push: + branches: [master] + pull_request: + branches: [master] jobs: build: @@ -10,11 +14,11 @@ jobs: - uses: purescript-contrib/setup-purescript@main with: - purescript: "0.14.0-rc3" + purescript: "unstable" - - uses: actions/setup-node@v1 + - uses: actions/setup-node@v2 with: - node-version: "12" + node-version: "14.x" - name: Install dependencies run: | diff --git a/.gitignore b/.gitignore index b846b63..5b50308 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ /node_modules/ /output/ package-lock.json +test/actual_output.txt diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..68339cc --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,95 @@ +# Changelog + +Notable changes to this project are documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [Unreleased] + +Breaking changes: + +New features: + +Bugfixes: + +Other improvements: + +## [v6.1.0](https://github.com/purescript/purescript-console/releases/tag/v6.1.0) - 2023-10-08 + +New features: +- Added `group`, `groupCollapsed`, and `groupEnd` (#42 by @pete-murphy) + +## [v6.0.0](https://github.com/purescript/purescript-console/releases/tag/v6.0.0) - 2022-04-27 + +Breaking changes: +- Migrated FFI to ES modules (#39 by @kl0tl and @JordanMartinez) + +New features: +- Added `debug` (#36) + +Bugfixes: + +Other improvements: + +## [v5.0.0](https://github.com/purescript/purescript-console/releases/tag/v5.0.0) - 2021-02-26 + +Breaking changes: + - Added support for PureScript 0.14 and dropped support for all previous versions (#30) + +New features: + +Bugfixes: + +Other improvements: + - Migrated CI to GitHub Actions and updated installation instructions to use Spago (#32) + - Added a CHANGELOG.md file and pull request template (#33, #34) + - Removed `return {}` from FFI functions for a small performance boost (#30) + +## [v4.4.0](https://github.com/purescript/purescript-console/releases/tag/v4.4.0) - 2020-01-26 + +Added `clear` (@iarthstar) + +## [v4.3.0](https://github.com/purescript/purescript-console/releases/tag/v4.3.0) - 2019-12-07 + +Added `timeLog` (@matoruru) + +## [v4.2.0](https://github.com/purescript/purescript-console/releases/tag/v4.2.0) - 2018-11-11 + +- Added `time` and `timeEnd` (@fehrenbach) + +## [v4.1.0](https://github.com/purescript/purescript-console/releases/tag/v4.1.0) - 2018-05-24 + +- Added `Effect.Class.Console`, the console functions lifted for `MonadEffect` (@justinwoo) + +## [v4.0.0](https://github.com/purescript/purescript-console/releases/tag/v4.0.0) - 2018-05-22 + +Updated for PureScript 0.12 + +## [v3.0.0](https://github.com/purescript/purescript-console/releases/tag/v3.0.0) - 2017-03-25 + +- Updated for PureScript 0.11 + +## [v2.0.0](https://github.com/purescript/purescript-console/releases/tag/v2.0.0) - 2016-10-02 + +- Updated dependencies + +## [v1.0.0](https://github.com/purescript/purescript-console/releases/tag/v1.0.0) - 2016-06-01 + +This release is intended for the PureScript 0.9.1 compiler and newer. + +**Note**: The v1.0.0 tag is not meant to indicate the library is “finished”, the core libraries are all being bumped to this for the 0.9 compiler release so as to use semver more correctly. + +## [v1.0.0-rc.1](https://github.com/purescript/purescript-console/releases/tag/v1.0.0-rc.1) - 2016-03-13 + +- Release candidate for the psc 0.8+ core libraries + +## [v0.1.1](https://github.com/purescript/purescript-console/releases/tag/v0.1.1) - 2015-08-20 + +Add `logAny` and `errorAny` (@zudov) + +## [v0.1.0](https://github.com/purescript/purescript-console/releases/tag/v0.1.0) - 2015-06-30 + +This release works with versions 0.7.\* of the PureScript compiler. It will not work with older versions. If you are using an older version, you should require an older, compatible version of this library. + +## [v0.1.0-rc.1](https://github.com/purescript/purescript-console/releases/tag/v0.1.0-rc.1) - 2015-06-06 + +Initial release candidate. + diff --git a/README.md b/README.md index 0edcea3..27bf254 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,8 @@ # purescript-console -[![Latest release](http://img.shields.io/github/release/purescript/purescript-eff.svg)](https://github.com/purescript/purescript-console/releases) +[![Latest release](http://img.shields.io/github/release/purescript/purescript-console.svg)](https://github.com/purescript/purescript-console/releases) [![Build status](https://github.com/purescript/purescript-console/workflows/CI/badge.svg?branch=master)](https://github.com/purescript/purescript-console/actions?query=workflow%3ACI+branch%3Amaster) +[![Pursuit](https://pursuit.purescript.org/packages/purescript-console/badge)](https://pursuit.purescript.org/packages/purescript-console) Console-related functions and effect type. diff --git a/bower.json b/bower.json index 0b41d73..da93c7f 100644 --- a/bower.json +++ b/bower.json @@ -4,7 +4,7 @@ "license": "BSD-3-Clause", "repository": { "type": "git", - "url": "git://github.com/purescript/purescript-console.git" + "url": "https://github.com/purescript/purescript-console.git" }, "ignore": [ "**/.*", @@ -16,7 +16,7 @@ "package.json" ], "dependencies": { - "purescript-effect": "master", - "purescript-prelude": "master" + "purescript-effect": "^4.0.0", + "purescript-prelude": "^6.0.0" } } diff --git a/package.json b/package.json index bf1e132..6b85059 100644 --- a/package.json +++ b/package.json @@ -2,12 +2,13 @@ "private": true, "scripts": { "clean": "rimraf output && rimraf .pulp-cache", - "build": "eslint src && pulp build -- --censor-lib --strict" + "build": "eslint src && pulp build -- --censor-lib --strict", + "test": "npm run build && ./scripts/test" }, "devDependencies": { - "eslint": "^4.19.1", - "pulp": "^15.0.0", - "purescript-psa": "^0.6.0", - "rimraf": "^2.6.2" + "eslint": "^7.15.0", + "pulp": "16.0.0-0", + "purescript-psa": "^0.8.2", + "rimraf": "^3.0.2" } } diff --git a/scripts/test b/scripts/test new file mode 100755 index 0000000..cd6b2e8 --- /dev/null +++ b/scripts/test @@ -0,0 +1,5 @@ +#!/bin/bash -e + +pulp build -I test +node --input-type=module -e 'import { main } from "./output/Test.Main/index.js"; main();' > test/actual_output.txt 2>&1 +diff -u test/expected_output.txt test/actual_output.txt diff --git a/src/Effect/Class/Console.purs b/src/Effect/Class/Console.purs index 9a198bb..d11db86 100644 --- a/src/Effect/Class/Console.purs +++ b/src/Effect/Class/Console.purs @@ -1,5 +1,6 @@ module Effect.Class.Console where +import Control.Bind (discard, bind, pure) import Data.Function ((<<<)) import Data.Show (class Show) import Data.Unit (Unit) @@ -30,6 +31,12 @@ info = liftEffect <<< EffConsole.info infoShow :: forall m a. MonadEffect m => Show a => a -> m Unit infoShow = liftEffect <<< EffConsole.infoShow +debug :: forall m. MonadEffect m => String -> m Unit +debug = liftEffect <<< EffConsole.debug + +debugShow :: forall m a. MonadEffect m => Show a => a -> m Unit +debugShow = liftEffect <<< EffConsole.debugShow + time :: forall m. MonadEffect m => String -> m Unit time = liftEffect <<< EffConsole.time @@ -41,3 +48,19 @@ timeEnd = liftEffect <<< EffConsole.timeEnd clear :: forall m. MonadEffect m => m Unit clear = liftEffect EffConsole.clear + +group :: forall m. MonadEffect m => String -> m Unit +group = liftEffect <<< EffConsole.group + +groupCollapsed :: forall m. MonadEffect m => String -> m Unit +groupCollapsed = liftEffect <<< EffConsole.groupCollapsed + +groupEnd :: forall m. MonadEffect m => m Unit +groupEnd = liftEffect EffConsole.groupEnd + +grouped :: forall m a. MonadEffect m => String -> m a -> m a +grouped name inner = do + group name + result <- inner + groupEnd + pure result diff --git a/src/Effect/Console.js b/src/Effect/Console.js index 4009a17..8db1f20 100644 --- a/src/Effect/Console.js +++ b/src/Effect/Console.js @@ -1,47 +1,67 @@ -"use strict"; - -exports.log = function (s) { +export const log = function (s) { return function () { console.log(s); }; }; -exports.warn = function (s) { +export const warn = function (s) { return function () { console.warn(s); }; }; -exports.error = function (s) { +export const error = function (s) { return function () { console.error(s); }; }; -exports.info = function (s) { +export const info = function (s) { return function () { console.info(s); }; }; -exports.time = function (s) { +export const debug = function (s) { + return function () { + console.debug(s); + }; +}; + +export const time = function (s) { return function () { console.time(s); }; }; -exports.timeLog = function (s) { +export const timeLog = function (s) { return function () { console.timeLog(s); }; }; -exports.timeEnd = function (s) { +export const timeEnd = function (s) { return function () { console.timeEnd(s); }; }; -exports.clear = function () { +export const clear = function () { console.clear(); }; + +export const group = function (s) { + return function () { + console.group(s); + }; +}; + +export const groupCollapsed = function (s) { + return function () { + console.groupCollapsed(s); + }; +}; + +export const groupEnd = function () { + console.groupEnd(); +}; diff --git a/src/Effect/Console.purs b/src/Effect/Console.purs index 8a00758..f3d08df 100644 --- a/src/Effect/Console.purs +++ b/src/Effect/Console.purs @@ -1,5 +1,6 @@ module Effect.Console where +import Control.Bind (discard, bind, pure) import Effect (Effect) import Data.Show (class Show, show) @@ -45,6 +46,16 @@ foreign import info infoShow :: forall a. Show a => a -> Effect Unit infoShow a = info (show a) +-- | Write an debug message to the console. +foreign import debug + :: String + -> Effect Unit + +-- | Write an debug value to the console, using its `Show` instance to produce a +-- | `String`. +debugShow :: forall a. Show a => a -> Effect Unit +debugShow a = debug (show a) + -- | Start a named timer. foreign import time :: String -> Effect Unit @@ -56,3 +67,22 @@ foreign import timeEnd :: String -> Effect Unit -- | Clears the console foreign import clear :: Effect Unit + +-- | Creates a new inline group in the console. This indents following console +-- | messages by an additional level, until `groupEnd` is called. +foreign import group :: String -> Effect Unit + +-- | Same as `group`, but groups are collapsed by default. +foreign import groupCollapsed :: String -> Effect Unit + +-- | Exits the current inline group in the console. +foreign import groupEnd :: Effect Unit + +-- | Perform an effect within the context of an inline group in the console. +-- | Calls `group` and `groupEnd` before and after the effect, respectively. +grouped :: forall a. String -> Effect a -> Effect a +grouped name inner = do + group name + result <- inner + groupEnd + pure result diff --git a/test/Main.purs b/test/Main.purs new file mode 100644 index 0000000..fee924f --- /dev/null +++ b/test/Main.purs @@ -0,0 +1,22 @@ +module Test.Main where + +import Prelude + +import Effect (Effect) +import Effect.Class.Console as Console + +main :: Effect Unit +main = do + Console.log "log" + Console.warn "warn" + Console.error "error" + Console.info "info" + Console.debug "debug" + Console.group "group" + Console.log "log in group" + Console.groupCollapsed "groupCollapsed" + Console.log "log in groupCollapsed" + Console.groupEnd + Console.groupEnd + Console.grouped "grouped" do + Console.log "log in grouped" diff --git a/test/expected_output.txt b/test/expected_output.txt new file mode 100644 index 0000000..08e6d63 --- /dev/null +++ b/test/expected_output.txt @@ -0,0 +1,11 @@ +log +warn +error +info +debug +group + log in group + groupCollapsed + log in groupCollapsed +grouped + log in grouped