-
Notifications
You must be signed in to change notification settings - Fork 73
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
Open
BlackFenix2
wants to merge
4
commits into
sveltejs:master
Choose a base branch
from
BlackFenix2:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,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); | ||
} | ||
}); | ||
}); | ||
}; | ||
|
||
const parseSvelte = async (source, destination) => { | ||
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(); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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 comment
The 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 comment
The 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.
tsc --declaration --outDir dist
It will then compile the files over to the out directory.
Done this way, I would say copying the files over is unnecessaryWe still need to copy though so non-preprocessed files can be imported, like plain js. Perhaps we should only preprocess svelte files in this script, and let any non-svelte files be handled separately afterwards (possibly by their native compilers).