diff --git a/examples/cjs-js/haetae.config.mjs b/examples/cjs-js/haetae.config.mjs index 5b1c821..354fc1a 100644 --- a/examples/cjs-js/haetae.config.mjs +++ b/examples/cjs-js/haetae.config.mjs @@ -9,7 +9,7 @@ export default configure({ env: { foo: 'bar', }, - run: () => ({ hi: 'there' }), + run: () => console.log('hi!'), }, }, }) diff --git a/examples/cjs-ts-1/haetae.config.mts b/examples/cjs-ts-1/haetae.config.mts index 5b1c821..354fc1a 100644 --- a/examples/cjs-ts-1/haetae.config.mts +++ b/examples/cjs-ts-1/haetae.config.mts @@ -9,7 +9,7 @@ export default configure({ env: { foo: 'bar', }, - run: () => ({ hi: 'there' }), + run: () => console.log('hi!'), }, }, }) diff --git a/examples/cjs-ts-2/haetae.config.mts b/examples/cjs-ts-2/haetae.config.mts index 5b1c821..354fc1a 100644 --- a/examples/cjs-ts-2/haetae.config.mts +++ b/examples/cjs-ts-2/haetae.config.mts @@ -9,7 +9,7 @@ export default configure({ env: { foo: 'bar', }, - run: () => ({ hi: 'there' }), + run: () => console.log('hi!'), }, }, }) diff --git a/examples/esm-js/haetae.config.js b/examples/esm-js/haetae.config.js index f7c57a9..354fc1a 100644 --- a/examples/esm-js/haetae.config.js +++ b/examples/esm-js/haetae.config.js @@ -2,14 +2,14 @@ import { configure } from 'haetae' export default configure({ commands: { - foo: { + helloworld: { run: () => ({ hello: 'world' }), }, - bar: { + hi: { env: { - hi: 'there', + foo: 'bar', }, - run: () => ({ hello: 'world' }), + run: () => console.log('hi!'), }, }, }) diff --git a/examples/esm-ts/haetae.config.ts b/examples/esm-ts/haetae.config.ts index 5b1c821..354fc1a 100644 --- a/examples/esm-ts/haetae.config.ts +++ b/examples/esm-ts/haetae.config.ts @@ -9,7 +9,7 @@ export default configure({ env: { foo: 'bar', }, - run: () => ({ hi: 'there' }), + run: () => console.log('hi!'), }, }, }) diff --git a/examples/my-calculator/README.md b/examples/my-calculator/README.md new file mode 100644 index 0000000..878f025 --- /dev/null +++ b/examples/my-calculator/README.md @@ -0,0 +1,3 @@ +# my-calculator-test + +This is an example project guided by the official *Getting Started* docs. diff --git a/examples/my-calculator/haetae.config.js b/examples/my-calculator/haetae.config.js new file mode 100644 index 0000000..bd49442 --- /dev/null +++ b/examples/my-calculator/haetae.config.js @@ -0,0 +1,25 @@ +import { configure, $, git, js, utils } from 'haetae' + +export default configure({ + commands: { + test: { + run: async () => { + // An array of changed files + const changedFiles = await git.changedFiles() + // console.log(changedFiles) + // An array of test files that (transitively) depend on changed files + const affectedTestFiles = await js.dependOn({ + dependents: ['**/*.test.js'], // glob pattern + // dependents: await utils.glob(['**/*.test.js']), // glob pattern + dependencies: changedFiles, + }) + + if (affectedTestFiles.length > 0) { + // Equals to "pnpm jest /path/to/foo.test.ts /path/to/bar.test.ts ..." + // Change 'pnpm jest' to your test runner. + await $`pnpm jest ${affectedTestFiles}` + } + }, + }, + }, +}) diff --git a/examples/my-calculator/package.json b/examples/my-calculator/package.json new file mode 100644 index 0000000..ee0d5cc --- /dev/null +++ b/examples/my-calculator/package.json @@ -0,0 +1,17 @@ +{ + "name": "my-calculator", + "version": "0.0.0", + "type": "module", + "private": true, + "scripts": { + "haetae": "haetae", + "ht": "haetae", + "jest": "cross-env NODE_OPTIONS=--experimental-vm-modules jest", + "test": "haetae test" + }, + "devDependencies": { + "cross-env": "^7.0.3", + "haetae": "workspace:*", + "jest": "^29.5.0" + } +} diff --git a/examples/my-calculator/src/add.js b/examples/my-calculator/src/add.js new file mode 100644 index 0000000..d64a34e --- /dev/null +++ b/examples/my-calculator/src/add.js @@ -0,0 +1,3 @@ +export default function add(a, b) { + return a + b +} diff --git a/examples/my-calculator/src/exponent.js b/examples/my-calculator/src/exponent.js new file mode 100644 index 0000000..79981a7 --- /dev/null +++ b/examples/my-calculator/src/exponent.js @@ -0,0 +1,10 @@ +import multiply from './multiply.js' + +export default function exponent(a, b) { + let agg = 1 + for (let i = 0; i < b; i += 1) { + agg = multiply(agg, a) + } + + return agg // === a^b +} diff --git a/examples/my-calculator/src/multiply.js b/examples/my-calculator/src/multiply.js new file mode 100644 index 0000000..8eb339b --- /dev/null +++ b/examples/my-calculator/src/multiply.js @@ -0,0 +1,10 @@ +import add from './add.js' + +export default function multiply(a, b) { + let agg = 0 + for (let i = 0; i < b; i += 1) { + agg = add(agg, a) + } + + return agg // === a * b +} diff --git a/examples/my-calculator/src/subtract.js b/examples/my-calculator/src/subtract.js new file mode 100644 index 0000000..d524d36 --- /dev/null +++ b/examples/my-calculator/src/subtract.js @@ -0,0 +1,5 @@ +import add from './add.js' + +export default function subtract(a, b) { + return add(a, -b) // a - b +} diff --git a/examples/my-calculator/test/add.test.js b/examples/my-calculator/test/add.test.js new file mode 100644 index 0000000..5d0a697 --- /dev/null +++ b/examples/my-calculator/test/add.test.js @@ -0,0 +1,9 @@ +import add from '../src/add.js' + +describe('add()', () => { + test('basic usage', () => { + expect(add(1, 2)).toBe(3) + expect(add(4, 2)).toBe(6) + expect(add(12, 5)).toBe(17) + }) +}) diff --git a/examples/my-calculator/test/exponent.test.js b/examples/my-calculator/test/exponent.test.js new file mode 100644 index 0000000..7f9986a --- /dev/null +++ b/examples/my-calculator/test/exponent.test.js @@ -0,0 +1,9 @@ +import exponent from '../src/exponent.js' + +describe('exponent()', () => { + test('basic usage', () => { + expect(exponent(0, 2)).toBe(0) + expect(exponent(1, 3)).toBe(1) + expect(exponent(2, 4)).toBe(16) + }) +}) diff --git a/examples/my-calculator/test/multiply.test.js b/examples/my-calculator/test/multiply.test.js new file mode 100644 index 0000000..397d7dc --- /dev/null +++ b/examples/my-calculator/test/multiply.test.js @@ -0,0 +1,9 @@ +import multiply from '../src/multiply.js' + +describe('multiply()', () => { + test('basic usage', () => { + expect(multiply(1, 1)).toBe(1) + expect(multiply(2, 4)).toBe(8) + expect(multiply(3, 3)).toBe(9) + }) +}) diff --git a/examples/my-calculator/test/subtract.test.js b/examples/my-calculator/test/subtract.test.js new file mode 100644 index 0000000..dad7d5a --- /dev/null +++ b/examples/my-calculator/test/subtract.test.js @@ -0,0 +1,9 @@ +import subtract from '../src/subtract.js' + +describe('subtract()', () => { + test('basic usage', () => { + expect(subtract(1, 2)).toBe(-1) + expect(subtract(4, 2)).toBe(2) + expect(subtract(12, 5)).toBe(7) + }) +}) diff --git a/package.json b/package.json index 680ba95..aec5d7c 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,8 @@ "lint:ci": "eslint \"*.{js,cjs,mjs,jsx,ts,cts,mts,tsx,md,mdx}\"", "lint:md": "pnpm lint:md:ci --fix", "lint:md:ci": "markdownlint", - "test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --coverage", + "jest": "cross-env NODE_OPTIONS=--experimental-vm-modules NODE_NO_WARNINGS=1 jest", + "test": "cross-env NODE_OPTIONS=--experimental-vm-modules NODE_NO_WARNINGS=1 jest --coverage", "husky-skip": "cross-env HUSKY=0", "commit": "git cz", "prepare": "husky install", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index dafb89c..e2209b2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -195,6 +195,18 @@ importers: specifier: ^4.8.2 version: 4.8.2 + examples/my-calculator: + devDependencies: + cross-env: + specifier: ^7.0.3 + version: 7.0.3 + haetae: + specifier: workspace:* + version: link:../../packages/haetae + jest: + specifier: ^29.5.0 + version: 29.5.0(@types/node@18.6.0)(ts-node@10.9.1) + packages/cli: dependencies: '@haetae/common': @@ -6560,7 +6572,7 @@ packages: resolution: {integrity: sha512-Kijeg9Dag6CKtIDA7O21zNTACqD5MD/8HfIV8pdD94vFyFuer52SigdC3IQMhab3vACxXMiFk+yMHNdbqtyTGA==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} dependencies: - '@babel/code-frame': 7.22.5 + '@babel/code-frame': 7.22.13 '@jest/types': 29.5.0 '@types/stack-utils': 2.0.1 chalk: 4.1.2