Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const test = require("ava");
const ui5Builder = require("../../../");
const tasks = ui5Builder.builder.tasks;
const ui5Fs = require("@ui5/fs");
const resourceFactory = ui5Fs.resourceFactory;
const DuplexCollection = ui5Fs.DuplexCollection;
test("integration: replace copyright", (t) => {
const reader = resourceFactory.createAdapter({
virBasePath: "/"
});
const writer = resourceFactory.createAdapter({
virBasePath: "/"
});
const workspace = new DuplexCollection({reader, writer});
/* eslint-disable no-useless-escape */
const content = `/*!
* $\{copyright\}
*/
console.log('HelloWorld');`;
const test = require("ava");
const ui5Builder = require("../../../");
const tasks = ui5Builder.builder.tasks;
const ui5Fs = require("@ui5/fs");
const resourceFactory = ui5Fs.resourceFactory;
const DuplexCollection = ui5Fs.DuplexCollection;
test("integration: replace copyright", (t) => {
const reader = resourceFactory.createAdapter({
virBasePath: "/"
});
const writer = resourceFactory.createAdapter({
virBasePath: "/"
});
const workspace = new DuplexCollection({reader, writer});
/* eslint-disable no-useless-escape */
const content = `/*!
* $\{copyright\}
*/
console.log('HelloWorld');`;
/* eslint-enable no-useless-escape */
test.serial("writeResourcesToDir with byGlobSource", async (t) => {
const writeStub = sinon.stub().resolves();
const createAdapterStub = sinon.stub(require("@ui5/fs").resourceFactory, "createAdapter").returns({
write: writeStub
});
await generateJsdoc._writeResourcesToDir({
workspace: {
// stub byGlobSource
byGlobSource: (pattern) => {
t.deepEqual(pattern, "some pattern", "Glob with correct pattern");
return Promise.resolve(["resource A", "resource B"]);
}
},
pattern: "some pattern",
targetPath: path.join("/", "some", "target", "path")
});
t.deepEqual(createAdapterStub.getCall(0).args[0], {
const zip = new yazl.ZipFile();
const rBasePath = new RegExp(`^/resources/${options.namespace}/`);
archiveContent.forEach((content, path) => {
if (!rBasePath.test(path)) {
log.verbose(`Not bundling resource with path ${path} since it is not based on path ` +
`/resources/${options.namespace}/`);
return;
}
// Remove base path. Absolute paths are not allowed in ZIP files
const normalizedPath = path.replace(rBasePath, "");
zip.addBuffer(content, normalizedPath);
});
zip.end();
const pathPrefix = "/resources/" + options.namespace + "/";
const res = resourceFactory.createResource({
path: pathPrefix + options.bundleName,
stream: zip.outputStream
});
resolve([res]);
}));
};
return Promise.all(bundles.map(function({name, content, bundleInfo}) {
// console.log("creating bundle as '%s'", "/resources/" + name);
const resource = new EvoResource({
path: "/resources/" + name,
string: content
});
return resource;
}));
});
async build({
tree, destPath, cleanDest = false,
buildDependencies = false, includedDependencies = [], excludedDependencies = [],
dev = false, selfContained = false, jsdoc = false,
includedTasks = [], excludedTasks = [], devExcludeProject = []
}) {
const startTime = process.hrtime();
log.info(`Building project ${tree.metadata.name}` + (buildDependencies ? "" : " not") +
" including dependencies..." + (dev ? " [dev mode]" : ""));
log.verbose(`Building to ${destPath}...`);
const selectedTasks = composeTaskList({dev, selfContained, jsdoc, includedTasks, excludedTasks});
const fsTarget = resourceFactory.createAdapter({
fsBasePath: destPath,
virBasePath: "/"
});
const buildContext = new BuildContext();
const cleanupSigHooks = registerCleanupSigHooks(buildContext);
const projects = {}; // Unique project index to prevent building the same project multiple times
const projectWriters = {}; // Collection of memory adapters of already built libraries
function projectFilter(project) {
function projectMatchesAny(deps) {
return deps.some((dep) => dep instanceof RegExp ?
dep.test(project.metadata.name) : dep === project.metadata.name);
}
// if everything is included, this overrules exclude lists
const resourceFactory = require("@ui5/fs").resourceFactory;
function pad(v) {
return String(v).padStart(2, "0");
}
function getTimestamp() {
const date = new Date();
const year = date.getFullYear();
const month = pad(date.getMonth() + 1);
const day = pad(date.getDate());
const hours = pad(date.getHours());
const minutes = pad(date.getMinutes());
// yyyyMMddHHmm
return year + month + day + hours + minutes;
}
/**
const {promisify} = require("util");
const rimraf = promisify(require("rimraf"));
const log = require("@ui5/logger").getGroupLogger("builder:builder");
const resourceFactory = require("@ui5/fs").resourceFactory;
const MemAdapter = require("@ui5/fs").adapters.Memory;
const typeRepository = require("../types/typeRepository");
const taskRepository = require("../tasks/taskRepository");
const BuildContext = require("./BuildContext");
const definedTasks = taskRepository.getAllTasks();
// Set of tasks for development
const devTasks = [
"replaceCopyright",
"replaceVersion",
"buildThemes"
];
/**
* Calculates the elapsed build time and returns a prettified output
name: options.rootProjectName,
version: options.rootProjectVersion, // TODO: insert current application version here
buildTimestamp: buildTimestamp,
scmRevision: "", // TODO: insert current application scm revision here
// gav: "", // TODO: insert current application id + version here
libraries: options.libraryInfos.map(function(libraryInfo) {
return {
name: libraryInfo.name,
version: libraryInfo.version,
buildTimestamp: buildTimestamp,
scmRevision: "" // TODO: insert current library scm revision here
};
})
};
return [resourceFactory.createResource({
path: "/resources/sap-ui-version.json",
string: JSON.stringify(versionJson, null, "\t")
})];
};
module.exports = function({workspace, dependencies, options}) {
const combo = new ReaderCollectionPrioritized({
name: `libraryManifestGenerator - prioritize workspace over dependencies: ${options.projectName}`,
readers: [workspace, dependencies]
});
// Note:
// *.library files are needed to identify libraries
// *.json files are needed to avoid overwriting them
// *.js files are needed to identify nested components
// *.less, *.css, *.theming and *.theme files are needed to identify supported themes
// *.properties to identify existence of i18n bundles (e.g. messagebundle.properties)
return combo.byGlob("/**/*.{js,json,library,less,css,theming,theme,properties}").then((resources) => {
// Find all libraries and create a manifest.json file
return workspace.byGlob("/resources/**/.library").then((libraryIndicatorResources) => {
if (libraryIndicatorResources.length < 1) {
// No library found - nothing to do
log.verbose(`Could not find a ".library" file for project ${options.projectName}. Skipping library manifest generation.`);
return;