Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Changelog

## 0.1.9
## 0.1.12

Initial release
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "publisher"
version = "0.1.9"
version = "0.1.12"

authors = ["Pavan Kumar Sunkara <[email protected]>"]
description = "Tool to publish & distribute CLI tools"
Expand Down
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ Used for installing the built binary:
- [AUR (binary)](https://aur.archlinux.org)
- [Scoop](https://scoop.sh)
- [Nix](https://nixos.org)
- [NPM](https://www.npmjs.com)

Used for building from source:

Expand Down Expand Up @@ -117,6 +118,13 @@ scoop install publisher
nix profile install github:termapps/nixpkgs#publisher
```

<!-- omit from toc -->
#### With [NPM](https://npmjs.com)

```
npm install -g @termapps/publisher
```

<!-- omit from toc -->
#### Direct

Expand All @@ -142,6 +150,7 @@ Publisher can be configured using `publisher.toml` file. The below options are a
| `aur_bin` | object | No | [AUR (binary)](#aur-binary) |
| `scoop` | object | Yes | [Scoop](#scoop) |
| `nix` | object | No | [Nix](#nix) |
| `npm` | object | No | [NPM](#npm) |

[^1]: If `cargo` binary and `Cargo.toml` file are present, they can be omitted from the config.

Expand Down Expand Up @@ -205,6 +214,15 @@ Publisher can be configured using `publisher.toml` file. The below options are a
- `%n` can be used in `path` to substitute with name. For example, `%n/flake.nix` creates the package at `publisher/flake.nix` location.
- `lockfile` defaults to `true` and is needed to install the package most of the time.

<!-- omit from toc -->
#### NPM

| Name | Type | Required | Description |
| ------ | :------: | :------: | ------------------- |
| `name` | string | No | Name of the package |

- `name` defaults to the binary name.

<!-- omit from toc -->
#### Package Repository selection

Expand All @@ -221,7 +239,6 @@ Here is a list of [Contributors](http://github.com/termapps/publisher/contributo
- Package repositories
+ Alpine Linux ([#1](https://github.com/termapps/publisher/issues/1))
+ Debian ([#11](https://github.com/termapps/publisher/issues/11))
+ NPM
+ PyPi
- Platforms ([#4](https://github.com/termapps/publisher/issues/4))
- Shell completions ([#8](https://github.com/termapps/publisher/issues/8))
Expand Down
3 changes: 3 additions & 0 deletions publisher.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ repository = "termapps/nixpkgs"

lockfile = false
path = "%n.nix"

[npm]
name = "@termapps/publisher"
3 changes: 2 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
error::Result,
repositories::{
aur::AurConfig, aur_bin::AurBinConfig, homebrew::HomebrewConfig, nix::NixConfig,
scoop::ScoopConfig,
npm::NPMConfig, scoop::ScoopConfig,
},
};

Expand All @@ -32,6 +32,7 @@ pub struct AppConfig {
pub aur_bin: Option<AurBinConfig>,
pub scoop: Option<ScoopConfig>,
pub nix: Option<NixConfig>,
pub npm: Option<NPMConfig>,
}

#[derive(Debug, Clone, Default, Deserialize)]
Expand Down
18 changes: 17 additions & 1 deletion src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::{
error::Result,
repositories::{
Repositories, aur::AurConfig, aur_bin::AurBinConfig, homebrew::HomebrewConfig,
nix::NixConfig, scoop::ScoopConfig,
nix::NixConfig, npm::NPMConfig, scoop::ScoopConfig,
},
};

Expand Down Expand Up @@ -168,6 +168,21 @@ impl Init {
None
};

let npm = if package_repositories.contains(&Repositories::NPM) {
let npm_name = Text::new("NPM package name?")
.with_initial_value(&name)
.with_validator(required!())
.prompt()?;

let different_name = npm_name != name;

different_name.then_some(NPMConfig {
name: Some(npm_name),
})
} else {
None
};

let exclude = Repositories::value_variants()
.iter()
.filter(|r| !package_repositories.contains(r))
Expand Down Expand Up @@ -203,6 +218,7 @@ impl Init {
aur_bin,
scoop,
nix,
npm,
};

write(Path::new(CONFIG_FILE), to_string(&config)?)?;
Expand Down
34 changes: 33 additions & 1 deletion src/publish.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{
fmt::Debug,
fs::{create_dir_all, remove_dir_all, write},
fs::{create_dir_all, remove_dir_all, remove_file, write},
path::Path,
};

Expand Down Expand Up @@ -131,6 +131,38 @@ where
Ok(())
}

pub fn download_binary<P>(sh: &Shell, dir: &str, path: P, archive_url: &str) -> Result
where
P: AsRef<str> + Debug,
{
let path = path.as_ref();

let archive_path = Path::new(dir).join("archive.zip");
let full_path = Path::new(dir).join(path);

// Ensure the parent directory exists, otherwise fails on linux
if let Some(parent) = full_path.parent() {
create_dir_all(parent)?;
}

info!(" {:>11} {}", "downloading".magenta(), path.cyan());

cmd!(sh, "curl -L {archive_url} -o {archive_path}")
.quiet()
.ignore_stdout()
.ignore_stderr()
.run()?;

cmd!(sh, "unzip -o {archive_path} -d {full_path}")
.quiet()
.ignore_stdout()
.run()?;

remove_file(archive_path)?;

Ok(())
}

pub fn commit_and_push(sh: &Shell, name: &str, version: &str) -> Result {
let message = format!("{name}: {version}");

Expand Down
4 changes: 4 additions & 0 deletions src/repositories/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub mod aur;
pub mod aur_bin;
pub mod homebrew;
pub mod nix;
pub mod npm;
pub mod scoop;

use clap::ValueEnum;
Expand All @@ -32,6 +33,8 @@ pub enum Repositories {
AurBin,
Scoop,
Nix,
#[allow(clippy::upper_case_acronyms)]
NPM,
}

impl Display for Repositories {
Expand All @@ -48,6 +51,7 @@ impl Repositories {
Repositories::AurBin => Box::new(aur_bin::AurBin),
Repositories::Scoop => Box::new(scoop::Scoop),
Repositories::Nix => Box::new(nix::Nix),
Repositories::NPM => Box::new(npm::NPM),
}
}
}
Expand Down
Loading
Loading