Skip to content

Commit

Permalink
Add cli in the repo to truly become a MONOREPO 🎉
Browse files Browse the repository at this point in the history
  • Loading branch information
simonprev committed Mar 4, 2019
1 parent b2750d0 commit be9f6be
Show file tree
Hide file tree
Showing 62 changed files with 5,933 additions and 0 deletions.
1 change: 1 addition & 0 deletions cli/.eslintignore
@@ -0,0 +1 @@
/lib
3 changes: 3 additions & 0 deletions cli/.eslintrc
@@ -0,0 +1,3 @@
{
"extends": "oclif"
}
6 changes: 6 additions & 0 deletions cli/.gitignore
@@ -0,0 +1,6 @@
*-debug.log
*-error.log
.oclif.manifest.json
/lib
/node_modules
/tmp
9 changes: 9 additions & 0 deletions cli/LICENSE.md
@@ -0,0 +1,9 @@
Copyright (c) 2018, Mirego All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
Neither the name of the Mirego nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
173 changes: 173 additions & 0 deletions cli/README.md
@@ -0,0 +1,173 @@
Accent CLI
======

[![Version](https://img.shields.io/npm/v/accent-cli.svg)](https://npmjs.org/package/accent-cli)
[![Build Status](https://img.shields.io/travis/v/accent-cli.svg?branch=master)](https://travis-ci.com/mirego/accent-cli)

<!-- toc -->
* [Usage](#usage)
* [Configuration](#configuration)
* [Commands](#commands)
* [License](#license)
* [About Mirego](#about-mirego)
<!-- tocstop -->

# Usage
<!-- usage -->
```sh-session
$ npm install -g accent-cli
$ accent COMMAND
running command...
$ accent (-v|--version|version)
accent-cli/0.6.0 darwin-x64 node-v9.5.0
$ accent --help [COMMAND]
USAGE
$ accent COMMAND
...
```
<!-- usagestop -->

# Configuration

accent-cli reads from a `accent.json` file. The file should contain valid JSON representing the configuration of your project.

## Example

```
{
"apiUrl": "http://your.accent.instance",
"apiKey": "2nziVSaa8yUJxLkwoZA",
"files": [
{
"language": "fr",
"format": "json",
"source": "localization/fr/*.json",
"target": "localization/%slug%/%original_file_name%.json",
"hooks": {
"afterSync": "touch sync-done.txt"
}
}
]
}
```

## Document configuration

Each operation section `sync` and `addTranslations` can contain the following object:

- `language`: The identifier of the document’s language
- `format`: The format of the document
- `source`: The path of the document. This can contain glob pattern (See [the node glob library] used as a dependancy (https://github.com/isaacs/node-glob))
- `target`: Path of the target languages
- `hooks`: List of hooks to be run

## Hooks

Here is a list of available hooks. Those are self-explanatory

- `beforeSync`
- `afterSync`
- `beforeExport`
- `afterExport`

# Commands
<!-- commands -->
* [`accent export`](#accent-export)
* [`accent help [COMMAND]`](#accent-help-command)
* [`accent jipt PSEUDOLANGUAGENAME`](#accent-jipt-pseudolanguagename)
* [`accent stats`](#accent-stats)
* [`accent sync`](#accent-sync)

## `accent export`

Export files from Accent and write them to your local filesystem

```
USAGE
$ accent export
OPTIONS
--order-by=index|key-asc [default: index] Will be used in the export call as the order of the keys
EXAMPLE
$ accent export
```

## `accent help [COMMAND]`

display help for accent

```
USAGE
$ accent help [COMMAND]
ARGUMENTS
COMMAND command to show help for
OPTIONS
--all see all commands in CLI
```

_See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v2.1.4/src/commands/help.ts)_

## `accent jipt PSEUDOLANGUAGENAME`

Export jipt files from Accent and write them to your local filesystem

```
USAGE
$ accent jipt PSEUDOLANGUAGENAME
ARGUMENTS
PSEUDOLANGUAGENAME The pseudo language for in-place-translation-editing
EXAMPLE
$ accent jipt
```

## `accent stats`

Fetch stats from the API and display it beautifully

```
USAGE
$ accent stats
EXAMPLE
$ accent stats
```

## `accent sync`

Sync files in Accent and write them to your local filesystem

```
USAGE
$ accent sync
OPTIONS
--add-translations Add translations in Accent to help translators if you already have translated
strings
--merge-type=smart|passive|force [default: smart] Will be used in the add translations call as the "merge_type" param
--order-by=index|key-asc [default: index] Will be used in the export call as the order of the keys
--sync-type=smart|passive [default: smart] Will be used in the sync call as the "sync_type" param
--write Write the file from the export _after_ the operation
EXAMPLE
$ accent sync
```
<!-- commandsstop -->

# License

`accent-cli` is © 2019 [Mirego](http://www.mirego.com) and may be freely distributed under the [New BSD license](http://opensource.org/licenses/BSD-3-Clause). See the [`LICENSE.md`](https://github.com/mirego/accent-cli/blob/master/LICENSE.md) file.

# About Mirego

[Mirego](http://mirego.com) is a team of passionate people who believe that work is a place where you can innovate and have fun. We’re a team of [talented people](http://life.mirego.com) who imagine and build beautiful Web and mobile applications. We come together to share ideas and [change the world](http://mirego.org).

We also [love open-source software](http://open.mirego.com) and we try to give back to the community as much as we can.
4 changes: 4 additions & 0 deletions cli/bin/run
@@ -0,0 +1,4 @@
#!/usr/bin/env node

require('@oclif/command').run()
.catch(require('@oclif/errors/handle'))
3 changes: 3 additions & 0 deletions cli/bin/run.cmd
@@ -0,0 +1,3 @@
@echo off

node "%~dp0\run" %*
24 changes: 24 additions & 0 deletions cli/examples/core/accent.json
@@ -0,0 +1,24 @@
{
"files": [
{
"language": "fr",
"format": "json",
"source": "core/*.json",
"target": "core/%original_file_name%-%slug%.json",
"hooks": {
"beforeSync": [
"rm -rf core",
"mkdir -p core",
"ruby core.rb unmerge translations.json fr > core/core-is-awesome.json"
],
"beforeAddTranslations": [
"ruby core.rb unmerge translations.json en > core/core-is-awesome-en.json"
],
"afterExport": [
"ruby core.rb merge core/core-is-awesome-en.json core/core-is-awesome-fr.json > translations.json",
"rm -rf core"
]
}
}
]
}
49 changes: 49 additions & 0 deletions cli/examples/core/core.rb
@@ -0,0 +1,49 @@
# Merge and unmerge files to be "core translations" compliant and Accent compliant.

# ## Merge
# The file used in this command contains en and fr translations and outputs
# "key" => value in the specified language.
#
# Given the file en.json:
# {"key": "foo"}
# Given the file fr.json:
# {"key": "bar"}
# ruby core.rb merge en.json fr.json
# {
# "key": {
# "en": "bar",
# "fr": "foo"
# }
# }
#
# ## Unmerge
# The file used in this command contains en and fr translations and outputs
# "key" => value in the specified language.
#
# Given the file:
# {
# "key": {
# "en": "bar",
# "fr": "foo"
# }
# }
# `ruby core.rb unmerge file.json fr`
#
# {
# "key": "foo"
# }

require 'json'

if ARGV[0] === 'merge'
en_json = JSON.parse(File.read(ARGV[1]))
fr_json = JSON.parse(File.read(ARGV[2]))

output = en_json.each_with_object({}) { |(key, value), memo| memo[key] = {fr: fr_json[key], en: value} }
puts JSON.pretty_generate(output)
end

if ARGV[0] === 'unmerge'
output = JSON.parse(File.read(ARGV[1])).each_with_object({}) { |(key, value), memo| memo[key] = value[ARGV[2]] }
puts JSON.pretty_generate(output)
end
6 changes: 6 additions & 0 deletions cli/examples/core/translations.json
@@ -0,0 +1,6 @@
{
"key": {
"fr": "valeur",
"en": "value"
}
}
10 changes: 10 additions & 0 deletions cli/examples/ember/accent.json
@@ -0,0 +1,10 @@
{
"files": [
{
"language": "en",
"format": "json",
"source": "translations/en.json",
"target": "translations/%slug%.json"
}
]
}
5 changes: 5 additions & 0 deletions cli/examples/ember/translations/en.json
@@ -0,0 +1,5 @@
{
"key": {
"nested": "Value"
}
}
5 changes: 5 additions & 0 deletions cli/examples/ember/translations/fr.json
@@ -0,0 +1,5 @@
{
"key": {
"nested": "Valeur"
}
}
10 changes: 10 additions & 0 deletions cli/examples/phoenix/accent.json
@@ -0,0 +1,10 @@
{
"files": [
{
"language": "en",
"format": "gettext",
"source": "priv/en/*.po",
"target": "priv/%slug%/%original_file_name%.po"
}
]
}
6 changes: 6 additions & 0 deletions cli/examples/phoenix/priv/en/my-file.po
@@ -0,0 +1,6 @@
msgid ""
msgstr ""
"Language: en"

msgid "key"
msgstr "Value"
6 changes: 6 additions & 0 deletions cli/examples/phoenix/priv/fr/my-file.po
@@ -0,0 +1,6 @@
msgid ""
msgstr ""
"Language: fr"

msgid "key"
msgstr "Valeur"
2 changes: 2 additions & 0 deletions cli/examples/rails-with-aigu/.aigu.yml
@@ -0,0 +1,2 @@
output-directory: config/locales
input-directory: config/locales
3 changes: 3 additions & 0 deletions cli/examples/rails-with-aigu/Gemfile
@@ -0,0 +1,3 @@
source 'https://rubygems.org'

gem 'aigu'
17 changes: 17 additions & 0 deletions cli/examples/rails-with-aigu/Gemfile.lock
@@ -0,0 +1,17 @@
GEM
remote: https://rubygems.org/
specs:
aigu (1.2)
nokogiri (~> 1.6)
mini_portile2 (2.3.0)
nokogiri (1.8.5)
mini_portile2 (~> 2.3.0)

PLATFORMS
ruby

DEPENDENCIES
aigu

BUNDLED WITH
1.16.2
29 changes: 29 additions & 0 deletions cli/examples/rails-with-aigu/accent.json
@@ -0,0 +1,29 @@
{
"files": [
{
"language": "en",
"format": "json",
"source": "aigu/*.json",
"target": "aigu/%original_file_name%-%slug%.json",
"hooks": {
"beforeSync": [
"rm -rf aigu",
"mkdir -p aigu",
"aigu rails-export --locale=en --output-file=aigu/aigu-is-awesome.json >/dev/null 2>&1"
],
"beforeAddTranslations": [
"aigu rails-export --locale=fr --output-file=aigu/aigu-is-awesome-fr.json >/dev/null 2>&1"
],
"beforeExport": [
"rm -rf aigu",
"mkdir -p aigu"
],
"afterExport": [
"aigu rails-import --locale=en --input-file=aigu/aigu-is-awesome-en.json >/dev/null 2>&1",
"aigu rails-import --locale=fr --input-file=aigu/aigu-is-awesome-fr.json >/dev/null 2>&1",
"rm -rf aigu"
]
}
}
]
}
4 changes: 4 additions & 0 deletions cli/examples/rails-with-aigu/config/locales/my_file.en.yml
@@ -0,0 +1,4 @@
---
en:
my_file:
key: Value

0 comments on commit be9f6be

Please sign in to comment.