Skip to content

Commit

Permalink
Update to TS
Browse files Browse the repository at this point in the history
  • Loading branch information
WCByrne committed Aug 27, 2021
1 parent 9c3d742 commit 512cb95
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 15 deletions.
3 changes: 1 addition & 2 deletions .apiToken.base.js → .apiToken.base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
const spaceId = 0
const apiToken = "<apitoken>"


module.exports = {
export default {
spaceId,
apiToken
}
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
# Package manager locks
yarn.lock

This comment has been minimized.

Copy link
@dilos1984

dilos1984 Aug 29, 2022

@.apiToken.base.ts

node_modules
yarn-error.log

.DS_STORE

apiToken.js
apiToken.*
!.apiToken.base.ts
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ A starter project for writing scripts using the Lingo API.
1. Clone this repo
2. `npm install` or `yarn`
3. Create an API token and add it to apiToken.js
4. `npm start` or `yarn start`
5. Start updating index.js to
4. `npm run start` or `yarn start`
5. Start updating index.ts to

> Make sure you never share your api token. A postinstall script in package.json will create `apiToken.js` but is included in the .gitignore to ensure it is not committed with changes back to your repo.
> Make sure you never share your api token. A postinstall script in package.json will create `apiToken.ts` but it is included in .gitignore to ensure it is not committed back to your repo with your token.
15 changes: 10 additions & 5 deletions index.js → index.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
const { default: lingo, AssetType, ItemType, LingoError } = require("@lingo-app/node")
import lingo, { AssetType, ItemType, LingoError } from "@lingo-app/node";

const auth = require("./apiToken")
import auth from "./apiToken"
// Add your spaceId and API token
lingo.setup(auth.spaceId, auth.apiToken)

// Wrap the script in a function so we can use async/await
async function runScript() {


// Log all kit names
const kits = await lingo.fetchKits()
console.log(`Your space has ${kits.length} kits`)


if (kits.length > 0) {
// Print the names of all kits
console.log(kits.map(k => `${k.short_id} - ${k.name}`))
console.log(kits.map(k => `${k.shortId} - ${k.name}`))

const kitId = kits[0].kit_uuid
const kitId = kits[0].kitId
const kit = await lingo.fetchKit(kitId)
const kitOutline = await lingo.fetchKitOutline(kitId)
console.log(kit)
Expand All @@ -29,6 +30,10 @@ async function runScript() {

// const kit = lingo.createKit("My new kit")
}

// Search
let results = await lingo.search().limit(5).ofType(AssetType.SVG).fetch()
console.log(`There are ${results.total} SVGs in your space`)
}

runScript()
12 changes: 8 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,22 @@
"name": "lingo-demo",
"version": "1.0.0",
"description": "",
"main": "index.js",
"directories": {
"test": "test"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node ./index",
"postinstall": "cp -n ./.apiToken.base.js ./apiToken.js || true"
"start": "ts-node ./index",
"postinstall": "cp -n ./.apiToken.base.ts ./apiToken.ts || true"
},
"author": "",
"license": "ISC",
"dependencies": {
"@lingo-app/node": "^1.0.0"
"@lingo-app/node": "^1.0.1"
},
"devDependencies": {
"@types/node": "^16.7.3",
"ts-node": "^10.2.1",
"typescript": "^4.4.2"
}
}
8 changes: 8 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"moduleResolution": "node",
"esModuleInterop": true
}
}

0 comments on commit 512cb95

Please sign in to comment.