Skip to content

Commit

Permalink
Add linter rules
Browse files Browse the repository at this point in the history
  • Loading branch information
shamsartem committed Aug 3, 2022
1 parent 72056b1 commit 68287e1
Show file tree
Hide file tree
Showing 27 changed files with 293 additions and 1 deletion.
56 changes: 55 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@
"error",
"never"
],
"curly": [
"error",
"all"
],
"no-unused-expressions": [
"error"
],
"dot-notation": [
"error",
{
Expand All @@ -142,6 +149,54 @@
"case": "camelCase"
}
],
"padding-line-between-statements": [
"error",
{
"blankLine": "always",
"prev": "multiline-expression",
"next": "*"
},
{
"blankLine": "always",
"prev": "*",
"next": "multiline-expression"
},
{
"blankLine": "always",
"prev": "multiline-block-like",
"next": "*"
},
{
"blankLine": "always",
"prev": "*",
"next": "multiline-block-like"
},
{
"blankLine": "always",
"prev": "multiline-const",
"next": "*"
},
{
"blankLine": "always",
"prev": "*",
"next": "multiline-const"
},
{
"blankLine": "always",
"prev": "multiline-let",
"next": "*"
},
{
"blankLine": "always",
"prev": "*",
"next": "multiline-let"
},
{
"blankLine": "any",
"prev": "case",
"next": "case"
}
],
"@typescript-eslint/explicit-function-return-type": [
"warn",
{
Expand Down Expand Up @@ -192,7 +247,6 @@
"./resources/license-header.js"
],
"brace-style": "off",
"padding-line-between-statements": "off",
"lines-between-class-members": "off",
"padded-blocks": "off",
"indent": "off",
Expand Down
8 changes: 8 additions & 0 deletions src/commands/dependency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const NAME = "NAME";
const RECOMMENDED = "recommended";
const VERSION_FLAG_NAME = "version";
const USE_FLAG_NAME = "use";

const RESET_ALL_MESSAGE = `If you omit ${color.yellow(
NAME
)} argument and include ${color.yellow(
Expand Down Expand Up @@ -97,15 +98,18 @@ export default class Dependency extends Command {
const dependencyConfig = await initDependencyConfig(this);
dependencyConfig.dependency = {};
await dependencyConfig.$commit();

for (const dependencyName of dependencyList) {
// eslint-disable-next-line no-await-in-loop
await ensureDependency(dependencyName, this);
}

this.log(
`Successfully reset all dependencies to ${color.yellow(
RECOMMENDED
)} versions`
);

return;
}

Expand Down Expand Up @@ -136,6 +140,7 @@ export default class Dependency extends Command {
}

const dependencyName = name;

const { recommendedVersion, packageName } = {
...npmDependencies,
...cargoDependencies,
Expand Down Expand Up @@ -244,8 +249,10 @@ const ensureDependency = async (
name: dependencyName,
commandObj,
});

break;
}

default: {
const _exhaustiveCheck: never = dependencyName;
return _exhaustiveCheck;
Expand All @@ -265,6 +272,7 @@ const handleUse = async ({
version,
}: HandleUseArg): Promise<void> => {
const dependencyConfig = await initDependencyConfig(commandObj);

const updatedDependencyVersionsConfig = {
...dependencyConfig.dependency,
[dependencyName]: version === RECOMMENDED ? undefined : version,
Expand Down
40 changes: 40 additions & 0 deletions src/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,21 +102,28 @@ export default class Deploy extends Command {
await ensureFluenceProject(this, isInteractive);

const keyPair = await getKeyPairFromFlags(flags, this, isInteractive);

if (keyPair instanceof Error) {
this.error(keyPair.message);
}

const fluenceConfig = await initReadonlyFluenceConfig(this);

if (fluenceConfig === null) {
this.error("You must init Fluence project first to deploy");
}

const relay = flags.relay ?? getRandomRelayAddr(fluenceConfig.relays);

const preparedForDeployItems = await prepareForDeploy({
commandObj: this,
fluenceConfig,
});

const aquaCli = await initAquaCli(this);
const tmpDeployJSONPath = await ensureFluenceTmpDeployJsonPath();
const appConfig = await initAppConfig(this);

if (appConfig !== null) {
// Prompt user to remove previously deployed app if
// it was already deployed before
Expand Down Expand Up @@ -144,11 +151,13 @@ export default class Deploy extends Command {
}

const successfullyDeployedServices: ServicesV2 = {};

this.log(
`Going to deploy project described in ${color.yellow(
replaceHomeDir(fluenceConfig.$getPath())
)}`
);

for (const {
count,
deployJSON,
Expand All @@ -170,23 +179,30 @@ export default class Deploy extends Command {
tmpDeployJSONPath,
commandObj: this,
});

if (res !== null) {
const { deployedServiceConfig, deployId, serviceName } = res;

const successfullyDeployedServicesByName =
successfullyDeployedServices[serviceName] ?? {};

successfullyDeployedServicesByName[deployId] = [
...(successfullyDeployedServicesByName[deployId] ?? []),
deployedServiceConfig,
];

successfullyDeployedServices[serviceName] =
successfullyDeployedServicesByName;
}
}
}

if (Object.keys(successfullyDeployedServices).length === 0) {
this.error("No services were deployed successfully");
}

await generateDeployedAppAqua(successfullyDeployedServices);

await generateRegisterApp({
deployedServices: successfullyDeployedServices,
aquaCli,
Expand Down Expand Up @@ -254,6 +270,7 @@ const prepareForDeploy = async ({
}>;

CliUx.ux.action.start("Making sure all services are downloaded");

const servicePaths = await Promise.all(
Object.entries(fluenceConfig.services).map(
([serviceName, { get, deploy }]): ServicePathPromises =>
Expand All @@ -272,6 +289,7 @@ const prepareForDeploy = async ({
}))()
)
);

CliUx.ux.action.stop();

type ServiceConfigPromises = Promise<{
Expand Down Expand Up @@ -330,6 +348,7 @@ const prepareForDeploy = async ({
).filter(
(moduleName): boolean => !(moduleName in serviceConfig.modules)
);

if (modulesNotFoundInServiceYaml.length > 0) {
commandObj.error(
`${color.yellow(
Expand All @@ -345,8 +364,10 @@ const prepareForDeploy = async ({
)} spelled correctly `
);
}

const { [FACADE_MODULE_NAME]: facadeModule, ...otherModules } =
serviceConfig.modules;

return [
...Object.entries(otherModules).map(
([moduleName, mod]): ModuleV0 =>
Expand All @@ -369,8 +390,10 @@ const prepareForDeploy = async ({
)
),
];

const marineCli = await initMarineCli(commandObj);
CliUx.ux.action.start("Making sure all modules are downloaded and built");

const mapOfAllModuleConfigs = new Map(
await Promise.all(
setOfAllGets.map(
Expand All @@ -397,11 +420,13 @@ const prepareForDeploy = async ({
workingDir: path.dirname(moduleConfig.$getPath()),
});
}

return [get, moduleConfig];
})()
)
)
);

CliUx.ux.action.stop();

return allDeployInfos.map(
Expand All @@ -416,10 +441,12 @@ const prepareForDeploy = async ({
commandObj.error(
`Unreachable. Wasn't able to find module config for ${get}`
);

return serviceModuleToJSONModuleConfig(moduleConfig, overrides);
}),
},
};

return {
...rest,
deployJSON,
Expand Down Expand Up @@ -453,6 +480,7 @@ const serviceModuleToJSONModuleConfig = (
overrides: Omit<ModuleV0, "get">
): JSONModuleConf => {
const overriddenConfig = { ...moduleConfig, ...overrides };

const {
name,
loggerEnabled,
Expand All @@ -468,30 +496,38 @@ const serviceModuleToJSONModuleConfig = (
name,
path: getModuleWasmPath(overriddenConfig),
};

if (loggerEnabled === true) {
jsonModuleConfig.logger_enabled = true;
}

if (typeof loggingMask === "number") {
jsonModuleConfig.logging_mask = loggingMask;
}

if (typeof maxHeapSize === "string") {
jsonModuleConfig.max_heap_size = maxHeapSize;
}

if (volumes !== undefined) {
jsonModuleConfig.mapped_dirs = Object.entries(volumes);
jsonModuleConfig.preopened_files = [...new Set(Object.values(volumes))];
}

if (preopenedFiles !== undefined) {
jsonModuleConfig.preopened_files = [
...new Set([...Object.values(volumes ?? {}), ...preopenedFiles]),
];
}

if (envs !== undefined) {
jsonModuleConfig.envs = Object.entries(envs);
}

if (mountedBinaries !== undefined) {
jsonModuleConfig.mounted_binaries = Object.entries(mountedBinaries);
}

return jsonModuleConfig;
};
/* eslint-enable camelcase */
Expand Down Expand Up @@ -534,7 +570,9 @@ const deployService = async ({
JSON.stringify(deployJSON, null, 2),
FS_OPTIONS
);

let result: string;

try {
result = await aquaCli(
{
Expand All @@ -558,10 +596,12 @@ const deployService = async ({

const [, blueprintId] = /Blueprint id:\n(.*)/.exec(result) ?? [];
const [, serviceId] = /And your service id is:\n"(.*)"/.exec(result) ?? [];

if (blueprintId === undefined || serviceId === undefined) {
commandObj.warn(
`Deployment finished without errors but not able to parse serviceId or blueprintId from aqua cli output:\n\n${result}`
);

return null;
}

Expand Down
Loading

0 comments on commit 68287e1

Please sign in to comment.