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 vuejs scripts #221

Merged
merged 5 commits into from
Aug 11, 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
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.8.9",
"version": "1.9.0",
"description": "Scripts to init, run, test, deploy Mate academy homework projects",
"main": "bin/mateScripts.js",
"scripts": {
Expand Down
41 changes: 30 additions & 11 deletions mate-scripts/src/commands/Build.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ export interface BuildOptions {
export class BuildCommand extends Command {
private readonly parcel = new ParcelService(this.rootDir);

private readonly reactScripts =
this.config.nodejsMajorVersion === NodeJsVersions.v20
? new ViteService(this.rootDir)
: new ReactScriptsService(this.rootDir);
private readonly reactScripts = new ReactScriptsService(this.rootDir);

private readonly vite = new ViteService(this.rootDir);

protected common(): void {
// do nothing
Expand All @@ -32,19 +31,39 @@ export class BuildCommand extends Command {
this.layout(options);
};

protected react = (options: BuildOptions) => {
if (options.shouldShowInternalLogs) {
private buildReactScripts(showInternalLogs = false) {
if (showInternalLogs) {
console.log('START react-scripts build');
}

this.reactScripts.build(
DESTINATION_DIR,
options.shouldShowInternalLogs,
this.config.homepage,
);
this.reactScripts.build(DESTINATION_DIR, showInternalLogs);
}

private buildVite(showInternalLogs = false) {
if (showInternalLogs) {
console.log('START vite build');
}

this.vite.build(DESTINATION_DIR, showInternalLogs, this.config.homepage);
}

protected react = (options: BuildOptions) => {
if (this.config.nodejsMajorVersion === NodeJsVersions.v20) {
this.buildVite(options.shouldShowInternalLogs);
} else {
this.buildReactScripts(options.shouldShowInternalLogs);
}
};

protected reactTypescript = (options: BuildOptions) => {
this.react(options);
};

protected vue = (options: BuildOptions) => {
this.buildVite(options.shouldShowInternalLogs);
}

protected vueTypescript = (options: BuildOptions) => {
this.vue(options);
};
}
10 changes: 9 additions & 1 deletion mate-scripts/src/commands/Command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ export abstract class Command {
this.logNoImplementationWarning
);

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

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

protected [ProjectTypes.NodeJs]: (options?: any) => void = (
this.logNoImplementationWarning
);
Expand Down Expand Up @@ -80,7 +88,7 @@ export abstract class Command {
{
...
"mateAcademy": {
"projectType": "layout" | "javascript" | "react" | "reactTypescript" | "typescript" | "layoutDOM" | "nodeJs"
"projectType": "layout" | "javascript" | "react" | "reactTypescript" | "vue" | "vueTypescript" | "typescript" | "layoutDOM" | "nodeJs"
}
}
`,
Expand Down
8 changes: 8 additions & 0 deletions mate-scripts/src/commands/Deploy.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ export class DeployCommand extends Command {
this.react();
}

protected vue = () => {
this.ghPages.deploy(DESTINATION_DIR);
};

protected vueTypescript = () => {
this.vue();
};

private async setShellRunner() {
try {
await execBashCodeAsync('sh --version', { shouldBindStdout: false });
Expand Down
14 changes: 14 additions & 0 deletions mate-scripts/src/commands/Init.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,20 @@ export class InitCommand extends Command {
this.initGitHooks(ProjectTypes.ReactTypescript);
};

protected vue = () => {
this.copyGitIgnore(ProjectTypes.Vue);
// this.copyProjectTypeSpecificConfigs(ProjectTypes.Vue);
this.copyProjectTypeSpecificTemplates(ProjectTypes.Vue);
this.initGitHooks(ProjectTypes.Vue);
};

protected vueTypescript = () => {
this.copyGitIgnore(ProjectTypes.VueTypescript);
// this.copyProjectTypeSpecificConfigs(ProjectTypes.VueTypescript);
this.copyProjectTypeSpecificTemplates(ProjectTypes.VueTypescript);
this.initGitHooks(ProjectTypes.VueTypescript);
};

private copyCommonConfigs() {
const commonConfigsDir = path.join(InitCommand.configsDir, 'common');

Expand Down
14 changes: 13 additions & 1 deletion mate-scripts/src/commands/Lint.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,18 @@ export class LintCommand extends Command {
this.react(options);
};

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

if (styles) {
this.lintStyles(files);
}
};

protected vueTypescript = (options: LintOptions) => {
this.vue(options);
};

private mateLintHtml(files: LintOptions['files']) {
const filesToLint = files
? files.join(' ')
Expand Down Expand Up @@ -118,7 +130,7 @@ export class LintCommand extends Command {
: './src';

execBashCodeSilent(
`${this.binDir}eslint --ext .ts,.tsx,.js,.jsx ${filesToLint} --fix`,
`${this.binDir}eslint --ext .ts,.tsx,.js,.jsx,.vue ${filesToLint} --fix`,
);
}
}
14 changes: 14 additions & 0 deletions mate-scripts/src/commands/Migrate.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ export class MigrateCommand extends Command {
projectType: ProjectTypes.ReactTypescript,
},
},
[ProjectTypes.Vue]: {
mateAcademy: {
projectType: ProjectTypes.Vue,
},
},
[ProjectTypes.VueTypescript]: {
mateAcademy: {
projectType: ProjectTypes.VueTypescript,
},
},
[ProjectTypes.Typescript]: {
mateAcademy: {
projectType: ProjectTypes.Typescript,
Expand Down Expand Up @@ -217,6 +227,10 @@ export class MigrateCommand extends Command {

protected reactTypescript = emptyFn;

protected vue = emptyFn;

protected vueTypescript = emptyFn;

private static async safeRun(promise: Promise<any>) {
try {
await promise;
Expand Down
51 changes: 34 additions & 17 deletions mate-scripts/src/commands/Start.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ export class StartCommand extends Command {

private readonly jest = new JestService();

private readonly reactScripts =
this.config.nodejsMajorVersion === NodeJsVersions.v20
? new ViteService(this.rootDir)
: new ReactScriptsService(this.rootDir);
private readonly reactScripts = new ReactScriptsService(this.rootDir);

private readonly vite = new ViteService(this.rootDir);

protected common(): void {
// do nothing
Expand All @@ -37,21 +36,39 @@ export class StartCommand extends Command {
this.layout(options);
};

react = <
Async extends boolean,
Result = ExecResult<Async>
>(options: StartOptions, async?: Async): Result => (
this.reactScripts.start({
showLogs: options.shouldShowInternalLogs,
open: options.open,
react = <Async extends boolean, Result = ExecResult<Async>>(
options: StartOptions,
async?: Async,
): Result => {
const startOptions = {
port: options.port,
}, async)
);
open: options.open,
showLogs: options.shouldShowInternalLogs,
};

return (this.config.nodejsMajorVersion === NodeJsVersions.v20)
? this.vite.start(startOptions, async)
: this.reactScripts.start(startOptions, async);
}

reactTypescript = <
Async extends boolean,
Result = ExecResult<Async>
>(options: StartOptions, async?: Async): Result => this.react(options, async);
reactTypescript = <Async extends boolean, Result = ExecResult<Async>>(
options: StartOptions,
async?: Async,
): Result => this.react(options, async);

vue = <Async extends boolean, Result = ExecResult<Async>>(
options: StartOptions,
async?: Async,
): Result => this.vite.start({
port: options.port,
open: options.open,
showLogs: options.shouldShowInternalLogs,
}, async);

vueTypescript = <Async extends boolean, Result = ExecResult<Async>>(
options: StartOptions,
async?: Async,
): Result => this.vue(options, async);

protected javascript = () => {
this.jest.watch();
Expand Down
45 changes: 34 additions & 11 deletions mate-scripts/src/commands/Test.command.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ChildProcess } from 'child_process';
import getPort from 'get-port';
import { kill } from '../tools';
import { BackstopService, JestService } from '../services';
Expand Down Expand Up @@ -187,7 +188,26 @@ export class TestCommand extends Command {
});
};

protected react = async (options: TestOptions) => {
// eslint-disable-next-line arrow-body-style
private startReact = (port: number, shouldShowInternalLogs = false) => {
return this.startCommand.react(
{ shouldShowInternalLogs, open: false, port },
true,
);
};

// eslint-disable-next-line arrow-body-style
private startVue = (port: number, shouldShowInternalLogs = false) => {
return this.startCommand.vue(
{ shouldShowInternalLogs, open: false, port },
true,
);
};

private test = async (
options: TestOptions,
start: (port: number, shouldShowInternalLogs?: boolean) => ChildProcess,
) => {
this.showLogs = options.showLogs;

const {
Expand All @@ -197,16 +217,7 @@ export class TestCommand extends Command {

const startServer: StartServer = async () => {
const freePort = await TestCommand.getPort();

const childProcess = this.startCommand.react(
{
shouldShowInternalLogs: options.showLogs,
open: false,
port: freePort,
},
true,
);

const childProcess = start(freePort, options.showLogs);
let testsStarted = false;

const serverStartedPromise = new Promise<void>(
Expand Down Expand Up @@ -307,10 +318,22 @@ export class TestCommand extends Command {
});
}

protected react = async (options: TestOptions) => {
await this.test(options, this.startReact);
};

protected reactTypescript = async (options: TestOptions) => {
await this.react(options);
};

protected vue = async (options: TestOptions) => {
await this.test(options, this.startVue);
};

protected vueTypescript = async (options: TestOptions) => {
await this.vue(options);
};

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

protected reactTypescript = emptyFn;

protected typescript = emptyFn;

protected vue = emptyFn;

protected vueTypescript = emptyFn;
}
7 changes: 7 additions & 0 deletions mate-scripts/src/localScripts/getRepos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ export async function getRepos() {
const layout = [];
const layoutDOM = [];
const javascript = [];
const typescript = [];
const react = [];
const vue = [];

for (const name of repos) {
if (name.startsWith('layout_')) {
Expand All @@ -31,8 +33,12 @@ export async function getRepos() {
layoutDOM.push(name);
} else if (name.startsWith('js_')) {
javascript.push(name);
} else if (name.startsWith('ts_')) {
typescript.push(name);
} else if (name.startsWith('react_') || name.startsWith('redux_')) {
react.push(name);
} else if (name.startsWith('vue_')) {
vue.push(name);
} else {
none.push(name);
}
Expand All @@ -44,6 +50,7 @@ export async function getRepos() {
layoutDOM,
javascript,
react,
vue,
}, null, 2));
}

Expand Down
1 change: 1 addition & 0 deletions mate-scripts/src/tools/fileSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export function getRootDir() {
let folderContent = fs.readdirSync(rootDir);

try {
// eslint-disable-next-line no-constant-condition
while (true) {
if (isRoot(folderContent) && hasCorrectDependency(rootDir)) {
break;
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 @@ -7,6 +7,8 @@ export enum ProjectTypes {
React = 'react',
ReactTypescript = 'reactTypescript',
NodeJs = 'nodeJs',
Vue = 'vue',
VueTypescript = 'vueTypescript',
}

export enum NodeJsVersions {
Expand Down
Loading