Skip to content

Commit

Permalink
fix: 格式化代码并整理依赖 #2
Browse files Browse the repository at this point in the history
1.  格式化代码并整理依赖
2. 增加 script
  • Loading branch information
eliassama authored Jan 11, 2022
2 parents ecd04b2 + e2e5c42 commit c5f0207
Show file tree
Hide file tree
Showing 19 changed files with 384 additions and 307 deletions.
28 changes: 3 additions & 25 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,7 @@
module.exports = {
root: true,
env: {
'jest/globals': true,
},
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint', 'jest'],
extends: ['eliassama'],
overrides: [
{
files: ['*.ts'],
extends: ['eliassama'],
rules: {
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-use-before-define.md
'no-use-before-define': 'off',
'@typescript-eslint/no-use-before-define': ['error'],
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': ['error'],
},
},
],
settings: {
'import/resolver': {
node: {
extensions: ['.js', '.jsx', '.ts', '.tsx'],
},
},
extends: ['eliassama/typescript'],
rules: {
"@typescript-eslint/no-explicit-any": ["off"]
},
};
15 changes: 9 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
{
"name": "@eliassama/npm-package-cli",
"version": "0.0.0-alpha.1",
"version": "0.0.1",
"description": "A CLI tool used to normalize the creation, management, and distribution of NPM packages",
"main": "src/bin/index",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"build": "tsc",
"format": "prettier --write src/",
"lint": "eslint src/",
"prepare": "npm run build",
"prepublishOnly": "npm run lint",
"preversion": "npm run lint",
"version": "npm run format && git add -A src",
"postversion": "git push && git push --tags"
},
"bin": {
"npm-template": "lib/src/bin/index.js"
Expand All @@ -26,15 +33,11 @@
},
"devDependencies": {
"@types/inquirer": "8.1.3",
"@types/jest": "27.0.3",
"@typescript-eslint/eslint-plugin": "5.5.0",
"@typescript-eslint/parser": "5.5.0",
"eslint": "8.4.1",
"eslint-config-eliassama": "1.3.2",
"eslint-plugin-jest": "25.3.0",
"jest": "27.4.3",
"prettier": "2.5.1",
"ts-jest": "27.1.1",
"typescript": "4.5.2"
}
}
6 changes: 4 additions & 2 deletions src/commands/config/author/email.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import * as output from '../../../utils/output';
export function execute(data: string) {
if (ast.email(data)) {
if (LocalStorage.save('author.email', data)) {
return output.prompt( `The author email is successfully set to ${data}`)
return output.prompt(`The author email is successfully set to ${data}`);
}
}

output.error( `Failed to set author's email ${data}, because the set email is not valid`)
output.error(
`Failed to set author's email ${data}, because the set email is not valid`,
);
}
28 changes: 14 additions & 14 deletions src/commands/config/author/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,20 @@ interface ConfigAuthorOptionsType {
url?: string;
}

function commandAction(options: ConfigAuthorOptionsType) {
if (options.name) {
nameCommand.execute(options.name);
}

if (options.email) {
emailCommand.execute(options.email);
}

if (options.url) {
urlCommand.execute(options.url);
}
}

export function makeSubcommand() {
const Program = new Command('author').description(
'Set the default author information',
Expand All @@ -28,17 +42,3 @@ export function makeSubcommand() {

return Program;
}

function commandAction(options: ConfigAuthorOptionsType) {
if (options.name) {
nameCommand.execute(options.name);
}

if (options.email) {
emailCommand.execute(options.email);
}

if (options.url) {
urlCommand.execute(options.url);
}
}
4 changes: 2 additions & 2 deletions src/commands/config/author/name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as output from '../../../utils/output';

export function execute(data: string) {
if (LocalStorage.save('author.name', data)) {
return output.prompt(`The author name is successfully set to ${data}`)
return output.prompt(`The author name is successfully set to ${data}`);
}
output.error("Failed to set author's name because the set name is not valid")
output.error("Failed to set author's name because the set name is not valid");
}
10 changes: 6 additions & 4 deletions src/commands/config/author/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ import * as output from '../../../utils/output';
import * as ast from '../../../utils/ast';

export function execute(data: string) {
if (data[data.length - 1] === "/"){
data = data.substring(0, data.length - 1)
if (data[data.length - 1] === '/') {
data = data.substring(0, data.length - 1);
}

if (ast.httpUrl(data)) {
if (LocalStorage.save('author.url', data)) {
return output.prompt(`The author url is successfully set to ${data}`)
return output.prompt(`The author url is successfully set to ${data}`);
}
}
output.error(`Failed to set author's url ${data}, because the set url is not valid`)
output.error(
`Failed to set author's url ${data}, because the set url is not valid`,
);
}
12 changes: 6 additions & 6 deletions src/commands/init/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ interface ConfigAuthorOptionsType {
typescript?: boolean;
}

function commandAction(options: ConfigAuthorOptionsType) {
if (options.typescript) {
tsPackage.init();
}
}

export function makeSubcommand() {
const Program = new Command('init').description(
'Initialize to create an NPM Package template',
Expand All @@ -23,9 +29,3 @@ export function makeSubcommand() {

return Program;
}

function commandAction(options: ConfigAuthorOptionsType) {
if (options.typescript) {
tsPackage.init();
}
}
47 changes: 29 additions & 18 deletions src/commands/init/ts-package/file-path.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,45 @@
import { AnswersType } from './index';
import * as fs from "fs";
import * as path from "path";
import * as filepath from "../../../utils/filepath";
import * as fs from 'fs';
import * as path from 'path';
import * as filepath from '../../../utils/filepath';

export async function create(basicAnswers: AnswersType) {
const CopyFileArray = [
".editorconfig",
".eslintrc.js",
".prettierrc",
]
const CopyFileArray = ['.editorconfig', '.eslintrc.js', '.prettierrc'];

const CreateFileArray = [
path.join(basicAnswers.srcDir, `${basicAnswers.mainName}.ts`)
]
path.join(basicAnswers.srcDir, `${basicAnswers.mainName}.ts`),
];

const CreateDirectory = [
basicAnswers.srcDir,
basicAnswers.outDir,
"__test__",
]
'__test__',
];

for (let dirName of CreateDirectory ){
await filepath.recursionMkdir(path.join(basicAnswers.pkgPath, dirName))
for (const dirName of CreateDirectory) {
await filepath.recursionMkdir(path.join(basicAnswers.pkgPath, dirName));
}

for (let fileName of CreateFileArray ){
fs.writeFileSync(path.join(basicAnswers.pkgPath, fileName),"","utf-8")
for (const fileName of CreateFileArray) {
fs.writeFileSync(path.join(basicAnswers.pkgPath, fileName), '', 'utf-8');
}

for (let fileName of CopyFileArray ){
fs.writeFileSync(path.join(basicAnswers.pkgPath, fileName), fs.readFileSync(path.resolve( __dirname, "..", "..", "..", "template", "ts-package", fileName), "utf-8"), "utf-8");
for (const fileName of CopyFileArray) {
fs.writeFileSync(
path.join(basicAnswers.pkgPath, fileName),
fs.readFileSync(
path.resolve(
__dirname,
'..',
'..',
'..',
'template',
'ts-package',
fileName,
),
'utf-8',
),
'utf-8',
);
}
}
18 changes: 9 additions & 9 deletions src/commands/init/ts-package/git.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { AnswersType } from "./index";
import { AnswersType } from './index';
import { execSync } from 'child_process';

export async function create(basicAnswers: AnswersType) {
const gitCommandArray : string[] = [
"git init",
"git add .",
const gitCommandArray: string[] = [
'git init',
'git add .',
'git commit -m "first commit"',
"git branch dev",
`git remote add origin ${basicAnswers.sshRepositoryUrl}`
]
for (let command of gitCommandArray){
await execSync(command, { cwd: basicAnswers.pkgPath })
'git branch dev',
`git remote add origin ${basicAnswers.sshRepositoryUrl}`,
];
for (const command of gitCommandArray) {
await execSync(command, { cwd: basicAnswers.pkgPath });
}
}
Loading

0 comments on commit c5f0207

Please sign in to comment.