Skip to content

Commit

Permalink
Enter license key - sublime functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
yuriyyakym committed Aug 7, 2018
1 parent 2dcfdec commit b28e417
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 5 deletions.
5 changes: 5 additions & 0 deletions Main.sublime-menu
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@
"args": {
"file": "${packages}/r-factor/LICENSE"
}
},
{ "caption": "-" },
{
"caption": "Enter License",
"command": "enter_license"
}
]
}
Expand Down
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
"babel-loader": "^8.0.0-beta.4",
"better-npm-run": "^0.1.0",
"jest": "23.4.1",
"raw-loader": "^0.5.1",
"webpack": "^4.16.1",
"webpack-bundle-analyzer": "^2.13.1",
"webpack-cli": "^3.0.8"
Expand Down
34 changes: 33 additions & 1 deletion r-factor.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
'index.js'
)

LICENSE_PATH = os.path.join(
sublime.packages_path(),
os.path.dirname(os.path.realpath(__file__)),
'user_license'
)

class BaseCommand(sublime_plugin.TextCommand):
def run(self, edit):
selection = self.view.sel()
Expand All @@ -28,13 +34,25 @@ def run(self, edit):
def is_enabled(self):
return True

def get_license(self):
try:
file = open(LICENSE_PATH, 'r')
license = file.read()
file.close()
return license
except:
return None

def execute(self, data, refactoring_name):
NODE_BIN = self.get_setting('NODE_BIN')
try:
if not self.get_license():
return 'Please buy your R-Facotr license at http://r-factor.io/buy'

return node_bridge(data, NODE_BIN, BIN_PATH, [
'-r', refactoring_name,
'-s', json.dumps(self.get_settings()),
'-l', self.get_setting('license')
'-l', self.get_license()
])
except Exception as e:
return str(e)
Expand Down Expand Up @@ -176,3 +194,17 @@ class ToggleWithRouterHoc(BaseCommand):
def __init__(self, arg):
super(ToggleWithRouterHoc, self).__init__(arg)
self.refactoring_name = 'toggle-with-router-hoc'


class EnterLicense(sublime_plugin.WindowCommand):
def run(self):
self.window.show_input_panel("R-Factor license:", "", self.on_done, None, None)
pass

def on_done(self, license):
try:
file = open(LICENSE_PATH, 'w', encoding='utf-8')
file.write(license)
file.close()
except ValueError as e:
pass
2 changes: 1 addition & 1 deletion src/utils/license.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const jwt = require('jsonwebtoken');

// eslint-disable-next-line
const LICENSE_SECRET = 'YC3@6jyLqq%!b#Br22iL7h9hmn%TYEGw5SoJVCrXWcAAzykoqXHkqX8AwJwbIVlR^PCnzbq%7W5x^&BYZObsr*IbrP&VmxanuxOU';
const LICENSE_PUBLIC_KEY = process.env.LICENSE_PUBLIC_KEY;
const LICENSE_PUBLIC_KEY = require('../../license.pub');

const sha256 = (string) => crypto.createHash('sha256').update(string).digest('hex');

Expand Down
1 change: 1 addition & 0 deletions user_license
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJmdWxsbmFtZSI6Ill1cml5IFlha3ltIiwiZW1haWwiOiJ5YWt5bS55dXJpeUBnbWFpbC5jb20iLCJrZXkiOiJhMjZiNDU0MTg0ZGQwOTZhYTA1MWUzM2M5NTQyYjJjMzQ0MWZkZGJiNGEwZDgzZDNhZWQ3MTgxYjVkNWEwMTc3IiwiaWF0IjoxNTMzNjU4OTE1fQ.GsuDuiA5mJ03zJm7D-hKWyieZFPBF481lTRTQ7tHw1n2Gsan4Nj2lIxXHnZow3yCMvcpLYzXu9ohX_2PNRBVoR7lJXxAdgkDPFoobfWpm6kS5sBQv-EW3ShDO7e2uTGfvkgfdMQ6U4JT8UbYxF_jjlOBj4fnNzMCCVDj8EVmA9DZE1zWhL_TI5kDggX3Q2qocfHrnEmEnoVNORzqUq9uDgL8K-SHfsZ1k-ewuVR_3z0s5KljfZWMxwtCRQqjlGFsnqQBMwRcTJPLJJlesHoyrh764UgIpjo2RHFPOpWsm8gDH90j9jlHcC4DTB09DQOrf2u2MNeA1cxy270cNtCp9Q
8 changes: 5 additions & 3 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ const webpackConfig = {
]
}
}
},
{
test: /license\.pub$/,
exclude: /node_modules/,
use: 'raw-loader'
}
]
},
Expand All @@ -49,9 +54,6 @@ const webpackConfig = {
plugins: [
new webpack.NormalModuleReplacementPlugin(/@babel-parser/, (resource) => {
resource.request = '@babel-parser';
}),
new webpack.DefinePlugin({
LICENSE_PUBLIC_KEY: fs.readFileSync(path.resolve(__dirname, 'license.pub'))
})
]
};
Expand Down

0 comments on commit b28e417

Please sign in to comment.