Skip to content
This repository was archived by the owner on Jul 25, 2022. It is now read-only.

Commit 4720ed0

Browse files
committed
refactor: Rename plugins to packages for better comprehension
1 parent bc4cb76 commit 4720ed0

File tree

21 files changed

+183
-182
lines changed

21 files changed

+183
-182
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ dist/
22
node_modules/
33
.idea/
44
build/icon.*
5-
common/plugins/local/
5+
common/packages/local/
66

77
resources/cli/cli.js
88
.DS_STORE

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Please report any issues or new features you wish to see for Squid.
4040
Documentation is available at [https://squidjs.github.io/docs](https://squidjs.github.io/docs);
4141

4242
## Extending
43-
The config file is located in your user's home directory, and called `.squidrc.json`. Squid is higly customizable thanks to a powerful **plugins** system. With plugins, you can easily share and add custom **themes**, and add **new features**.
43+
The config file is located in your user's home directory, and called `.squidrc.json`. Squid is higly customizable thanks to a powerful **packages** system. With packages, you can easily share and add custom **themes** and **packages** to add new features.
4444

4545
See the [documentation](https://squidjs.github.io/docs/configuration) for more information.
4646

@@ -52,7 +52,7 @@ You can choose to use our server (this is the default configuration), or you can
5252
See the [documentation](https://squidjs.github.io/docs/cloud) for more information.
5353

5454
## CLI
55-
Squid ships with an easy-to-use CLI, used to start the app from any terminal and manage themes and plugins easily.
55+
Squid ships with an easy-to-use CLI, used to start the app from any terminal and manage packages easily.
5656
Run `squid --help` for a list of available commands.
5757

5858
See the [documentation](https://squidjs.github.io/docs/cli) for more information.

cli/src/commands/install.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { Arguments, Argv, CommandModule } from 'yargs';
22
import chalk from 'chalk';
3-
import { getConfig, PLUGINS_PATH, saveConfig } from '../utils/config';
3+
import { getConfig, PACKAGES_PATH, saveConfig } from '../utils/config';
44
import { spawn } from 'child_process';
55
import { getInstalledPath } from 'get-installed-path';
66

77
export const install: CommandModule = {
88

99
command: 'install <name>',
1010
aliases: ['i', 'add'],
11-
describe: 'Install a theme or plugin',
11+
describe: 'Install a package',
1212
builder: (args: Argv) => {
1313

1414
return args
@@ -25,12 +25,12 @@ export const install: CommandModule = {
2525

2626
if(!useYarn) {
2727

28-
console.log(chalk.red('NPM is not yet supported to install plugins and themes.'));
28+
console.log(chalk.red('NPM is not yet supported to install packages.'));
2929
return;
3030
}
3131

3232
console.log(' ');
33-
console.log(`Installing ${packageName} in ${chalk.green(PLUGINS_PATH)}...`);
33+
console.log(`Installing ${packageName} in ${chalk.green(PACKAGES_PATH)}...`);
3434
console.log(' ');
3535

3636
getInstalledPath('yarn').then((path) => {
@@ -51,7 +51,7 @@ export const install: CommandModule = {
5151
const config = getConfig();
5252
saveConfig({
5353
...config,
54-
plugins: [...config.plugins, packageName],
54+
packages: [...config.packages, packageName],
5555
});
5656

5757
console.log(' ');

cli/src/commands/list.ts

+18-18
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
11
import { CommandModule } from 'yargs';
2-
import { getConfig, PLUGINS_PATH } from '../utils/config';
2+
import { getConfig, PACKAGES_PATH } from '../utils/config';
33
import path from 'path';
44
import fs from 'fs';
55
import chalk from 'chalk';
66

7-
interface PluginItem {
7+
interface PackageItem {
88

99
name: string;
1010
version: string;
1111
error?: string;
1212
}
1313

14-
export const getPlugins = (): PluginItem[] => {
14+
export const getPackages = (): PackageItem[] => {
1515

16-
if(!fs.existsSync(PLUGINS_PATH))
17-
fs.mkdirSync(PLUGINS_PATH);
16+
if(!fs.existsSync(PACKAGES_PATH))
17+
fs.mkdirSync(PACKAGES_PATH);
1818

19-
const { plugins } = getConfig();
19+
const { packages } = getConfig();
2020

21-
return plugins.map((pluginDir) => {
21+
return packages.map((packageDir) => {
2222

23-
const pluginPath = path.join(PLUGINS_PATH, pluginDir);
24-
const packagePath = path.join(pluginPath, 'package.json');
25-
const indexPath = path.join(pluginPath, 'dist', 'index.js');
23+
const packagePath = path.join(PACKAGES_PATH, packageDir);
24+
const packageJsonPath = path.join(packagePath, 'package.json');
25+
const indexPath = path.join(packagePath, 'dist', 'index.js');
2626

2727
let name = '<name>';
2828
let version = '<version>';
2929
let error: string | undefined = undefined;
3030

31-
if(!fs.existsSync(pluginPath))
32-
error = 'Could not locate plugin folder';
31+
if(!fs.existsSync(packagePath))
32+
error = 'Could not locate package folder';
3333
else if(!fs.existsSync(indexPath))
34-
error = 'Could not find plugin sources';
35-
else if(!fs.existsSync(packagePath))
34+
error = 'Could not find package sources';
35+
else if(!fs.existsSync(packageJsonPath))
3636
error = 'Could not locate package.json';
3737
else {
3838

@@ -52,22 +52,22 @@ export const getPlugins = (): PluginItem[] => {
5252
name,
5353
version,
5454
error,
55-
} as PluginItem;
55+
} as PackageItem;
5656
});
5757
}
5858

5959
export const list: CommandModule = {
6060

6161
command: 'list',
6262
aliases: 'ls',
63-
describe: 'List installed themes and plugins',
63+
describe: 'List installed package',
6464
handler: () => {
6565

6666
console.log(' ');
67-
console.log(`Installed plugins and themes in ${chalk.green(PLUGINS_PATH)}`);
67+
console.log(`Installed packages in ${chalk.green(PACKAGES_PATH)}`);
6868
console.log(' ');
6969

70-
getPlugins().forEach(({ name, version, error }) => {
70+
getPackages().forEach(({ name, version, error }) => {
7171

7272
console.log(` - ${name} ${chalk.gray('v' + version)}`);
7373
error && console.log(` \\=> ${chalk.red(error)}`);

cli/src/commands/new.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { Arguments, Argv, CommandModule } from 'yargs';
22
import inquirer from 'inquirer'
33
import { resolveArgPath } from '../utils/utils';
4-
import { initializeProject, Language, Template } from '../new/new';
4+
import { initializeProject, Language, PackageType } from '../new/new';
55

66
export const newCommand: CommandModule = {
77

88
command: 'new [name]',
9-
describe: 'Initialize a new theme or plugin',
9+
describe: 'Initialize a package',
1010
builder: (args: Argv) => {
1111

1212
return args
@@ -31,16 +31,16 @@ export const newCommand: CommandModule = {
3131
inquirer.prompt([
3232
{
3333
type: 'input',
34-
message: 'Plugin / theme name:',
34+
message: 'Package name:',
3535
default: name,
3636
name: 'name',
3737
},
3838
{
3939
type: 'list',
4040
message: 'Type of project:',
41-
choices: ['Plugin', 'Theme'] as Template[],
42-
default: 'Plugin' as Template,
43-
name: 'template',
41+
choices: ['Plugin', 'Theme'] as PackageType[],
42+
default: 'Plugin' as PackageType,
43+
name: 'packageType',
4444
},
4545
{
4646
type: 'list',
@@ -53,9 +53,9 @@ export const newCommand: CommandModule = {
5353
]).then((answers) => {
5454

5555
name = answers.name;
56-
const { template, language }: { template: Template, language: Language } = answers
56+
const { packageType, language }: { packageType: PackageType, language: Language } = answers
5757

58-
initializeProject(name, path, useYarn, template, language);
58+
initializeProject(name, path, useYarn, packageType, language);
5959
});
6060
},
6161
};

cli/src/commands/uninstall.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
11
import { Arguments, CommandModule } from 'yargs';
22
import chalk from 'chalk';
3-
import { getConfig, PLUGINS_PATH, saveConfig } from '../utils/config';
3+
import { getConfig, PACKAGES_PATH, saveConfig } from '../utils/config';
44
import { spawn } from 'child_process';
55
import path from 'path';
6-
import { getPlugins } from './list';
6+
import { getPackages } from './list';
77

88
export const uninstall: CommandModule = {
99

1010
command: 'uninstall <name>',
1111
aliases: ['u', 'remove'],
12-
describe: 'Uninstall a theme or plugin',
12+
describe: 'Uninstall a package',
1313
handler: (args: Arguments) => {
1414

1515
const packageName = args.name as string;
16-
const plugins = getPlugins();
16+
const packages = getPackages();
1717

18-
if(plugins.every(({ name }) => name !== packageName)) {
18+
if(packages.every(({ name }) => name !== packageName)) {
1919

2020
console.log(chalk.red(`${packageName} is not installed.`));
2121
return;
2222
}
2323

2424
console.log(' ');
25-
console.log(`Uninstalling ${packageName} in ${chalk.green(PLUGINS_PATH)}...`);
25+
console.log(`Uninstalling ${packageName} in ${chalk.green(PACKAGES_PATH)}...`);
2626
console.log(' ');
2727

28-
const install = spawn('rm', ['-rf', path.join(PLUGINS_PATH, packageName)], { stdio: 'inherit' });
28+
const install = spawn('rm', ['-rf', path.join(PACKAGES_PATH, packageName)], { stdio: 'inherit' });
2929

3030
install.on('exit', () => {
3131

3232
const config = getConfig();
3333
saveConfig({
3434
...config,
35-
plugins: [...config.plugins].filter((current) => current !== packageName),
35+
packages: [...config.packages].filter((current) => current !== packageName),
3636
});
3737

3838
console.log('Success!');

cli/src/new/new.ts

+21-21
Original file line numberDiff line numberDiff line change
@@ -7,46 +7,48 @@ import { javascriptPluginTemplate } from './templates/javascript-plugin';
77
import { typescriptPluginTemplate } from './templates/typescript-plugin';
88
import { typescriptThemeTemplate } from './templates/typescript-theme';
99

10-
export type Template = 'Theme' | 'Plugin';
10+
export type PackageType = 'Theme' | 'Plugin';
1111
export type Language = 'TypeScript' | 'JavaScript';
1212

13-
export const initializeProject = (name: string, path: string, useYarn: boolean, template: Template, language: Language) => {
13+
export const initializeProject = (name: string, path: string, useYarn: boolean, packageType: PackageType, language: Language) => {
1414

15-
const projectName = `squid-${template.toLowerCase()}-${name.toLowerCase()}`;
15+
const projectName = `squid-${packageType.toLowerCase()}-${name.toLowerCase()}`;
1616
const projectPath = join(path, projectName);
1717

1818
console.log(' ');
19-
console.log(`Initializing a new Squid ${template} in ${chalk.green(projectPath)}...`);
19+
console.log(`Initializing a new Squid ${packageType} in ${chalk.green(projectPath)}...`);
2020
console.log(' ');
2121

2222
if(!fs.existsSync(projectPath))
2323
fs.mkdirSync(projectPath);
2424

25-
const packagePath = join(projectPath, 'package.json');
26-
27-
fs.writeFileSync(packagePath, JSON.stringify({
25+
fs.writeFileSync(join(projectPath, 'package.json'), JSON.stringify({
2826
name: projectName,
2927
version: '1.0.0',
3028
scripts: language === 'TypeScript' ? {
3129
dist: 'tsc',
3230
watch: 'tsc -w'
3331
} : undefined,
3432
keywords: [
35-
`squid-${template.toLowerCase()}`,
36-
template.toLowerCase(),
37-
'squid',
33+
'squid-package',
34+
`squid-${packageType.toLowerCase()}`,
35+
packageType.toLowerCase(),
3836
],
3937
}, null, 2));
4038

41-
const packages = ['squid-plugins'];
39+
fs.writeFileSync(join(projectPath, '.gitignore'), `.node_modulees
40+
.idea
41+
.vscode
42+
43+
.DS_STORE`);
44+
45+
const packages = ['squid-packages'];
4246

4347
if(language === 'TypeScript') {
4448

4549
packages.push('typescript');
4650

47-
const tsconfigPath = join(projectPath, 'tsconfig.json');
48-
49-
fs.writeFileSync(tsconfigPath, JSON.stringify({
51+
fs.writeFileSync(join(projectPath, 'tsconfig.json'), JSON.stringify({
5052
compilerOptions: {
5153
target: 'es5',
5254
module: 'commonjs',
@@ -57,22 +59,20 @@ export const initializeProject = (name: string, path: string, useYarn: boolean,
5759
}, null, 2));
5860

5961
const srcPath = join(projectPath, 'src');
60-
const indexPath = join(srcPath, 'index.ts');
6162

62-
const content = template === 'Plugin' ? typescriptPluginTemplate(name) : typescriptThemeTemplate(name);
63+
const content = packageType === 'Plugin' ? typescriptPluginTemplate(name) : typescriptThemeTemplate(name);
6364

64-
fs.mkdirSync(srcPath);
65-
fs.writeFileSync(indexPath, content);
65+
fs.mkdirSync(join(projectPath, 'src'));
66+
fs.writeFileSync(join(srcPath, 'index.ts'), content);
6667

6768
} else {
6869

6970
const distPath = join(projectPath, 'dist');
70-
const indexPath = join(distPath, 'index.js');
7171

72-
const content = template === 'Plugin' ? javascriptPluginTemplate(name): javascriptThemeTemplate(name);
72+
const content = packageType === 'Plugin' ? javascriptPluginTemplate(name): javascriptThemeTemplate(name);
7373

7474
fs.mkdirSync(distPath);
75-
fs.writeFileSync(indexPath, content);
75+
fs.writeFileSync(join(distPath, 'index.js'), content);
7676
}
7777

7878
console.log('Installing packages. This might take a few seconds.');

cli/src/utils/config.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import path from 'path';
22
import fs from 'fs';
33

44
const CONFIG_PATH = path.join(process.env.HOME, '.squidrc.json');
5-
export const PLUGINS_PATH = path.join(process.env.HOME, '.squid');
5+
export const PACKAGES_PATH = path.join(process.env.HOME, '.squid');
66

77
export const getConfig = (): IConfig => {
88

@@ -17,5 +17,5 @@ export const saveConfig = (config: IConfig) => {
1717

1818
export interface IConfig {
1919

20-
plugins: string[];
20+
packages: string[];
2121
}

common/config/Config.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { defaultConfig } from '@common/config/defaultConfig';
55
import { FontWeight } from 'xterm';
66
import { UndefinedObject } from '@common/types/types';
77
import { IShortcut } from '@common/shortcuts/shortcuts';
8-
import { callTrigger } from '@common/plugins/plugins';
9-
import { getProcessTrigger } from '@common/plugins/hooks';
8+
import { callTrigger } from '@common/packages/packages';
9+
import { getProcessTrigger } from '@common/packages/hooks';
1010
import { lazyload } from '@common/utils/lazyload';
1111
import type watch from 'node-watch';
1212

@@ -194,9 +194,9 @@ export interface IConfig {
194194
*/
195195
cloudUrl: string;
196196
/**
197-
* The list of names of enabled plugin and theme.
197+
* The list of names of enabled packages.
198198
*/
199-
plugins: string[];
199+
packages: string[];
200200
}
201201

202202
export interface ITheme {

common/config/defaultConfig.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,5 +163,5 @@ export const defaultConfig: IConfig = {
163163
localSSHHosts,
164164
// TODO
165165
cloudUrl: '',
166-
plugins: [],
166+
packages: [],
167167
}

common/plugins/hooks.ts common/packages/hooks.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { BrowserWindow, BrowserWindowConstructorOptions, app } from 'electron';
22
import { IConfig } from '@common/config/Config';
33
import { isMainProcess, Process } from '@common/utils/utils';
4-
import { Provider } from '@common/plugins/providers';
4+
import { Provider } from '@common/packages/providers';
55
import { INotification } from '@app/notifications/notification';
6-
import { TabIconParam } from '@common/plugins/package';
6+
import { TabIconParam } from '@common/packages/package';
77

88
// The list of availables parameters for the triggers
99
export type TriggerParams =

0 commit comments

Comments
 (0)