-
Notifications
You must be signed in to change notification settings - Fork 71
added script to upload vanilla .svelte components. #31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
const svelte = require("svelte/compiler"); | ||
const autoprocessor = require("svelte-preprocess"); | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
const glob = require("glob"); | ||
|
||
const runCommand = async () => { | ||
// source file paths | ||
const srcPath = path.join(__dirname, "src"); | ||
|
||
// read glob of files in directory | ||
glob(path.join(srcPath, "**/*.svelte"), {}, (error, files) => { | ||
// handling error | ||
if (error) { | ||
return console.log("Unable to scan directory: " + error); | ||
} | ||
// listing all files using forEach | ||
files.forEach(async (file) => { | ||
// load file | ||
const sourceFile = fs.readFileSync(file, "utf-8"); | ||
const distFile = file.replace("/src/", "/dist/"); | ||
|
||
// process .svelte file | ||
if (file.includes(".svelte")) { | ||
// run autopreprocessor | ||
await ParseSvelte(sourceFile, distFile); | ||
} | ||
// copy other files | ||
else { | ||
// copy static files | ||
fs.copyFileSync(file, distFile); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just copying other files will not work if they need preprocessing, too, like TS files. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The svelte pre-processor can handle the .svelte files, i was thinking of using the typescript plugin for rollup to compile the .ts files after the preprocessing. I can just get rid of the copy file logic to prevent the .ts files from going into the output folder. as an alternative, i could change the postbuild to a prebuild script so that the preprocessor can spit our compiled .svelte files and then have rollup bundle/minify the remaining .svelte and .ts files. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note typescript (and maybe other) compiler can simply be called directly on the source with the output directory specified. |
||
} | ||
}); | ||
}); | ||
}; | ||
|
||
const ParseSvelte = async (source, destination) => { | ||
BlackFenix2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
await svelte | ||
.preprocess(source, autoprocessor(), { | ||
filename: path.basename(destination), | ||
}) | ||
.then((item) => { | ||
// create directory and file | ||
fs.mkdirSync(path.dirname(destination), { | ||
recursive: true, | ||
}); | ||
// write compiled code to dist file | ||
fs.writeFileSync(destination, item.code); | ||
}) | ||
.catch((error) => { | ||
console.error(error.message); | ||
}); | ||
}; | ||
runCommand(); |
Uh oh!
There was an error while loading. Please reload this page.