mirror of
https://github.com/fluencelabs/examples
synced 2025-04-25 10:42:16 +00:00
hello-world
This commit is contained in:
parent
9d7e32eb8c
commit
f36f92297a
8
fluence-js-examples/hello-world/.prettierrc.js
Normal file
8
fluence-js-examples/hello-world/.prettierrc.js
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
module.exports = {
|
||||||
|
semi: true,
|
||||||
|
trailingComma: 'all',
|
||||||
|
singleQuote: true,
|
||||||
|
printWidth: 120,
|
||||||
|
tabWidth: 4,
|
||||||
|
useTabs: false,
|
||||||
|
};
|
5
fluence-js-examples/hello-world/jest.config.js
Normal file
5
fluence-js-examples/hello-world/jest.config.js
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
module.exports = {
|
||||||
|
preset: 'ts-jest',
|
||||||
|
testEnvironment: 'node',
|
||||||
|
testPathIgnorePatterns: ['dist'],
|
||||||
|
};
|
23394
fluence-js-examples/hello-world/package-lock.json
generated
23394
fluence-js-examples/hello-world/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -1,25 +1,29 @@
|
|||||||
{
|
{
|
||||||
"name": "hello-world",
|
"name": "hello-world",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"prestart": "npm run compile-aqua",
|
"prestart": "npm run compile-aqua",
|
||||||
"start": "node -r ts-node/register src/index.ts",
|
"start": "node -r ts-node/register src/index.ts",
|
||||||
"compile-aqua": "aqua --import . -i ./aqua/ -o ./src/_aqua",
|
"test": "jest",
|
||||||
"watch-aqua": "chokidar \"**/*.aqua\" -c \"npm run compile-aqua\""
|
"compile-aqua": "aqua --import . -i ./aqua/ -o ./src/_aqua",
|
||||||
},
|
"watch-aqua": "chokidar \"**/*.aqua\" -c \"npm run compile-aqua\""
|
||||||
"author": "",
|
},
|
||||||
"license": "ISC",
|
"author": "",
|
||||||
"devDependencies": {
|
"license": "ISC",
|
||||||
"@fluencelabs/aqua": "^0.6.0-272",
|
"devDependencies": {
|
||||||
"@fluencelabs/aqua-lib": "^0.4.0",
|
"@fluencelabs/aqua": "^0.6.0-272",
|
||||||
"chokidar-cli": "^3.0.0",
|
"@fluencelabs/aqua-lib": "^0.4.0",
|
||||||
"ts-node": "^10.2.1",
|
"chokidar-cli": "^3.0.0",
|
||||||
"typescript": "^4.4.2"
|
"ts-node": "^10.2.1",
|
||||||
},
|
"typescript": "^4.4.2",
|
||||||
"dependencies": {
|
"@types/jest": "^27.0.3",
|
||||||
"@fluencelabs/fluence": "^0.19.1",
|
"jest": "^27.4.0",
|
||||||
"@fluencelabs/fluence-network-environment": "^1.0.13"
|
"ts-jest": "^27.0.7"
|
||||||
}
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@fluencelabs/fluence": "^0.19.1",
|
||||||
|
"@fluencelabs/fluence-network-environment": "^1.0.13"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
14
fluence-js-examples/hello-world/src/__test__/test.spec.ts
Normal file
14
fluence-js-examples/hello-world/src/__test__/test.spec.ts
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
import { main } from '../main';
|
||||||
|
|
||||||
|
describe('smoke test', () => {
|
||||||
|
it('should work', async () => {
|
||||||
|
console.log = jest.fn();
|
||||||
|
|
||||||
|
await main();
|
||||||
|
|
||||||
|
expect(console.log).toBeCalledTimes(3);
|
||||||
|
expect(console.log).toHaveBeenNthCalledWith(1, 'Hello, world!');
|
||||||
|
expect(console.log).toHaveBeenNthCalledWith(2, 'Wealth awaits you very soon.');
|
||||||
|
expect(console.log).toHaveBeenNthCalledWith(3, 'The relay time is: ', expect.anything());
|
||||||
|
});
|
||||||
|
});
|
@ -1,36 +1,3 @@
|
|||||||
import { Fluence } from "@fluencelabs/fluence";
|
import { main } from './main';
|
||||||
import { krasnodar } from "@fluencelabs/fluence-network-environment";
|
|
||||||
import {
|
|
||||||
registerHelloWorld,
|
|
||||||
sayHello,
|
|
||||||
getRelayTime,
|
|
||||||
tellFortune,
|
|
||||||
} from "./_aqua/hello-world";
|
|
||||||
|
|
||||||
async function main() {
|
|
||||||
await Fluence.start({ connectTo: krasnodar[0] });
|
|
||||||
|
|
||||||
registerHelloWorld({
|
|
||||||
hello: (str) => {
|
|
||||||
console.log(str);
|
|
||||||
},
|
|
||||||
getFortune: async () => {
|
|
||||||
await new Promise((resolve) => {
|
|
||||||
setTimeout(resolve, 1000);
|
|
||||||
});
|
|
||||||
return "Wealth awaits you very soon.";
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
await sayHello();
|
|
||||||
|
|
||||||
console.log(await tellFortune());
|
|
||||||
|
|
||||||
const relayTime = await getRelayTime();
|
|
||||||
|
|
||||||
console.log("The relay time is: ", new Date(relayTime).toLocaleString());
|
|
||||||
|
|
||||||
await Fluence.stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
main();
|
main();
|
||||||
|
29
fluence-js-examples/hello-world/src/main.ts
Normal file
29
fluence-js-examples/hello-world/src/main.ts
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
import { Fluence } from '@fluencelabs/fluence';
|
||||||
|
import { krasnodar } from '@fluencelabs/fluence-network-environment';
|
||||||
|
import { registerHelloWorld, sayHello, getRelayTime, tellFortune } from './_aqua/hello-world';
|
||||||
|
|
||||||
|
export async function main() {
|
||||||
|
await Fluence.start({ connectTo: krasnodar[0] });
|
||||||
|
|
||||||
|
registerHelloWorld({
|
||||||
|
hello: (str) => {
|
||||||
|
console.log(str);
|
||||||
|
},
|
||||||
|
getFortune: async () => {
|
||||||
|
await new Promise((resolve) => {
|
||||||
|
setTimeout(resolve, 1000);
|
||||||
|
});
|
||||||
|
return 'Wealth awaits you very soon.';
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
await sayHello();
|
||||||
|
|
||||||
|
console.log(await tellFortune());
|
||||||
|
|
||||||
|
const relayTime = await getRelayTime();
|
||||||
|
|
||||||
|
console.log('The relay time is: ', new Date(relayTime).toLocaleString());
|
||||||
|
|
||||||
|
await Fluence.stop();
|
||||||
|
}
|
@ -1,7 +1,25 @@
|
|||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"target": "ES2015",
|
"lib": [
|
||||||
"module": "CommonJS",
|
"es2015",
|
||||||
"skipLibCheck": true
|
"dom"
|
||||||
}
|
],
|
||||||
|
"outDir": "./dist/",
|
||||||
|
"target": "es5",
|
||||||
|
"module": "commonjs",
|
||||||
|
"strict": true,
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"skipLibCheck": true,
|
||||||
|
"forceConsistentCasingInFileNames": true,
|
||||||
|
"declaration": true,
|
||||||
|
"declarationMap": false,
|
||||||
|
"sourceMap": true,
|
||||||
|
},
|
||||||
|
"exclude": [
|
||||||
|
"node_modules",
|
||||||
|
"dist"
|
||||||
|
],
|
||||||
|
"include": [
|
||||||
|
"src"
|
||||||
|
],
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user