Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add mondaycoderc check #103

Merged
merged 11 commits into from
Sep 29, 2024
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mondaycom/apps-cli",
"version": "4.1.1",
"version": "4.1.2",
danielva-monday marked this conversation as resolved.
Show resolved Hide resolved
"description": "A cli tool to manage apps (and monday-code projects) in monday.com",
"author": "monday.com Apps Team",
"type": "module",
Expand Down
28 changes: 18 additions & 10 deletions src/services/files-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
import path from 'node:path';

import archiver from 'archiver';
import glob from 'glob';

Check warning on line 6 in src/services/files-service.ts

View workflow job for this annotation

GitHub Actions / Run validations

Using exported name 'glob' as identifier for default export
import parseGitIgnore from 'parse-gitignore';

import { CONFIG_NAME } from 'services/config-service';
import { mondaycodercSchema } from 'services/schemas/mondaycoderc-schema';

import logger from '../utils/logger.js';

Expand Down Expand Up @@ -113,18 +114,25 @@
**/
export const validateIfCanBuild = (directoryPath: string): void => {
const filePath = path.join(directoryPath, 'yarn.lock');
if (!checkIfFileExists(filePath)) {
return;
if (checkIfFileExists(filePath)) {
const packageJsonPath = path.join(directoryPath, 'package.json');
const packageJsonContent = fs.readFileSync(packageJsonPath, 'utf8');
const packageJson = JSON.parse(packageJsonContent) as { scripts?: { build?: string } };
const hasBuildCommand = packageJson?.scripts?.build;
if (hasBuildCommand) {
throw new Error(
'monday-code does not support yarn projects with a build command. If you need a build step, use npm instead',
);
}
}

const packageJsonPath = path.join(directoryPath, 'package.json');
const packageJsonContent = fs.readFileSync(packageJsonPath, 'utf8');
const packageJson = JSON.parse(packageJsonContent) as { scripts?: { build?: string } };
const hasBuildCommand = packageJson?.scripts?.build;
if (hasBuildCommand) {
throw new Error(
'monday-code does not support yarn projects with a build command. If you need a build step, use npm instead',
);
const rcFilePath = path.join(directoryPath, '.mondaycoderc');
if (checkIfFileExists(rcFilePath)) {
const rcFileContent = JSON.parse(fs.readFileSync(rcFilePath, 'utf8')) as {
RUNTIME: string;
RUNTIME_VERSION: string;
};
mondaycodercSchema.parse(rcFileContent);
}
};

Expand Down Expand Up @@ -156,7 +164,7 @@
ignoreSearchPattern = ignoreSearchPattern.replaceAll('\\', '/');
}

const [ignorePath] = glob.sync(ignoreSearchPattern);

Check warning on line 167 in src/services/files-service.ts

View workflow job for this annotation

GitHub Actions / Run validations

Caution: `glob` also has a named export `sync`. Check if you meant to write `import {sync} from 'glob'` instead
return ignorePath;
};

Expand All @@ -164,7 +172,7 @@
const DEBUG_TAG = 'ignore_files_for_archive';
logger.debug(`${DEBUG_TAG} - Found ${ignorePath}`);
logger.debug(`${DEBUG_TAG} - Creating exclude files list`);
const parsedIgnore = parseGitIgnore.parse(ignorePath);

Check warning on line 175 in src/services/files-service.ts

View workflow job for this annotation

GitHub Actions / Run validations

Caution: `parseGitIgnore` also has a named export `parse`. Check if you meant to write `import {parse} from 'parse-gitignore'` instead
logger.debug(`${DEBUG_TAG} - validating and aligning exclude files list`);
const filesToExclude = alignPatternsForArchive(parsedIgnore?.patterns, directoryPath);
return filesToExclude;
Expand Down
45 changes: 45 additions & 0 deletions src/services/schemas/mondaycoderc-schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { z } from 'zod';

export const mondaycodercSchema = z
danielva-monday marked this conversation as resolved.
Show resolved Hide resolved
.object({
RUNTIME: z.enum(['Python', 'Java', 'Go', 'PHP', 'Ruby', 'Nodejs', 'NETCore']).optional(),
RUNTIME_VERSION: z.string().optional(),
})
.refine(
data => {
if (data.RUNTIME) {
if (data.RUNTIME === 'Python') {
return /^3\.(10|11|12)\.\d+$/.test(data.RUNTIME_VERSION || '');
}

if (data.RUNTIME === 'Java') {
return ['11', '17', '18'].includes(data.RUNTIME_VERSION || '');
}

if (data.RUNTIME === 'Go') {
return /^1\.\d+\.\d+$/.test(data.RUNTIME_VERSION || '');
}

if (data.RUNTIME === 'PHP') {
return /^8\.(1|2)\.\d+$/.test(data.RUNTIME_VERSION || '');
}

if (data.RUNTIME === 'Ruby') {
return /^3\.(1|2)\.\d+$/.test(data.RUNTIME_VERSION || '');
}

if (data.RUNTIME === 'Nodejs') {
return /^(12|14|16|18|20)\.\d+\.\d+$/.test(data.RUNTIME_VERSION || '');
}

if (data.RUNTIME === 'NETCore') {
return /^(6|7)\.\d+$/.test(data.RUNTIME_VERSION || '');
}
}

return true;
},
{
message: 'Invalid RUNTIME_VERSION for the specified RUNTIME',
},
);
31 changes: 28 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8884,7 +8884,16 @@ string-length@^4.0.1:
char-regex "^1.0.2"
strip-ansi "^6.0.0"

"string-width-cjs@npm:string-width@^4.2.0", "string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.0.0, string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
"string-width-cjs@npm:string-width@^4.2.0":
version "4.2.3"
resolved "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
dependencies:
emoji-regex "^8.0.0"
is-fullwidth-code-point "^3.0.0"
strip-ansi "^6.0.1"

"string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.0.0, string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
version "4.2.3"
resolved "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
Expand Down Expand Up @@ -8943,7 +8952,14 @@ string_decoder@~1.1.1:
dependencies:
safe-buffer "~5.1.0"

"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
version "6.0.1"
resolved "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
dependencies:
ansi-regex "^5.0.1"

strip-ansi@^6.0.0, strip-ansi@^6.0.1:
version "6.0.1"
resolved "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
Expand Down Expand Up @@ -9669,7 +9685,7 @@ wordwrap@^1.0.0:
resolved "https://registry.npmjs.org/wordwrap/-/wordwrap-1.0.0.tgz"
integrity sha512-gvVzJFlPycKc5dZN4yPkP8w7Dc37BtP1yczEneOb4uq34pXZcvrtRTmWV8W+Ume+XCxKgbjM+nevkyFPMybd4Q==

"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
version "7.0.0"
resolved "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
Expand All @@ -9687,6 +9703,15 @@ wrap-ansi@^6.0.1:
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrap-ansi@^7.0.0:
version "7.0.0"
resolved "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
dependencies:
ansi-styles "^4.0.0"
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrap-ansi@^8.0.1, wrap-ansi@^8.1.0:
version "8.1.0"
resolved "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-8.1.0.tgz"
Expand Down
Loading