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

Maorba/feature/mapps local repository token #50

Merged
merged 6 commits into from
Oct 29, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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": "1.3.5",
"version": "1.3.6",
maorb-dev 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
13 changes: 13 additions & 0 deletions src/commands/init/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { Flags } from '@oclif/core';
import { BaseCommand } from 'commands-base/base-command';
import { CONFIG_KEYS } from 'consts/config';
import { CONFIG_NAME, ConfigService } from 'services/config-service';
import { getCurrentWorkingDirectory } from 'services/env-service';
import { createGitignoreAndAppendConfigFileIfNeeded } from 'services/files-service';
import { PromptService } from 'services/prompt-service';
import { InitCommandArguments } from 'types/commands/init';
import logger from 'utils/logger';
Expand All @@ -27,6 +29,12 @@ export default class Init extends BaseCommand {
char: 't',
description: 'monday.com api access token (https://developer.monday.com/api-reference/docs/authentication)',
}),
local: Flags.boolean({
char: 'l',
description: 'create the configuration file locally, in the current project working directory',
default: false,
required: false,
}),
});

static args = {};
Expand All @@ -39,6 +47,11 @@ export default class Init extends BaseCommand {
};

try {
if (flags.local) {
this.config.configDir = getCurrentWorkingDirectory();
createGitignoreAndAppendConfigFileIfNeeded(this.config.configDir);
}

ConfigService.init(args, this.config.configDir, { override: true, setInProcessEnv: true });
logger.info(`'${CONFIG_NAME}' created`);
} catch (error) {
Expand Down
10 changes: 7 additions & 3 deletions src/hooks/init.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import { Command } from '@oclif/core';

import { ConfigService } from 'services/config-service';
import { getAppsDomain, initCurrentWorkingDirectory } from 'services/env-service';
import { getAppsDomain, getCurrentWorkingDirectory, initCurrentWorkingDirectory } from 'services/env-service';
import { enablePrintCommand } from 'utils/command-printer';
import logger, { enableDebugMode } from 'utils/logger';

export default function init(opts: Command) {
initCurrentWorkingDirectory();

if (ConfigService.checkLocalConfigExists()) {
opts.config.configDir = getCurrentWorkingDirectory();
}

ConfigService.loadConfigToProcessEnv(opts.config.configDir);
if (opts.argv.includes('--verbose')) {
enableDebugMode();
Expand All @@ -15,6 +21,4 @@ export default function init(opts: Command) {
if (opts.argv.includes('--print-command') || opts.argv.includes('--pc')) {
enablePrintCommand();
}

initCurrentWorkingDirectory();
}
11 changes: 11 additions & 0 deletions src/services/config-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { existsSync, mkdirSync, readFileSync, unlinkSync, writeFileSync } from '
import { join } from 'node:path';

import { BadConfigError } from 'errors/bad-config-error';
import { getCurrentWorkingDirectory } from 'services/env-service';
import { ConfigData, InitConfigOptions } from 'types/services/config-service';
import logger from 'utils/logger';

Expand All @@ -19,6 +20,14 @@ const checkConfigExists = (directoryPath: string, fileName = CONFIG_NAME) => {
return configExists;
};

const checkLocalConfigExists = (fileName = CONFIG_NAME) => {
const filePath = join(getCurrentWorkingDirectory(), fileName);
const localConfigExists = existsSync(filePath);
if (!configExists) configExists = localConfigExists;

return localConfigExists;
};

const camelToUpperSnakeCase = (str: string) => str.replaceAll(/[A-Z]/g, letter => `_${letter}`).toUpperCase();

const generateConfigKeyInProcessEnv = (configKey: keyof ConfigData) => {
Expand Down Expand Up @@ -57,6 +66,8 @@ const writeConfig = (data: ConfigData, directoryPath: string, fileName = CONFIG_
export const ConfigService = {
checkConfigExists,

checkLocalConfigExists,

getConfigDataByKey(key: keyof ConfigData): string {
const configKeyInProcessEnv = generateConfigKeyInProcessEnv(key);
return process.env[configKeyInProcessEnv] as string;
Expand Down
14 changes: 14 additions & 0 deletions src/services/files-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
import path from 'node:path';

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

Check warning on line 5 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 logger from '../utils/logger.js';

export const readFileData = (filePath: string): Buffer => {
Expand Down Expand Up @@ -46,6 +48,18 @@
}
};

export const createGitignoreAndAppendConfigFileIfNeeded = (directoryPath: string, fileName = CONFIG_NAME) => {
maorb-dev marked this conversation as resolved.
Show resolved Hide resolved
const filePath = path.join(directoryPath, '.gitignore');
if (!checkIfFileExists(filePath)) {
fs.writeFileSync(filePath, '', 'utf8');
}

const gitignoreContent = fs.readFileSync(filePath, 'utf8');
if (!gitignoreContent.includes(fileName)) {
fs.appendFileSync(filePath, `\n${fileName}`, 'utf8');
}
};

const getFilesToExcludeForArchive = (directoryPath: string): string[] => {
const DEBUG_TAG = 'ignore_files_for_archive';
const mappsIgnorePath = getIgnorePath(directoryPath, '.mappsignore');
Expand All @@ -68,7 +82,7 @@
const DEBUG_TAG = 'ignore_files_for_archive';
logger.debug(`${DEBUG_TAG} - Searching for ${ignoreFile} file`);
const ignoreSearchPattern = `${directoryPath}/**/${ignoreFile}`;
const [ignorePath] = glob.sync(ignoreSearchPattern);

Check warning on line 85 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 @@ -76,7 +90,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 93 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
2 changes: 1 addition & 1 deletion src/services/push-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export const buildAssetToDeployTask = async (
try {
if (!ctx.directoryPath) {
const currentDirectoryPath = getCurrentWorkingDirectory();
logger.debug(`Directory path not provided using current directory: ${currentDirectoryPath}`);
logger.debug(`Directory path not provided. using current directory: ${currentDirectoryPath}`);
ctx.directoryPath = currentDirectoryPath;
}

Expand Down