Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple masterfile support #29

Merged
merged 4 commits into from
Aug 27, 2024
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
1 change: 1 addition & 0 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ jobs:
Release:
runs-on: ubuntu-latest
needs: Test
if: github.ref == 'refs/heads/master'
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
Expand Down
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
**Installation**

```sh
$ yarn global add @treatwell/wti
$ yarn add @treatwell/wti
```

**Configuration**

Basically, `wti` is to be run on a project root directory, and looks for a `wti-config.json` file containing your project's informations.
Basically, `wti` is to be run on a project root directory, and looks for a `wti-config.json` file containing your project's information.

The command `wti init` lets you create this file.

Expand All @@ -36,6 +36,13 @@ Initializing...... [SUCCESS] Project is initialized

You can find the API token in your project settings.

Note that if your config is in a different directory then you can pass this with
`--configPath` to any command that needs it:

```
wti push --configFile ./config/wti-config.json
```

**Usage**

Execute `wti help` to see the usage:
Expand Down Expand Up @@ -68,6 +75,10 @@ See `wti help <command>` for more information on a specific command.
| wti rmLocale fr | Remove a locale from the project |
| wti status | View project statistics |

# Overview

![](./docs/wti-process.png)

# i18next example

**1. Prerequisite**
Expand Down
Binary file added docs/wti-process.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
"typescript": "^4.0.2"
},
"engines": {
"node": ">= 18.0.0"
"node": ">= 20.0.0"
},
"preferGlobal": true,
"publishConfig": {
Expand All @@ -117,5 +117,9 @@
"warn-if-update-available": {
"timeoutInDays": 7
}
},
"volta": {
"node": "20.16.0",
"yarn": "1.22.22"
}
}
41 changes: 25 additions & 16 deletions src/commands/pull.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,37 @@ export default class Pull extends Command {
configPath: flags.string({
name: 'configPath',
required: false,
description: 'Path to wti-config.json file. If not provided, default to git root directory.'
})
description:
'Path to wti-config.json file. If not provided, default to git root directory.',
}),
};

async run() {
const { flags: { configPath } } = this.parse(Pull);
const {
flags: { configPath },
} = this.parse(Pull);
const { projectFiles } = await Project.init(configPath);

let masterFile = projectFiles.filter(
(file) => file.master_project_file_id === null
)[0],
masterFileId = masterFile.id;

const masterFiles = projectFiles.filter(
(file) => file.master_project_file_id === null
);
const tasks = new Listr(
projectFiles.reduce(
(acc, current) =>
acc.concat({
title: `Pulling ${current.name}`,
task: async () => await new MasterFile(masterFileId).show(current, configPath),
}),
[] as Listr.ListrTask<Listr.ListrContext>[]
)
projectFiles.reduce((acc, current) => {
const masterFileToUpdate = masterFiles.find(
(file) => file.id === current.master_project_file_id
);
if (!masterFileToUpdate) {
return acc;
}
return acc.concat({
title: `Pulling ${current.name}`,
task: async () =>
await new MasterFile(masterFileToUpdate?.id).show(
current,
configPath
),
});
}, [] as Listr.ListrTask<Listr.ListrContext>[])
);

tasks.run().catch((err) => {
Expand Down
34 changes: 18 additions & 16 deletions src/commands/push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,31 @@ export default class Push extends Command {
configPath: flags.string({
name: 'configPath',
required: false,
description: 'Path to wti-config.json file. If not provided, default to git root directory.'
})
description:
'Path to wti-config.json file. If not provided, default to git root directory.',
}),
};

async run() {
const { flags : { configPath, ...flags } } = this.parse(Push);
const {
flags: { configPath, ...flags },
} = this.parse(Push);
const { projectFiles } = await Project.init(configPath);

let masterFile = projectFiles.filter(
const masterFiles = projectFiles.filter(
(file) => file.master_project_file_id === null
)[0];

cli.action.start(`Pushing master file ${masterFile.name}...`);

await new MasterFile(masterFile.id).update(
masterFile.name,
masterFile.locale_code,
flags,
configPath
);

cli.action.stop(
'done. Note that it can take up to 1 min for 1000 segments to be uploaded'
);
console.log(`${masterFiles.length} master file(s) to process...`);
for (const masterFile of masterFiles) {
console.log(`Pushing ${masterFile.name}...`);
await new MasterFile(masterFile.id).update(
masterFile.name,
masterFile.locale_code,
flags,
configPath
);
}
console.log('done.');
}
}
Loading