Skip to content

Commit

Permalink
code formatted and unnecessary types removed
Browse files Browse the repository at this point in the history
  • Loading branch information
NazmusSayad committed Sep 27, 2024
1 parent 2ac3eed commit f809525
Show file tree
Hide file tree
Showing 19 changed files with 247 additions and 297 deletions.
20 changes: 20 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"arrowParens": "always",
"bracketSpacing": true,
"endOfLine": "lf",
"htmlWhitespaceSensitivity": "css",
"insertPragma": false,
"singleAttributePerLine": false,
"bracketSameLine": false,
"jsxSingleQuote": false,
"printWidth": 100,
"proseWrap": "preserve",
"quoteProps": "as-needed",
"requirePragma": false,
"semi": false,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "es5",
"useTabs": false,
"embeddedLanguageFormatting": "auto"
}
9 changes: 2 additions & 7 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
{
"cSpell.words": [
"npmignore",
"noarg",
"npmize",
"lskit"
]
}
"cSpell.words": ["npmignore", "noarg", "npmize", "lskit"]
}
328 changes: 164 additions & 164 deletions LICENSE.md

Large diffs are not rendered by default.

23 changes: 20 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
{
"name": "npmize",
"version": "1.1.8",
"version": "1.1.9",
"description": "Let's create an npm package without worrying about anything.",
"bin": "./dist/index.js",
"scripts": {
"dev": "tsc -w",
"build": "node ./build.cjs",
"tsc": "tsc --noEmit --watch",
"lab": "run ./src/__lab__/index.ts",
"lab-js": "node --watch --watch ./dist/__lab__/index.js"
"lab-js": "node --watch --watch ./dist/__lab__/index.js",
"format": "prettier --write ."
},
"dependencies": {
"@babel/parser": "^7.25.6",
Expand All @@ -20,7 +21,8 @@
},
"devDependencies": {
"@types/cross-spawn": "^6.0.6",
"@types/node": "^22.5.5"
"@types/node": "^22.5.5",
"prettier": "^3.3.3"
},
"keywords": [
"npm",
Expand Down
32 changes: 8 additions & 24 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,12 @@ export const init = app.create('init', {
],

flags: {
pkg: NoArg.boolean()
.default(true)
.description('Make package.json with needed fields'),
tsconfig: NoArg.boolean()
.default(true)
.description('Write "tsconfig.json"'),
workflow: NoArg.boolean()
.default(true)
.description('Write a workflow file'),
install: NoArg.boolean()
.default(true)
.description('Install needed npm packages'),
sample: NoArg.boolean()
.default(true)
.description('Write a sample file ./src/index.ts'),
ignore: NoArg.boolean()
.default(true)
.description("Write '.gitignore' and '.npmignore'"),
pkg: NoArg.boolean().default(true).description('Make package.json with needed fields'),
tsconfig: NoArg.boolean().default(true).description('Write "tsconfig.json"'),
workflow: NoArg.boolean().default(true).description('Write a workflow file'),
install: NoArg.boolean().default(true).description('Install needed npm packages'),
sample: NoArg.boolean().default(true).description('Write a sample file ./src/index.ts'),
ignore: NoArg.boolean().default(true).description("Write '.gitignore' and '.npmignore'"),

npmignore: NoArg.boolean().default(true).description('Write .npmignore'),
gitignore: NoArg.boolean().default(true).description('Write .gitignore'),
Expand All @@ -60,9 +48,7 @@ const devAndBuild = NoArg.defineConfig({
],

flags: {
module: NoArg.string('cjs', 'mjs')
.aliases('m')
.description('Output module type .cjs or .mjs'),
module: NoArg.string('cjs', 'mjs').aliases('m').description('Output module type .cjs or .mjs'),

node: NoArg.boolean()
.aliases('n')
Expand Down Expand Up @@ -92,9 +78,7 @@ export const dev = app.create('dev', {
focus: NoArg.string('cjs', 'mjs')
.aliases('f')
.default('mjs')
.description(
'Focus the typescript compilation process of a specific module'
),
.description('Focus the typescript compilation process of a specific module'),
},
})

Expand Down
12 changes: 3 additions & 9 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ app.dev.on(([root = '.', railingArgs], options) => {
const tsConfig = readTSConfig(rootPath)

if (!tsConfig) {
return console.log(
ansiColors.bgRed(' ERROR: '),
'Could not find "tsconfig.json"'
)
return console.log(ansiColors.bgRed(' ERROR: '), 'Could not find "tsconfig.json"')
}

if (!tsConfig?.outDir) {
Expand All @@ -57,10 +54,7 @@ app.build.on(([root = '.', railingArgs], options) => {
const tsConfig = readTSConfig(rootPath)

if (!tsConfig) {
return console.log(
ansiColors.bgRed(' ERROR: '),
'Could not find "tsconfig.json"'
)
return console.log(ansiColors.bgRed(' ERROR: '), 'Could not find "tsconfig.json"')
}

if (!tsConfig?.outDir) {
Expand All @@ -72,7 +66,7 @@ app.build.on(([root = '.', railingArgs], options) => {

build(rootPath, {
...options,
tsc: railingArgs,
tsc: railingArgs,
tsConfig: { ...tsConfig, outDir: tsConfig.outDir },
})
})
4 changes: 1 addition & 3 deletions src/program/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ async function runBuild(
console.log(
`Built ${ansiColors.yellow(
String(fileSizes.length)
)} JavaScript files with a total size of ${ansiColors.yellow(
(totalSize / 1024).toFixed(2)
)} KB`
)} JavaScript files with a total size of ${ansiColors.yellow((totalSize / 1024).toFixed(2))} KB`
)

cleanDir(tempOutDir, false)
Expand Down
13 changes: 2 additions & 11 deletions src/program/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,7 @@ export default function (basePath: string, options: InitOptions) {
}

if (options.writeNpmIgnore) {
updateIgnoreFile('./.npmignore', [
'*',
'!lib/**',
'!dist/**',
'!README.md',
'!package.json',
])
updateIgnoreFile('./.npmignore', ['*', '!lib/**', '!dist/**', '!README.md', '!package.json'])
} else {
console.log(ansiColors.bgGreen(' INFO: '), 'Npmignore is disabled')
}
Expand All @@ -86,10 +80,7 @@ export default function (basePath: string, options: InitOptions) {
const srcExists = fs.existsSync(srcPath)

if (srcExists) {
console.log(
ansiColors.bgYellow(' WARN: '),
"'./src/index.ts' folder already exists"
)
console.log(ansiColors.bgYellow(' WARN: '), "'./src/index.ts' folder already exists")
} else {
writeFileSync(
path.join(srcPath, './index.ts'),
Expand Down
10 changes: 2 additions & 8 deletions src/scripts/generateOutput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ import getNodeCode from './getNodeCode'
import updateImports from '../updateImports'
import { MakeOutputOptions } from './makeOutputFile'

export default async function (
filePath: string,
fileContent: string,
options: MakeOutputOptions
) {
export default async function (filePath: string, fileContent: string, options: MakeOutputOptions) {
const updatedContent = await updateImports(
options.tempOutDir,
filePath,
Expand All @@ -16,9 +12,7 @@ export default async function (
options.tsConfig?.paths
)

return options.pushNodeCode &&
options.moduleType === 'mjs' &&
filePath.endsWith('.js')
return options.pushNodeCode && options.moduleType === 'mjs' && filePath.endsWith('.js')
? getNodeCode(updatedContent) + updatedContent
: updatedContent
}
8 changes: 3 additions & 5 deletions src/scripts/generateOutputWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ import generateOutput from './generateOutput'
import { MakeOutputOptions } from './makeOutputFile'

parentPort!.on('message', (options: WorkerMessage) => {
generateOutput(options.filePath, options.fileContent, options.options).then(
(data) => {
parentPort!.postMessage(data)
}
)
generateOutput(options.filePath, options.fileContent, options.options).then((data) => {
parentPort!.postMessage(data)
})
})

export type WorkerMessage = {
Expand Down
4 changes: 1 addition & 3 deletions src/scripts/getNodeCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ export default function (fileContent: string) {
}

if (isDirnameExist) {
nodeCodeContents.push(
`var __dirname=${varName}(new URL('.',import.meta.url));`
)
nodeCodeContents.push(`var __dirname=${varName}(new URL('.',import.meta.url));`)
}

return nodeCodeContents.join('\n') + '\n/* END: AUTO-GENERATED CODE */\n\n'
Expand Down
5 changes: 1 addition & 4 deletions src/scripts/ghWorkflows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@ export default function (baseDir: string) {
const workflowDir = path.join(baseDir, './.github/workflows')
const publishWorkflowPath = path.join(workflowDir, 'npm-publish.yml')

writeFileSync(
publishWorkflowPath,
publishWorkflowTemplate(getNodeVersion()?.toString())
)
writeFileSync(publishWorkflowPath, publishWorkflowTemplate(getNodeVersion()?.toString()))

console.log(
ansiColors.bgGreen(' INFO: '),
Expand Down
18 changes: 4 additions & 14 deletions src/scripts/tsconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ export function readTSConfig(targetPath: string) {

const configJsonString = ts.readConfigFile(configFilePath, ts.sys.readFile)
if (configJsonString.error) {
throw new Error(
ts.formatDiagnostic(configJsonString.error, ts.createCompilerHost({}))
)
throw new Error(ts.formatDiagnostic(configJsonString.error, ts.createCompilerHost({})))
}

const configObj = ts.parseJsonConfigFileContent(
Expand Down Expand Up @@ -44,15 +42,10 @@ export function updateTSConfig(
}

const configFileContent = fs.readFileSync(configFilePath, 'utf-8')
const configObj = ts.parseConfigFileTextToJson(
configFilePath,
configFileContent
)
const configObj = ts.parseConfigFileTextToJson(configFilePath, configFileContent)

if (configObj.error) {
throw new Error(
ts.formatDiagnostic(configObj.error, ts.createCompilerHost({}))
)
throw new Error(ts.formatDiagnostic(configObj.error, ts.createCompilerHost({})))
}

const updatedConfig = {
Expand All @@ -63,10 +56,7 @@ export function updateTSConfig(
...newConfig.compilerOptions,
},

include: [
...(configObj.config.include ?? []),
...(newConfig.include ?? []),
],
include: [...(configObj.config.include ?? []), ...(newConfig.include ?? [])],
}

if (updatedConfig.include?.length) {
Expand Down
8 changes: 2 additions & 6 deletions src/updateImports/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { NodeType } from './types.t'

export function getUpdatedData(fileData: any, found: NodeType[], cb: any) {
const newEntries: NodeType[] = [
{ start: 0, end: 0, value: '', filename: '' },
{ start: 0, end: 0, value: '' },
...found.sort((a, b) => a.start - b.start),
]

Expand All @@ -25,9 +25,5 @@ export function resolveJsFilePath(target: string) {
if (fs.existsSync(target) && fs.statSync(target).isFile()) return target
}

return (
isExists(target) ||
isExists(target + '.js') ||
isExists(target + '/index.js')
)
return isExists(target) || isExists(target + '.js') || isExists(target + '/index.js')
}
Loading

0 comments on commit f809525

Please sign in to comment.