Skip to content

Commit

Permalink
Merge pull request #52 from appworks-lab/release-next
Browse files Browse the repository at this point in the history
Release 0.2.1
  • Loading branch information
luhc228 authored Aug 5, 2021
2 parents c901e69 + 4643b69 commit 7ec3e31
Show file tree
Hide file tree
Showing 64 changed files with 779 additions and 241 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = getESLintConfig('react-ts', {
'@typescript-eslint/explicit-function-return-type': 0,
'react-hooks/exhaustive-deps': 0,
'@iceworks/best-practices/recommend-polyfill': 0,
'import/order': 1,
'import/order': 0,
'no-param-reassign': 0,
'@typescript-eslint/no-require-imports': 0,
'no-await-in-loop': 0
Expand Down
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# CHANGELOG

## 0.2.1

- Fix: fail to get internal npm package info

## 0.2.0

- Feat: git manager, including global config, user config and SSH key
- Feat: npm register manager, fast switch between different registries, e.g: npm, yarn, taobao
- Feat: npm package manager, fast install, upgrade, reinstall and uninstall global dependencies

## 0.1.1

- Feat: record DAU
- Feat: download package automatically
- Fix: nvm install fail when bash profile files exist
- Fix: icon size
- Fix: code command was not found

## 0.1.0

- Feat: fast install packages, including VS Code/Git/Node.js/AppWorks/Chrome
- Feat: node version manager
14 changes: 7 additions & 7 deletions main/constants.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import * as path from 'path';
import * as os from 'os';
import { ILocalPackageInfo } from './types';

export const APPLICATIONS_DIR_PATH = '/Applications';

export const HOME_DIR = os.homedir();
export const PACKAGE_JSON_FILE_NAME = 'package.json';

export const TOOLKIT_DIR = path.join(process.env.HOME, '.toolkit');
Expand All @@ -26,15 +27,14 @@ export const INSTALL_COMMAND_PACKAGES = [
commandRelativePath: './Contents/Resources/app/bin/code',
},
];
export const NOT_REINSTALL_DEPENDENCIES = ['npm'];
// bash profile
export const PROFILE_FILES = ['.bash_profile', '.bashrc', '.zshrc'];
export const DEFAULT_PROFILE_FILE = '.bash_profile';
export const ZSHRC_FILE_NAME = '.zshrc';
export const BASH_PROFILE_FILE_NAME = '.bash_profile';
export const PROFILE_FILES = [BASH_PROFILE_FILE_NAME, '.bashrc', ZSHRC_FILE_NAME];
// npm
export const NPMRC_PATH = path.join(process.env[(process.platform === 'win32') ? 'USERPROFILE' : 'HOME'], '.npmrc');
export const NPMRC_PATH = path.join(HOME_DIR, '.npmrc');
export const NPM_REGISTRY = 'https://registry.npmjs.org/';
export const TAOBAO_NPM_REGISTRY = 'https://registry.npm.taobao.org';
export const ALI_NPM_REGISTRY = 'https://registry.npm.alibaba-inc.com/';
export const TAOBAO_NODE_MIRROR = 'https://npm.taobao.org/mirrors/node';
// git
export const GLOBAL_GITCONFIG_PATH = path.join(process.env[(process.platform === 'win32') ? 'USERPROFILE' : 'HOME'], '.gitconfig');
export const GLOBAL_GITCONFIG_PATH = path.join(HOME_DIR, '.gitconfig');
8 changes: 2 additions & 6 deletions main/data/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,8 @@
{
"name": "taobao",
"registry": "https://registry.npm.taobao.org/",
"isInternal": false
},
{
"name": "tnpm",
"registry": " https://registry.npm.alibaba-inc.com/",
"isInternal": true
"isInternal": false,
"recommended": true
}
],
"browserExtensions": [
Expand Down
2 changes: 1 addition & 1 deletion main/data/shells/install-nvm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ nvm_source() {
elif [ "_$NVM_METHOD" = "_git" ] || [ -z "$NVM_METHOD" ]; then
# NVM_SOURCE_URL="https://github.com/${NVM_GITHUB_REPO}.git"
# use China mirror
NVM_SOURCE_URL="https://gitee.com/mirrors/nvm.git"
NVM_SOURCE_URL="https://gitee.com/luhengchang/nvm.git"
else
nvm_echo >&2 "Unexpected value \"$NVM_METHOD\" for \$NVM_METHOD"
return 1
Expand Down
26 changes: 26 additions & 0 deletions main/git/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
removeSSHConfig,
addSSHConfig,
} from './ssh';
import { record } from '../recorder';

const USER_GIT_CONFIG_FILENAME_PREFIX = '.gitconfig-';
const IGNORE_CONFIG_KEYS = ['gitDir'];
Expand All @@ -24,6 +25,10 @@ export async function getGlobalGitConfig() {
export async function updateGlobalGitConfig(gitConfig: object) {
log.info('update-global-git-config', gitConfig);
await writeGitConfig(GLOBAL_GITCONFIG_PATH, gitConfig);
record({
module: 'git',
action: 'updateGlobalGitConfig',
});
}

export async function getExistedUserGitConfigNames() {
Expand Down Expand Up @@ -70,6 +75,10 @@ export async function addUserGitConfig(userGitConfig: IAddUserConfig) {
delete userGitConfig.configName;
await writeGitConfig(gitConfigPath, userGitConfig);
await addSSHConfig({ hostName, configName, userName });
record({
module: 'git',
action: 'addUserGitConfig',
});
}

export async function updateUserGitConfig(gitConfig: any, configName: string) {
Expand All @@ -85,6 +94,10 @@ export async function updateUserGitConfig(gitConfig: any, configName: string) {
await writeGitConfig(gitConfigPath, gitConfig);

log.info('update-user-git-config', configName, gitConfig);
record({
module: 'git',
action: 'updateUserGitConfig',
});
}

async function getUserGitDirs() {
Expand Down Expand Up @@ -125,6 +138,10 @@ export async function updateUserGitDir(
await writeGitConfig(GLOBAL_GITCONFIG_PATH, globalGitConfig);

log.info('update-user-git-dir: ', currentIncludeIfKey, globalGitConfig[currentIncludeIfKey]);
record({
module: 'git',
action: 'updateUserGitDir',
});
}

export async function removeUserGitDir(gitDir: string, configName: string) {
Expand All @@ -137,6 +154,10 @@ export async function removeUserGitDir(gitDir: string, configName: string) {
delete globalGitConfig[includeIfKey];
await writeGitConfig(GLOBAL_GITCONFIG_PATH, globalGitConfig);
log.info('remove-user-git-dir: ', includeIfKey, gitConfigPath);
record({
module: 'git',
action: 'removeUserGitDir',
});
} else {
const error = new Error(`Can not remove ${gitDir}. The ${includeIfValue} is not found.`);
log.error(error);
Expand All @@ -154,6 +175,11 @@ export async function removeUserGitConfig(configName: string, gitDirs = []) {
// remove the gitconfig file
const gitConfigPath = getGitConfigPath(configName);
await fse.remove(gitConfigPath);

record({
module: 'git',
action: 'removeUserGitConfig',
});
}

async function parseGitConfig(gitConfigPath: string) {
Expand Down
2 changes: 1 addition & 1 deletion main/git/ssh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import * as fse from 'fs-extra';
import SSHKeyGen = require('ssh-keygen');
import SSHConfig = require('ssh-config');
import log from '../utils/log';
import { HOME_DIR } from '../constants';

const SSHKeyGenAsync = util.promisify(SSHKeyGen);

const HOME_DIR = process.env[(process.platform === 'win32') ? 'USERPROFILE' : 'HOME'];
export const SSHDir = path.join(HOME_DIR, '.ssh');
const SSHConfigPath = path.join(SSHDir, 'config');

Expand Down
8 changes: 8 additions & 0 deletions main/ipc/checkIsAliInternal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { ipcMain } from 'electron';
import checkIsAliInternal from '../utils/checkIsAliInternal';

export default () => {
ipcMain.handle('check-is-ali-internal', async () => {
return await checkIsAliInternal();
});
};
35 changes: 35 additions & 0 deletions main/ipc/handleNpmDependency.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import * as child_process from 'child_process';
import * as path from 'path';
import { ipcMain, IpcMainInvokeEvent } from 'electron';
import { send as sendMainWindow } from '../window';
import {
getGlobalDependencies,
uninstallGlobalDependency,
updateGlobalDependency,
reinstallGlobalDependency,
searchNpmDependencies,
installGlobalDependency,
getGlobalDependenciesInfo,
} from '../npm/dependency';
import killChannelChildProcess from '../utils/killChannelChildProcess';
import { record } from '../recorder';

const childProcessMap = new Map();

export default () => {
ipcMain.handle('get-global-npm-dependencies', async (e: IpcMainInvokeEvent, force) => {
Expand All @@ -33,4 +41,31 @@ export default () => {
ipcMain.handle('search-npm-dependencies', async (e: IpcMainInvokeEvent, query: string) => {
return await searchNpmDependencies(query);
});

ipcMain.handle('get-global-dependencies-info', async () => {
return await getGlobalDependenciesInfo();
});

ipcMain.handle('create-custom-global-dependencies-dir', async (e: IpcMainInvokeEvent, channel: string, currentGlobalDepsPath: string) => {
const childProcess = child_process.fork(path.join(__dirname, '..', 'npm/dependency/createCustomGlobalDepsDir'));
childProcessMap.set(channel, childProcess);

childProcess.send({ currentGlobalDepsPath, channel });

childProcessMap.set(channel, childProcess);

childProcess.on('message', ({ data }: any) => {
if (data.status === 'done') {
record({
module: 'node',
action: 'createCustomGlobalDependenciesDir',
});
}
sendMainWindow(channel, data);
});
});

ipcMain.handle('cancel-create-custom-global-dependencies-dir', async (e: IpcMainInvokeEvent, channel: string) => {
killChannelChildProcess(childProcessMap, channel);
});
};
3 changes: 3 additions & 0 deletions main/ipc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import handleGitConfig from './handleGitConfig';
import getFolderPath from './getFolderPath';
import handleNpmRegistry from './handleNpmRegistry';
import handleNpmDependency from './handleNpmDependency';
import checkIsAliInternal from './checkIsAliInternal';

export default () => {
getBasePackagesInfo();
Expand All @@ -23,4 +24,6 @@ export default () => {
handleNpmRegistry();

handleNpmDependency();

checkIsAliInternal();
};
5 changes: 5 additions & 0 deletions main/ipc/installBasePackages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import killChannelChildProcess from '../utils/killChannelChildProcess';
import log from '../utils/log';
import nodeCache from '../utils/nodeCache';
import store, { packagesDataKey } from '../store';
import { record } from '../recorder';

const childProcessMap = new Map();

Expand All @@ -33,6 +34,10 @@ export default () => {
if (channel === processChannel) {
if (data.status === 'done') {
killChannelChildProcess(childProcessMap, installChannel);
record({
module: 'base',
action: 'installPackages',
});
}
// save process data to cache
const processCaches = nodeCache.get(channel) || [];
Expand Down
15 changes: 11 additions & 4 deletions main/ipc/installNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { send as sendMainWindow } from '../window';
import killChannelChildProcess from '../utils/killChannelChildProcess';
import nodeCache from '../utils/nodeCache';
import log from '../utils/log';
import { record } from '../recorder';

const childProcessMap = new Map();

Expand All @@ -15,13 +16,11 @@ export default () => {
{
managerName,
nodeVersion,
reinstallGlobalDeps,
installChannel,
processChannel,
}: {
managerName: string;
nodeVersion: string;
reinstallGlobalDeps: boolean;
installChannel: string;
processChannel: string;
},
Expand All @@ -38,7 +37,6 @@ export default () => {
childProcess.send({
managerName,
nodeVersion,
reinstallGlobalDeps,
installChannel,
processChannel,
});
Expand All @@ -48,8 +46,16 @@ export default () => {
const { status, result } = data;
if (status === 'done') {
killChannelChildProcess(childProcessMap, installChannel);
record({
module: 'node',
action: 'installNode',
data: {
version: nodeVersion,
nodeManager: managerName,
},
});
} else if (status === 'success' && result && result.nodePath) {
// nodeEnvPath e.g: /Users/xxx/.nvm/versions/node/v14.15.0/bin/path -> Users/xxx/.nvm/versions/node/v14.15.0/bin
// nodeEnvPath e.g: /Users/xxx/.nvm/versions/node/v14.15.0/bin/node -> Users/xxx/.nvm/versions/node/v14.15.0/bin
const nodeEnvPath = result.nodePath.replace('/bin/node', '/bin');
// process.env.PATH: /usr/local/bin -> /Users/xxx/.nvm/versions/node/v14.15.0/bin:/usr/local/bin
process.env.PATH = `${nodeEnvPath}${path.delimiter}${process.env.PATH}`;
Expand All @@ -66,6 +72,7 @@ export default () => {
}
nodeCache.set(channel, processCaches);
}

sendMainWindow(channel, data);
});
});
Expand Down
Loading

0 comments on commit 7ec3e31

Please sign in to comment.