-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from takuma-ru/release/2024_08_06T03_02_07_307Z
Release/2024 08 06 t03 02 07 307 z
- Loading branch information
Showing
13 changed files
with
299 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Command } from "commander"; | ||
|
||
import consola from "consola"; | ||
import { releaseAction } from "./action/releaseAction"; | ||
import { loadRlseConfig } from "./config/loadRlseConfig"; | ||
|
||
const program = new Command(); | ||
|
||
program | ||
.name("rlse") | ||
.description("Release npm package") | ||
.option("-n, --name <name>", "package name") | ||
.option("--pre", "Release new pre-release") | ||
.option("-l, --level <patch | minor | major | pre>", "release level") | ||
.option("-c, --build-cmd <cmd>", "build command") | ||
.option("--dry-run", "dry run") | ||
.option("--no-run", "no run") | ||
.action(async (options) => { | ||
const optionFromFile = await loadRlseConfig(); | ||
consola.info("optionFromFile", optionFromFile); | ||
const mergedOptions = { ...optionFromFile, ...options }; | ||
releaseAction(mergedOptions); | ||
}); | ||
|
||
program.parse(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import type { RlseConfig } from "../types/RlseConfig"; | ||
|
||
export const defineConfig = (config: RlseConfig) => { | ||
return config; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import { execSync } from "node:child_process"; | ||
import fs from "node:fs"; | ||
import path from "node:path"; | ||
import { cwd } from "node:process"; | ||
import { promisify } from "node:util"; | ||
|
||
const readFile = promisify(fs.readFile); | ||
const configFiles = [ | ||
"rlse.config.ts", | ||
"rlse.config.js", | ||
"rlse.config.mjs", | ||
"rlse.config.cjs", | ||
"rlse.config.json", | ||
]; | ||
|
||
export const loadRlseConfig = async () => { | ||
for (const file of configFiles) { | ||
const filePath = path.resolve(cwd(), file); | ||
if (fs.existsSync(filePath)) { | ||
const ext = path.extname(file); | ||
switch (ext) { | ||
case ".ts": | ||
// TypeScriptファイルの処理 | ||
return await importTypeScriptConfig(filePath); | ||
case ".js": | ||
case ".mjs": | ||
case ".cjs": | ||
// JavaScriptファイルの処理 | ||
return require(filePath); | ||
case ".json": { | ||
// JSONファイルの処理 | ||
const content = await readFile(filePath, "utf-8"); | ||
return JSON.parse(content); | ||
} | ||
default: | ||
throw new Error(`Unsupported file extension: ${ext}`); | ||
} | ||
} | ||
} | ||
throw new Error("No configuration file found"); | ||
}; | ||
|
||
const importTypeScriptConfig = async (filePath: string) => { | ||
const tempDir = path.resolve(cwd(), ".temp"); | ||
const tempFilePath = path.resolve(tempDir, "rlse.config.js"); | ||
const customTsConfigPath = path.resolve(tempDir, "tsconfig.json"); | ||
|
||
// 一時ディレクトリが存在しない場合は作成する | ||
try { | ||
fs.mkdirSync(tempDir, { recursive: true }); | ||
} catch (error) { | ||
console.error("Error creating temporary directory:", error); | ||
throw error; | ||
} | ||
|
||
// カスタムのtsconfig.jsonを作成 | ||
fs.writeFileSync( | ||
customTsConfigPath, | ||
JSON.stringify({ | ||
compilerOptions: { | ||
target: "ES2022", | ||
useDefineForClassFields: true, | ||
module: "ESNext", | ||
lib: ["ESNext", "DOM", "DOM.Iterable", "ES2022"], | ||
skipLibCheck: true, | ||
noErrorTruncation: true, | ||
|
||
/* Bundler mode */ | ||
moduleResolution: "bundler", | ||
allowImportingTsExtensions: true, | ||
resolveJsonModule: true, | ||
isolatedModules: true, | ||
emitDeclarationOnly: true, | ||
declaration: true, | ||
declarationMap: true, | ||
outDir: tempDir, | ||
rootDir: path.dirname(filePath), | ||
|
||
/* Linting */ | ||
strict: true, | ||
noUnusedLocals: true, | ||
noUnusedParameters: true, | ||
noFallthroughCasesInSwitch: true, | ||
}, | ||
exclude: ["node_modules"], | ||
include: [filePath], | ||
}) | ||
); | ||
|
||
try { | ||
execSync(`tsc --project ${customTsConfigPath}`, { stdio: "inherit" }); | ||
const config = await import(tempFilePath); | ||
return config.default; | ||
} catch (error) { | ||
console.error("Error compiling TypeScript file:", error); | ||
throw error; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,3 @@ | ||
import { Command } from "commander"; | ||
import { releaseAction } from "./action/releaseAction"; | ||
import { defineConfig } from "./config/defineConfig"; | ||
|
||
const program = new Command(); | ||
|
||
program | ||
.name("rlse") | ||
.description("Release npm package") | ||
.option("-n, --name <name>", "package name") | ||
.option("--pre", "Release new pre-release") | ||
.option("-l, --level <patch | minor | major | pre>", "release level") | ||
.option("-c, --build-cmd <cmd>", "build command") | ||
.option("--dry-run", "dry run") | ||
.action(async (options) => { | ||
releaseAction(options); | ||
}); | ||
|
||
program.parse(); | ||
export { defineConfig }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,10 @@ | ||
// export type RlseConfig = {}; | ||
import type { ReleaseSchemaType } from "../validation/validation"; | ||
|
||
export type RlseConfig = ReleaseSchemaType & { | ||
/** | ||
* Stop Release Flow | ||
* | ||
* @default false | ||
*/ | ||
isStopFlow: boolean; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,19 @@ | ||
{ | ||
"name": "vanilla-ts", | ||
"private": true, | ||
"version": "0.0.1", | ||
"version": "0.0.0", | ||
"type": "module", | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "tsc && vite build", | ||
"preview": "vite preview", | ||
"link:core": "pnpm link ../../packages/core", | ||
"rlse:test": "pnpm link:core && rlse -n vanilla-ts -c \"pnpm build\" -l patch --dry-run" | ||
"rlse:test": "pnpm link:core && rlse -n vanilla-ts -c \"pnpm build\" -l patch --dry-run --no-run" | ||
}, | ||
"devDependencies": { | ||
"@takuma-ru/rlse": "workspace:*", | ||
"ts-node": "^10.9.2", | ||
"typescript": "^5.2.2", | ||
"vite": "^5.3.5" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { defineConfig } from "@takuma-ru/rlse"; | ||
|
||
export default defineConfig({ | ||
isStopFlow: false, | ||
name: "vanilla-ts", | ||
level: "patch", | ||
pre: false, | ||
buildCmd: "pnpm build", | ||
dryRun: true, | ||
noRun: true, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.