Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const transpilePackage = async (packageName) => {
try {
// Compile TypeScript for the given project.
// Reference the local `node_modules` version of `tsc` since on Windows
// it will call the version in `Microsoft SDKs/TypeScript`.
await exec(`npm run local-tsc -- -b packages/${packageName}`);
// Mirror all `.ts` files with `.mjs` files.
const tsFiles = await globby(`**/*.ts`, {
cwd: path.join('packages', packageName, 'src'),
});
for (const tsFile of tsFiles) {
const assetBasename = path.basename(tsFile, '.ts');
const mjsFile = path.join('packages',
packageName, path.dirname(tsFile), assetBasename + '.mjs');
if (!(await fs.pathExists(mjsFile))) {
const mjsSource = `export * from './${assetBasename}.js';`;
// console.log({mjsFile, tsFile, assetBasename})
fs.outputFileSync(mjsFile, mjsSource);
}
}
} catch (error) {
logHelper.error(error.stdout);
throw error;
}
};
// file or folder does not exist, is probably a glob...
if (FastGlob.isDynamicPattern(relativeFilePath)) {
globs.push(relativeFilePath);
}
}
}
const assets = await FastGlob(globs, {
cwd: libraryPath
}); // folder/something.svg
const commonPath = this.findCommonParentFolderPath(assets); // folder
// console.log('COMMON PATH:', commonPath);
for (const asset of assets) {
const absoluteFilePath = upath.join(libraryPath, asset); // /project/node_modules/library/folder/something.svg
const relativeFilePath = upath.relative(commonPath, asset); // something.svg
const targetFilePath = upath.join(targetPath, relativeFilePath); // /project/wwwroot/target/something.svg
// console.log(relativeFilePath);
// console.log(absoluteFilePath);
// console.log(targetFilePath);
const task = this.tryCopyFile(absoluteFilePath, targetFilePath, overwrite);
tasks.push(task)
}
const success = await Promise.all(tasks);
return success.filter(Q => Q).length;
}
async scaffold(template: string): Promise {
const templateFolder = upath.join(__dirname, '../templates', template);
const exist = await fse.pathExists(templateFolder);
if (!exist) {
Shout.error('Unable to find new project template for:', chalk.cyan(template));
return;
}
let mergedPackageJson: unknown;
const projectPackageJsonPath = upath.join(this.projectFolder, 'package.json');
const templatePackageJsonPath = upath.join(templateFolder, 'package.json');
if (await fse.pathExists(projectPackageJsonPath) && await fse.pathExists(templatePackageJsonPath)) {
// would override, should merge fields instead: instapack, dependencies, and devDependencies
const projectPackageJson = await fse.readJson(projectPackageJsonPath);
const templatePackageJson = await fse.readJson(templatePackageJsonPath);
mergedPackageJson = mergePackageJson(projectPackageJson, templatePackageJson);
}
console.log('Initializing new project using template:', chalk.cyan(template));
console.log('Scaffolding project into your web app...');
await fse.copy(templateFolder, this.projectFolder);
if (mergedPackageJson) {
console.log(`Merging ${chalk.blue('package.json')}...`);
await fse.writeJson(projectPackageJsonPath, mergedPackageJson, {
spaces: 2
break;
}
}
if (!found) {
throw new qx.tool.utils.Utils.UserError(`Template ${template_name} does not exist.`);
}
let template = await fs.readFileAsync(template_path, "utf-8");
// handle header macro in the project root
let header_template;
let header_template_path = path.join(process.cwd(), "header.js");
try {
header_template = fs.readFileSync(header_template_path, "utf-8");
} catch (e) {
// if none exists, use header template in the same folder as the template itself
header_template_path = path.join(path.dirname(template_path), "header.tmpl.js");
try {
header_template = fs.readFileSync(header_template_path, "utf-8");
} catch (e) {}
}
if (header_template) {
// replace template vars in header
if (header_template_path.includes(".tmpl.js")) {
for (let var_name in values) {
header_template = header_template.replace(new RegExp(`\\$\{${var_name}\}`, "g"), values[var_name]);
}
}
values.header = header_template;
}
// replace template vars
let final_content = template;
it(`should support projects that bundle WASM code`, function(done) {
const outputDir = tempy.directory();
const srcDir = upath.join(__dirname, '..', 'static', 'wasm-project');
const config = {
mode: 'production',
entry: {
index: upath.join(srcDir, 'index.js'),
},
output: {
filename: '[name].js',
globalObject: 'self',
path: outputDir,
},
plugins: [
new WorkerPlugin(),
new GenerateSW(),
],
};
get inputCssFolder() {
return upath.join(this.inputFolder, 'css');
}
get jsEntry() {
const getMainFile = (outputDir, sha) => {
const files = sha.output;
const mainFile = files[files.length - 1];
return path.join(outputDir, mainFile);
};
get scssGlob(): string {
return upath.join(this.cssInputFolder, '**', '*.scss');
}
function readElmJson(repoPath) {
let elmFilePath = path.join(repoPath, 'elm.json');
let gitDepsPath = path.join(repoPath, 'elm-git.json');
let elmFileJson = {};
if (fs.existsSync(elmFilePath)) {
const elmFile = fs.readFileSync(elmFilePath, { encoding: 'utf-8' });
elmFileJson = JSON.parse(elmFile);
}
let gitDepsJson = {};
if (fs.existsSync(gitDepsPath)) {
const gitDeps = fs.readFileSync(gitDepsPath, { encoding: 'utf-8' });
gitDepsJson = JSON.parse(gitDeps);
}
return Object.assign(elmFileJson, gitDepsJson);
}
get outputJsFile(): string {
return upath.join(this.outputJsFolder, this.jsOut);
}