-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
155 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,12 @@ | ||
#!/usr/bin/env node | ||
|
||
import program from './src/executer/cli.js'; | ||
import rescue from './src/executer/rescue.js'; | ||
import ExtensionHandler from './src/handlers/extension.js'; | ||
|
||
program.parse(process.argv); | ||
if (['rescue', 'r'].includes(process.argv[2])) await rescue(); | ||
else { | ||
ExtensionHandler.init(); | ||
ExtensionHandler.load(process); | ||
program.parse(process.argv); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import InfoHandler from '../handlers/information.js'; | ||
import ExtensionHandler from '../handlers/extension.js'; | ||
|
||
async function install(packageName) { | ||
InfoHandler.bind('ext'); | ||
|
||
await ExtensionHandler.install(packageName); | ||
} | ||
|
||
async function uninstall(packageName) { | ||
InfoHandler.bind('ext'); | ||
|
||
await ExtensionHandler.uninstall(packageName); | ||
} | ||
|
||
export { install, uninstall }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import IO from '../base/io.js'; | ||
import NpmHandler from '../handlers/npm.js'; | ||
import { error, start } from '../base/console.js'; | ||
|
||
async function rescue() { | ||
start('project rescue...'); | ||
if (!(IO.exists('package.json') && IO.exists('.serein.json'))) | ||
console.log( | ||
error( | ||
'Fix failed, make sure you have serein.json with package.json!' | ||
) | ||
); | ||
else { | ||
await NpmHandler.install(); | ||
done('project rescue.'); | ||
} | ||
} | ||
|
||
export default rescue; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { done, error, start } from '../base/console.js'; | ||
import IO from '../base/io.js'; | ||
import NpmHandler from './npm.js'; | ||
import InfoHandler from './information.js'; | ||
|
||
class ExtensionClass { | ||
constructor() { | ||
this.context = {}; | ||
this.extList = []; | ||
} | ||
|
||
init() { | ||
if (IO.exists('.serein.json')) { | ||
this.context = IO.readJSON('.serein.json'); | ||
if (!this.context['extensions']) this.context['extension'] = []; | ||
else this.extList = this.context['extension']; | ||
} | ||
} | ||
|
||
async install(packageNames) { | ||
start('Install extensions...'); | ||
|
||
await NpmHandler.add(packageNames.join(' ')); | ||
this.context.extension.push(...packageNames); | ||
IO.writeJSON('.serein.json', this.context); | ||
|
||
done('Intstall extension.'); | ||
} | ||
|
||
async uninstall(packageNames) { | ||
start('Uninstall extensions...'); | ||
|
||
await NpmHandler.del(packageNames.join(' ')); | ||
this.context.extension = this.context.extension.filter( | ||
(v) => !packageNames.includes(v) | ||
); | ||
IO.writeJSON('.serein.json', this.context); | ||
|
||
done('Uninstall extensions.'); | ||
} | ||
|
||
async load(program) { | ||
if (this.extList.length) { | ||
start('Load extensions...'); | ||
try { | ||
for (const packageName in this.extList) | ||
(await import(packageName)).cli((program, InfoHandler)); | ||
} catch (e) { | ||
console.log(error('Failed to load extension!'), e); | ||
} | ||
done('Load extensions.'); | ||
} | ||
} | ||
} | ||
|
||
const ExtensionHandler = new ExtensionClass(); | ||
|
||
export default ExtensionHandler; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters