Skip to content

Commit

Permalink
v0.1.0-alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
ooyyloo committed Feb 17, 2022
1 parent 5cffbea commit fc49b59
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 95 deletions.
2 changes: 2 additions & 0 deletions .vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
**/.eslintrc.json
**/*.map
**/*.ts
tsconfig.tsbuildinfo
packages/cli/**
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "rtf-readme",
"publisher": "Mufan",
"displayName": "PleaseREADME",
"publisher": "mufan",
"displayName": "rtf-README",
"description": "README hint for users who need to read the README",
"version": "0.1.0",
"private": true,
Expand Down
9 changes: 4 additions & 5 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"name": "please-readme-cli",
"name": "rtf-readme",
"publisher": "mufan",
"description": "",
"version": "0.1.0",
"license": "MIT",
"bin": {
"readme-cli": "out/program/readme-cli.js"
"rtfr": "out/program/main.js",
"rtf-readme": "out/program/main.js"
},
"dependencies": {
"clime": "^0.5.14",
Expand All @@ -14,7 +15,5 @@
"please-readme.lib": "*",
"simple-git": "^3.1.1"
},
"scripts": {
"debug": "tsc -p ./tsconfig.json && node out/program/readme-cli.js E:\\MyFiles\\Projects\\working\\makeflow-web"
}
"scripts": {}
}
11 changes: 6 additions & 5 deletions packages/cli/src/program/commands/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@ export default class extends Command {
}

let logResult = await simpleGitObject.log({file: readmeFilePath});
let commit = logResult.latest === null ? '' : logResult.latest.hash;

if (logResult.latest === null) {
return;
}

let commit = logResult.latest.hash;

if (Array.isArray(cache.users)) {
let user = _.find(cache.users, {name: username, email});
Expand Down Expand Up @@ -186,10 +191,6 @@ export default class extends Command {
file.path === readmeFilesPattern.readmePosixRelativePath,
)?.commit;

// 找到该用户最后提交的README的commit,然后和latestCommitRead比较,得到用户读过的最新的commit。
// 如果最新的commit在当前commit之后,那就不报错。
// 如果最新的commit在当前commit之前,报错。

let count1 = 1;

if (latestCommitRead) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import * as Path from 'path';
import {CLI, Shim} from 'clime';

let cli = new CLI('readme-cli', Path.join(__dirname, 'commands'));
let cli = new CLI('rtfr', Path.join(__dirname, 'commands'));

let shim = new Shim(cli);
shim.execute(process.argv);
56 changes: 28 additions & 28 deletions packages/extension/package.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
{
"name": "please-readme.ext",
"publisher": "mufan",
"description": "",
"version": "0.1.0",
"scripts": {
"build": "tsc -p ./"
},
"dependencies": {
"@types/glob": "^7.2.0",
"@types/lodash": "^4.14.178",
"@types/mkdirp": "^1.0.2",
"@types/mocha": "^9.0.0",
"@types/node": "14.x",
"@types/rimraf": "^3.0.2",
"@types/vscode": "^1.63.0",
"@typescript-eslint/eslint-plugin": "^5.9.1",
"@typescript-eslint/parser": "^5.9.1",
"@vscode/test-electron": "^2.0.3",
"chokidar": "^3.5.3",
"glob": "^7.2.0",
"lodash": "^4.17.21",
"minimatch": "^3.0.5",
"mkdirp": "^1.0.4",
"mocha": "^9.1.3",
"please-readme.lib": "*",
"rimraf": "^3.0.2",
"simple-git": "^3.1.1"
}
"name": "rtf-readme.ext",
"publisher": "mufan",
"description": "",
"version": "0.1.0",
"scripts": {
"build": "tsc -p ./"
},
"dependencies": {
"@types/glob": "^7.2.0",
"@types/lodash": "^4.14.178",
"@types/mkdirp": "^1.0.2",
"@types/mocha": "^9.0.0",
"@types/node": "14.x",
"@types/rimraf": "^3.0.2",
"@types/vscode": "^1.63.0",
"@typescript-eslint/eslint-plugin": "^5.9.1",
"@typescript-eslint/parser": "^5.9.1",
"@vscode/test-electron": "^2.0.3",
"chokidar": "^3.5.3",
"glob": "^7.2.0",
"lodash": "^4.17.21",
"minimatch": "^3.0.5",
"mkdirp": "^1.0.4",
"mocha": "^9.1.3",
"please-readme.lib": "*",
"rimraf": "^3.0.2",
"simple-git": "^3.1.1"
}
}
69 changes: 20 additions & 49 deletions packages/extension/src/program/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import {TextEncoder} from 'util';
import * as vscode from 'vscode';

import {
CONFIG_FILENAME,
CACHE_FILENAME,
README_FILE_NAMES,
READMEInfo,
UserInfo,
getFilesPatternsOfREADME,
pathToPosixPath,
posixPathToPath,
getSimpleGitObject,
Expand Down Expand Up @@ -146,35 +147,18 @@ async function loadREADMEFile(absolutePath: string): Promise<void> {
);

if (workspaceFolders) {
let filesPatterns = [];

let readmeContent = (
await vscode.workspace.fs.readFile(
vscode.Uri.from({scheme: 'file', path: absolutePath}),
)
).toString();

let readmeParts = readmeContent.split(/<!--/g);

for (let i = 1; i < readmeParts.length; ++i) {
let parts = readmeParts[i].split(/-->/g);

if (parts.length <= 1) {
continue;
}

let matchResult = parts[0].match(/\s*readme\s*\:\s*(.+\S)\s*/);

if (matchResult && matchResult.length >= 2) {
filesPatterns.push(matchResult[1].split(Path.sep).join(Path.posix.sep));
}
}
let filesPatterns = getFilesPatternsOfREADME(readmeContent);

for (let workspaceFolder of workspaceFolders) {
let workspacePath = workspaceFolder.uri.path;
let relativePath = Path.posix.relative(workspacePath, absolutePath);

let commit: string = '';
let commit: string | undefined = undefined;

let simpleGitObject = workspacePathToGitDict[workspacePath];

Expand All @@ -183,17 +167,11 @@ async function loadREADMEFile(absolutePath: string): Promise<void> {
}

try {
let diffResult = await simpleGitObject.diff([relativePath]);

if (diffResult) {
commit = '';
} else {
let logResult = await simpleGitObject.log({
file: posixPathToPath(absolutePath),
});
let logResult = await simpleGitObject.log({
file: posixPathToPath(absolutePath),
});

commit = logResult.latest === null ? '' : logResult.latest.hash;
}
commit = logResult.latest === null ? undefined : logResult.latest.hash;
} catch (e) {
if (
!(e as any)
Expand All @@ -206,6 +184,10 @@ async function loadREADMEFile(absolutePath: string): Promise<void> {
}
}

if (commit === undefined) {
continue;
}

if (!pleaseREADMEConfigs[workspacePath]) {
pleaseREADMEConfigs[workspacePath] = {
files: [
Expand Down Expand Up @@ -282,7 +264,7 @@ async function readREADMEFile(absolutePath: string): Promise<void> {

let readme = _.find(config.files, {path: relativePath});

if (!readme) {
if (!readme || !readme.commit) {
continue;
}

Expand All @@ -298,12 +280,6 @@ async function readREADMEFile(absolutePath: string): Promise<void> {
config.users.push(user);
}

if (readme.commit === '') {
await writeToCacheFile(workspacePath);

continue;
}

let file = _.find(user.files, {path: relativePath});

if (!file) {
Expand Down Expand Up @@ -345,7 +321,7 @@ function deleteREADMEFile(absolutePath: string) {
}

async function loadCacheFile(workspacePath: string) {
let cacheFilePath = Path.posix.resolve(workspacePath, CONFIG_FILENAME);
let cacheFilePath = Path.posix.resolve(workspacePath, CACHE_FILENAME);

try {
let stat = await vscode.workspace.fs.stat(
Expand Down Expand Up @@ -428,7 +404,7 @@ async function writeToCacheFile(workspacePath: string) {
let pleaseREADMEConfigsClone: any = {users: pleaseREADMEConfig.users};
let uri = vscode.Uri.from({
scheme: 'file',
path: Path.posix.resolve(workspacePath, CONFIG_FILENAME),
path: Path.posix.resolve(workspacePath, CACHE_FILENAME),
});

let stringToWrite = JSON.stringify(pleaseREADMEConfigsClone, undefined, 2);
Expand Down Expand Up @@ -483,11 +459,6 @@ async function hintIfNotRead(absolutePath: string) {
}

for (let readme of config.files) {
// if the readme has been modified by this user, do not hint
if (readme.commit === '') {
continue;
}

// if the readme has been read, do not hint
let file = _.find(user.files, {path: readme.path, commit: readme.commit});

Expand Down Expand Up @@ -601,7 +572,7 @@ async function handleSpecialFilesAndConditionalHint(
let filePath = uri.path;
let fileName = Path.posix.basename(filePath);

if (fileName === CONFIG_FILENAME) {
if (fileName === CACHE_FILENAME) {
switch (eventType) {
case vscode.FileChangeType.Changed:
case vscode.FileChangeType.Created:
Expand Down Expand Up @@ -736,10 +707,6 @@ export async function activate(context: vscode.ExtensionContext) {
}),
);

await loadFiles();

await writeToCacheFiles();

for (let workspaceFolder of vscode.workspace.workspaceFolders || []) {
let workspacePosixPath = workspaceFolder.uri.path;
let workspacePath = posixPathToPath(workspacePosixPath);
Expand All @@ -754,6 +721,10 @@ export async function activate(context: vscode.ExtensionContext) {
workspacePathToGitDict[workspacePosixPath] = simpleGitObject;
}

await loadFiles();

await writeToCacheFiles();

for (let document of vscode.workspace.textDocuments) {
let absolutePath = pathToPosixPath(document.fileName);

Expand Down
5 changes: 0 additions & 5 deletions packages/extension/src/program/file-system-provider.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/* --------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
* ------------------------------------------------------------------------------------------ */

import * as chokidar from 'chokidar';
import * as fs from 'fs';
import mkdirp from 'mkdirp';
Expand Down

0 comments on commit fc49b59

Please sign in to comment.