Skip to content

Commit

Permalink
(chore) Run prettier on entire codebase (#75)
Browse files Browse the repository at this point in the history
* add pre-commit hook to format changed files with prettier, test on App.tsx

* apply formatting to entire codebase with prettier

Co-authored-by: Yan Chen <[email protected]>
  • Loading branch information
taylorham and chenyan-dfinity authored Aug 12, 2021
1 parent cd7f899 commit d6f13b5
Show file tree
Hide file tree
Showing 34 changed files with 941 additions and 632 deletions.
56 changes: 28 additions & 28 deletions .github/workflows/backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Backend

on:
push:
branches: [ main ]
branches: [main]
pull_request:

jobs:
Expand All @@ -14,30 +14,30 @@ jobs:
VESSEL_VERSION: v0.6.2
CI: true
steps:
- uses: actions/checkout@v2
- name: Install
run: |
echo y | DFX_VERSION=$DFX_VERSION bash -ci "$(curl -fsSL https://sdk.dfinity.org/install.sh)"
wget https://github.com/chenyan2002/ic-repl/releases/download/$IC_REPL_VERSION/ic-repl-linux64
cp ./ic-repl-linux64 /usr/local/bin/ic-repl
chmod a+x /usr/local/bin/ic-repl
wget https://github.com/dfinity/vessel/releases/download/$VESSEL_VERSION/vessel-linux64
cp ./vessel-linux64 /usr/local/bin/vessel
chmod a+x /usr/local/bin/vessel
- name: Build
run: |
dfx cache install
dfx start --background --no-artificial-delay
dfx canister --no-wallet create backend
dfx canister --no-wallet create wasm-utils
dfx build backend
- name: Test
run: |
(for f in service/pool/tests/*.test.sh; do
echo "==== Run test $f ===="
ic-repl -r http://localhost:8000 "$f" || exit
done)
- name: stop dfx
run: |
echo "dfx stop"
dfx stop
- uses: actions/checkout@v2
- name: Install
run: |
echo y | DFX_VERSION=$DFX_VERSION bash -ci "$(curl -fsSL https://sdk.dfinity.org/install.sh)"
wget https://github.com/chenyan2002/ic-repl/releases/download/$IC_REPL_VERSION/ic-repl-linux64
cp ./ic-repl-linux64 /usr/local/bin/ic-repl
chmod a+x /usr/local/bin/ic-repl
wget https://github.com/dfinity/vessel/releases/download/$VESSEL_VERSION/vessel-linux64
cp ./vessel-linux64 /usr/local/bin/vessel
chmod a+x /usr/local/bin/vessel
- name: Build
run: |
dfx cache install
dfx start --background --no-artificial-delay
dfx canister --no-wallet create backend
dfx canister --no-wallet create wasm-utils
dfx build backend
- name: Test
run: |
(for f in service/pool/tests/*.test.sh; do
echo "==== Run test $f ===="
ic-repl -r http://localhost:8000 "$f" || exit
done)
- name: stop dfx
run: |
echo "dfx stop"
dfx stop
2 changes: 1 addition & 1 deletion canister_ids.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
"wasm-utils": {
"ic": "ozk6r-tyaaa-aaaab-qab4a-cai"
}
}
}
13 changes: 10 additions & 3 deletions craco.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ let canisterEnv;
function initCanisterIds() {
let localCanisters, prodCanisters, canisters;
try {
localCanisters = require(path.resolve(".dfx", "local", "canister_ids.json"));
localCanisters = require(path.resolve(
".dfx",
"local",
"canister_ids.json"
));
} catch (error) {
console.log("No local canister_ids.json found. Continuing production");
}
Expand All @@ -26,7 +30,10 @@ function initCanisterIds() {
for (const canister in canisters) {
const canisterName = canister.toUpperCase() + "_CANISTER_ID";
process.env[canisterName] = canisters[canister][network];
canisterEnv = { ...canisterEnv, [canisterName]: canisters[canister][network] };
canisterEnv = {
...canisterEnv,
[canisterName]: canisters[canister][network],
};
}
}
initCanisterIds();
Expand All @@ -40,7 +47,7 @@ const overrideWebpackConfig = ({ webpackConfig }) => {
);
webpackConfig.plugins = [
...webpackConfig.plugins,
new webpack.EnvironmentPlugin(canisterEnv)
new webpack.EnvironmentPlugin(canisterEnv),
];

return webpackConfig;
Expand Down
4 changes: 1 addition & 3 deletions dfx.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
"type": "custom",
"candid": "service/wasm-utils/wasm-utils.did",
"wasm": "service/wasm-utils/target/wasm32-unknown-unknown/release/wasm_opt.wasm",
"build": [
"sh -c 'cd service/wasm-utils && ./build.sh'"
]
"build": ["sh -c 'cd service/wasm-utils && ./build.sh'"]
},
"backend": {
"dependencies": ["wasm-utils"],
Expand Down
7 changes: 3 additions & 4 deletions src/assets/styles/candid.css
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@

.InitArgs input,
.InitArgs select,
.InitArgs label {
margin-right: 0.8rem;
margin-bottom: 0.8rem;
margin-right: 0.8rem;
margin-bottom: 0.8rem;
}
.InitArgs .status {
color: var(--colorError);
color: var(--colorError);
}
77 changes: 51 additions & 26 deletions src/build.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { blobFromUint8Array, BinaryBlob } from "@dfinity/candid";
import { Principal } from "@dfinity/principal";
import { backend } from "./config/actor";
import { ILoggingStore } from './components/Logger';
import { ILoggingStore } from "./components/Logger";

export interface CanisterInfo {
id: Principal,
isExternal: bool,
timestamp?: bigint,
name?: string,
candid?: string | null,
id: Principal;
isExternal: bool;
timestamp?: bigint;
name?: string;
candid?: string | null;
}
/*
export function interpret(file: string, logger: ILoggingStore): void {
Expand All @@ -28,26 +28,35 @@ export function interpret(file: string, logger: ILoggingStore): void {
}*/

interface Diagnostics {
message: String,
message: String;
range: {
start: { line: number, character: number },
end: { line: number, character: number },
},
severity: number,
source: string,
start: { line: number; character: number };
end: { line: number; character: number };
};
severity: number;
source: string;
}

function logDiags(diagnostics: Diagnostics[], logger: ILoggingStore) {
diagnostics.forEach(d => {
const { message,severity, source, range: { start } } = d;
diagnostics.forEach((d) => {
const {
message,
severity,
source,
range: { start },
} = d;
const severityText = severity === 1 ? "Error" : "Warning";
const out = `${severityText} in file ${source}:${start.line}:${start.character} ${message}`
const out = `${severityText} in file ${source}:${start.line}:${start.character} ${message}`;
logger.log(out);
})
});
}

export async function compileCandid(worker, file: string, logger: ILoggingStore): Promise<string|undefined> {
const candid_result = await worker.Moc({ type:"candid", file });
export async function compileCandid(
worker,
file: string,
logger: ILoggingStore
): Promise<string | undefined> {
const candid_result = await worker.Moc({ type: "candid", file });
if (candid_result.diagnostics) logDiags(candid_result.diagnostics, logger);
// setMarkers(candid_result.diagnostics);
const candid_source = candid_result.code;
Expand All @@ -61,18 +70,27 @@ export async function compileCandid(worker, file: string, logger: ILoggingStore)
return candid_source;
}

export async function deploy(worker, canisterName: string, canisterInfo: CanisterInfo|null, args: BinaryBlob, mode: string, file: string, profiling: boolean, logger: ILoggingStore): Promise<CanisterInfo | undefined> {
logger.log('Compiling code...');
export async function deploy(
worker,
canisterName: string,
canisterInfo: CanisterInfo | null,
args: BinaryBlob,
mode: string,
file: string,
profiling: boolean,
logger: ILoggingStore
): Promise<CanisterInfo | undefined> {
logger.log("Compiling code...");

// NOTE: Will change to "ic" in a future moc release
const out = await worker.Moc({ type:"compile", file });
const out = await worker.Moc({ type: "compile", file });
if (out.diagnostics) logDiags(out.diagnostics, logger);
// setMarkers(out.diagnostics);
if (out.code === null) {
logger.log("syntax error");
} else {
const wasm = out.code;
logger.log(`Compiled Wasm size: ${Math.floor(wasm.length/1024)}KB`);
logger.log(`Compiled Wasm size: ${Math.floor(wasm.length / 1024)}KB`);
const module = blobFromUint8Array(wasm);
try {
logger.log(`Deploying code...`);
Expand Down Expand Up @@ -114,7 +132,10 @@ export async function deploy(worker, canisterName: string, canisterInfo: Caniste
}
}

async function createCanister(worker, logger: ILoggingStore): Promise<CanisterInfo> {
async function createCanister(
worker,
logger: ILoggingStore
): Promise<CanisterInfo> {
const timestamp = BigInt(Date.now()) * BigInt(1_000_000);
const nonce = await worker.pow(timestamp);
const info = await backend.getCanisterId(nonce);
Expand All @@ -136,8 +157,8 @@ async function install(
args: BinaryBlob,
mode: string,
profiling: boolean,
logger: ILoggingStore): Promise<CanisterInfo>
{
logger: ILoggingStore
): Promise<CanisterInfo> {
if (!canisterInfo) {
throw new Error("no canister id");
}
Expand All @@ -148,7 +169,11 @@ async function install(
mode: { [mode]: null },
canister_id: canisterId,
};
const new_info = await backend.installCode(canisterInfo, installArgs, profiling);
const new_info = await backend.installCode(
canisterInfo,
installArgs,
profiling
);
canisterInfo = new_info;
logger.log(`Code installed at canister id ${canisterInfo.id}`);
return canisterInfo;
Expand Down
13 changes: 7 additions & 6 deletions src/components/CandidUI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ export function CandidUI({ canisterId, candid, setCandidWidth, forceUpdate }) {
setIsExpanded(true);
}, [canisterId, candid, forceUpdate]);

const url = `${CANDID_UI_CANISTER_URL}/?id=${canisterId}&tag=${forceUpdate}` + didParam;
const url =
`${CANDID_UI_CANISTER_URL}/?id=${canisterId}&tag=${forceUpdate}` + didParam;
return (
<CandidPanel isExpanded={isExpanded}>
<PanelHeader>
Expand All @@ -62,19 +63,19 @@ export function CandidUI({ canisterId, candid, setCandidWidth, forceUpdate }) {
src={iconCollapse}
alt="Collapse icon"
/>
{isExpanded ? "CANDID UI" : null}
{isExpanded ? "CANDID UI" : null}
</Button>
{isExpanded ? (
<Button
onClick={() => { window.open(url, "_blank") }}
onClick={() => {
window.open(url, "_blank");
}}
>
<OpenIcon src={iconOpen} />
</Button>
) : null}
</PanelHeader>
{isExpanded ? (
<CandidFrame src={url} />
) : null}
{isExpanded ? <CandidFrame src={url} /> : null}
</CandidPanel>
);
}
Loading

0 comments on commit d6f13b5

Please sign in to comment.