From 8cb14e0323a4be7621c134d27e97b17021ed4f71 Mon Sep 17 00:00:00 2001
From: AkiraFukushima
Date: Sat, 24 Aug 2019 21:33:30 +0900
Subject: [PATCH] refs #53 Fix compile target
---
example/javascript/authorization.js | 45 ++++++++++++++++-------------
example/javascript/favourite.js | 20 +++++--------
example/javascript/refresh.js | 2 +-
example/javascript/streaming.js | 4 +--
example/javascript/timeline.js | 4 +--
example/javascript/toot.js | 16 +++++-----
example/javascript/web_socket.js | 2 +-
example/typescript/favourite.ts | 24 ++++++++-------
example/typescript/instance.ts | 2 +-
example/typescript/streaming.ts | 13 +++++----
example/typescript/timeline.ts | 8 ++++-
example/typescript/toot.ts | 16 +++++-----
example/typescript/web_socket.ts | 3 +-
example/typescript/yarn.lock | 2 +-
package.json | 4 +--
tsconfig.json | 4 +--
16 files changed, 88 insertions(+), 81 deletions(-)
diff --git a/example/javascript/authorization.js b/example/javascript/authorization.js
index 74f6b78..df62d37 100644
--- a/example/javascript/authorization.js
+++ b/example/javascript/authorization.js
@@ -1,5 +1,5 @@
const readline = require('readline')
-const Mastodon = require( '../../lib/mastodon')
+const Mastodon = require('../../lib/src/mastodon')
const rl = readline.createInterface({
input: process.stdin,
@@ -7,30 +7,36 @@ const rl = readline.createInterface({
})
const SCOPES = 'read write follow'
-const BASE_URL = 'https://pleroma.io'
+const BASE_URL = 'https://mastodon.social'
let clientId
let clientSecret
-Mastodon.registerApp('Test App', {
- scopes: SCOPES
-}, BASE_URL).then(appData => {
- clientId = appData.clientId
- clientSecret = appData.clientSecret
- console.log('\nclient_id:')
- console.log(clientId)
- console.log('\nclient_secret:')
- console.log(clientSecret)
- console.log('\nAuthorization URL is generated.')
- console.log(appData.url)
- console.log()
- return new Promise(resolve => {
- rl.question('Enter the authorization code from website: ', code => {
- resolve(code)
- rl.close()
+Mastodon.registerApp(
+ 'Test App',
+ {
+ scopes: SCOPES
+ },
+ BASE_URL
+)
+ .then(appData => {
+ clientId = appData.clientId
+ clientSecret = appData.clientSecret
+ console.log('\nclient_id:')
+ console.log(clientId)
+ console.log('\nclient_secret:')
+ console.log(clientSecret)
+ console.log('\nAuthorization URL is generated.')
+ console.log(appData.url)
+ console.log()
+ return new Promise(resolve => {
+ rl.question('Enter the authorization code from website: ', code => {
+ resolve(code)
+ rl.close()
+ })
})
})
-}).then(code => Mastodon.fetchAccessToken(clientId, clientSecret, code, BASE_URL))
+ .then(code => Mastodon.fetchAccessToken(clientId, clientSecret, code, BASE_URL))
.then(tokenData => {
console.log('\naccess_token:')
console.log(tokenData.accessToken)
@@ -39,4 +45,3 @@ Mastodon.registerApp('Test App', {
console.log()
})
.catch(err => console.error(err))
-
diff --git a/example/javascript/favourite.js b/example/javascript/favourite.js
index fd47438..13fb396 100644
--- a/example/javascript/favourite.js
+++ b/example/javascript/favourite.js
@@ -1,16 +1,12 @@
-const Mastodon = require( '../../lib/mastodon')
+const Mastodon = require('../../lib/src/mastodon')
-const BASE_URL = 'https://mstdn.jp'
+const BASE_URL = 'https://mastodon.social'
-const access_token = '...'
+const access_token = process.env.MASTODON_ACCESS_TOKEN
-const client = new Mastodon(
- access_token,
- BASE_URL + '/api/v1'
-)
+const client = new Mastodon(access_token, BASE_URL + '/api/v1')
-client.get('/favourites')
- .then((res) => {
- console.log(res.headers)
- console.log(res.data)
- })
+client.get('/favourites').then(res => {
+ console.log(res.headers)
+ console.log(res.data)
+})
diff --git a/example/javascript/refresh.js b/example/javascript/refresh.js
index fe64ff1..73fb4b6 100644
--- a/example/javascript/refresh.js
+++ b/example/javascript/refresh.js
@@ -1,7 +1,7 @@
// Please use this function after authorization.js
// Now mastodon and pleroma don't have refersh token method.
// So this example is failed.
-const Mastodon = require( '../../lib/mastodon')
+const Mastodon = require('../../lib/src/mastodon')
const BASE_URL = 'https://pleroma.io'
diff --git a/example/javascript/streaming.js b/example/javascript/streaming.js
index 2715025..866330c 100644
--- a/example/javascript/streaming.js
+++ b/example/javascript/streaming.js
@@ -1,6 +1,6 @@
-const Mastodon = require('../../lib/mastodon')
+const Mastodon = require('../../lib/src/mastodon')
-const BASE_URL = 'https://mstdn.jp'
+const BASE_URL = 'https://mastodon.social'
const access_token = process.env.MASTODON_ACCESS_TOKEN
diff --git a/example/javascript/timeline.js b/example/javascript/timeline.js
index 8bca617..531590d 100644
--- a/example/javascript/timeline.js
+++ b/example/javascript/timeline.js
@@ -1,6 +1,6 @@
-const Mastodon = require('../../lib/mastodon')
+const Mastodon = require('../../lib/src/mastodon')
-const BASE_URL = 'https://mstdn.jp'
+const BASE_URL = 'https://mastodon.social'
const access_token = process.env.MASTODON_ACCESS_TOKEN
diff --git a/example/javascript/toot.js b/example/javascript/toot.js
index a56bec4..4236ddf 100644
--- a/example/javascript/toot.js
+++ b/example/javascript/toot.js
@@ -1,5 +1,5 @@
const readline = require('readline')
-const Mastodon = require('../../lib/mastodon')
+const Mastodon = require('../../lib/src/mastodon')
const rl = readline.createInterface({
input: process.stdin,
@@ -8,17 +8,15 @@ const rl = readline.createInterface({
const BASE_URL = 'https://mastodon.social'
-const access_token = '...'
+const access_token = process.env.MASTODON_ACCESS_TOKEN
-const client = new Mastodon(
- access_token,
- BASE_URL + '/api/v1'
-)
+const client = new Mastodon(access_token, BASE_URL + '/api/v1')
new Promise(resolve => {
rl.question('Toot: ', status => {
- client.post('/statuses', {
- status: status
- })
+ client
+ .post('/statuses', {
+ status: status
+ })
.then(res => {
console.log(res)
rl.close()
diff --git a/example/javascript/web_socket.js b/example/javascript/web_socket.js
index 4b74f10..38d2abc 100644
--- a/example/javascript/web_socket.js
+++ b/example/javascript/web_socket.js
@@ -1,4 +1,4 @@
-const Mastodon = require('../../lib/mastodon')
+const Mastodon = require('../../lib/src/mastodon')
const BASE_URL = 'wss://pleroma.io'
diff --git a/example/typescript/favourite.ts b/example/typescript/favourite.ts
index 3d1a505..fea7ee9 100644
--- a/example/typescript/favourite.ts
+++ b/example/typescript/favourite.ts
@@ -1,16 +1,18 @@
import Mastodon, { Status, Response } from 'megalodon'
-const BASE_URL: string = 'https://mstdn.jp'
+declare var process: {
+ env: {
+ MASTODON_ACCESS_TOKEN: string
+ }
+}
-const access_token: string = '...'
+const BASE_URL: string = 'https://mastodon.social'
-const client = new Mastodon(
- access_token,
- BASE_URL + '/api/v1'
-)
+const access_token: string = process.env.MASTODON_ACCESS_TOKEN
-client.get<[Status]>('/favourites')
- .then((res: Response<[Status]>) => {
- console.log(res.headers)
- console.log(res.data)
- })
+const client = new Mastodon(access_token, BASE_URL + '/api/v1')
+
+client.get<[Status]>('/favourites').then((res: Response<[Status]>) => {
+ console.log(res.headers)
+ console.log(res.data)
+})
diff --git a/example/typescript/instance.ts b/example/typescript/instance.ts
index 29e8f96..6d73dc6 100644
--- a/example/typescript/instance.ts
+++ b/example/typescript/instance.ts
@@ -1,6 +1,6 @@
import Mastodon, { Instance } from 'megalodon'
-const BASE_URL: string = 'http://mstdn.jp'
+const BASE_URL: string = 'http://mastodon.social'
Mastodon.get('/api/v1/instance', {}, BASE_URL).then(res => {
console.log(res)
diff --git a/example/typescript/streaming.ts b/example/typescript/streaming.ts
index ee2a73a..a912329 100644
--- a/example/typescript/streaming.ts
+++ b/example/typescript/streaming.ts
@@ -1,13 +1,16 @@
import Mastodon, { Status, Notification, StreamListener } from 'megalodon'
+declare var process: {
+ env: {
+ MASTODON_ACCESS_TOKEN: string
+ }
+}
+
const BASE_URL: string = 'https://mastodon.social'
-const access_token: string = '...'
+const access_token: string = process.env.MASTODON_ACCESS_TOKEN
-const client = new Mastodon(
- access_token,
- BASE_URL + '/api/v1'
-)
+const client = new Mastodon(access_token, BASE_URL + '/api/v1')
const stream: StreamListener = client.stream('/streaming/public')
stream.on('connect', _ => {
diff --git a/example/typescript/timeline.ts b/example/typescript/timeline.ts
index 636141b..aa0a83a 100644
--- a/example/typescript/timeline.ts
+++ b/example/typescript/timeline.ts
@@ -1,8 +1,14 @@
import Mastodon, { Status, Response } from 'megalodon'
+declare var process: {
+ env: {
+ MASTODON_ACCESS_TOKEN: string
+ }
+}
+
const BASE_URL: string = 'https://mastodon.social'
-const access_token: string = '...'
+const access_token: string = process.env.MASTODON_ACCESS_TOKEN
const client = new Mastodon(access_token, BASE_URL + '/api/v1')
diff --git a/example/typescript/toot.ts b/example/typescript/toot.ts
index 533e284..60ee9a3 100644
--- a/example/typescript/toot.ts
+++ b/example/typescript/toot.ts
@@ -6,19 +6,17 @@ const rl: readline.ReadLine = readline.createInterface({
output: process.stdout
})
-const BASE_URL: string = 'https://mastodon.social'
+const BASE_URL: string = 'https://pleroma.io'
-const access_token: string = '...'
+const access_token: string = process.env.PLEROMA_ACCESS_TOKEN as string
-const client = new Mastodon(
- access_token,
- BASE_URL + '/api/v1'
-)
+const client = new Mastodon(access_token, BASE_URL + '/api/v1')
new Promise(resolve => {
rl.question('Toot: ', status => {
- client.post('/statuses', {
- status: status
- })
+ client
+ .post('/statuses', {
+ status: status
+ })
.then((res: Response) => {
console.log(res)
rl.close()
diff --git a/example/typescript/web_socket.ts b/example/typescript/web_socket.ts
index 01c2fc8..2e9dc81 100644
--- a/example/typescript/web_socket.ts
+++ b/example/typescript/web_socket.ts
@@ -2,12 +2,11 @@ import Mastodon, { Status, Notification, WebSocket } from 'megalodon'
declare var process: {
env: {
- PLEROMA_HOST: string
PLEROMA_ACCESS_TOKEN: string
}
}
-const BASE_URL: string = process.env.PLEROMA_HOST
+const BASE_URL: string = 'wss://pleroma.io'
const access_token: string = process.env.PLEROMA_ACCESS_TOKEN
diff --git a/example/typescript/yarn.lock b/example/typescript/yarn.lock
index ce1483c..a7e1978 100644
--- a/example/typescript/yarn.lock
+++ b/example/typescript/yarn.lock
@@ -282,7 +282,7 @@ jsprim@^1.2.2:
verror "1.10.0"
"megalodon@file:../..":
- version "0.8.2"
+ version "0.9.0"
dependencies:
"@types/oauth" "^0.9.0"
"@types/request" "^2.47.0"
diff --git a/package.json b/package.json
index 1b748f6..afa98e1 100644
--- a/package.json
+++ b/package.json
@@ -2,8 +2,8 @@
"name": "megalodon",
"version": "0.9.0",
"description": "Mastodon API client for node.js",
- "main": "./lib/index.js",
- "typings": "./lib/index.d.ts",
+ "main": "./lib/src/index.js",
+ "typings": "./lib/src/index.d.ts",
"scripts": {
"build": "tsc -p ./",
"lint": "eslint --ext .js,.ts src",
diff --git a/tsconfig.json b/tsconfig.json
index 2b69aac..cca43d9 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -12,7 +12,7 @@
// "sourceMap": true, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
"outDir": "./lib", /* Redirect output structure to the directory. */
- "rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
+ "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "composite": true, /* Enable project compilation */
"removeComments": true, /* Do not emit comments to output. */
// "noEmit": true, /* Do not emit outputs. */
@@ -59,6 +59,6 @@
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
},
- "include": ["src/*", "test/*"],
+ "include": ["./src", "./test"],
"exclude": ["node_modules", "example"]
}