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

added nodeJs type project, which uses different test.yml file #210

Merged
merged 2 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
26 changes: 26 additions & 0 deletions mate-scripts/configs/git-hooks/nodeJs/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

function join_by { local IFS="$1"; shift; echo "$*"; }

PASS=true

# ESLint
STAGED_JS_FILES=$(git diff --cached --name-only --diff-filter=ACM ./src | grep ".\(j\|t\)sx\{0,1\}$")

if [[ "$STAGED_JS_FILES" != "" ]]; then
echo "Linting nodeJs files"

npx mate-scripts lint --nodeJs $(join_by " " ${STAGED_JS_FILES})

if [[ "$?" == 0 ]]; then
printf "\033[32mESLint Passed\033[0m\n\n"
else
printf "\033[031mESLint Failed\033[0m\n\n"
PASS=false
fi
fi

if ! ${PASS}; then
printf "Pre-commits check failed. Fix problems above before commit.\n\n"
exit 1
fi
20 changes: 20 additions & 0 deletions mate-scripts/configs/git-hooks/nodeJs/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

PASS=true

# Tests
echo "Testing nodeJs"

npx mate-scripts test

if [[ "$?" == 0 ]]; then
printf "\033[32mTests Passed\033[0m\n\n"
else
printf "\033[031mTests Failed\033[0m\n\n"
PASS=false
fi

if ! ${PASS}; then
printf "Pre-push check failed. Fix problems above before commit.\n\n"
exit 1
fi
9 changes: 9 additions & 0 deletions mate-scripts/configs/gitignoreTemplates/.gitignore.nodeJs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# IDE
.idea
.vscode

# Node
node_modules

# MacOS
.DS_Store
10 changes: 10 additions & 0 deletions mate-scripts/configs/nodeJs/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
extends: '@mate-academy/eslint-config',
env: {
jest: true
},
rules: {
'no-proto': 0
},
plugins: ['jest']
};
44 changes: 44 additions & 0 deletions mate-scripts/configs/nodeJs/.github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Test

on:
pull_request:
branches: [master]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x]
services:
postgres:
image: postgres:latest
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
POSTGRES_DB: students
POSTGRES_PORT: 5432
POSTGRES_HOST: localhost
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v1
with:
node-version: '14'
- name: Install dependencies
run: npm install
- name: Run tests
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
POSTGRES_DB: students
POSTGRES_HOST: localhost
POSTGRES_PORT: 5432
run: npm test
2 changes: 1 addition & 1 deletion mate-scripts/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion mate-scripts/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mate-academy/scripts",
"version": "1.3.3",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The version must be 1.4.0

"version": "1.7.0",
"description": "Scripts to init, run, test, deploy Mate academy homework projects",
"main": "bin/mateScripts.js",
"scripts": {
Expand Down
6 changes: 5 additions & 1 deletion mate-scripts/src/commands/Command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ export abstract class Command {
this.logNoImplementationWarning
);

protected [ProjectTypes.NodeJs]: (options?: any) => void = (
this.logNoImplementationWarning
);

constructor(rootDir: string) {
this.rootDir = rootDir;
this.binDir = path.join(rootDir, 'node_modules/.bin/');
Expand Down Expand Up @@ -76,7 +80,7 @@ export abstract class Command {
{
...
"mateAcademy": {
"projectType": "layout" | "javascript" | "react" | "reactTypescript" | "typescript" | "layoutDOM"
"projectType": "layout" | "javascript" | "react" | "reactTypescript" | "typescript" | "layoutDOM" | "nodeJs"
}
}
`,
Expand Down
6 changes: 6 additions & 0 deletions mate-scripts/src/commands/Init.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ export class InitCommand extends Command {
this.initGitHooks(ProjectTypes.Javascript);
};

protected nodeJs = () => {
this.copyGitIgnore(ProjectTypes.NodeJs);
this.copyProjectTypeSpecificConfigs(ProjectTypes.NodeJs);
this.initGitHooks(ProjectTypes.NodeJs);
}

protected react = () => {
this.copyGitIgnore(ProjectTypes.React);
this.copyProjectTypeSpecificConfigs(ProjectTypes.React);
Expand Down
8 changes: 8 additions & 0 deletions mate-scripts/src/commands/Lint.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ export class LintCommand extends Command {
}
};

protected nodeJs = (options: LintOptions) => {
const { nodeJs, files } = options;

if (nodeJs) {
this.lintJs(files);
}
};

protected react = (options: LintOptions) => {
const { javascript, styles, files } = options;

Expand Down
41 changes: 41 additions & 0 deletions mate-scripts/src/commands/Migrate.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ export class MigrateCommand extends Command {
postinstall: 'npm run update',
test: 'npm run lint && npm run test:only',
},
nodeJs: {
init: 'mate-scripts init',
start: 'mate-scripts start',
lint: 'mate-scripts lint',
'test:only': 'mate-scripts test',
update: 'mate-scripts update',
postinstall: 'npm run update',
test: 'npm run lint && npm run test:only',
},
};

private static mateConfig: Record<ProjectTypes, any> = {
Expand Down Expand Up @@ -65,6 +74,11 @@ export class MigrateCommand extends Command {
projectType: ProjectTypes.Typescript,
},
},
[ProjectTypes.NodeJs]: {
mateAcademy: {
projectType: ProjectTypes.NodeJs,
},
},
};

protected async common(options: MigrateOptions) {
Expand Down Expand Up @@ -166,6 +180,33 @@ export class MigrateCommand extends Command {
await execBashCodeAsync(`${this.binDir}eslint ./ --fix`);
};

protected nodeJs = async () => {
await execBashCodeAsync('npm i -D @mate-academy/scripts');

const pkg = await this.getPackage();

pkg.scripts = MigrateCommand.scripts.nodeJs;

delete pkg['lint-staged'];
delete pkg.husky;

await nodeFs.writeFile(
path.join(this.rootDir, 'package.json'),
JSON.stringify({
...pkg,
...MigrateCommand.mateConfig.nodeJs,
}, null, 2),
);

await MigrateCommand.safeRun(
fs.remove(path.join(this.rootDir, '.travis.yml')),
);

await execBashCodeAsync('npm rm husky lint-staged');
await execBashCodeAsync('npm i');
await execBashCodeAsync(`${this.binDir}eslint ./ --fix`);
};

async getPackage(): Promise<any> {
const pkg = await fs.readFile(path.join(this.rootDir, 'package.json'), { encoding: 'utf-8' });

Expand Down
4 changes: 4 additions & 0 deletions mate-scripts/src/commands/Test.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,10 @@ export class TestCommand extends Command {
this.jest.once();
};

protected nodeJs = () => {
this.jest.once();
}

protected typescript = () => {
this.jest.once();
};
Expand Down
2 changes: 2 additions & 0 deletions mate-scripts/src/commands/Update.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export class UpdateCommand extends Command {

protected javascript = emptyFn;

protected nodeJs = emptyFn;

protected react = emptyFn;

protected reactTypescript = emptyFn;
Expand Down
1 change: 1 addition & 0 deletions mate-scripts/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const defaultLintersConfig: Linters = {
styles: true,
javascript: true,
htmlLint: false,
nodeJs: true,
};

export const defaultTestsConfig: Tests = {
Expand Down
6 changes: 4 additions & 2 deletions mate-scripts/src/controllers/lint.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,26 @@ export const lintController: Controller<LintOptions> = (
bem,
javascript,
htmlLint,
nodeJs,
} = command;

const ensuredFiles = !files || !files.length
? null
: files;

if (!(styles || html || javascript || bem || htmlLint)) {
if (!(styles || html || javascript || bem || htmlLint || nodeJs)) {
return {
styles: true,
html: true,
bem: true,
javascript: true,
htmlLint: true,
nodeJs: true,
files: ensuredFiles,
};
}

return {
styles, html, bem, javascript, files: ensuredFiles, htmlLint,
styles, html, bem, javascript, files: ensuredFiles, htmlLint, nodeJs,
};
};
1 change: 1 addition & 0 deletions mate-scripts/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ program
.option('-m, --mate-htmllint', 'Mate HTML linter: lint html (markup-style) only', false)
.option('-b, --bem', 'lint html (BEM) only', false)
.option('-j, --javascript', 'lint javascript only', false)
.option('-j, --nodeJs', 'lint nodeJs only', false)
.description('lint html, css and js files')
.action(commandFactory.make(LintCommand, lintController));

Expand Down
2 changes: 2 additions & 0 deletions mate-scripts/src/typedefs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export enum ProjectTypes {
Typescript = 'typescript',
React = 'react',
ReactTypescript = 'reactTypescript',
NodeJs = 'nodeJs',
}

export interface Linters {
Expand All @@ -14,6 +15,7 @@ export interface Linters {
styles: boolean;
javascript: boolean;
htmlLint: boolean;
nodeJs: boolean;
}

export interface Tests {
Expand Down
Loading