-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpackage.py
70 lines (50 loc) · 1.83 KB
/
package.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import shutil
import os
class Package:
def __init__(self):
# create package folder
self.dirPath = os.path.abspath("package")
os.makedirs(self.dirPath, exist_ok=True)
# The contents of the files that will be included in the npm package are kept in this object.
self.files = {
".npmignore": """.vscode
.idea
.__pycache__
.gitignore
.gitattribiutes
main.py
setup.py
mytheme.py
mycursor.py
__init__.py
__main__.py""",
"index.js": """function mycolorscheme() {
console.log("this is not a function!")
}
module.exports = mycolorscheme;""",
}
# We create our .npmignore file.
def __npmignore__(self):
with open(os.path.abspath(os.path.join(self.dirPath, ".npmignore")), "w", encoding="utf-8") as file:
file.write(self.files[".npmignore"])
# We create our index.js file.
def __index_js__(self):
with open(os.path.abspath(os.path.join(self.dirPath, "index.js")), "w", encoding="utf-8") as file:
file.write(self.files["index.js"])
# We create our package.json file.
def __package_json__(self):
shutil.copy(os.path.abspath("manifest.json"), os.path.abspath(os.path.join(self.dirPath, "package.json")))
# We also copy our README.md file, which is located in a higher directory and prepared for github, into this directory.
def __readme_md__(self):
shutil.copy(os.path.abspath("README.md"), os.path.abspath(os.path.join(self.dirPath, "README.md")))
def for_npm(self):
self.__npmignore__()
self.__index_js__()
self.__package_json__()
self.__readme_md__()
print(f"successfully packaged for npm!\npackage folder : {self.dirPath}")
def main():
package = Package()
package.for_npm()
if __name__ == "__main__":
main()