diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100755 index 0000000..4fc309a --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,21 @@ +name: Publish + +on: + push: + tags: + - 'v*.*.*' + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - uses: actions/setup-node@v1 + with: + node-version: 12 + registry-url: https://registry.npmjs.org/ + - run: npm install + - run: npm version "${GITHUB_REF:11}" --git-tag-version false --commit-hooks false + - run: npm publish --access public + env: + NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} diff --git a/.github/workflows/quality.yml b/.github/workflows/quality.yml new file mode 100755 index 0000000..fac5026 --- /dev/null +++ b/.github/workflows/quality.yml @@ -0,0 +1,29 @@ +on: + push: + branches: + - '*' # matches every branch + - '*/*' # matches every branch containing a single '/' +jobs: + eslint: + name: eslint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Use Node.js + uses: actions/setup-node@v1 + with: + node-version: 12.x + - run: npm install + - run: npm run eslint + + prettier: + name: prettier + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Use Node.js + uses: actions/setup-node@v1 + with: + node-version: 12.x + - run: npm install + - run: npm run prettier diff --git a/.gitignore b/.gitignore index 3c3629e..f06235c 100755 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ node_modules +dist diff --git a/dist/clever-date.js b/dist/clever-date.js deleted file mode 100644 index 5f85e6a..0000000 --- a/dist/clever-date.js +++ /dev/null @@ -1 +0,0 @@ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.CleverDate=t():e.CleverDate=t()}(window,(function(){return function(e){var t={};function r(n){if(t[n])return t[n].exports;var u=t[n]={i:n,l:!1,exports:{}};return e[n].call(u.exports,u,u.exports,r),u.l=!0,u.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var u in e)r.d(n,u,function(t){return e[t]}.bind(null,u));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=0)}([function(e,t,r){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});var u=n(r(1));e.exports=new u.default},function(e,t,r){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});var u=n(r(2)),o=n(r(3)),a=n(r(5)),i=n(r(9)),f=n(r(10)),s=function(){function e(){this.items=[],this.rules=[]}return e.prototype.start=function(e){var t=this;void 0===e&&(e={});var r=this.mergeConfiguration(e),n=f.default.validate(r);if(n instanceof Error)throw n;var u=function(){t.extractItems(r.selector),t.analyse()};this.timer||(this.timer=this.startTimer(r.refresh,u)),this.rules=r.rules,u()},e.prototype.extractItems=function(e){var t=this;document.querySelectorAll("["+e+"]").forEach((function(r){var n=new u.default;n.reference=r,n.initialText=r.innerHTML;var o=r.getAttribute(e);if(!Number.isNaN(Number(o))){var a=parseInt(o,10);n.date=new Date(1e3*a),t.items.push(n)}r.removeAttribute(e),r.hasAttribute("title")||r.setAttribute("title",n.initialText)}))},e.prototype.analyse=function(){var e=this,t=new Date;this.items.filter((function(e){return!e.nextUpdate||e.nextUpdate=0&&e.second<30},text:{fr:"à l'instant",en:"just now"}},{condition:function(e){return 0===e.day&&0===e.hour&&0===e.minute&&e.second>=0&&e.second<60},text:{en:"%ds second{%ds||s} ago",fr:"il y a %ds seconde{%ds||s}"}},{condition:function(e){return 0===e.day&&0===e.hour&&e.minute>=0&&e.minute<60},text:{en:"%dm minute{%dm||s} ago",fr:"il y a %dm minute{%dm||s}"}},{condition:function(e){return 0===e.day&&e.hour>0&&e.hour>=0&&e.hour<12},refresh:300,text:{en:"%dh hour[%dh||s] ago",fr:"il y a %dh heure{%dh||s}"}},{condition:function(e){return(new Date).toDateString()===e.date.toDateString()},refresh:60,text:{en:"today at %H:%i",fr:"aujourd'hui à %H\\h%i"}},{condition:function(e){var t=new Date,r=t.setDate(t.getDate()-1);return new Date(r).toDateString()===e.date.toDateString()},refresh:60,text:{en:"yesterday at %H:%i",fr:"hier à %H\\h%i"}},{condition:function(e){return e.day>0&&e.day<7},refresh:3600,text:{en:"%l at %H:%i",fr:"%l à %H\\h%i"}},{condition:function(e){return e.date.getFullYear()===(new Date).getFullYear()},refresh:1e5,text:{en:"%F %d",fr:"le %d{%d|er|} %F"}},{condition:function(){return!0},refresh:1e5,text:{en:"%F %d, %Y",fr:"le %d{%d|er|} %F %Y"}}]}},function(e,t,r){"use strict";function n(e){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}Object.defineProperty(t,"__esModule",{value:!0}),t.default=new(function(){function e(){}return e.prototype.validate=function(e){if("number"!=typeof e.refresh)return new Error("Refresh value must be a number.");for(var t=0,r=e.rules;t boolean; - text: { - [key: string]: string; - }; - refresh?: number; -} diff --git a/dist/src/Rule/RuleInterpreter.d.ts b/dist/src/Rule/RuleInterpreter.d.ts deleted file mode 100644 index a4e49c0..0000000 --- a/dist/src/Rule/RuleInterpreter.d.ts +++ /dev/null @@ -1,13 +0,0 @@ -import DateInterval from '../DateInterval/DateInterval'; -import Rule from './Rule'; -declare class RuleInterpreter { - render(rules: Rule[], itemDateInterval: DateInterval): { - render: string; - nextUpdate: Date | null; - } | null; - private parseRule; - private calculateNextUpdate; - private getVariableValue; -} -declare const _default: RuleInterpreter; -export default _default; diff --git a/dist/src/defaultConfiguration.d.ts b/dist/src/defaultConfiguration.d.ts deleted file mode 100644 index 722acf5..0000000 --- a/dist/src/defaultConfiguration.d.ts +++ /dev/null @@ -1,21 +0,0 @@ -import DateInterval from './DateInterval/DateInterval'; -declare const _default: { - refresh: number; - selector: string; - rules: ({ - condition: (itemDate: DateInterval) => boolean; - text: { - fr: string; - en: string; - }; - refresh?: undefined; - } | { - condition: (itemDate: DateInterval) => boolean; - refresh: number; - text: { - en: string; - fr: string; - }; - })[]; -}; -export default _default; diff --git a/dist/src/index.d.ts b/dist/src/index.d.ts deleted file mode 100644 index cb0ff5c..0000000 --- a/dist/src/index.d.ts +++ /dev/null @@ -1 +0,0 @@ -export {}; diff --git a/package-lock.json b/package-lock.json index cfe673b..3be65d1 100755 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "clever-date", - "version": "1.0.0", + "version": "0.0.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index f342b9f..af50f2e 100755 --- a/package.json +++ b/package.json @@ -1,9 +1,10 @@ { "name": "clever-date", - "version": "1.0.0", + "version": "0.0.0-version", "description": "A Javascript module to show an intelligent date refreshing at regular intervals.", "main": "dist/clever-date.js", "scripts": { + "prepare": "webpack", "eslint": "eslint ./src --ext .ts,.js,.d.ts", "eslint-fix": "eslint ./src --ext .ts,.js,.d.ts --fix", "watch": "webpack --watch",