Skip to content

Commit

Permalink
add mondaycoderc check
Browse files Browse the repository at this point in the history
  • Loading branch information
danielva-monday committed Sep 25, 2024
1 parent d56cef6 commit 1cbe138
Show file tree
Hide file tree
Showing 5 changed files with 178 additions and 14 deletions.
3 changes: 2 additions & 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",
"description": "A cli tool to manage apps (and monday-code projects) in monday.com",
"author": "monday.com Apps Team",
"type": "module",
Expand Down Expand Up @@ -53,6 +53,7 @@
"@oclif/core": "^3.18.1",
"@oclif/plugin-autocomplete": "^3.0.5",
"@oclif/plugin-help": "^6.0.12",
"ajv": "^8.17.1",
"archiver": "^5.3.1",
"args-parser": "^1.3.0",
"axios": "^1.6.5",
Expand Down
95 changes: 95 additions & 0 deletions src/assets/mondaycodercSchema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"RUNTIME": {
"type": "string",
"enum": ["Python", "Java", "Go", "PHP", "Ruby", "Nodejs", "NETCore"]
},
"RUNTIME_VERSION": {
"type": "string"
}
},
"dependencies": {
"RUNTIME": ["RUNTIME_VERSION"]
},
"allOf": [
{
"if": { "properties": { "RUNTIME": { "const": "Python" } } },
"then": {
"properties": {
"RUNTIME_VERSION": {
"type": "string",
"pattern": "^3\\.(10|11|12)\\.\\d+$"
}
}
}
},
{
"if": { "properties": { "RUNTIME": { "const": "Java" } } },
"then": {
"properties": {
"RUNTIME_VERSION": {
"type": "string",
"enum": ["11", "17", "18"]
}
}
}
},
{
"if": { "properties": { "RUNTIME": { "const": "Go" } } },
"then": {
"properties": {
"RUNTIME_VERSION": {
"type": "string",
"pattern": "^1\\.\\d+.\\d+$"
}
}
}
},
{
"if": { "properties": { "RUNTIME": { "const": "PHP" } } },
"then": {
"properties": {
"RUNTIME_VERSION": {
"type": "string",
"pattern": "^8\\.(1|2)\\.\\d+$"
}
}
}
},
{
"if": { "properties": { "RUNTIME": { "const": "Ruby" } } },
"then": {
"properties": {
"RUNTIME_VERSION": {
"type": "string",
"pattern": "^3\\.(1|2)\\.\\d+$"
}
}
}
},
{
"if": { "properties": { "RUNTIME": { "const": "Nodejs" } } },
"then": {
"properties": {
"RUNTIME_VERSION": {
"type": "string",
"pattern": "^(12|14|16|18|20)\\.\\d+\\.\\d+$"
}
}
}
},
{
"if": { "properties": { "RUNTIME": { "const": "NETCore" } } },
"then": {
"properties": {
"RUNTIME_VERSION": {
"type": "string",
"pattern": "^(6|7)\\.\\d+$"
}
}
}
}
]
}
34 changes: 24 additions & 10 deletions src/services/files-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';

import Ajv from 'ajv';
import archiver from 'archiver';
import glob from 'glob';
import parseGitIgnore from 'parse-gitignore';

import rcFileSchema from 'assets/mondaycodercSchema.json';

Check failure on line 10 in src/services/files-service.ts

View workflow job for this annotation

GitHub Actions / Run validations

Cannot find module 'assets/mondaycodercSchema.json' or its corresponding type declarations.
import { CONFIG_NAME } from 'services/config-service';

import logger from '../utils/logger.js';
Expand Down Expand Up @@ -113,18 +115,30 @@ export const createGitignoreAndAppendConfigFileIfNeeded = (directoryPath: string
**/
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;
};
const ajv = new Ajv();
const validate = ajv.compile(rcFileSchema);
const isValid = validate(rcFileContent);
if (!isValid) {
throw new Error('Invalid .mondaycoderc file');
}
}
};

Expand Down
4 changes: 4 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"baseUrl": ".",
"strict": true,
"target": "ESNext",
"resolveJsonModule": true,
"lib": [
"ES2022",
"DOM"
Expand Down Expand Up @@ -46,6 +47,9 @@
],
"commands-base/*": [
"./src/commands-base/*"
],
"assets/*": [
"./src/assets/*"
]
}
},
Expand Down
56 changes: 53 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2983,6 +2983,16 @@ ajv@^6.12.4:
json-schema-traverse "^0.4.1"
uri-js "^4.2.2"

ajv@^8.17.1:
version "8.17.1"
resolved "https://registry.yarnpkg.com/ajv/-/ajv-8.17.1.tgz#37d9a5c776af6bc92d7f4f9510eba4c0a60d11a6"
integrity sha512-B/gBuNg5SiMTrPkC+A2+cW0RszwxYmn6VYxB/inlBStS5nx6xHIt/ehKRhIMhqusl7a8LjQoZnjCs5vhwxOQ1g==
dependencies:
fast-deep-equal "^3.1.3"
fast-uri "^3.0.1"
json-schema-traverse "^1.0.0"
require-from-string "^2.0.2"

ansi-align@^3.0.1:
version "3.0.1"
resolved "https://registry.npmjs.org/ansi-align/-/ansi-align-3.0.1.tgz"
Expand Down Expand Up @@ -4978,6 +4988,11 @@ fast-safe-stringify@^2.1.1:
resolved "https://registry.npmjs.org/fast-safe-stringify/-/fast-safe-stringify-2.1.1.tgz"
integrity sha512-W+KJc2dmILlPplD/H4K9l9LcAHAfPtP6BY84uVLXQ6Evcz9Lcg33Y2z1IVblT6xdY54PXYVHEv+0Wpq8Io6zkA==

fast-uri@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/fast-uri/-/fast-uri-3.0.1.tgz#cddd2eecfc83a71c1be2cc2ef2061331be8a7134"
integrity sha512-MWipKbbYiYI0UC7cl8m/i/IWTqfC8YXsqjzybjddLsFjStroQzsHXkc73JutMvBiXmOvapk+axIl79ig5t55Bw==

[email protected]:
version "4.2.5"
resolved "https://registry.npmjs.org/fast-xml-parser/-/fast-xml-parser-4.2.5.tgz#a6747a09296a6cb34f2ae634019bf1738f3b421f"
Expand Down Expand Up @@ -6590,6 +6605,11 @@ json-schema-traverse@^0.4.1:
resolved "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz"
integrity sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==

json-schema-traverse@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz#ae7bcb3656ab77a73ba5c49bf654f38e6b6860e2"
integrity sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==

json-stable-stringify-without-jsonify@^1.0.1:
version "1.0.1"
resolved "https://registry.npmjs.org/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz"
Expand Down Expand Up @@ -8406,6 +8426,11 @@ require-directory@^2.1.1:
resolved "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz"
integrity sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==

require-from-string@^2.0.2:
version "2.0.2"
resolved "https://registry.yarnpkg.com/require-from-string/-/require-from-string-2.0.2.tgz#89a7fdd938261267318eafe14f9c32e598c36909"
integrity sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==

resolve-alpn@^1.0.0, resolve-alpn@^1.2.0:
version "1.2.1"
resolved "https://registry.npmjs.org/resolve-alpn/-/resolve-alpn-1.2.1.tgz"
Expand Down Expand Up @@ -8884,7 +8909,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 +8977,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 +9710,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 +9728,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

0 comments on commit 1cbe138

Please sign in to comment.