Skip to content

Commit

Permalink
feat: done
Browse files Browse the repository at this point in the history
  • Loading branch information
maxgfr committed Nov 13, 2022
1 parent 3f18934 commit e0b22b7
Show file tree
Hide file tree
Showing 13 changed files with 3,264 additions and 106 deletions.
1 change: 0 additions & 1 deletion .env.example

This file was deleted.

1 change: 0 additions & 1 deletion .env.test

This file was deleted.

23 changes: 23 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Publish package to npm

on:
workflow_dispatch:
push:
branches:
- 'main'

jobs:
publish:
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install
run: yarn install --frozen-lockfile
- name: Build
run: yarn build
- name: Release
run: yarn release
17 changes: 17 additions & 0 deletions .releaserc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"branches": [
"+([0-9])?(.{+([0-9]),x}).x",
"main",
"next",
"next-major",
{ "name": "beta", "prerelease": true },
{ "name": "alpha", "prerelease": true }
],
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
"@semantic-release/npm",
"@semantic-release/github",
"@semantic-release/git"
]
}
38 changes: 8 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,15 @@
# typescript-swc-starter
# insta-who-unfollowed-me

A simple node boilerplate made in typescript using swc.
Utility to make it easy to track unfollowers on Instagram.

> NOTE : A version without rust compiler [swc](https://swc.rs/) is available [here](https://github.com/maxgfr/boilerplate-typescript-node).
![Alt Text](https://raw.githubusercontent.com/maxgfr/insta-who-unfollowed-me/main/.github/assets/main.gif)

## Clone repository and install dependencies
## Usage

```sh
git clone https://github.com/maxgfr/typescript-swc-starter # For cloning the repository
cd typescript-swc-starter # To navigate to the repository root
yarn # Install dependencies
cp .env.example .env
```

## Running the code

```sh
yarn build # For building the code with typechecking
yarn build:swc # For building without typechecking
yarn start # For running the code builded
```

Or in `development` mode:
npm install -g insta-who-unfollowed-me
insta-who-unfollowed-me

```sh
yarn dev # For running the code in development thanks to swc and nodemon
```

> **:warning: No typechecking made in dev mode**
## Testing the code

```sh
yarn test # For running unit test
yarn test:watch # For watching unit test
# or by using npx
npx insta-who-unfollowed-me
```
1 change: 0 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ module.exports = {
transform: {
'^.+\\.(t|j)s$': '@swc/jest',
},
setupFiles: ['dotenv/config'],
testPathIgnorePatterns: ['/node_modules/', '/build/'],
};
34 changes: 22 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,50 +1,59 @@
{
"name": "typescript-swc-starter",
"name": "insta-who-unfollowed-me",
"version": "1.0.0",
"author": "maxgfr",
"license": "MIT",
"description": "A minimalist typescript swc starter",
"description": "Utility to make it easy to track unfollowers on Instagram",
"main": "./build/index.js",
"repository": {
"type": "git",
"url": "https://github.com/maxgfr/typescript-swc-starter.git"
"url": "https://github.com/maxgfr/insta-who-unfollowed-me.git"
},
"bugs": {
"url": "https://github.com/maxgfr/typescript-swc-starter/issues"
"url": "https://github.com/maxgfr/insta-who-unfollowed-me/issues"
},
"homepage": "https://github.com/maxgfr/typescript-swc-starter#readme",
"homepage": "https://github.com/maxgfr/insta-who-unfollowed-me#readme",
"files": [
"build"
],
"keywords": [
"boilerplate",
"typescript",
"swc"
"instagram",
"unfollowed",
"unfollowers"
],
"scripts": {
"start": "node build/index.js",
"dev": "nodemon",
"develop": "node -r @swc-node/register ./src/index.ts",
"test": "DOTENV_CONFIG_PATH=.env.test jest",
"test:watch": "DOTENV_CONFIG_PATH=.env.test jest --watch",
"test": "jest --passWithNoTests",
"test:watch": "jest --watch --passWithNoTests",
"clean": "rimraf build",
"build": "tsc -p tsconfig.build.json",
"build:watch": "tsc -w -p tsconfig.build.json",
"build:swc": "swc ./src -d build",
"build:swc:watch": "swc ./src -d build -w",
"lint": "eslint ./src --ext .ts",
"prettier": "prettier --write './src/**/*.{ts,js,json}'"
"prettier": "prettier --write './src/**/*.{ts,js,json}'",
"release": "semantic-release"
},
"dependencies": {
"dotenv": "16.0.3"
"commander": "^9.4.1",
"instagram-private-api": "^1.45.3",
"prompts": "^2.4.2"
},
"devDependencies": {
"@semantic-release/commit-analyzer": "^9.0.2",
"@semantic-release/git": "^10.0.1",
"@semantic-release/github": "^8.0.6",
"@semantic-release/npm": "^9.0.1",
"@semantic-release/release-notes-generator": "^10.0.3",
"@swc-node/register": "1.5.4",
"@swc/cli": "0.1.57",
"@swc/core": "1.3.15",
"@swc/jest": "0.2.23",
"@types/jest": "29.2.2",
"@types/node": "18.11.9",
"@types/prompts": "^2.4.1",
"@typescript-eslint/eslint-plugin": "5.42.1",
"@typescript-eslint/parser": "5.42.1",
"eslint": "8.27.0",
Expand All @@ -54,6 +63,7 @@
"nodemon": "2.0.20",
"prettier": "2.7.1",
"rimraf": "3.0.2",
"semantic-release": "^19.0.5",
"typescript": "4.8.4"
}
}
5 changes: 0 additions & 5 deletions src/__tests__/env.test.ts

This file was deleted.

47 changes: 47 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import prompts from 'prompts';
import { Command } from 'commander';

type PromptResult = {
username: string;
password: string;
};

const questions: Array<prompts.PromptObject> = [
{
type: 'text',
name: 'username',
message: 'My instagram username:',
},
{
type: 'password',
name: 'password',
message: 'My instagram password:',
},
];

async function promptUser(): Promise<Partial<PromptResult>> {
const { username, password } = await prompts(
questions,
);
return { username, password };
}

async function processUserInformations() {
const { username, password } = await promptUser();
if (!username || !password) {
console.log('Missing informations 😭');
return;
}

}

export async function runCommand() {
const program = new Command();

program
.name('insta-who-unfollowed-me')
.description('Utility to make it easy to track unfollowers on Instagram')
.action(() => processUserInformations());

program.parse();
}
3 changes: 0 additions & 3 deletions src/hello.ts

This file was deleted.

12 changes: 5 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import 'dotenv/config'; // To use our .env
import { sayHello } from './hello';
#! /usr/bin/env node
import { runCommand } from './cli';

async function main() {
sayHello();
}

main();
if (require.main === module) {
runCommand();
}
24 changes: 24 additions & 0 deletions src/insta.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { IgApiClient, Feed } from 'instagram-private-api';

export async function getNotFollowingUsers(username: string, password: string): Promise<string[]> {
const ig = new IgApiClient();
ig.state.generateDevice(username);
await ig.simulate.preLoginFlow();
await ig.account.login(username, password);
const followersFeed = ig.feed.accountFollowers(ig.state.cookieUserId);
const followingFeed = ig.feed.accountFollowing(ig.state.cookieUserId);
const followers = await getAllItemsFromFeed(followersFeed);
const following = await getAllItemsFromFeed(followingFeed);
const followersUsername = new Set(followers.map(({ username }) => username));
const notFollowingYou = following.filter(({ username }) => !followersUsername.has(username));
return notFollowingYou.map(({ username }) => username);
}

async function getAllItemsFromFeed<T>(feed: Feed<any, T>): Promise<T[]> {
let items: any = [];
do {
items = items.concat(await feed.items());
} while (feed.isMoreAvailable());
return items;

}
Loading

0 comments on commit e0b22b7

Please sign in to comment.