mirror of
https://github.com/DeLaGuardo/setup-clojure.git
synced 2024-12-27 16:41:06 +08:00
Use linux-install script
This commit is contained in:
parent
0c3aaf47fb
commit
b43e1c94d9
82
dist/index.js
vendored
82
dist/index.js
vendored
@ -4052,9 +4052,12 @@ function setup(version) {
|
||||
core.info(`Clojure CLI found in cache ${toolPath}`);
|
||||
}
|
||||
else {
|
||||
const clojureToolsFile = yield tc.downloadTool(`https://download.clojure.org/install/clojure-tools${version === 'latest' ? '' : `-${version}`}.tar.gz`);
|
||||
const tempDir = path.join(tempDirectory, `temp_${Math.floor(Math.random() * 2000000000)}`);
|
||||
const clojureToolsDir = yield installClojureToolsDeps(clojureToolsFile, tempDir);
|
||||
const clojureInstallScript = yield tc.downloadTool(`https://download.clojure.org/install/linux-install${version === 'latest' ? '' : `-${version}`}.sh`);
|
||||
if (utils.isMacOS()) {
|
||||
yield MacOSDeps(clojureInstallScript);
|
||||
}
|
||||
const clojureToolsDir = yield runLinuxInstall(clojureInstallScript, tempDir);
|
||||
core.debug(`clojure tools deps installed to ${clojureToolsDir}`);
|
||||
toolPath = yield tc.cacheDir(clojureToolsDir, 'ClojureToolsDeps', utils.getCacheVersionString(version));
|
||||
}
|
||||
@ -4064,6 +4067,28 @@ function setup(version) {
|
||||
});
|
||||
}
|
||||
exports.setup = setup;
|
||||
function runLinuxInstall(installScript, destinationFolder) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
yield io.mkdirP(destinationFolder);
|
||||
const file = path.normalize(installScript);
|
||||
yield exec.exec('bash', [file, '--prefix', destinationFolder]);
|
||||
return destinationFolder;
|
||||
});
|
||||
}
|
||||
function MacOSDeps(file) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
fs.readFile(file, 'utf-8', function (err, data) {
|
||||
if (err)
|
||||
throw err;
|
||||
const newValue = data.replace(/install -D/gim, '$(brew --prefix coreutils)/bin/ginstall -D');
|
||||
fs.writeFile(file, newValue, 'utf-8', function (e) {
|
||||
if (e)
|
||||
throw e;
|
||||
});
|
||||
});
|
||||
yield exec.exec(`brew install coreutils`);
|
||||
});
|
||||
}
|
||||
function setupWindows(version) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const url = `download.clojure.org/install/win-install-${version}.ps1`;
|
||||
@ -4073,53 +4098,6 @@ function setupWindows(version) {
|
||||
});
|
||||
}
|
||||
exports.setupWindows = setupWindows;
|
||||
function installClojureToolsDeps(installScript, destinationFolder) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
yield io.mkdirP(destinationFolder);
|
||||
const file = path.normalize(installScript);
|
||||
const stats = fs.statSync(file);
|
||||
if (stats.isFile()) {
|
||||
const binDir = path.join(destinationFolder, 'clojure', 'bin');
|
||||
const libDir = path.join(destinationFolder, 'clojure', 'lib');
|
||||
const manDir = path.join(destinationFolder, 'clojure', 'share', 'man', 'man1');
|
||||
const clojureLibDir = path.join(libDir, 'clojure');
|
||||
const clojureLibexecDir = path.join(clojureLibDir, 'libexec');
|
||||
yield tc.extractTar(file, destinationFolder);
|
||||
const sourceDir = path.join(destinationFolder, 'clojure-tools');
|
||||
yield io.mkdirP(binDir);
|
||||
yield io.mkdirP(manDir);
|
||||
yield io.mkdirP(clojureLibexecDir);
|
||||
yield Promise.all(fs
|
||||
.readdirSync(sourceDir)
|
||||
.filter(f => f.endsWith('jar') || f.endsWith('edn'))
|
||||
.map((f) => __awaiter(this, void 0, void 0, function* () {
|
||||
return yield io.mv(path.join(sourceDir, f), f.endsWith('jar') ? clojureLibexecDir : clojureLibDir);
|
||||
})));
|
||||
yield readWriteAsync(path.join(sourceDir, 'clojure'), '"$CLOJURE_INSTALL_DIR"');
|
||||
yield io.mv(path.join(sourceDir, 'clj'), binDir);
|
||||
yield io.mv(path.join(sourceDir, 'clojure'), binDir);
|
||||
yield io.mv(path.join(sourceDir, 'clojure.1'), manDir);
|
||||
yield io.mv(path.join(sourceDir, 'clj.1'), manDir);
|
||||
return path.join(destinationFolder, 'clojure');
|
||||
}
|
||||
else {
|
||||
throw new Error(`Not a file`);
|
||||
}
|
||||
});
|
||||
}
|
||||
function readWriteAsync(file, replacement) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
fs.readFile(file, 'utf-8', function (err, data) {
|
||||
if (err)
|
||||
throw err;
|
||||
const newValue = data.replace(/PREFIX/gim, replacement);
|
||||
fs.writeFile(file, newValue, 'utf-8', function (e) {
|
||||
if (e)
|
||||
throw e;
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/***/ }),
|
||||
@ -5373,7 +5351,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.isWindows = exports.getTempDir = exports.getCacheVersionString = void 0;
|
||||
exports.isMacOS = exports.isWindows = exports.getTempDir = exports.getCacheVersionString = void 0;
|
||||
const path = __importStar(__webpack_require__(622));
|
||||
const version_1 = __webpack_require__(775);
|
||||
function getCacheVersionString(version) {
|
||||
@ -5411,6 +5389,10 @@ function isWindows() {
|
||||
return process.platform === 'win32';
|
||||
}
|
||||
exports.isWindows = isWindows;
|
||||
function isMacOS() {
|
||||
return process.platform === 'darwin';
|
||||
}
|
||||
exports.isMacOS = isMacOS;
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
2
dist/index.js.map
vendored
2
dist/index.js.map
vendored
File diff suppressed because one or more lines are too long
1631
package-lock.json
generated
1631
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
12
package.json
12
package.json
@ -32,17 +32,17 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^27.0.3",
|
||||
"@types/node": "^16.11.9",
|
||||
"@types/node": "^16.11.11",
|
||||
"@types/semver": "^7.3.9",
|
||||
"@typescript-eslint/parser": "^5.4.0",
|
||||
"@typescript-eslint/parser": "^5.5.0",
|
||||
"@zeit/ncc": "^0.22.3",
|
||||
"eslint": "^8.3.0",
|
||||
"eslint-plugin-github": "^4.3.5",
|
||||
"eslint-plugin-jest": "^25.2.4",
|
||||
"jest": "^27.3.1",
|
||||
"jest-circus": "^27.3.1",
|
||||
"eslint-plugin-jest": "^25.3.0",
|
||||
"jest": "^27.4.3",
|
||||
"jest-circus": "^27.4.2",
|
||||
"js-yaml": "^4.1.0",
|
||||
"prettier": "2.4.1",
|
||||
"prettier": "2.5.0",
|
||||
"ts-jest": "^27.0.7",
|
||||
"typescript": "^4.5.2"
|
||||
}
|
||||
|
93
src/cli.ts
93
src/cli.ts
@ -19,19 +19,21 @@ export async function setup(version: string): Promise<void> {
|
||||
if (toolPath && version !== 'latest') {
|
||||
core.info(`Clojure CLI found in cache ${toolPath}`)
|
||||
} else {
|
||||
const clojureToolsFile = await tc.downloadTool(
|
||||
`https://download.clojure.org/install/clojure-tools${
|
||||
version === 'latest' ? '' : `-${version}`
|
||||
}.tar.gz`
|
||||
)
|
||||
const tempDir: string = path.join(
|
||||
tempDirectory,
|
||||
`temp_${Math.floor(Math.random() * 2000000000)}`
|
||||
)
|
||||
const clojureToolsDir = await installClojureToolsDeps(
|
||||
clojureToolsFile,
|
||||
tempDir
|
||||
const clojureInstallScript = await tc.downloadTool(
|
||||
`https://download.clojure.org/install/linux-install${
|
||||
version === 'latest' ? '' : `-${version}`
|
||||
}.sh`
|
||||
)
|
||||
|
||||
if (utils.isMacOS()) {
|
||||
await MacOSDeps(clojureInstallScript)
|
||||
}
|
||||
|
||||
const clojureToolsDir = await runLinuxInstall(clojureInstallScript, tempDir)
|
||||
core.debug(`clojure tools deps installed to ${clojureToolsDir}`)
|
||||
toolPath = await tc.cacheDir(
|
||||
clojureToolsDir,
|
||||
@ -45,80 +47,37 @@ export async function setup(version: string): Promise<void> {
|
||||
core.addPath(path.join(toolPath, 'bin'))
|
||||
}
|
||||
|
||||
export async function setupWindows(version: string): Promise<void> {
|
||||
const url = `download.clojure.org/install/win-install-${version}.ps1`
|
||||
exec.exec(`powershell -c "iwr -useb ${url} | iex"`, [], {
|
||||
input: Buffer.from('1')
|
||||
})
|
||||
}
|
||||
|
||||
async function installClojureToolsDeps(
|
||||
async function runLinuxInstall(
|
||||
installScript: string,
|
||||
destinationFolder: string
|
||||
): Promise<string> {
|
||||
await io.mkdirP(destinationFolder)
|
||||
|
||||
const file = path.normalize(installScript)
|
||||
const stats = fs.statSync(file)
|
||||
if (stats.isFile()) {
|
||||
const binDir = path.join(destinationFolder, 'clojure', 'bin')
|
||||
const libDir = path.join(destinationFolder, 'clojure', 'lib')
|
||||
const manDir = path.join(
|
||||
destinationFolder,
|
||||
'clojure',
|
||||
'share',
|
||||
'man',
|
||||
'man1'
|
||||
)
|
||||
const clojureLibDir = path.join(libDir, 'clojure')
|
||||
const clojureLibexecDir = path.join(clojureLibDir, 'libexec')
|
||||
await exec.exec('bash', [file, '--prefix', destinationFolder])
|
||||
|
||||
await tc.extractTar(file, destinationFolder)
|
||||
|
||||
const sourceDir = path.join(destinationFolder, 'clojure-tools')
|
||||
|
||||
await io.mkdirP(binDir)
|
||||
await io.mkdirP(manDir)
|
||||
await io.mkdirP(clojureLibexecDir)
|
||||
|
||||
await Promise.all(
|
||||
fs
|
||||
.readdirSync(sourceDir)
|
||||
.filter(f => f.endsWith('jar') || f.endsWith('edn'))
|
||||
.map(
|
||||
async (f): Promise<void> =>
|
||||
await io.mv(
|
||||
path.join(sourceDir, f),
|
||||
f.endsWith('jar') ? clojureLibexecDir : clojureLibDir
|
||||
)
|
||||
)
|
||||
)
|
||||
await readWriteAsync(
|
||||
path.join(sourceDir, 'clojure'),
|
||||
'"$CLOJURE_INSTALL_DIR"'
|
||||
)
|
||||
await io.mv(path.join(sourceDir, 'clj'), binDir)
|
||||
await io.mv(path.join(sourceDir, 'clojure'), binDir)
|
||||
await io.mv(path.join(sourceDir, 'clojure.1'), manDir)
|
||||
await io.mv(path.join(sourceDir, 'clj.1'), manDir)
|
||||
|
||||
return path.join(destinationFolder, 'clojure')
|
||||
} else {
|
||||
throw new Error(`Not a file`)
|
||||
}
|
||||
return destinationFolder
|
||||
}
|
||||
|
||||
async function readWriteAsync(
|
||||
file: string,
|
||||
replacement: string
|
||||
): Promise<void> {
|
||||
async function MacOSDeps(file: string): Promise<void> {
|
||||
fs.readFile(file, 'utf-8', function (err, data) {
|
||||
if (err) throw err
|
||||
|
||||
const newValue = data.replace(/PREFIX/gim, replacement)
|
||||
const newValue = data.replace(
|
||||
/install -D/gim,
|
||||
'$(brew --prefix coreutils)/bin/ginstall -D'
|
||||
)
|
||||
|
||||
fs.writeFile(file, newValue, 'utf-8', function (e) {
|
||||
if (e) throw e
|
||||
})
|
||||
})
|
||||
await exec.exec(`brew install coreutils`)
|
||||
}
|
||||
|
||||
export async function setupWindows(version: string): Promise<void> {
|
||||
const url = `download.clojure.org/install/win-install-${version}.ps1`
|
||||
exec.exec(`powershell -c "iwr -useb ${url} | iex"`, [], {
|
||||
input: Buffer.from('1')
|
||||
})
|
||||
}
|
||||
|
@ -33,3 +33,7 @@ export function getTempDir(): string {
|
||||
export function isWindows(): boolean {
|
||||
return process.platform === 'win32'
|
||||
}
|
||||
|
||||
export function isMacOS(): boolean {
|
||||
return process.platform === 'darwin'
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user