Refactoring: Move logic around
This commit is contained in:
parent
83fd79f674
commit
61df58cc7b
11 changed files with 123 additions and 99 deletions
|
@ -1,72 +1,41 @@
|
|||
import { fileURLToPath } from 'url'
|
||||
import path from 'path'
|
||||
import fs from 'fs'
|
||||
import { cp } from './utils.js'
|
||||
|
||||
// Get the directory of the current file
|
||||
const __filename = fileURLToPath(import.meta.url)
|
||||
const __dirname = path.dirname(__filename)
|
||||
|
||||
// Path relative to the script file's directory
|
||||
const DEFAULT_PROJECT_PATH = path.join(__dirname, 'empty')
|
||||
|
||||
export function newProject() {
|
||||
console.log("Initialize a new project")
|
||||
console.log(DEFAULT_PROJECT_PATH)
|
||||
cp(DEFAULT_PROJECT_PATH, ".")
|
||||
}
|
||||
|
||||
import { readConfig } from './site.js'
|
||||
import { build } from './site.js'
|
||||
import ProjectConfig from './project-config.js'
|
||||
|
||||
|
||||
export default class Project {
|
||||
public config = new ProjectConfig() // should be injected
|
||||
private __filename: string
|
||||
private __dirname: string
|
||||
private DEFAULT_PROJECT_PATH: string
|
||||
|
||||
constructor() {
|
||||
// Get the directory of the current file
|
||||
this.__filename = fileURLToPath(import.meta.url)
|
||||
this.__dirname = path.dirname(this.__filename)
|
||||
|
||||
// Path relative to the script file's directory
|
||||
this.DEFAULT_PROJECT_PATH = path.join(this.__dirname, '..', 'empty')
|
||||
|
||||
export function buildProject() {
|
||||
console.log("building")
|
||||
|
||||
let config = {
|
||||
... readConfig(),
|
||||
buildDir: './.build',
|
||||
ignore: [".build", ".sajt"]
|
||||
}
|
||||
|
||||
config.remote.port = 22
|
||||
config.remote.privateKey = fs.readFileSync(path.resolve(process.env.HOME ?? "", '.ssh/id_rsa'))
|
||||
new() {
|
||||
console.log("Initialize a new project")
|
||||
console.log(this.DEFAULT_PROJECT_PATH)
|
||||
cp(this.DEFAULT_PROJECT_PATH, ".")
|
||||
|
||||
console.log(this.config)
|
||||
this.config.load()
|
||||
}
|
||||
|
||||
build(config)
|
||||
existing() {
|
||||
this.config.load()
|
||||
}
|
||||
|
||||
//loadTemplate()
|
||||
//parseMD()
|
||||
//buildProject(config)
|
||||
}
|
||||
|
||||
//import { run } from './src/desktop/main.js'
|
||||
import * as proc from 'child_process'
|
||||
|
||||
//import { app, BrowserWindow } from 'electron'
|
||||
|
||||
import * as electron from 'electron'
|
||||
|
||||
export function appProject() {
|
||||
//run()
|
||||
|
||||
//const child = proc.spawn(electron, ["."])
|
||||
// console.log(electron)
|
||||
// console.log(electron.default)
|
||||
|
||||
// const child = proc.spawn(electron.default, [".build"])
|
||||
|
||||
// https://www.matthewslipper.com/2019/09/22/everything-you-wanted-electron-child-process.html
|
||||
// exec('node start', (error, stdout, stderr) => {
|
||||
// if (error) {
|
||||
// console.error(`error: ${error.message}`)
|
||||
// return;
|
||||
// }
|
||||
|
||||
// if (stderr) {
|
||||
// console.error(`stderr: ${stderr}`);
|
||||
// return
|
||||
// }
|
||||
|
||||
// console.log(`stdout:\n${stdout}`)
|
||||
// })
|
||||
build() {
|
||||
this.config.load()
|
||||
build(this.config.config)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue