refs #53 Fix compile target

This commit is contained in:
AkiraFukushima 2019-08-24 21:33:30 +09:00
parent 7dfa9e4704
commit 8cb14e0323
16 changed files with 88 additions and 81 deletions

View file

@ -1,5 +1,5 @@
const readline = require('readline') const readline = require('readline')
const Mastodon = require( '../../lib/mastodon') const Mastodon = require('../../lib/src/mastodon')
const rl = readline.createInterface({ const rl = readline.createInterface({
input: process.stdin, input: process.stdin,
@ -7,30 +7,36 @@ const rl = readline.createInterface({
}) })
const SCOPES = 'read write follow' const SCOPES = 'read write follow'
const BASE_URL = 'https://pleroma.io' const BASE_URL = 'https://mastodon.social'
let clientId let clientId
let clientSecret let clientSecret
Mastodon.registerApp('Test App', { Mastodon.registerApp(
scopes: SCOPES 'Test App',
}, BASE_URL).then(appData => { {
clientId = appData.clientId scopes: SCOPES
clientSecret = appData.clientSecret },
console.log('\nclient_id:') BASE_URL
console.log(clientId) )
console.log('\nclient_secret:') .then(appData => {
console.log(clientSecret) clientId = appData.clientId
console.log('\nAuthorization URL is generated.') clientSecret = appData.clientSecret
console.log(appData.url) console.log('\nclient_id:')
console.log() console.log(clientId)
return new Promise(resolve => { console.log('\nclient_secret:')
rl.question('Enter the authorization code from website: ', code => { console.log(clientSecret)
resolve(code) console.log('\nAuthorization URL is generated.')
rl.close() 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 => { .then(tokenData => {
console.log('\naccess_token:') console.log('\naccess_token:')
console.log(tokenData.accessToken) console.log(tokenData.accessToken)
@ -39,4 +45,3 @@ Mastodon.registerApp('Test App', {
console.log() console.log()
}) })
.catch(err => console.error(err)) .catch(err => console.error(err))

View file

@ -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( const client = new Mastodon(access_token, BASE_URL + '/api/v1')
access_token,
BASE_URL + '/api/v1'
)
client.get('/favourites') client.get('/favourites').then(res => {
.then((res) => { console.log(res.headers)
console.log(res.headers) console.log(res.data)
console.log(res.data) })
})

View file

@ -1,7 +1,7 @@
// Please use this function after authorization.js // Please use this function after authorization.js
// Now mastodon and pleroma don't have refersh token method. // Now mastodon and pleroma don't have refersh token method.
// So this example is failed. // So this example is failed.
const Mastodon = require( '../../lib/mastodon') const Mastodon = require('../../lib/src/mastodon')
const BASE_URL = 'https://pleroma.io' const BASE_URL = 'https://pleroma.io'

View file

@ -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 const access_token = process.env.MASTODON_ACCESS_TOKEN

View file

@ -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 const access_token = process.env.MASTODON_ACCESS_TOKEN

View file

@ -1,5 +1,5 @@
const readline = require('readline') const readline = require('readline')
const Mastodon = require('../../lib/mastodon') const Mastodon = require('../../lib/src/mastodon')
const rl = readline.createInterface({ const rl = readline.createInterface({
input: process.stdin, input: process.stdin,
@ -8,17 +8,15 @@ const rl = readline.createInterface({
const BASE_URL = 'https://mastodon.social' const BASE_URL = 'https://mastodon.social'
const access_token = '...' const access_token = process.env.MASTODON_ACCESS_TOKEN
const client = new Mastodon( const client = new Mastodon(access_token, BASE_URL + '/api/v1')
access_token,
BASE_URL + '/api/v1'
)
new Promise(resolve => { new Promise(resolve => {
rl.question('Toot: ', status => { rl.question('Toot: ', status => {
client.post('/statuses', { client
status: status .post('/statuses', {
}) status: status
})
.then(res => { .then(res => {
console.log(res) console.log(res)
rl.close() rl.close()

View file

@ -1,4 +1,4 @@
const Mastodon = require('../../lib/mastodon') const Mastodon = require('../../lib/src/mastodon')
const BASE_URL = 'wss://pleroma.io' const BASE_URL = 'wss://pleroma.io'

View file

@ -1,16 +1,18 @@
import Mastodon, { Status, Response } from 'megalodon' 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( const access_token: string = process.env.MASTODON_ACCESS_TOKEN
access_token,
BASE_URL + '/api/v1'
)
client.get<[Status]>('/favourites') const client = new Mastodon(access_token, BASE_URL + '/api/v1')
.then((res: Response<[Status]>) => {
console.log(res.headers) client.get<[Status]>('/favourites').then((res: Response<[Status]>) => {
console.log(res.data) console.log(res.headers)
}) console.log(res.data)
})

View file

@ -1,6 +1,6 @@
import Mastodon, { Instance } from 'megalodon' import Mastodon, { Instance } from 'megalodon'
const BASE_URL: string = 'http://mstdn.jp' const BASE_URL: string = 'http://mastodon.social'
Mastodon.get<Instance>('/api/v1/instance', {}, BASE_URL).then(res => { Mastodon.get<Instance>('/api/v1/instance', {}, BASE_URL).then(res => {
console.log(res) console.log(res)

View file

@ -1,13 +1,16 @@
import Mastodon, { Status, Notification, StreamListener } from 'megalodon' import Mastodon, { Status, Notification, StreamListener } from 'megalodon'
declare var process: {
env: {
MASTODON_ACCESS_TOKEN: string
}
}
const BASE_URL: string = 'https://mastodon.social' const BASE_URL: string = 'https://mastodon.social'
const access_token: string = '...' const access_token: string = process.env.MASTODON_ACCESS_TOKEN
const client = new Mastodon( const client = new Mastodon(access_token, BASE_URL + '/api/v1')
access_token,
BASE_URL + '/api/v1'
)
const stream: StreamListener = client.stream('/streaming/public') const stream: StreamListener = client.stream('/streaming/public')
stream.on('connect', _ => { stream.on('connect', _ => {

View file

@ -1,8 +1,14 @@
import Mastodon, { Status, Response } from 'megalodon' import Mastodon, { Status, Response } from 'megalodon'
declare var process: {
env: {
MASTODON_ACCESS_TOKEN: string
}
}
const BASE_URL: string = 'https://mastodon.social' 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')

View file

@ -6,19 +6,17 @@ const rl: readline.ReadLine = readline.createInterface({
output: process.stdout 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( const client = new Mastodon(access_token, BASE_URL + '/api/v1')
access_token,
BASE_URL + '/api/v1'
)
new Promise(resolve => { new Promise(resolve => {
rl.question('Toot: ', status => { rl.question('Toot: ', status => {
client.post<Status>('/statuses', { client
status: status .post<Status>('/statuses', {
}) status: status
})
.then((res: Response<Status>) => { .then((res: Response<Status>) => {
console.log(res) console.log(res)
rl.close() rl.close()

View file

@ -2,12 +2,11 @@ import Mastodon, { Status, Notification, WebSocket } from 'megalodon'
declare var process: { declare var process: {
env: { env: {
PLEROMA_HOST: string
PLEROMA_ACCESS_TOKEN: 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 const access_token: string = process.env.PLEROMA_ACCESS_TOKEN

View file

@ -282,7 +282,7 @@ jsprim@^1.2.2:
verror "1.10.0" verror "1.10.0"
"megalodon@file:../..": "megalodon@file:../..":
version "0.8.2" version "0.9.0"
dependencies: dependencies:
"@types/oauth" "^0.9.0" "@types/oauth" "^0.9.0"
"@types/request" "^2.47.0" "@types/request" "^2.47.0"

View file

@ -2,8 +2,8 @@
"name": "megalodon", "name": "megalodon",
"version": "0.9.0", "version": "0.9.0",
"description": "Mastodon API client for node.js", "description": "Mastodon API client for node.js",
"main": "./lib/index.js", "main": "./lib/src/index.js",
"typings": "./lib/index.d.ts", "typings": "./lib/src/index.d.ts",
"scripts": { "scripts": {
"build": "tsc -p ./", "build": "tsc -p ./",
"lint": "eslint --ext .js,.ts src", "lint": "eslint --ext .js,.ts src",

View file

@ -12,7 +12,7 @@
// "sourceMap": true, /* Generates corresponding '.map' file. */ // "sourceMap": true, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */ // "outFile": "./", /* Concatenate and emit output to single file. */
"outDir": "./lib", /* Redirect output structure to the directory. */ "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 */ // "composite": true, /* Enable project compilation */
"removeComments": true, /* Do not emit comments to output. */ "removeComments": true, /* Do not emit comments to output. */
// "noEmit": true, /* Do not emit outputs. */ // "noEmit": true, /* Do not emit outputs. */
@ -59,6 +59,6 @@
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
}, },
"include": ["src/*", "test/*"], "include": ["./src", "./test"],
"exclude": ["node_modules", "example"] "exclude": ["node_modules", "example"]
} }