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

[INTERNAL] move tasks to typescript #1278

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
10,378 changes: 5,698 additions & 4,680 deletions package-lock.json

Large diffs are not rendered by default.

22 changes: 14 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@
"scripts": {
"lint": "eslint src",
"prebuild": "rimraf dist",
"build": "npm run lint && tsc && node tasks/build.js",
"git-stage-and-push": "node tasks/git-stage-and-push.js",
"npm-publish": "node tasks/npm-publish.js",
"build": "npm run lint && tsc && ts-node --files tasks/build.ts",
"git-stage-and-push": "ts-node --files tasks/git-stage-and-push.js",
"npm-publish": "ts-node --files tasks/npm-publish.ts",
"publish-major": "npm run version-major && npm run test-silent && npm run git-stage-and-push && npm run npm-publish",
"publish-minor": "npm run version-minor && npm run test-silent && npm run git-stage-and-push && npm run npm-publish",
"publish-patch": "npm run version-patch && npm run test-silent && npm run git-stage-and-push && npm run npm-publish",
"test": "npm run build && node tasks/mochaTest.js",
"test-silent": "npm run build && node tasks/mochaTest.js --silent",
"version-major": "node tasks/version.js --type=\"major\"",
"version-minor": "node tasks/version.js --type=\"minor\"",
"version-patch": "node tasks/version.js --type=\"patch\"",
"test": "npm run build && ts-node --files tasks/mochaTest.ts",
"test-silent": "npm run build && ts-node --files tasks/mochaTest.ts --silent",
"version-major": "ts-node --files tasks/version.js --type=\"major\"",
"version-minor": "ts-node --files tasks/version.js --type=\"minor\"",
"version-patch": "ts-node --files tasks/version.js --type=\"patch\"",
"prepare": "husky install"
},
"lint-staged": {
Expand Down Expand Up @@ -49,20 +49,26 @@
"devDependencies": {
"@types/accept-language-parser": "1.5.3",
"@types/async": "3.2.10",
"@types/chai": "4.2.22",
"@types/colors": "1.2.1",
"@types/cross-spawn": "6.0.2",
"@types/errorhandler": "1.5.0",
"@types/express": "4.17.13",
"@types/fs-extra": "9.0.13",
"@types/glob": "^7.2.0",
"@types/livereload": "0.9.1",
"@types/lodash": "4.14.177",
"@types/minimist": "1.2.2",
"@types/mocha": "9.0.0",
"@types/morgan": "1.9.3",
"@types/multer": "1.4.7",
"@types/node": "16.11.7",
"@types/node-emoji": "1.8.1",
"@types/parse-author": "2.0.1",
"@types/read": "0.0.29",
"@types/response-time": "2.3.5",
"@types/semver": "7.3.9",
"@types/sinon": "^10.0.6",
"@types/targz": "1.0.1",
"@types/yargs": "17.0.5",
"@typescript-eslint/eslint-plugin": "5.4.0",
Expand Down
18 changes: 9 additions & 9 deletions src/cli/programmatic-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,31 +43,31 @@ function getDeps(options: {

export default {
dev: (
{ logger, ...options }: Options<typeof dev> & { logger: Logger },
{ logger, ...options }: Options<typeof dev> & { logger?: Logger },
cb: Cb<typeof dev>
): void => {
const deps = getDeps({ logger });

dev(deps)(options, cb);
},
init: (
{ logger, ...options }: Options<typeof init> & { logger: Logger },
{ logger, ...options }: Options<typeof init> & { logger?: Logger },
cb: Cb<typeof init>
): void => {
const deps = getDeps({ logger });

init(deps)(options, cb);
},
mock: (
{ logger, ...options }: Options<typeof mock> & { logger: Logger },
{ logger, ...options }: Options<typeof mock> & { logger?: Logger },
cb: Cb<typeof mock>
): void => {
const deps = getDeps({ logger });

mock(deps)(options, cb);
},
package: (
{ logger, ...options }: Options<typeof packageScript> & { logger: Logger },
{ logger, ...options }: Options<typeof packageScript> & { logger?: Logger },
cb: Cb<typeof packageScript>
): void => {
const deps = getDeps({ logger });
Expand All @@ -78,7 +78,7 @@ export default {
{
logger,
...options
}: Options<typeof publish> & { logger: Logger; registry?: string },
}: Options<typeof publish> & { logger?: Logger; registry?: string },
cb: Cb<typeof publish>
): void => {
const deps = getDeps({ logger, withRegistry: true });
Expand All @@ -89,7 +89,7 @@ export default {
{
logger,
...options
}: Options<typeof preview> & { logger: Logger; registry?: string },
}: Options<typeof preview> & { logger?: Logger; registry?: string },
cb: Cb<typeof preview>
): void => {
const deps = getDeps({ logger, withRegistry: true });
Expand All @@ -102,7 +102,7 @@ export default {
logger,
...options
}: Options<typeof registryAdd> & {
logger: Logger;
logger?: Logger;
registry?: string;
},
cb: Cb<typeof registryAdd>
Expand All @@ -116,7 +116,7 @@ export default {
logger,
...options
}: Options<typeof registryLs> & {
logger: Logger;
logger?: Logger;
registry?: string;
},
cb: Cb<typeof registryLs>
Expand All @@ -130,7 +130,7 @@ export default {
logger,
...options
}: Options<typeof registryRemove> & {
logger: Logger;
logger?: Logger;
registry?: string;
},
cb: Cb<typeof registryRemove>
Expand Down
1 change: 1 addition & 0 deletions src/globals.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
declare module 'oc-client';
declare module 'try-require';
declare module 'basic-auth-connect';
declare module 'injectr';

declare module 'semver-extra' {
interface SemverExtra {
Expand Down
23 changes: 12 additions & 11 deletions tasks/build.js → tasks/build.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
'use strict';
import fs from 'fs-extra';
import ocClientBrowser from 'oc-client-browser';
import log from './logger';
import path from 'path';
import Local from '../src/cli/domain/local';

const fs = require('fs-extra');
const ocClientBrowser = require('oc-client-browser');
const log = require('./logger');
const path = require('path');
const packageJson = require('../package');
const packageJson = fs.readJsonSync(path.join(__dirname, '..', 'package.json'));

const ocVersion = packageJson.version;
const clientComponentDir = '../src/components/oc-client/';
const ocClientPackageInfo = require(`${clientComponentDir}package.json`);
const ocClientPackageInfo = fs.readJsonSync(
path.join(__dirname, clientComponentDir, 'package.json')
);

log['start']('Building client');

fs.emptyDirSync(path.join(__dirname, clientComponentDir, 'src'));

ocClientBrowser.getLib((err, libContent) => {
if (err) {
log['error'](err);
log['error'](String(err));
}

ocClientPackageInfo.version = ocVersion;
Expand All @@ -33,14 +35,13 @@ ocClientBrowser.getLib((err, libContent) => {

ocClientBrowser.getMap((err, mapContent) => {
if (err) {
log['error'](err);
log['error'](String(err));
}
fs.writeFileSync(
path.join(__dirname, clientComponentDir, 'src/oc-client.min.map'),
mapContent
);

const Local = require('../dist/cli/domain/local').default;
const local = Local();
const packageOptions = {
componentPath: path.join(__dirname, clientComponentDir),
Expand All @@ -54,7 +55,7 @@ ocClientBrowser.getLib((err, libContent) => {
path.join(__dirname, clientComponentDir.replace('src', 'dist'))
);
log[err ? 'error' : 'complete'](
err ? err : 'Client has been built and packaged'
err ? String(err) : 'Client has been built and packaged'
);
});
});
Expand Down
41 changes: 0 additions & 41 deletions tasks/changelog.js

This file was deleted.

33 changes: 33 additions & 0 deletions tasks/changelog.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import fs from 'fs-extra';
import path from 'path';
import get from './git';

type Result = Array<{
tag: { to: string; from: string };
changes: string[];
}>;

export default async () => {
const writeChangelog = (changelog: Result) => {
let result = '## Change Log';
changelog.forEach(pr => {
if (pr.changes.length > 0) {
result += `\n\n### ${pr.tag.to}\n${pr.changes.join('\n')}`;
}
});
return fs.writeFile(path.join(__dirname, '../CHANGELOG.md'), result);
};

const result: Result = [];
const tags = await get.tags();

for (const tag of tags) {
const changes = await get.prs(tag);
result.push({
tag,
changes
});
}

return writeChangelog(result);
};
10 changes: 5 additions & 5 deletions tasks/git-stage-and-push.js → tasks/git-stage-and-push.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use strict';
import changelog from './changelog';
import path from 'path';
import fs from 'fs-extra';
import simpleGit from 'simple-git';

const changelog = require('./changelog');
const packageJson = require('../package');
const path = require('path');
const simpleGit = require('simple-git');
const packageJson = fs.readJsonSync(path.join(__dirname, '..', 'package.json'));

const git = simpleGit(path.join(__dirname, '..'));
const ocVersion = packageJson.version;
Expand Down
61 changes: 28 additions & 33 deletions tasks/git.js → tasks/git.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
'use strict';
import path from 'path';
import simpleGit, { ListLogLine, TaskOptions } from 'simple-git';
import fs from 'fs';

const path = require('path');
const simpleGit = require('simple-git');
const git = simpleGit(path.join(__dirname, '..'));
const fs = require('fs');

const utils = {
formatPrs: commits => {
const result = [];
formatPrs(
commits: ReadonlyArray<
{
message: string;
body: string;
} & ListLogLine
>
) {
const result: string[] = [];

commits.forEach(commit => {
const commitMessages = commit.message.split('Merge pull request');
Expand Down Expand Up @@ -46,15 +52,12 @@ const utils = {

return result;
},
getFirstCommitHash: cb => {
git.log(['--reverse'], (err, changes) => {
if (err) {
cb(err, null);
}
cb(null, changes.latest.hash);
});
async getFirstCommitHash() {
const changes = await git.log(['--reserve']);

return changes!.latest!.hash;
},
tagIntervals: (tags, hash) => {
tagIntervals(tags: string[], hash: string) {
const logIntervals = [];
for (let i = tags.length; i > 0; i--) {
const logInterval = {
Expand All @@ -74,31 +77,23 @@ const utils = {
}
};

module.exports = {
// Fetches PRs
prs: (options, cb) => {
export default {
async prs(options: TaskOptions) {
const opts = Object.assign({}, options, {
format: {
message: '%s',
body: '%b'
}
});
git.log(opts, (err, changes) => {
if (err) {
cb(err, null);
}
cb(null, utils.formatPrs(changes.all));
});
const changes = await git.log(opts);
return utils.formatPrs(changes.all);
},
// Fetches all tags
tags: cb => {
utils.getFirstCommitHash((err, hash) => {
git.tags((err, tags) => {
if (err) {
cb(err, null);
}
cb(null, utils.tagIntervals(tags.all, hash));
});
});
async tags() {
const [hash, tags] = await Promise.all([
utils.getFirstCommitHash(),
git.tags()
]);

return utils.tagIntervals(tags.all, hash);
}
};
Loading